From 7aa0e0f68d2a3d1268a64e49ab47c0c046265e84 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 20 五月 2025 11:48:23 +0800 Subject: [PATCH] 1.采购台账-开发联调 2.表格合计方法封装 --- src/views/procurementManagement/procurementLedger/index.vue | 122 ++++++++++++---------------------------- 1 files changed, 38 insertions(+), 84 deletions(-) diff --git a/src/views/procurementManagement/procurementLedger/index.vue b/src/views/procurementManagement/procurementLedger/index.vue index cc81c8e..887f786 100644 --- a/src/views/procurementManagement/procurementLedger/index.vue +++ b/src/views/procurementManagement/procurementLedger/index.vue @@ -40,9 +40,9 @@ <el-table-column label="鍗曚綅" prop="unit" /> <el-table-column label="鏁伴噺" prop="quantity" /> <el-table-column label="绋庣巼(%)" prop="taxRate" /> - <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" /> - <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" /> - <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" /> + <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber" /> + <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber" /> + <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber" /> </el-table> </template> </el-table-column> @@ -50,9 +50,8 @@ <el-table-column label="閲囪喘鍚堝悓鍙�" prop="purchaseContractNumber" show-overflow-tooltip/> <el-table-column label="閿�鍞悎鍚屽彿" prop="salesContractNo" show-overflow-tooltip/> <el-table-column label="渚涘簲鍟嗗悕绉�" prop="supplierName" show-overflow-tooltip/> - <el-table-column label="涓氬姟鍛�" prop="businessPerson" show-overflow-tooltip/> <el-table-column label="椤圭洰鍚嶇О" prop="projectName" show-overflow-tooltip/> - <el-table-column label="鍚堝悓閲戦(鍏�)" prop="contractAmount" show-overflow-tooltip/> + <el-table-column label="鍚堝悓閲戦(鍏�)" prop="contractAmount" show-overflow-tooltip :formatter="formattedNumber"/> <el-table-column label="褰曞叆浜�" prop="recorderName" show-overflow-tooltip/> <el-table-column label="褰曞叆鏃ユ湡" prop="entryDate" show-overflow-tooltip/> <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center"> @@ -82,27 +81,15 @@ </el-row> <el-row :gutter="30"> <el-col :span="12"> - <el-form-item label="渚涘簲鍟嗗悕绉帮細" prop="supplierName"> - <el-input v-model="form.supplierName" placeholder="璇疯緭鍏�" clearable/> + <el-form-item label="渚涘簲鍟嗗悕绉帮細" prop="supplierId"> + <el-select v-model="form.supplierId" placeholder="璇烽�夋嫨" clearable> + <el-option v-for="item in supplierList" :key="item.id" :label="item.supplierName" :value="item.id"/> + </el-select> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="椤圭洰鍚嶇О锛�" prop="projectName"> <el-input v-model="form.projectName" placeholder="璇疯緭鍏�" clearable/> - </el-form-item> - </el-col> - </el-row> - <el-row :gutter="30"> - <el-col :span="12"> - <el-form-item label="涓氬姟鍛橈細" prop="businessPersonId"> - <el-select v-model="form.businessPersonId" placeholder="璇烽�夋嫨" clearable @change="setPhone"> - <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"/> - </el-select> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="鐢佃瘽锛�" prop="phoneNumber"> - <el-input v-model="form.phoneNumber" placeholder="璇疯緭鍏�" clearable/> </el-form-item> </el-col> </el-row> @@ -135,7 +122,7 @@ <el-button plain type="danger" @click="deleteProduct">鍒犻櫎</el-button> </el-form-item> </el-row> - <el-table :data="productData" border @selection-change="productSelected"> + <el-table :data="productData" border @selection-change="productSelected" show-summary :summary-method="summarizeProTable"> <el-table-column align="center" type="selection" width="55" /> <el-table-column align="center" label="搴忓彿" type="index" width="60" /> <el-table-column label="浜у搧澶х被" prop="productCategory" /> @@ -143,12 +130,12 @@ <el-table-column label="鍗曚綅" prop="unit" /> <el-table-column label="鏁伴噺" prop="quantity" /> <el-table-column label="绋庣巼(%)" prop="taxRate" /> - <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" /> - <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" /> - <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" /> + <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" :formatter="formattedNumber"/> + <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" :formatter="formattedNumber"/> + <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="taxExclusiveTotalPrice" :formatter="formattedNumber"/> <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center"> <template #default="scope"> - <el-button link type="primary" size="small" @click="openProductForm('edit', scope.row);">缂栬緫</el-button> + <el-button link type="primary" size="small" @click="openProductForm('edit', scope.row, scope.$index);">缂栬緫</el-button> </template> </el-table-column> </el-table> @@ -227,7 +214,7 @@ <el-row :gutter="30"> <el-col :span="12"> <el-form-item label="鍚◣鍗曚环(鍏�)锛�" prop="taxInclusiveUnitPrice"> - <el-input v-model="productForm.taxInclusiveUnitPrice" placeholder="璇疯緭鍏�" clearable/> + <el-input-number v-model="productForm.taxInclusiveUnitPrice" :precision="2" :step="0.1" clearable style="width: 100%"/> </el-form-item> </el-col> <el-col :span="12"> @@ -243,12 +230,12 @@ <el-row :gutter="30"> <el-col :span="12"> <el-form-item label="鍚◣鎬讳环(鍏�)锛�" prop="taxInclusiveTotalPrice"> - <el-input v-model="productForm.taxInclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable/> + <el-input-number v-model="productForm.taxInclusiveTotalPrice" :precision="2" :step="0.1" clearable style="width: 100%"/> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="涓嶅惈绋庢�讳环(鍏�)锛�" prop="taxExclusiveTotalPrice"> - <el-input v-model="productForm.taxExclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable/> + <el-input-number v-model="productForm.taxExclusiveTotalPrice" :precision="2" :step="0.1" clearable style="width: 100%"/> </el-form-item> </el-col> </el-row> @@ -288,7 +275,7 @@ delPurchase, getSalesNo, purchaseList, - productList, getPurchaseById + productList, getPurchaseById, getOptions } from "@/api/procurementManagement/procurementLedger.js"; const { proxy } = getCurrentInstance() const tableData = ref([]) @@ -297,6 +284,7 @@ const productSelectedRows = ref([]) const userList = ref([]) const salesContractList = ref([]) +const supplierList = ref([]) const tableLoading = ref(false) const page = reactive({ current: 1, @@ -322,23 +310,21 @@ recorderId: '', entryDate: '', productData: [], - businessPersonId: '', - phoneNumber: '', supplierName: '', + supplierId: '', }, rules: { purchaseContractNumber: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], salesLedgerId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }], projectName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], - businessPersonId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }], - phoneNumber: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], - supplierName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], + supplierId: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], } }) const { searchForm, form, rules } = toRefs(data) // 浜у搧琛ㄥ崟寮规鏁版嵁 const productFormVisible = ref(false) const productOperationType = ref('') +const productOperationIndex = ref('') const currentId = ref('') const productFormData = reactive({ productForm: { @@ -372,7 +358,9 @@ headers: { Authorization: "Bearer " + getToken() }, }) - +const formattedNumber = (row, column, cellValue) => { + return parseFloat(cellValue).toFixed(2); +}; // 鏌ヨ鍒楄〃 /** 鎼滅储鎸夐挳鎿嶄綔 */ const handleQuery = () => { @@ -427,50 +415,12 @@ } // 涓昏〃鍚堣鏂规硶 const summarizeMainTable = (param) => { - const { columns, data } = param; - const sums = []; - columns.forEach((column, index) => { - if (index === 0) { - sums[index] = '鍚堣'; - return; - } - const prop = column.property; - if (['contractAmount'].includes(prop)) { - const values = data.map(item => Number(item[prop])); - if (!values.every(value => isNaN(value))) { - sums[index] = values.reduce((acc, val) => (!isNaN(val) ? acc + val : acc), 0); - } else { - sums[index] = ''; - } - } else { - sums[index] = ''; - } - }) - return sums; + return proxy.summarizeTable(param, ['contractAmount']); }; // 瀛愯〃鍚堣鏂规硶 -const summarizeChildrenTable = (param) => { - const { columns, data } = param; - const sums = []; - columns.forEach((column, index) => { - if (index === 0) { - sums[index] = '鍚堣'; - return; - } - const prop = column.property; - if (['taxInclusiveUnitPrice', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice'].includes(prop)) { - const values = data.map(item => Number(item[prop])); - if (!values.every(value => isNaN(value))) { - sums[index] = values.reduce((acc, val) => (!isNaN(val) ? acc + val : acc), 0); - } else { - sums[index] = ''; - } - } else { - sums[index] = ''; - } - }); - return sums; -} +const summarizeProTable = (param) => { + return proxy.summarizeTable(param, ['taxInclusiveUnitPrice', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice']); +}; // 鎵撳紑寮规 const openForm = (type, row) => { operationType.value = type @@ -482,6 +432,9 @@ }) getSalesNo().then(res => { salesContractList.value = res + }) + getOptions().then(res => { + supplierList.value = res.data }) form.value.recorderId = userStore.id form.value.entryDate = getCurrentDate(); @@ -498,10 +451,6 @@ }) } dialogFormVisible.value = true -} -// 璧嬪�肩數璇� -const setPhone = (id) => { - form.value.phoneNumber = userList.value.find(u => u.userId === id)?.phonenumber || ''; } // 涓婁紶鍓嶆牎妫� function handleBeforeUpload(file) { @@ -570,8 +519,9 @@ dialogFormVisible.value = false } // 鎵撳紑浜у搧寮规 -const openProductForm = (type, row) => { +const openProductForm = (type, row, index) => { productOperationType.value = type + productOperationIndex.value = index productForm.value = {} proxy.resetForm("productFormRef") if (type === 'edit') { @@ -586,7 +536,11 @@ if (operationType.value === "edit") { submitProductEdit() } else { - productData.value.push({...productForm.value}) + if (productOperationType.value === 'add') { + productData.value.push({...productForm.value}) + } else { + productData.value[productOperationIndex.value] = {...productForm.value} + } closeProductDia() } } -- Gitblit v1.9.3