From 0e4933fe67a777d7069a1c9be7a09c6d227e64c4 Mon Sep 17 00:00:00 2001 From: hyingbo <1363390067@qq.com> Date: 星期一, 14 七月 2025 15:18:07 +0800 Subject: [PATCH] 仓库管理-新增时存在默认值的情况下保存出现“展示序号不能小于0!”的验证信息 --- src/views/tms/modules/WarehouseForm.vue | 66 +++++++++++++++++++++++++++------ 1 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/views/tms/modules/WarehouseForm.vue b/src/views/tms/modules/WarehouseForm.vue index 2ff4a66..73fc95c 100644 --- a/src/views/tms/modules/WarehouseForm.vue +++ b/src/views/tms/modules/WarehouseForm.vue @@ -4,13 +4,13 @@ <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail"> <a-row> <a-col :span="12"> - <a-form-model-item label="鐖惰妭鐐圭紪鍙�" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parentId"> - <a-input v-model="model.parentId" placeholder="璇疯緭鍏ョ埗鑺傜偣缂栧彿" ></a-input> + <a-form-model-item label="鐖惰妭鐐圭紪鍙�" :labelCol="labelCol" :wrapperCol="wrapperCol"> + <a-input :disabled="true" v-model="model.parentWarehouseId" placeholder="璇疯緭鍏ョ埗鑺傜偣缂栧彿" ></a-input> </a-form-model-item> </a-col> <a-col :span="12"> - <a-form-model-item label="鐖惰妭鐐瑰悕绉�" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="parentName"> - <a-input v-model="model.parentName" placeholder="璇疯緭鍏ョ埗鑺傜偣鍚嶇О" ></a-input> + <a-form-model-item label="鐖惰妭鐐瑰悕绉�" :labelCol="labelCol" :wrapperCol="wrapperCol"> + <a-input :disabled="true" v-model="model.parentWarehouseName" placeholder="璇疯緭鍏ョ埗鑺傜偣鍚嶇О" ></a-input> </a-form-model-item> </a-col> <a-col :span="12"> @@ -25,15 +25,15 @@ </a-col> <a-col :span="12"> <a-form-model-item label="鍙跺瓙鑺傜偣鏍囪瘑" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="leafFlag"> - <a-radio-group v-model="model.leafFlag" @change="onChange" placeholder="璇烽�夋嫨鏄惁鍙跺瓙鑺傜偣"> - <a-radio :value="2">鏈夊瓙鑺傜偣</a-radio> - <a-radio :value="1">鏄彾瀛愯妭鐐�</a-radio> + <a-radio-group :disabled="leafDisableFlag" v-model="model.leafFlag" placeholder="璇烽�夋嫨鏄惁鍙跺瓙鑺傜偣"> + <a-radio :value="'2'">鏈夊瓙鑺傜偣</a-radio> + <a-radio :value="'1'">鏄彾瀛愯妭鐐�</a-radio> </a-radio-group> </a-form-model-item> </a-col> <a-col :span="12"> <a-form-model-item label="灞曠ず搴忓彿" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="seq"> - <a-input type="number" v-model="model.seq" placeholder="璇疯緭鍏ュ睍绀哄簭鍙�" ></a-input> + <a-input type="number" min="0" v-model="model.seq" placeholder="璇疯緭鍏ュ睍绀哄簭鍙�" ></a-input> </a-form-model-item> </a-col> <a-col :span="12"> @@ -66,11 +66,12 @@ }, data () { return { + leafDisableFlag: false, model:{ }, labelCol: { xs: { span: 24 }, - sm: { span: 5 }, + sm: { span: 8 }, }, wrapperCol: { xs: { span: 24 }, @@ -80,6 +81,7 @@ validatorRules: { warehouseId: [ { required: true, message: '璇疯緭鍏ヤ粨搴撶紪鍙�!'}, + { validator: (rule, value, callback) => validateDuplicateValue('tms_warehouse', 'warehouse_id', value, this.model.id, callback)} ], warehouseName: [ { required: true, message: '璇疯緭鍏ヤ粨搴撳悕绉�!'}, @@ -91,10 +93,22 @@ { required: true, message: '璇疯緭鍏ユ槸鍚﹀彾瀛愯妭鐐�!'}, ], seq: [ - { min: 0, message: '灞曠ず搴忓彿涓嶈兘灏忎簬0!'}, + { validator: (rule, value, callback) => { + if (!value && value !== 0) { + return; + } + const num = Number(value); + if (isNaN(num) || num < 0) { + callback(new Error('灞曠ず搴忓彿涓嶈兘灏忎簬0')); + } else { + callback(); + } + } + } ], }, url: { + list: "/tms/warehouse/list", add: "/tms/warehouse/add", edit: "/tms/warehouse/edit", queryById: "/tms/warehouse/queryById" @@ -104,17 +118,37 @@ computed: { formDisabled(){ return this.disabled - }, + } }, created () { //澶囦唤model鍘熷鍊� this.modelDefault = JSON.parse(JSON.stringify(this.model)); }, methods: { - add () { + async updateLeafDisableFlag() { + const parentId = this.model.id; + try { + const res = await getAction(this.url.list, { parentId: parentId }); + if (res.success) { + this.leafDisableFlag = res.result.total > 0; + } + } catch (e) { + console.error(e); + } + }, + add (treeSelected, nextSeq) { + this.modelDefault.parentId = treeSelected.key + this.modelDefault.parentWarehouseId = treeSelected.entity.warehouseId + this.modelDefault.parentWarehouseName = treeSelected.entity.warehouseName + this.modelDefault.seq = String(nextSeq >= 0 ? nextSeq : 0) + this.modelDefault.leafFlag = '2' this.edit(this.modelDefault); }, edit (record) { + if (record.parentId === '-1') { + record.parentWarehouseId = '-1' + record.parentWarehouseName = '鑸畤鏁戠敓' + } this.model = Object.assign({}, record); this.visible = true; }, @@ -129,6 +163,7 @@ if(!this.model.id){ httpurl+=this.url.add; method = 'post'; + this.model.status = '1' }else{ httpurl+=this.url.edit; method = 'put'; @@ -147,6 +182,13 @@ }) }, + }, + watch: { + 'model.id': function(newVal) { + if (newVal) { + this.updateLeafDisableFlag() + } + } } } </script> \ No newline at end of file -- Gitblit v1.9.3