import axios from 'axios'
export default {
    execute(context, param) {
        if (!param.billId || !param.billDefine) {
            context.dom.$Message.info("请配置查询单据参数");
            return;
        }
        if(context.selects.length==0){
            context.dom.$Message.info("请勾择需要撤销的数据");
            return;
        }
        let that = this;
        let billDefine = param.billDefine.replace(/_E/ig, "").replace(/_R/ig, "").replace(/_A/ig, "");
        let arr=[];
        context.selects.forEach(v=>{
            arr.push({
                id:v[param.billId],
                billCode:v[param.billCode],
                billDefine:billDefine
            })
        })
        that.deleteVchrAsync(arr,context);
    },
    deleteVchrAsync(list,context){
        axios({
              method: 'POST',
              url:GMS.url+'/v1/reimbursePort/deleteVchr',
              headers: {
                  Authorization:GMS.token,
              },
              data:list
            }).then(res => {
              if (res.status === 200) {
                if(res.data.data.showVoucher){//展示凭证
                    GMS.vbus.$emit('previewVoucher',res.data.data);
                }else{
                    if(res.data.data.successVchrs && res.data.data.successVchrs.length > 0){
                        GMS.vbus.$emit('custom-query-refresh');
                        GMS.vbus.$emit('tab-count-refresh');
                    }
                    context.dom.$Modal.warning({
                        title: '信息提示',
                        content: res.data.data.processMsg,
                        onOk: () => {},
                    });
                }
              }
            })
    }
}