import {DateFormat} from '$utils/tool/date';

import money from "$utils/tool/money";

import orderControl from "$utils/control/order";

import modeData from '../data/mode';
import {OrderPayStatus} from "$utils/control/order/const/order";

export default <LibMixins>{

    computed:{
      mode(){
          return modeData[this.orderStatus];
      }
    },

    methods:{

        fetch(obj){

            return this.$request({
                url:this.mode.url,
                data:{
                    status: this.status
                },
                page:obj.data,
                token:true
            }).then((data)=>{

                let resultData = data.data || [];

                resultData = resultData.map((item)=>{

                    item.add_time_format = DateFormat(item.add_time,'YYYY-MM-DD hh:mm');

                    item.price = money.checkIntMoney(item.price);

                    item.total_amount = money.checkIntMoney(item.total_amount);

                    // 执行判断状态是否为取消
                    if (item.is_over == 3 && item.status === OrderPayStatus.completed) {
                        item.status = OrderPayStatus.cancel;
                    } else if (item.is_over == 2) {
                        item.status = OrderPayStatus.overtime;
                    }


                    item.buttonGroup = orderControl.getButtonGroup(item.status,this.orderStatus);

                    item.statusName = orderControl.getStatusName(item.status,this.orderStatus);

                    return item;

                });


                obj.success(resultData);

            }).catch(obj.fail);

        }

    }

}