import { Orders } from '../../../pages/tab-bar/user/user.d'
export const OrderStateMap: Record<number, any> = {
    10: { id: 10, name: "未付款", color: "#ff0056" },
    20: { id: 20, name: "已驳回", color: "#ff0056" },
    30: { id: 30, name: "待发货", color: "#FA6905" },
    40: { id: 40, name: "待审核", color: "#ff7500" },
    50: { id: 50, name: "发货中", color: "#1a64d3" },
    60: { id: 60, name: "已签收", color: "#00bc12" },
    70: { id: 70, name: "售后中", color: "#00b1dd" },
    80: { id: 80, name: "全退款", color: "#ff0000" },
    90: { id: 90, name: "部分退款", color: "#d90000" },
    100: { id: 100, name: "已取消", color: "#ffba00" },
};

export const DeliveryStateMap: Record<number, any> = {
    10: { id: 10, name: "待确认", color: "#ff4c3e" },
    15: { id: 15, name: "定时发货", color: "#ff4c3e" },
    20: { id: 20, name: "待发送ERP", color: "gold" },
    30: { id: 30, name: "仓库待发货", color: "#ff7500" },
    40: { id: 40, name: "仓库已发货", color: "#FABD14" },
    50: { id: 50, name: "物流已揽收", color: "#057748" },
    60: { id: 60, name: "客户签收", color: "#00bc12" },
    70: { id: 70, name: "客户半签", color: "#52c41a" },
    80: { id: 80, name: "客户拒收", color: "#ff0000" },
    100: { id: 100, name: "已取消", color: "#ffba00" },
    110: { id: 110, name: "售后中", color: "#00B4F4" },
    120: { id: 120, name: "售后完成", color: "#156AA8" },
};

//不能查看物流信息
Component({
    properties: {
        order: {
            type: Object,
            value: {} as Orders,
        },
        isDetail: {
            type: Boolean,
            value: false
        }
    },
    data: {
        item: [] as any[],
        state: {},
        orderTime: "",
        payTime: "",
        showHistoryPopup: false,
        deliveryState: null
    },
    observers: {
        'order': function (order: Orders) {
            if (order && order.good) {
                // @ts-ignore
                this.setData({
                    item: order.good,
                    state: OrderStateMap[order.state],
                    orderTime: order.orderTime.replace("T", " "),
                    payTime: order.payTime ? order.payTime.replace("T", " ") : ""
                })
            }
            if (order && order.deliveryState) {
                // @ts-ignore
                this.setData({
                    deliveryState: DeliveryStateMap[order.deliveryState]
                })
            }
        }
    },
    methods: {
        // openPopup() {
        //   this.setData({ showHistoryPopup: true })
        // },
        // closePopup() {
        //   this.setData({ showHistoryPopup: false })
        // }
        handleDetail(this: WechatMiniprogram.Component.TrivialInstance) {
            if (this.data.isDetail) return;
                wx.navigateTo({ url: `/pages/common/order-detail/order-detail?id=${this.data.order.orderNo}` })
        }
    }
})
export { }
