From 3f69b4dfc585c4dfbc3c07a6acf5cdd838033636 Mon Sep 17 00:00:00 2001 From: liuguocan <527956374@qq.com> Date: 星期二, 28 十一月 2023 14:45:49 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- admin-web/src/views/stock/procure/purchaseOrder/edit.vue | 238 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 135 insertions(+), 103 deletions(-) diff --git a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue index 259b8c8..e5afac4 100644 --- a/admin-web/src/views/stock/procure/purchaseOrder/edit.vue +++ b/admin-web/src/views/stock/procure/purchaseOrder/edit.vue @@ -1,5 +1,5 @@ <template> - <win-md class="stock-edit" :title="`${setting.title}閲囪喘鍏ュ簱`" @close="close" :width="'800px'"> + <win-md class="stock-edit" :title="`${setting.title}閲囪喘鍏ュ簱`" @close="close" :width="'800px'" :loading="loading"> <el-form class="form" ref="ruleForm" :model="formData" :rules="rules" label-width="120px"> <div class="main-w"> <el-row :gutter="24" class="headerHeight"> @@ -65,11 +65,7 @@ <el-form-item label="鐗╁搧鍚嶇О" :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`" - :rules="{ - required: true, - message: '璇烽�夋嫨', - trigger: 'change', - }" + :rules="rules.baseGoodsTemplateId" > <el-select v-model="goodsItem.baseGoodsTemplateId" @@ -135,14 +131,32 @@ {{ scope.row.unit }} </template> </el-table-column> - <el-table-column prop="price" label="鍗曚环锛堝厓锛�" align="center"> + <el-table-column prop="priceYuan" label="鍗曚环锛堝厓锛�" align="center"> <template slot-scope="scope"> - <el-input type="number" v-model="scope.row.price"></el-input> + <el-form-item + label-width="0" + style="margin-bottom: 0" + :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].priceYuan`" + :rules="rules.priceYuan" + > + <el-input + type="number" + v-model.number="scope.row.priceYuan" + @change="priceChange($event, goodsIndex, scope.$index)" + ></el-input> + </el-form-item> </template> </el-table-column> <el-table-column prop="counts" label="閲囪喘鏁伴噺" align="center"> <template slot-scope="scope"> - <el-input type="number" v-model="scope.row.counts"></el-input> + <el-form-item + label-width="0" + style="margin-bottom: 0" + :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].counts`" + :rules="rules.counts" + > + <el-input v-model.number="scope.row.counts"></el-input> + </el-form-item> </template> </el-table-column> </el-table> @@ -170,8 +184,8 @@ </div> </el-form> <div slot="footer" align="center" class="dialog-footer"> - <my-button name="鍙栨秷" site="form" @click="close"/> - <my-button name="淇濆瓨" site="form" @click="handleSubmit"/> + <my-button name="鍙栨秷" site="form" @click="close" /> + <my-button name="淇濆瓨" site="form" @click="handleSubmit" /> </div> </win-md> </template> @@ -188,43 +202,81 @@ import MyButton from '@/components/myButton/myButton'; import winMd from '@/components/win/win-md'; import upload from '@/components/upload/index'; -import { getUploadUrl,getDownUrl} from '@/utils/base'; - -import SettingIplatform from '../../../../../public/static/config'; +import { getUploadUrl, getDownUrl } from '@/utils/base'; +import { findParentIds } from '@/utils/index'; +import { mapGetters } from 'vuex'; export default { components: { MyButton, winMd, upload }, props: { setting: { type: Object, - default: () => { - } - } + default: () => {}, + }, }, data() { + // 鑷畾涔夋牎楠� + // 鐗╁搧閲嶅鏍¢獙 + var checkGoodsTemplateId = (rule, value, callback) => { + if (!value) { + return callback(new Error('璇烽�夋嫨')); + } + let temp = this.formData.procureGoods.filter((v) => v.baseGoodsTemplateId == value); + if (!temp || temp.length != 1) { + return callback(new Error('宸查�夎繃姝ょ墿鍝�')); + } + callback(); + }; + // 閲戦鏍¢獙 + var checkPrice = (rule, value, callback) => { + if (!value) { + return callback(new Error('璇疯緭鍏�')); + } + if (value == 0) { + this.$message.warning('鏁板瓧鍊间笉鑳戒负0'); + return callback(new Error('鏁板瓧鍊间笉鑳戒负0')); + } + callback(); + }; + // 鏁伴噺鏍¢獙 + var checkCounts = (rule, value, callback) => { + if (!value) { + return callback(new Error('璇疯緭鍏�')); + } + if (!Number.isInteger(value)) { + this.$message.warning('璇疯緭鍏ユ暟瀛楀��'); + return callback(new Error('璇疯緭鍏ユ暟瀛楀��')); + } + if (value == 0) { + this.$message.warning('鏁板瓧鍊间笉鑳戒负0'); + return callback(new Error('鏁板瓧鍊间笉鑳戒负0')); + } + callback(); + }; return { - visible: false, - loading: false, - buyTypeOptions:[{ - label:'闆嗛噰', - value: '1' - },{ - label:'鑷噰', - value: '2' - }], - fileList:[], + loading: true, + buyTypeOptions: [ + { + label: '闆嗛噰', + value: '1', + }, + { + label: '鑷噰', + value: '2', + }, + ], + fileList: [], warehouses: [], // 鍏ュ簱浠撳簱鍒楄〃 categoryOptions: [], // 鐗╁搧鍒嗙被鍒楄〃 modelList: [], //鍨嬪彿鍒楄〃 formData: { - procureDoc:'', + procureDoc: '', warehouseId: '', // 鍏ュ簱浠撳簱id procureTime: '', // 閲囪喘鏃堕棿 buyType: '2', // 閲囪喘鏂瑰紡锛�1锛氶泦閲囷紱2=鑷噰锛� procureGoods: [], }, goodsItem: { - whFormProcureId: '', // 閲囪喘鍗旾D baseCategoryIds: '', // 鍒嗙被缂栧彿鏁扮粍 baseCategoryId: '', // 鍒嗙被缂栧彿 baseGoodsTemplateId: '', // 鐗╁搧妯$増缂栧彿 @@ -238,9 +290,9 @@ }, modelsItem: { baseGoodsModelsId: '', // 瑙勬牸鍨嬪彿缂栧彿 - price: 0, // 鍗曚环(閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�) - counts: 0, // 鎿嶄綔鏁伴噺 - supplier: '', // 渚涘簲鍟� + priceYuan: null, // 鍗曚环(鍏�) + price: null, // 鍗曚环(鍒� 閲囪喘闇�瑕侊紝璋冩嫧涓嶉渶瑕�) + counts: null, // 鎿嶄綔鏁伴噺 unit: null, //鍗曚綅 }, rules: { @@ -250,15 +302,16 @@ procureDoc: [{ required: true, message: '璇蜂笂浼�', trigger: 'change' }], baseCategoryIds: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }], - baseGoodsTemplateId: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }], + baseGoodsTemplateId: [{ validator: checkGoodsTemplateId, trigger: ['blur', 'change'] }], modelsIds: [{ required: true, message: '璇烽�夋嫨', trigger: 'change' }], + priceYuan: [{ validator: checkPrice, trigger: 'blur' }], + counts: [{ validator: checkCounts, trigger: 'blur' }], }, uploadSettings: { title: '涓婁紶', max: 20, // 鏈�澶уぇ灏忥紝鍗曚綅M num: 10, // 鏀寔涓婁紶鍥剧墖涓暟 - accept: '.jpg,.png', // 闄愬埗鏍煎紡 tip: '', // 鎻愮ず 榛樿锛歚鍙兘涓婁紶${this.defaultSettings.num}涓�${this.defaultSettings.accept}鏂囦欢锛屼笖涓嶈秴杩�${this.defaultSettings.max}kb` uploadUrl: getUploadUrl(), // 涓婁紶璺緞 multiple: true, // 鏄惁鏀寔鎵归噺涓婁紶 @@ -267,45 +320,55 @@ }, }; }, + computed: { + ...mapGetters(['userInfo']), + }, created() { - this.init() + this.init(); }, methods: { async init() { this.getWarehouseList(); - this.getgoodsTemplate() + this.getgoodsTemplate(); this.getgoodsModel(); // 鑾峰彇鐗╁搧鍒嗙被鍒楄〃 const treeRes = await getTree(); this.categoryOptions = this.removeEmptyChildren(treeRes); if (this.setting.id) { - const detail = await procureDetail({ id:this.setting.id }); + const detail = await procureDetail({ id: this.setting.id }); this.formData = Object.assign(this.formData, detail); - if(this.formData.procureDoc) { - this.fileList = JSON.parse(this.formData.procureDoc) + if (this.formData.procureDoc) { + this.fileList = JSON.parse(this.formData.procureDoc); } - this.$set(this.formData,'buyType',this.formData.buyType.toString()) + this.$set(this.formData, 'buyType', this.formData.buyType.toString()); this.formData.procureTime = this.formData.procureTime.toString(); this.formData.procureGoods.map((item, index) => { // 鏍规嵁瀛愰泦ID鎷兼帴鐗╁搧鍒嗙被鍒楄〃 - let pIds = this.findParentIds(this.categoryOptions, item.baseCategoryId); - item.baseCategoryIds = [...pIds, item.baseCategoryId]; - this.$set(this.formData.procureGoods[index],'modelsIds',item.models.map((v) => v.baseGoodsModelsId)) + item.baseCategoryIds = findParentIds(this.categoryOptions, item.baseCategoryId); + this.$set( + this.formData.procureGoods[index], + 'modelsIds', + item.models.map((v) => v.baseGoodsModelsId), + ); this.getgoodsTemplate(item.baseCategoryId, index); this.getgoodsModel(item.baseGoodsTemplateId, index); - return item + item.models.forEach((child, childIndex) => { + this.$set(this.formData.procureGoods[index].models[childIndex], 'priceYuan', child.price / 100); + }); + return item; }); - } else { - this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); } - this.visible = true; + this.loading = false; }, // 鑾峰彇鍏ュ簱浠撳簱鍒楄〃 getWarehouseList() { - selectTenantWarehouse() + selectTenantWarehouse({ agencyId: this.userInfo.tenantId }) .then((res) => { this.warehouses = res; + if (!this.setting.id && res.length) { + this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); + } if (this.warehouses.length && !this.formData.warehouseId) { // 榛樿閫変腑绗竴涓粨搴� this.formData.warehouseId = this.warehouses[0].id; @@ -332,7 +395,7 @@ goodsTemplate({ categoryId: id || '' }).then((res) => { if (index || index == 0) { this.$set(this.formData.procureGoods[index], 'goodsOptions', res); - }else { + } else { this.goodsTemplatelAll = res; } }); @@ -369,12 +432,12 @@ // 鐗╁搧鍒嗙被閫夋嫨 categoryChange(e, index) { - this.formData.procureGoods[index].goodsOptions = [] - this.formData.procureGoods[index].baseGoodsTemplateId = '' - this.formData.procureGoods[index].goodsTemplateName = '' - this.formData.procureGoods[index].modelsOptions = [] - this.formData.procureGoods[index].modelsIds = [] - this.formData.procureGoods[index].models = [] + this.formData.procureGoods[index].goodsOptions = []; + this.formData.procureGoods[index].baseGoodsTemplateId = ''; + this.formData.procureGoods[index].goodsTemplateName = ''; + this.formData.procureGoods[index].modelsOptions = []; + this.formData.procureGoods[index].modelsIds = []; + this.formData.procureGoods[index].models = []; this.formData.procureGoods[index].baseCategoryId = e[e.length - 1]; // 鏍规嵁閫変腑鍒嗙被璇锋眰鐗╁搧鍚嶇О鍒楄〃 @@ -383,11 +446,11 @@ // 鐗╁搧鍚嶇О鍒楄〃 goodsTemplateChange(e, index) { - this.formData.procureGoods[index].modelsOptions = [] - this.formData.procureGoods[index].modelsIds = [] - this.formData.procureGoods[index].models = [] + this.formData.procureGoods[index].modelsOptions = []; + this.formData.procureGoods[index].modelsIds = []; + this.formData.procureGoods[index].models = []; - this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e) + this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e); // 鏍规嵁閫変腑鐗╁搧鍚嶇Оid鑾峰彇瑙勬牸鍨嬪彿鍒楄〃 this.getgoodsModel(e, index); }, @@ -412,10 +475,15 @@ this.formData.procureGoods[index].models.splice(delIndex, 1); }, + // 浠锋牸input鐩戝惉 杞负鍒� + priceChange(e, goodsIndex, index) { + this.formData.procureGoods[goodsIndex].models[index].price = e * 100; + }, + // 涓婁紶 uploadChange() { - let arr = this.$refs.uploadRef.fileList - this.formData.procureDoc = JSON.stringify(arr) + let arr = this.$refs.uploadRef.fileList; + this.formData.procureDoc = JSON.stringify(arr); }, // 鐐瑰嚮鏂板鐗╁搧 @@ -432,7 +500,7 @@ handleSubmit() { this.$refs['ruleForm'].validate((valid) => { if (valid) { - console.log('this.formData', this.formData); + this.loading = true; if (!this.setting.id) { procureAdd(this.formData) .then((res) => { @@ -441,7 +509,7 @@ this.$emit('search'); }) .catch((err) => { - console.log('create err', err); + this.loading = false; this.$message.error('淇濆瓨澶辫触'); }); } else { @@ -452,7 +520,7 @@ this.$emit('search'); }) .catch((err) => { - console.log('edit err', err); + this.loading = false; this.$message.error('淇濆瓨澶辫触'); }); } @@ -463,48 +531,12 @@ }, close() { - this.formData ={ + this.formData = { warehouseId: '', // 鍏ュ簱浠撳簱id procureTime: '', // 閲囪喘鏃堕棿 procureGoods: [], - } - this.$emit('close') - }, - - // 閫氳繃瀛愰泦id鏌ュ埌鎵�浠ョ浉鍏崇埗绾d骞惰繑鍥炴暟缁� - findParentIds(dataSource, nodeId) { - const parentIds = [nodeId]; // 鐢ㄤ簬瀛樺偍鎵�鏈夌埗鑺傜偣ID鐨勬暟缁� - - // 瀹氫箟涓�涓�掑綊鍑芥暟锛岀敤浜庨亶鍘嗘暣妫垫爲骞舵煡鎵惧瓙鑺傜偣鐨勬墍鏈夌埗鑺傜偣 - function traverse(node, nodeId) { - if (node.id === nodeId) { - // 濡傛灉褰撳墠鑺傜偣鐨処D绛変簬瀛愯妭鐐圭殑ID锛屽垯琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣锛屽彲浠ュ紑濮嬪悜涓婃煡鎵剧埗鑺傜偣 - return true; // 杩斿洖true琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣 - } - - if (node.children) { - // 濡傛灉褰撳墠鑺傜偣鏈夊瓙鑺傜偣锛屽垯缁х画閬嶅巻瀛愯妭鐐� - for (const childNode of node.children) { - if (traverse(childNode, nodeId)) { - // 濡傛灉鍦ㄥ瓙鑺傜偣涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欏皢褰撳墠鑺傜偣鐨処D娣诲姞鍒扮埗鑺傜偣ID鏁扮粍涓紝骞惰繑鍥瀟rue琛ㄧず宸茬粡鎵惧埌浜嗗瓙鑺傜偣 - parentIds.unshift(node.id); - return true; - } - } - } - - return false; // 濡傛灉褰撳墠鑺傜偣涓嶆槸瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欒繑鍥瀎alse - } - - // 浠庢牴鑺傜偣寮�濮嬮亶鍘嗘暣妫垫爲锛屽苟璋冪敤閫掑綊鍑芥暟鏌ユ壘瀛愯妭鐐圭殑鎵�鏈夌埗鑺傜偣 - for (const node of dataSource) { - if (traverse(node, nodeId)) { - // 濡傛灉鍦ㄥ綋鍓嶈妭鐐圭殑瀛愭爲涓壘鍒颁簡瀛愯妭鐐圭殑鐖惰妭鐐癸紝鍒欑洿鎺ラ��鍑哄惊鐜� - break; - } - } - - return parentIds; // 杩斿洖鎵�鏈夌埗鑺傜偣ID鐨勬暟缁� + }; + this.$emit('close'); }, }, }; -- Gitblit v1.9.1