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, 57 insertions(+), 65 deletions(-) diff --git a/src/views/procurementManagement/procurementLedger/index.vue b/src/views/procurementManagement/procurementLedger/index.vue index 504bfa5..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="salesman" 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,8 +81,10 @@ </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"> @@ -95,7 +96,7 @@ <el-row :gutter="30"> <el-col :span="12"> <el-form-item label="褰曞叆浜猴細" prop="recorderId"> - <el-select v-model="form.recorderId" placeholder="璇烽�夋嫨" clearable> + <el-select v-model="form.recorderId" placeholder="璇烽�夋嫨" clearable disabled> <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"/> </el-select> </el-form-item> @@ -103,6 +104,7 @@ <el-col :span="12"> <el-form-item label="褰曞叆鏃ユ湡锛�" prop="entryDate"> <el-date-picker + disabled style="width: 100%" v-model="form.entryDate" value-format="YYYY-MM-DD" @@ -120,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" /> @@ -128,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> @@ -212,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"> @@ -228,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> @@ -273,7 +275,7 @@ delPurchase, getSalesNo, purchaseList, - productList, getPurchaseById + productList, getPurchaseById, getOptions } from "@/api/procurementManagement/procurementLedger.js"; const { proxy } = getCurrentInstance() const tableData = ref([]) @@ -282,6 +284,7 @@ const productSelectedRows = ref([]) const userList = ref([]) const salesContractList = ref([]) +const supplierList = ref([]) const tableLoading = ref(false) const page = reactive({ current: 1, @@ -289,6 +292,9 @@ }) const total = ref(0) const fileList = ref([]) +import useUserStore from "@/store/modules/user" + +const userStore = useUserStore() // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁 const operationType = ref('') @@ -303,20 +309,22 @@ projectName: '', recorderId: '', entryDate: '', - productData: [] + productData: [], + supplierName: '', + supplierId: '', }, rules: { purchaseContractNumber: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], salesLedgerId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }], projectName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }], - recorderId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }], - entryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }], + 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: { @@ -350,6 +358,9 @@ headers: { Authorization: "Bearer " + getToken() }, }) +const formattedNumber = (row, column, cellValue) => { + return parseFloat(cellValue).toFixed(2); +}; // 鏌ヨ鍒楄〃 /** 鎼滅储鎸夐挳鎿嶄綔 */ const handleQuery = () => { @@ -404,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 @@ -460,6 +433,11 @@ getSalesNo().then(res => { salesContractList.value = res }) + getOptions().then(res => { + supplierList.value = res.data + }) + form.value.recorderId = userStore.id + form.value.entryDate = getCurrentDate(); if (type === 'edit') { currentId.value = row.id; getPurchaseById({id: row.id, type: 2}).then(res => { @@ -477,7 +455,7 @@ // 涓婁紶鍓嶆牎妫� function handleBeforeUpload(file) { // 鏍℃鏂囦欢澶у皬 - if (file.size > 1024 * 1024) { + if (file.size > 1024 * 1024 * 10) { proxy.$modal.msgError('涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃10MB!') return false } @@ -541,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') { @@ -557,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() } } @@ -565,6 +548,7 @@ } const submitProductEdit = () => { productForm.value.salesLedgerId = currentId.value + productForm.value.type = 2 addOrUpdateSalesLedgerProduct(productForm.value).then(res => { proxy.$modal.msgSuccess("鎻愪氦鎴愬姛") closeProductDia() @@ -657,6 +641,14 @@ proxy.$modal.msg("宸插彇娑�") }) } +// 鑾峰彇褰撳墠鏃ユ湡骞舵牸寮忓寲涓� YYYY-MM-DD +function getCurrentDate() { + const today = new Date(); + const year = today.getFullYear(); + const month = String(today.getMonth() + 1).padStart(2, '0'); // 鏈堜唤浠�0寮�濮� + const day = String(today.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; +} getList() </script> -- Gitblit v1.9.3