hyingbo
2025-07-24 0fe10b533514a73915abd534493bffb6c5df016a
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="请输入货架名称"  ></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,20 @@
    data () {
      return {
        model:{
         },
          warehouseId: '',
          warehouseNum: '',
          warehouseName: '',
          shelfNumber: '',
          shelfName: '',
          storey: '',
          arrange: '',
          columnNumber: '',
          cellsNum:'',
          locationCode: '',
          remark: ''
        },
        autoLocationCode: '', // 自动拼接的库位号
        userEditedLocationCode: false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
@@ -96,30 +114,44 @@
           storey: [
              { required: true, message: '请输入层数!'},
           ],
           arrange: [
              { required: true, message: '请输入排数!'},
           ],
           columnNumber: [
              { required: true, message: '请输入列数!'},
           ],
          shelfNumber: [
              { required: true, message: '请输入货架号!'},
              { validator: this.validateShelfNumber },
          ],
          shelfName: [
              { required: true, message: '请输入货架名称!'},
          ],
        },
        url: {
          add: "/tms/goodsShelves/add",
          edit: "/tms/goodsShelves/edit",
          queryById: "/tms/goodsShelves/queryById"
        }
          queryById: "/tms/goodsShelves/queryById",
          checkShelfNum:"/tms/goodsShelves/checkShelfNum"
        },
        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
@@ -129,6 +161,7 @@
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
        this.warehouseId = record.warehouseId
      },
      submitForm () {
        const that = this;
@@ -159,6 +192,37 @@
        })
      },
      //验证 货架号
    validateShelfNumber(rule, value, callback) {
      var params = {
        warehouseId: this.warehouseId,
        shelfNumber: value,
      };
      getAction(this.url.checkShelfNum,params).then((res) => {
        if (res.success) {
          callback();
        } else {
          callback("货架编号已存在!");
        }
      })
    },
    },
    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>