extractCashAction.js 3.16 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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
export default {
    execute: function (bill, param) {
        let dataObject = bill.getMasterData();
        let id = dataObject.getValue('id');
        let rq = dataObject.getValue('RQ');
        let djlb = dataObject.getValue('DJLB').code;
        GMS.$http.post(`/rbc/bill/action/extractCash`, {
            id:id,
            date:rq,
            djlb:djlb
        }).then((res) => {
            if(res.data.code===0){
                this.setSubTableData(bill,'RIMXZZB',res.data.content)
            }else if(res.data.code == -1 && res.data.message){
                GAMS.Common.messagePrompt(res.data.message);
            }
        })
    },
    setSubTableData(bill,tableName,datas) {
        //清空子表
        let subData = bill.getSubData(tableName)
        let dataLength = subData.length
        if (dataLength > 0) {
            for (let i = 0; i < dataLength; i++) {
                bill.deleteSubData(tableName, 0,null)
            }
        }
        //子表字段
        let subField = this.getSubField(bill,tableName)
        let allFormula = null
        //赋值子表
        datas.forEach((data, index) => {
            const subData = bill.addSubData(tableName,index)
            for (const key in subField) {
                if(key == 'BZ' || key == 'DJLB' || key == 'BXBM' || key == 'SFKR'){
                    const idKey = key + 'ID'
                    const codeKey = key + 'CODE'
                    const nameKey = key + 'NAME'
                    const baseDataValue = { id: data[idKey],code:data[codeKey], name: data[nameKey] }
                    subData.setValue(key, baseDataValue)
                }else if(key == 'RQ'){
                    subData.setValue(key, new Date(data[key]).getTime())
                }else{
                    subData.setValue(key, data[key])
                }
            }
            //调用子表公式
            if (!allFormula) {
                allFormula = bill.getSubFormula(tableName)
            }
            this.funSubTableFormula(bill,allFormula.execution[tableName])
        })
        bill.refreshSubDataRow(tableName)
        if (datas.length > 0) {
            GMS.vbus.$Message.success('提取成功');
        } else {
            GMS.vbus.$Message.success('没有数据');
        }
    },
    getSubField(bill,tableName) {
        let fieldObj = {}
        if (bill.getAllSubFiledByName(tableName)) {
          fieldObj = JSON.parse(JSON.stringify(bill.getAllSubFiledByName(tableName)))
        } else {
          this.$message.error('子表字段获取失败')
        }
        return fieldObj
    },
    funSubTableFormula(bill,formuals){
      var subFormulaList = this.getSubFormulas(formuals);
      if(subFormulaList&&subFormulaList.length > 0){
          for (const _s_f_n of subFormulaList) {
              bill.runSubSumFormula(_s_f_n);
          }
      }
    },
    getSubFormulas(formuals){
        var subFormulaList = [];
        for (const _f in formuals) {
            for (const iterator of formuals[_f]) {
                subFormulaList.push(iterator);
            }
        }
        return Array.from(new Set(subFormulaList));
    }
}