batchDxStLocation.vue 3.68 KB
<template>
  <div class="batchDxStLocation-com">
    <dee-form
      ref="AddForm"
      :form="form"
      :form-data="AddData"
      form-btn-position="center"
      :rules="rules"
      :inline="true"
    >
      <span style="display:flex">
        <el-button
          type="primary"
          class="searchBtn"
          @click="addDxStLocation"
        >确定</el-button>

        <el-button
          class="searchBtn"
          @click="handleClose"
        >取消</el-button>
      </span>
    </dee-form>
  </div>
</template>

<script>
export default {
  name: 'BatchDxStLocation',
  components: {},
  props: {
    basicData: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      dxStAreaOptions: [],
      dxStLocationOptions: [],
      form: {},
      rules: {
        dxStArea: [
          { required: true, message: '请选择库区', trigger: 'change' }
        ],
        dxStLocation: [
          { required: true, message: '请选择库位', trigger: 'change' }
        ]
      }
    }
  },
  computed: {
    AddData() {
      return [
        {
          split: 1,
          data: [{
            key: 'dxStArea',
            title: '库区',
            component: {
              name: 'el-select',
              valueKey: 'id',
              options: this.dxStAreaOptions
            },
            handler: {
              change: (val) => {
                this.getDxStLocationOptions(val)
              }
            }
          },
          {
            key: 'dxStLocation',
            title: '库位',
            component: {
              name: 'el-select',
              valueKey: 'id',
              options: this.dxStLocationOptions
            }
          }]
        }
      ]
    }
  },
  watch: {
    basicData: {
      deep: true,
      immediate: true,
      handler: function(val) {
        if (val && val.dxStHouseId) {
          this.getDxStAreaOptions()
        }
      }
    }
  },
  created() {

  },
  mounted() {

  },
  methods: {
    getDxStAreaOptions() {
      const params = {
        'searchItems': {
          'items': [
            {
              'fieldName': 'parentId',
              'operator': 'EQ',
              'value': this.basicData.dxStHouseId
            }
          ],
          'operator': 'AND'
        },
        'sortItem': [
          {
            'fieldName': 'name',
            'sortOrder': 'ASC'
          }
        ]
      }
      this.$api.searchApi('DxStOrgArea', params).then(res => {
        this.dxStAreaOptions = res.items.content.map(r => {
          return {
            label: r.name,
            value: r
          }
        })
      })
    },
    // 查询库位
    getDxStLocationOptions(val) {
      this.dxStLocationOptions = []
      this.$set(this.form, 'dxStLocation', null)
      const params = {
        'searchItems': {
          'children': [
            {
              'items': [
                {
                  'fieldName': 'parentId',
                  'operator': 'EQ',
                  'value': val.id
                }
              ],
              'operator': 'AND'
            }
          ],
          'operator': 'AND'
        }
      }
      this.$api.searchApi('DxStOrgLocation', params).then(res => {
        this.dxStLocationOptions = res.items.content.map(r => {
          return {
            label: r.serialNumber,
            value: r
          }
        })
      })
    },

    // 批量添加库位
    addDxStLocation() {
      this.$refs.AddForm.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('addDxStLocation', this.form)
          this.handleClose()
        }
      })
    },
    handleClose() {
      this.$emit('handleClose')
    }
  }
}
</script>

<style lang="scss">

</style>