/*
 * @Author: shi ZongLiang
 * @Date: 2021-08-04 15:34:42
 * @LastEditors: shi ZongLiang
 * @Description:
 */
export default {
  // 计算会议培训-费用信息中的标准金额合计
  execute: async function(){
      console.log("进入：费用信息中的标准金额合计")
      if (arguments&&arguments[0]&&arguments[0][0]&&arguments[0][1]&&arguments[0][2]
        &&arguments[0][3]&&arguments[0][4]&&arguments[0][5]&&arguments[0][6]
        ) {
          let context = arguments[1]
          const zclbObject = arguments[0][0].getResult().Value;
          let hykbObject = arguments[0][1].getResult().Value;
          let pxlbObject = arguments[0][2].getResult().Value;
          const zcjrsValue = arguments[0][3].getResult().Value;
          const ztsValue = arguments[0][4].getResult().Value;
          const fylb = arguments[0][5].FieldCode;
          const bzjehj = arguments[0][6].FieldCode;
          const subTableName = arguments[0][5].FieldTableCode
          const tableObj = context.getTableType(subTableName)
          let subData = context.getSubData(tableObj.title)
          if (hykbObject||pxlbObject) {
            if (zclbObject&&zclbObject.code=='00101') {
              // 重新查询会议标准基础数据
              if (((!hykbObject.zsf)||(!hykbObject.hsf)||(!hykbObject.qtfy))&&(hykbObject._type)) {
                await	GMS.$http.post(`/baseData/data/list`, {
                    pagination: false,
                    tableName: hykbObject._type.split('.')[1],
                    code: hykbObject.code,
                    queryDataStructure:'ALL'
                  }).then((res) => {
                    if (res.data.rs.code == 0) {
                      hykbObject = res.data.rows[0]
                    }
                  })
              }
            } else if(zclbObject&&zclbObject.code=='00102') {
              // 重新查询培训标准基础数据
              if (((!pxlbObject.zsf)||(!pxlbObject.hsf)||(!pxlbObject.qtfy))&&(pxlbObject._type)) {
                await	GMS.$http.post(`/baseData/data/list`, {
                  pagination: false,
                  tableName: pxlbObject._type.split('.')[1],
                  code: pxlbObject.code,
                  queryDataStructure:'ALL'
                }).then((res) => {
                  if (res.data.rs.code == 0) {
                    pxlbObject = res.data.rows[0]
                  }
                })
              }
            }
            if(subData instanceof Array){
              for (const iterator of subData) {
                let fylbValue =iterator.getValue(fylb).code
                if (fylbValue) {
                  // 支出类别和费用信息子表选择不匹配的话，清空子表、
                  // 改成保存时触发校验公式 以避免清空子表字段时出现各种各样奇怪的问题
/*
                  if ((!zclbObject)||(zclbObject.code=='00101'&&!fylbValue.startsWith('00101')) || (zclbObject.code=='00102'&&!fylbValue.startsWith('00102'))) {
                    for (let i = 0; i < subData.length; i++) {
                        context.deleteSubData(tableObj.title, 0,null)
                    }
                    break;
                  }
*/
                  if (fylbValue=='0010101') { // 住宿费（会议）
                    if (hykbObject&&hykbObject.zsf&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                      ) {
                        const sum = (Number(hykbObject.zsf)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                        iterator.setValue(bzjehj,sum)
                    } else {
                        iterator.setValue(bzjehj,'')
                    }
                  } else if (fylbValue=='0010102') { // 伙食费（会议）
                    if (hykbObject&&hykbObject.hsf&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                    ) {
                      const sum = (Number(hykbObject.hsf)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                      iterator.setValue(bzjehj,sum)
                    } else {
                      iterator.setValue(bzjehj,'')
                    }
                  } else if (fylbValue=='0010103') { // 其他费（会议）
                    if (hykbObject&&hykbObject.qtfy&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                    ) {
                      const sum = (Number(hykbObject.qtfy)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                      iterator.setValue(bzjehj,sum)
                    } else {
                      iterator.setValue(bzjehj,'')
                    }
                  } else if (fylbValue=='0010201') { // 住宿费（培训）
                    if (pxlbObject&&pxlbObject.zsf&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                      ) {
                      const sum = (Number(pxlbObject.zsf)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                      iterator.setValue(bzjehj,sum)
                    } else {
                      iterator.setValue(bzjehj,'')
                    }
                  } else if (fylbValue=='0010202') { // 伙食费（培训）
                    if (pxlbObject&&pxlbObject.hsf&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                    ) {
                      const sum = (Number(pxlbObject.hsf)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                      iterator.setValue(bzjehj,sum)
                    } else {
                      iterator.setValue(bzjehj,'')
                    }
                  } else if (fylbValue=='0010203') { // 其他费用（培训）
                    if (pxlbObject&&pxlbObject.qtfy&&zcjrsValue&&ztsValue&&(!isNaN(Number(zcjrsValue)))
                      &&(!isNaN(Number(ztsValue)))
                    ) {
                      const sum = (Number(pxlbObject.qtfy)*Number(zcjrsValue)*Number(ztsValue)).toFixed(2)
                      iterator.setValue(bzjehj,sum)
                    } else {
                      iterator.setValue(bzjehj,'')
                    }
                  }
                }
              }
              context.refreshSubDataRow(tableObj.title)
            }
          }
      }
  },
  getResultType:function(){
      return FMR.ConstDataTypes.Float;
  }
}
