LocationForm.vue 8.54 KB
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="库位编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input v-model="model.code" placeholder="请输入库位编码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="库区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zoneCode">
              <a-select
                show-search
                placeholder="请选择库区"
                option-filter-prop="children"
                v-model="model.zoneCode">
                <a-select-option v-for="item in zoneList" :key="item.name" :value="item.code">{{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="库位类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationTypeCode">
              <a-select
                show-search
                placeholder="请选择库位类型"
                option-filter-prop="children"
                v-model="model.locationTypeCode">
                <a-select-option v-for="item in locationTypeList" :key="item.name" :value="item.code">{{ item.name }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="容器编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="containerCode">
              <a-input v-model="model.containerCode" placeholder="请输入容器编码"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="location_status" placeholder="请选择状态"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="巷道" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roadWay">
              <a-input-number v-model="model.roadWay" placeholder="请输入巷道" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="row">
              <a-input-number v-model="model.row" placeholder="请输入行" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="列" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="icolumn">
              <a-input-number v-model="model.icolumn" placeholder="请输入列" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="层" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="layer">
              <a-input-number v-model="model.layer" placeholder="请输入层" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="高低位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="high">-->
          <!--              <a-input-number v-model="model.high" placeholder="请输入高低位" style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="高低位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="high">
              <j-dict-select-tag type="list" v-model="model.high" dictCode="high_status" placeholder="请选择高低位"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="内外侧" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rowFlag">
              <j-dict-select-tag type="list" v-model="model.rowFlag" dictCode="row_type" placeholder="请选择内外侧"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="物料分区存放" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="materialAreaCode">
              <a-input v-model="model.materialAreaCode" placeholder="请输入物料分区存放"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="容器类型" :labelCol="labelCol" :wrapperCol="wrapperCol"
                               prop="containerTypeCode">
              <a-input v-model="model.containerTypeCode" placeholder="请输入容器类型"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否可用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enable">
              <j-dict-select-tag type="list" v-model="model.enable" dictCode="enable_status"
                                 placeholder="请选择是否可用"/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { getZoneList } from '@/api/api'
import { getLocationTypeList } from '@/api/api'

export default {
  name: 'LocationForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      zoneList: [],
      locationTypeList: [],
      validatorRules: {
        code: [
          { required: true, message: '请输入库位编码!' },
        ],
        locationTypeCode: [
          { required: true, message: '请输入库位类型!' },
        ],
        zoneCode: [
          { required: true, message: '请输入库区!' },
        ],
        status: [
          { required: true, message: '请输入状态!' },
        ],
        row: [
          { required: true, message: '请输入行!' },
        ],
        icolumn: [
          { required: true, message: '请输入列!' },
        ],
        layer: [
          { required: true, message: '请输入层!' },
        ],
        high: [
          { required: true, message: '请输入高低位!' },
        ],
        rowFlag: [
          { required: true, message: '请输入内外侧!' },
        ],
        enable: [
          { required: true, message: '请输入是否可用!' },
        ],
      },
      url: {
        add: '/config/location/add',
        edit: '/config/location/edit',
        queryById: '/config/location/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
    this.loadFrom()
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    loadFrom() {
      getZoneList().then((res) => {
        if (res.success) {
          this.zoneList = res.result
        }
      })
      getLocationTypeList().then((res) => {
        if (res.success) {
          this.locationTypeList = res.result
        }
      })
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
  }
}
</script>