<template>
    <router-link
        :to="{
            path: '/orderDetail',
            query: {
                id: info.id
            }
        }"
        class="orderInfo"
        @click="click"
    >
        <div class="order-top">
            <span>{{ info.minter }}</span>
            <span class="status">{{ getLabelName(info.status, statusOptions) }}</span>
        </div>
        <div class="order">
            <van-image :radius="6" width="74" height="104" :src="getImg(changeImgs(info.pic))" fit="cover" />

            <div class="content">
                <div class="name van-multi-ellipsis--l2">
                    {{ info.name }}
                </div>
                <div class="text">编号:{{ info.id }}</div>
                <div class="flex1"></div>
                <div class="price">¥{{ info.price }}</div>
            </div>
        </div>
        <div class="total-price">
            <span>实际支付</span>
            <span>¥{{ info.totalPrice }}</span>
        </div>

        <div class="btns">
            <van-button color="#939599" @click.prevent="del" plain size="mini" round> 删除订单 </van-button>
        </div>
    </router-link>
</template>

<script>
import order from '../../mixins/order';
import product from '../../mixins/product';
export default {
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    // setup() {
    //     const click = function () {
    //         // console.log('wyt6w');
    //     };

    //     return { click };
    // },
    mixins: [order, product],
    methods: {
        delInit() {
            this.$emit('delFn');
        },
        del() {
            this.Dialog.confirm({
                title: '确定删除吗？',
                message: '删除此记录将消失'
            }).then(() => {
                this.$http
                    .post('/order/hide/', {
                        id: this.info.id
                    })
                    .then(() => {
                        this.$toast.success('删除成功');
                        setTimeout(() => {
                            this.delInit();
                        }, 1000);
                    });
            });
            // this.$http
            //     .post('/order/hide/', {
            //         id: this.info.id
            //     })
            //     .then(() => {
            //         this.$toast.success('删除成功');
            //         setTimeout(() => {
            //             this.delInit();
            //         }, 1000);
            //     });
        },
        likeProduct() {
            if (!this.info.liked) {
                this.$http.get(`/collection/${this.info.id}/like`).then(() => {
                    this.$emit('update:info', {
                        ...this.info,
                        liked: true,
                        likes: this.info.likes + 1
                    });
                    this.$toast.success('收藏成功');
                });
            } else {
                this.$http.get(`/collection/${this.info.id}/unlike`).then(() => {
                    this.$emit('update:info', {
                        ...this.info,
                        liked: false,
                        likes: this.info.likes - 1
                    });
                    this.$toast.success('取消收藏');
                });
            }
        }
    }
};
</script>

<style lang="less" scoped>
.orderInfo {
    background: #181818;
    border-radius: 12px;
    color: #fff;
    padding: 16px 10px 0;
    margin: 20px 16px 0;
    display: block;
}

.order-top {
    display: flex;
    justify-content: space-between;
    span {
        font-size: 14px;
        color: #ffffff;
        line-height: 22px;
    }

    .status {
        color: @prim;
    }
}

.order {
    display: flex;
    padding: 16px 0;
    .van-image {
        flex-shrink: 0;
    }
    .content {
        flex-grow: 1;
        margin-left: 10px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        .name {
            font-size: 16px;
            font-weight: bold;
            line-height: 22px;
        }
        .text {
            font-size: 14px;
            color: @text3;
            line-height: 24px;
            margin-top: 4px;
        }

        .price {
            font-size: 16px;
            font-weight: bold;
            line-height: 24px;
        }
    }
}
.total-price {
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    line-height: 60px;
    text-align: right;
    span {
        &:last-child {
            color: @prim;
            margin-left: 10px;
            font-size: 16px;
        }
    }
}
.btns {
    border-top: 1px solid #202122;
    padding: 16px 0;
    display: flex;
    flex-direction: row-reverse;
    .van-button {
        padding: 3px 17px;
    }
}
</style>
