view.js 5.26 KB

import { findAreaListWithHouseId, getDxStInventoryAccount } from '@/api/storage'
import storageSelect from '@/components/storageSelect.vue'
export default {
  props: {},
  components: { storageSelect },
  data() {
    // const that = this
    return {
      optionsData: []

    }
  },
  computed: {
    tableColums() {
      const that = this
      return [
        {
          title: '库房', key: 'dxStHouseName', align: 'center'
        },
        {
          title: '库区', key: 'dxStAreaId', align: 'center',
          component: {
            render: function(h, data, column, index) {
              return (<el-select v-model={data.dxStAreaId} size='small'
                on-change={(val) => {
                  data.dxStAreaId = val
                  that.$set(that.tableData[index], 'dxStAreaId', val)
                  const findItem = that.dxStAreaOptions.find(r => r.value === val)
                  that.$set(that.tableData[index], 'dxStAreaName', findItem.label)
                  that.getDxStLocationOptions(val, index)
                }}>
                {
                  that.dxStAreaOptions.map(x => <el-option label={x.label} value={x.value}/>)
                }
              </el-select>)
            }
          }
        },
        {
          title: '库位', key: 'dxStLocationId', align: 'center',
          component: {
            render: function(h, data, column, index) {
              return (<el-select v-model={data.dxStLocationId} size='small'
                on-change={(val) => {
                  data.dxStLocationId = val
                  that.$set(that.tableData[index], 'dxStLocationId', val)
                  const findItem = that.tableData[index].dxStLocationOptions.find(r => r.value === val)
                  that.$set(that.tableData[index], 'dxStLocationName', findItem.label)

                  // 查询库内
                  // that.getDxStInventoryAccount('DxStLocation', val, index, that.tableData[index].dxStLocationOptions)
                }}>
                {
                  that.tableData[index].dxStLocationOptions.map(x => <el-option label={x.label} value={x.value}/>)
                }
              </el-select>)
            }
          }
        },
        // {
        //   title: '库内可存数量', key: 'dxStQuantity', align: 'center'
        // },
        {
          title: '实际入库数量', key: 'dxRealQuantity', align: 'center', component: {
            name: 'tableCellFormCheck',
            show: true,
            props: {
              bindKey: 'dxRealQuantity',
              component: {
                name: 'el-input'
              }
            },
            handler: {
              changeForm: (val) => {
                this.rowDataChange(val)
              }
            }
          }
        }
      ]
    }
  },
  watch: {

  },
  created() {
  },
  methods: {
    handleDelete(index, row) {
      this.$utils.showConfirm(
        `你是否确定删除选中的数据`,
        '提示',
        'warning',
        '确定',
        '取消',
        () => {
          this.tableData.splice(index, 1)
          this.countNums()
        }
      )
    },
    countNums() {
      this.totalNums = this.row.recordQuantity
      this.tableData.forEach(r => {
        this.totalNums = this.totalNums + Number(r.dxRealQuantity ? r.dxRealQuantity : 0)
      })
    },
    // row数据修改
    rowDataChange(val) {
      this.tableData[val.index][val.key] = val.val
      if (val.key === 'dxRealQuantity') {
        this.countNums()
      }
    },
    // 查询库区
    getDxStAreaOptions(val) {
      findAreaListWithHouseId(val, this.row.resourceClasscify.id).then(res => {
        this.dxStAreaOptions = res.items.map(r => {
          return {
            label: r.name,
            value: r.id,
            data: r
          }
        })
      })
    },
    // 查询库位
    getDxStLocationOptions(val, index) {
      const params = {
        'searchItems': {
          'children': [
            {
              'items': [
                {
                  'fieldName': 'parentId',
                  'operator': 'EQ',
                  'value': val
                }
              ],
              'operator': 'AND'
            }
          ],
          'operator': 'AND'
        }
      }
      this.$api.searchApi('DxStOrgLocation', params).then(res => {
        const arr = res.items.content.map(r => {
          return {
            label: r.serialNumber,
            value: r.id,
            data: r
          }
        })
        this.$set(this.tableData[index], 'dxStLocationOptions', arr)
        // 查询库内
        // !arr.length && this.getDxStInventoryAccount('DxStArea', val, index, this.dxStAreaOptions)
      })
    },
    // 查询库内信息
    getDxStInventoryAccount(type, locationId, index, options) {
      getDxStInventoryAccount(type, locationId).then(res => {
        const findItem = options.find(r => r.value === locationId)
        const maxLimit = findItem ? findItem.data.dynamicAttrs.maxLimit : 0
        this.tableData[index].dxStQuantity = maxLimit - res.items
        if (res.items) {
          // 生产单位的数量*(目标单位/原始单位)
          this.tableData[index].inCount = this.tableData[index].dxStQuantity * (this.unitInfo.targetUnitAmount / this.unitInfo.resourceUnitAmount)
        }
      })
    }
  }
}