CustomerSelect.vue 4.27 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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
<template>
  <div>
    <Drawer v-if="isDrawer" v-model="drawerShow" width="900" :mask-closable="false">
      <gms-query v-if="templateName" class="gms-query" :templateName="templateName" :extrCondition="extrCondition"></gms-query>
      <div class="drawer-footer">
        <Button style="margin-right: 8px" @click="drawerShow = false">取消</Button>
        <Button type="primary" :disabled="queryData.length === 0" @click="handleConfirm">确定</Button>
      </div>
    </Drawer>
  </div>
</template>

<script>
export default {
  name: 'CustomerSelect',
  props: {
    context: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      bill: {},
      drawerShow: false,
      templateName: '',
      queryData: [],
      tableName: '',
      isSub: true,
      field: {},
      baseDataFields: [],
      extrCondition: [],
      isDrawer: false,
      actionParam: null
    }
  },
  mounted() {
    GMS.vbus.$on('onSelectionChange', (selection) => {
      this.queryData = [...selection]
    })
    GMS.vbus.$on('onCurrentChange', (currentRow) => {
      this.queryData = [currentRow]
    })
  },

  methods: {
    handleConfirm() {
      
      if (!this.tableName) {
        this.$message.error('操作表名称为空')
        return
      }
      if (this.isSub) {
        // this.queryData = [
        //   { x: 1, y: 2 },
        //   { x: 3, y: 4 },
        // ]
        this.queryData.forEach((item, index) => {
          this.setSubTableData(item, index)
        })
        // 刷新
        this.bill.refreshSubDataRow(this.tableName)
      } else {
        this.setMasterData()
      }
      
      this.drawerShow = false
    },
    setSubTableData(sourceRow, index) {
      // 增行
      this.bill.addSubData(this.tableName)
      //赋值
      const subDataObj = this.bill.getSubData(this.tableName)
      const tableLength = subDataObj.length || 0
      const subDataIndex = tableLength  - 1
      const subRowData = this.getRowData(sourceRow)
      if (Array.isArray(subDataObj)) {
        for (const key in subRowData) {
          if (this.baseDataFields&&this.baseDataFields.includes(key)) {
            const idKey = this.field[key] + 'id'
            const baseDataValue = { id: sourceRow[idKey], name: subRowData[key].value }
            console.log('baseDataValue', baseDataValue)
            subDataObj[subDataIndex].setValue(key, baseDataValue)
          } else {
            subDataObj[subDataIndex].setValue(key, subRowData[key].value)
          }
        }
      }
    },
    getRowData(sourceRow) {
      let subField = this.getSubField()
      //  this.field = {
      //   a1: 'x',
      //   b1: 'y',
      // }
      console.log('field', this.field)
      for (let key in this.field) {
        if(key !== 'baseDataFields' && key !== 'filterField') {
          subField[key].value = sourceRow[this.field[key]]
          subField[key].readOnly = subField.hasOwnProperty(key)
        }
      }
      return subField
    },
    setMasterData() {
      let masterName = this.tableName.split('.')[1]
      let keys = Object.keys(this.field)
      keys.forEach((key) => {
        let value = ''
        let str = masterName + '.' + key
        for (let k in this.queryData[0]) {
          if (k === this.field[key]) {
            value = this.queryData[0][this.field[key]]
          }
        }
        this.bill.getMasterData().setValue(str, value)
      })
      this.bill.runFormulaCheckData(this.actionParam, function(msg){})
    },
    getSubField() {
      let fieldObj = {}
      if (this.bill.getAllSubFiledByName(this.tableName)) {
        fieldObj = JSON.parse(JSON.stringify(this.bill.getAllSubFiledByName(this.tableName)))
      } else {
        this.$message.error('子表字段获取失败')
      }
      return fieldObj
    },
  },
}
</script>

<style lang="less" scoped>
.gms-query.customQueryBody {
  padding-top: 40px;
  /deep/ .tabChangeBody {
    overflow: scroll;
      .spaceLine {
        height: 0;
        margin-top: 0;
      }
      .seniorQueryBody{
        margin-top: 30px;
      }
      .ivu-select-dropdown {
        top: -110px !important;
        left: -500px !important;
        }
    }  
}
.drawer-footer {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  background: #fff;
}
</style>