import order from '@/utils/controls/order';
import typeData from '../data/data';
export default {

    computed:{
      typeConfig(){
          return typeData[this.type] || {}
      }
    },

    methods:{

        fetch:function (obj) {

            return this.$request({
                url:this.typeConfig.url,
                page: obj,
                token:true
            }).then((data)=>{
                return obj.success((data.data || []).map((item)=>{

                    item.productList = item.productList || [];

                    item.statusOrder = order.getOrderStatus(order.createdOrderStatus(item));

                    item.statusOrder.buttonGroup = this.typeConfig.buttonGroup;

                    return item;

                }));
            }).catch(obj.fail);

        },

        /* 跳转到订单详情 */
        goOrderDetail:function (item) {

            if (item.id) {
                return this.$router.navigateTo({
                    name: 'order-detail',
                    params:{
                        id: item.id
                    },
                    memoryParams:{
                        item:item
                    }
                });
            }

        },

        /* 修改状态 */
        changeStatus:function (e) {

            // 触发更新规则
            return this.$emit('changeStatus',e);
        },

        openPayModal(e){
            // 触发更新规则
            return this.$emit('openPayModal',e);
        },

    },

    mounted(){

        this.$emit('use-target',{
            target: this,
            index: this.index,
            type: this.type
        });
    }

}