leafletGenerationAction.js 3.58 KB
Newer Older
1 2 3
/*
 * @Description:凭证中心/单张生成
 */
wangcong committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import axios from 'axios'
export default {
    execute(context, param) {
        let subTable = param.subTable||'BXMXZB';
        let directGeneration = param.directGeneration||false;
        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 arrApi1 = [];
        context.selects.forEach(v=>{
            arrApi1.push(that.searchBillObj(billDefine,v[param.billId]))
        })
        let arr = [];
        let arrApi = [];
        Promise.all(arrApi1).then((list) => {
qiaoyanqi committed
26
            list.forEach((res,i)=>{
wangcong committed
27 28
                if(res && res[subTable]){
                    res[subTable].forEach(v=>{
qiaoyanqi committed
29 30
                        let billDefine1 = v.BILLNAME && v.BILLNAME.replace(/_E/ig, "").replace(/_R/ig, "").replace(/_A/ig, "");
                        arrApi.push(that.searchBillObj(billDefine1,v.BILLID,i))
wangcong committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
                    })
                }
                arr.push({//直接生成
                    index:i,
                    data:res
                }) 
            })
            if(!directGeneration){//间接生成
                Promise.all(arrApi).then((subList) => {
                    arr.forEach(v=>{
                        v.detailData=[];
                        subList.forEach(f=>{
                            if(v.index==f.index){
                                v.detailData.push(f); 
                            }
                        })
                    })
                    that.generateVoucher(arr,context);
                }) 
            }else{
                that.generateVoucher(arr,context);//直接生成
            }
        })   
    },
    generateVoucher(list,context){
        axios({
              method: 'POST',
              url:GMS.url+'/v1/reimbursePort/singleCreateVchr',
              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: () => {},
                    });
                }
              }
            })
    },
    searchBillObj(billDefine, billId, index) {
        return new Promise((resolve, reject) => {
            GMS.$http.get(
                `/gms/bill/${billDefine}/${billId}?withSubs=true`
            ).then((data) => {
                if (data.status == 200 && data.data.code == 0) {
                    let obj = data.data.content
                    obj.billDefine = billDefine;
                    obj.index = index
                    resolve(obj);
                }
            }).catch((error)=>{
                reject(error)
            })
        })
    }
}