From 7f5306d896fa0c541a83c4b62d0c533a604dd184 Mon Sep 17 00:00:00 2001 From: haoxuan <haoxuan> Date: 星期日, 28 四月 2024 18:23:23 +0800 Subject: [PATCH] 供应商管理模块 添加新产品的时候供应商对应的产品和已增加的产品都不可选的逻辑处理 --- src/views/supplierManage/supplier/AddNewProduct.vue | 197 ++++++++++++++++++++++++++++++++++--------------- 1 files changed, 136 insertions(+), 61 deletions(-) diff --git a/src/views/supplierManage/supplier/AddNewProduct.vue b/src/views/supplierManage/supplier/AddNewProduct.vue index b9a1812..7e714b8 100644 --- a/src/views/supplierManage/supplier/AddNewProduct.vue +++ b/src/views/supplierManage/supplier/AddNewProduct.vue @@ -14,11 +14,19 @@ <div class="basic-info-title">浜у搧淇℃伅</div> <div class="basic-info-view"> <CommonFormTableView + ref="productTable" + :addTypeIdMultiple="true" + :disabledList="disabledList" :product-table-list="productTableList" + :detail-enter="detailEnter" + :isOperate="isOperate" @inputContent="inputContent" @addProductClick="addProductClick" + @getSelectArray="getSelectArray" @emptyProductClick="emptyProductClick" @clearupProduct="clearupProduct" + @selCommonName="selCommonName" + @handleProduct="handleProduct" /> </div> </div> @@ -31,7 +39,7 @@ </template> <script> -// import { createProduct, updateProduct } from "@/api/productManage/product" +import { createProduct, updateProduct } from "@/api/productManage/product" import CommonFormTableView from "@/components/makepager/CommonFormTableView" export default { name: "AddNewProduct", @@ -45,18 +53,30 @@ infomation: {} } } + }, + disabledList:{ + type:[Array], + default: () => { + return [] + } } }, components: { CommonFormTableView }, computed: {}, data() { return { - dialogWidth: "80%", + dialogWidth: "60%", editConfig: this.addCommonConfig, productTableList: {}, tableData: [], productId: 1, - isNoProduct: true + isNoProduct: true, + supplierId: this.addCommonConfig.infomation.supplierId, + detailEnter: true, + isOperate: true, + deliveryTime: this.addCommonConfig.infomation.deliveryTime, // 渚涜揣鏃堕暱 + shippingDuration: this.addCommonConfig.infomation.shippingDuration, // 鐗╂祦鏃堕暱 + purchasePrice: this.addCommonConfig.infomation.purchasePrice // 閲囪喘浠锋牸 } }, created() { @@ -71,50 +91,77 @@ }, // 淇濆瓨 saveClick() { - console.log(this.editConfig.infomation) - const params = this.saveParams() - console.log(params) - if (this.editConfig.title === "娣诲姞") { - // createProduct(params).then((res) => { - // console.log(res) - // this.editConfig.visible = false - // if (res.code === 200) { - // this.$message.success("娣诲姞鎴愬姛") - // this.$parent.getData() - // } - // }) - } else { - // updateProduct(params).then((res) => { - // console.log(res) - // this.editConfig.visible = false - // if (res.code === 200) { - // this.$message.success("缂栬緫鎴愬姛") - // this.$parent.getData() - // } - // }) - } + this.$refs.productTable.$refs.form.validate((valid) => { + if (valid) { + console.log(this.editConfig.infomation) + for (let i = 0; i < this.tableData.length; i++) { + if (this.tableData[i].name.length === 0) { + this.isNoProduct = true + break + } else { + this.isNoProduct = false + } + } + if (this.isNoProduct) { + this.$message.error("浜у搧鍚嶇О涓嶈兘涓虹┖") + } else { + if (this.editConfig.title === "娣诲姞") { + createProduct({ + list: this.tableData + }) + .then((res) => { + console.log(res) + this.editConfig.visible = false + if (res.code === 200) { + this.$message.success("娣诲姞鎴愬姛") + this.$parent.getProductList() + } + }) + .catch((e) => { + console.log(e) + }) + } else { + const params = this.saveParams() + updateProduct(params).then((res) => { + console.log(res) + this.editConfig.visible = false + if (res.code === 200) { + this.$message.success("缂栬緫鎴愬姛") + this.$parent.getProductList() + } + }) + } + } + } + }) }, saveParams() { - // let data = this.editConfig.infomation + let data = this.editConfig.infomation let params = { - deliveryTime: 0, - id: 0, - maximumStock: 0, - minimumStock: 0, - name: "string", - number: "string", - productType: "string", - purchasePrice: 0, - remark: "string", - shippingDuration: 0, - specifications: "string", - supplierId: 0, - unit: "string" + deliveryTime: this.deliveryTime || 0, + id: data.id || 0, + // maximumStock: data.maximumStock || 0, + // minimumStock: data.minimumStock || 0, + // modelNumber: data.modelNumber || "", + // name: data.name || "", + // number: data.number || "", + // productType: data.productType || "", + purchasePrice: this.purchasePrice || 0, + // remark: data.remark || "", + shippingDuration: this.shippingDuration || 0, + // specifications: data.specifications || "", + supplierId: this.supplierId || 0, + // unit: data.unit || "" + ...this.tableData[0] } return params }, + handleProduct(item, row) { + this.editConfig.infomation.id = row.id + }, setTableForm() { - if (this.editConfig.title === "娣诲姞" || this.editConfig.infomation.products.length === 0) { + if (this.editConfig.title === "娣诲姞") { + this.detailEnter = false this.tableData = [ { productId: this.productId, @@ -124,19 +171,19 @@ name: "", number: "", price: 0, - total: 0 + total: 0, + supplierId: this.supplierId } ] } else { - this.tableData = this.editConfig.infomation.products - this.tableData.map((item, index) => { - item.productId = index + 1 - }) + this.tableData = [{ ...this.editConfig.infomation }] + this.detailEnter = true } this.productTableList = { tableData: this.tableData, + isReturn: true, tableColumn: [ - { label: "浜у搧鍚嶇О", prop: "name", productName: true, isRequird: true }, + { label: "浜у搧鍚嶇О", prop: "name", productName: true, isRequird: true, width: 250 }, { label: "浜у搧缂栫爜", prop: "number" }, { label: "璁¢噺鍗曚綅", prop: "unit" }, { label: "瑙勬牸鍨嬪彿", prop: "specifications" }, @@ -148,26 +195,46 @@ }, // 浜у搧鍒楄〃杈撳叆 inputContent(val, prop, row) { - this.productId = row.productId this.tableData.map((item) => { - if (item.productId === row.productId) { + if (item.number == row.number) { item[prop] = val + item.supplierId = Number(this.supplierId) } }) }, // 浜у搧鏂板 addProductClick() { - this.productId++ - this.tableData.push({ - productId: this.productId, - id: 0, - amount: 0, - desc: "", - name: "", - number: "", - price: 0, - total: 0 - }) + // this.productId++ + // this.tableData.push({ + // productId: this.productId, + // id: 0, + // amount: 0, + // desc: "", + // name: "", + // number: "", + // purchasePrice: 0, + // total: 0, + // deliveryTime: 0, + // shippingDuration: 0, + // supplierId: this.supplierId + // }) + }, + // 鏂板鏂瑰紡淇敼 + getSelectArray(val, index) { + console.log(val, "ddd99999") + if (this.tableData.length == 1 && this.tableData[0].number.length == 0) { + this.tableData = [] + } + if (index < this.tableData.length) { + this.tableData.splice(index, 1) + val.map((item, ind) => { + this.tableData.splice(index + ind, 0, item) + }) + } else { + this.tableData = this.tableData.concat(val) + } + this.productTableList.tableData = this.tableData + // this.showSummary.show = true }, // 浜у搧娓呯┖ emptyProductClick() { @@ -180,8 +247,11 @@ desc: "", name: "", number: "", - price: 0, - total: 0 + purchasePrice: 0, + total: 0, + deliveryTime: 0, + shippingDuration: 0, + supplierId: this.supplierId } ] this.productTableList.tableData = this.tableData @@ -190,6 +260,11 @@ clearupProduct(data) { this.tableData = data this.productTableList.tableData = this.tableData + }, + selCommonName(row) { + console.log("1133") + console.log(row) + this.editConfig.infomation = row } } } -- Gitblit v1.8.0