hyingbo
4 小时以前 6ca4af64eda4d827adbe4cf4b5208b4e844ebddf
src/views/tms/modules/GoodsShelvesForm.vue
@@ -14,8 +14,13 @@
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="库位号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationCode">
              <a-input v-model="model.locationCode" placeholder="请输入库位号"  ></a-input>
            <a-form-model-item label="货架编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shelfNumber">
              <a-input v-model="model.shelfNumber" placeholder="请输入货架编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="货架名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shelfName">
              <a-input v-model="model.shelfName" placeholder="请输入货架名称" :disabled="shelfNameDisabled"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
@@ -33,18 +38,18 @@
              <a-input v-model="model.columnNumber" placeholder="请输入列数"  ></a-input>
            </a-form-model-item>
          </a-col>
           <a-col :span="12">
            <a-form-model-item label="格数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cellsNum">
              <a-input v-model="model.cellsNum" placeholder="请输入格数"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="库位号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-model="model.locationCode"  placeholder="请输入库位号"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="货架编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shelfNumber">
              <a-input v-model="model.shelfNumber" placeholder="请输入货架编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="货架名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shelfName">
              <a-input v-model="model.shelfName" placeholder="请输入货架名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
@@ -76,7 +81,22 @@
    data () {
      return {
        model:{
         },
          warehouseId: '',
          warehouseNum: '',
          warehouseName: '',
          shelfNumber: '',
          shelfName: '',
          storey: '',
          arrange: '',
          columnNumber: '',
          cellsNum:'',
          locationCode: '',
          remark: ''
        },
        autoLocationCode: '', // 自动拼接的库位号
        userEditedLocationCode: false,
        shelfNameDisabled: false, // 控制货架名称是否禁用
        lastEchoedShelfName: '', // 保存上次回显的货架名称
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
@@ -87,48 +107,72 @@
        },
        confirmLoading: false,
        validatorRules: {
           warehouseId: [
              { required: true, message: '请输入仓库编号!'},
           ],
           locationCode: [
              { required: true, message: '请输入库位号!'},
           ],
           storey: [
              { required: true, message: '请输入层数!'},
           ],
           arrange: [
              { required: true, message: '请输入排数!'},
           ],
           columnNumber: [
              { required: true, message: '请输入列数!'},
           ],
          shelfNumber: [
            { required: true, message: '请输入货架编号!'},
            { validator: this.validateShelfName }
          ],
          shelfName: [
            { required: true, message: '请输入货架名称!'},
          ],
          storey: [
            { required: true, message: '请输入层数!'},
          ],
          arrange: [
            { required: true, message: '请输入排数!'},
          ],
          columnNumber: [
            { required: true, message: '请输入列数!'},
          ],
          cellsNum: [
            { required: true, message: '请输入格数!'},
            { validator: this.validateDuplicate }
          ]
        },
        url: {
          add: "/tms/goodsShelves/add",
          edit: "/tms/goodsShelves/edit",
          queryById: "/tms/goodsShelves/queryById"
        }
          queryById: "/tms/goodsShelves/queryById",
          checkShelfName:"/tms/goodsShelves/checkShelfName",
          checkDuplicate:"/tms/goodsShelves/checkDuplicate"
        },
        warehouseId:''
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
      //拼接库位号
      autoGeneratedLocationCode() {
        const { shelfNumber, storey, arrange, columnNumber, cellsNum } = this.model;
        if (shelfNumber || storey || arrange || columnNumber || cellsNum) {
          return `${shelfNumber}${storey}${arrange}${columnNumber}${cellsNum}`;
        }
        return '';
      }
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      updateLocationCode() {
        this.model.locationCode = this.locationCode;
      },
      add (treeSelected) {
        this.modelDefault.warehouseId = treeSelected.key
        this.modelDefault.warehouseNum = treeSelected.entity.warehouseId
        this.modelDefault.warehouseName = treeSelected.entity.warehouseName
        this.modelDefault.cellsNum = '1' //格数设置默认值1
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        this.shelfNameDisabled = false
        // 重置回显标记
        this.lastEchoedShelfName = ''
        this.warehouseId = record.warehouseId
      },
      submitForm () {
        const that = this;
@@ -159,6 +203,56 @@
        })
      },
      //验证 货架号
    validateShelfName(rule, value, callback) {
      var params = {
        warehouseId: this.warehouseId,
        shelfNumber: value,
      };
      getAction(this.url.checkShelfName,params).then((res) => {
        if (res.success) {
          this.shelfNameDisabled = false
          // 只有在校验通过且当前货架名称是之前回显的值时才清空
          // 这通常发生在用户修改了已存在的货架编号为不存在的编号时
          if (this.model.shelfName === this.lastEchoedShelfName) {
            this.model.shelfName = ''
          }
          callback();
        } else {
          //存在该货架号,直接将结果回显到货架名称字段并禁用该字段
          this.model.shelfName = res.result;
          this.lastEchoedShelfName = res.result; // 保存回显的值
          this.shelfNameDisabled = true;
          callback();
        }
      })
    },
    validateDuplicate(rule, value, callback) {
      getAction(this.url.checkDuplicate, this.model).then(res => {
        if (res.success) {
          callback();
        } else {
          callback(res.message);
        }
      })
    }
    },
    watch: {
      autoGeneratedLocationCode(newVal) {
        // 只有当用户没有手动输入时才自动填充
        if (!this.userEditedLocationCode) {
          this.model.locationCode = newVal;
        }
        this.autoLocationCode = newVal;
      },
      'model.locationCode'(newVal) {
        // 如果用户手动输入,则标记为已编辑
        if (newVal !== this.autoLocationCode) {
          this.userEditedLocationCode = true;
        } else {
          this.userEditedLocationCode = false;
        }
      }
    }
  }
</script>