From 86d49bfd45dff8e89b7a102eeeff3e2fe86b7871 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期四, 08 一月 2026 18:08:47 +0800
Subject: [PATCH] 1、华玺砂浆采购代码移植至军泰伟业 2、华玺砂浆发货和发货审核代码移植至军泰伟业 3、华玺砂浆报修和报修审核代码移植至军泰伟业

---
 src/views/procurementManagement/procurementLedger/index.vue |  393 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 340 insertions(+), 53 deletions(-)

diff --git a/src/views/procurementManagement/procurementLedger/index.vue b/src/views/procurementManagement/procurementLedger/index.vue
index abdc474..7b81814 100644
--- a/src/views/procurementManagement/procurementLedger/index.vue
+++ b/src/views/procurementManagement/procurementLedger/index.vue
@@ -238,16 +238,25 @@
             </el-form-item>
           </el-col>
 					<el-col :span="12">
-						<el-form-item label="浠樻鏂瑰紡">
-							<el-input
-								v-model="form.paymentMethod"
-								placeholder="璇疯緭鍏�"
-								clearable
-							/>
-						</el-form-item>
+            <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="浠樻鏂瑰紡">
+              <el-input
+                  v-model="form.paymentMethod"
+                  placeholder="璇疯緭鍏�"
+                  clearable
+              />
+            </el-form-item>
+          </el-col>
 					<el-col :span="12">
 						<el-form-item label="绛捐鏃ユ湡锛�" prop="executionDate">
 							<el-date-picker
@@ -264,14 +273,26 @@
 				</el-row>
         <el-row :gutter="30">
           <el-col :span="12">
-            <el-form-item label="褰曞叆浜猴細" prop="recorderId">
+            <el-form-item label="瀹℃壒浜猴細" prop="approverId">
               <el-select
-                v-model="form.recorderId"
-                placeholder="璇烽�夋嫨"
-                clearable
-                filterable
-                default-first-option
-                :reserve-keyword="false"
+                  v-model="form.approverId"
+                  placeholder="璇烽�夋嫨瀹℃壒浜�"
+                  clearable
+              >
+                <el-option
+                    v-for="item in userList"
+                    :key="item.userId"
+                    :label="item.nickName"
+                    :value="item.userId"
+                />
+              </el-select>
+            </el-form-item>
+            <el-form-item label="褰曞叆浜猴細" prop="recorderId" v-show="false">
+              <el-select
+                  v-model="form.recorderId"
+                  placeholder="璇烽�夋嫨"
+                  clearable
+                  disabled
               >
                 <el-option
                   v-for="item in userList"
@@ -305,6 +326,37 @@
               >鍒犻櫎</el-button
             >
           </el-form-item>
+          <div class="select-button-group" style="width: 220px; margin: 20px 0;" v-if="operationType === 'add'">
+            <el-select
+                filterable
+                allow-create
+                :reserve-keyword="true"
+                :default-first-option="false"
+                v-model="templateName"
+                :input-value="filterInputValue"
+                @filter-change="onTemplateFilterChange"
+                @change="onTemplateChange"
+                style="width: 180px; border-right: none; border-radius: 4px 0 0 4px;"
+                placeholder="璇烽�夋嫨"
+                class="no-arrow-select"
+            >
+              <el-option
+                  v-for="item in templateList"
+                  :key="item.value"
+                  :label="item.templateName"
+                  :value="item.templateName"
+              ></el-option>
+            </el-select>
+            <!-- 鎸夐挳锛氫笌 Select 楂樺害鍖归厤锛屽幓鎺夊乏渚ц竟妗嗭紝鏃犵紳琛旀帴 -->
+            <el-button
+                size="small"
+                style="height: 32px; border-radius: 0 4px 4px 0; margin-left: -1px;"
+                @click="handleButtonClick"
+                :disabled="!templateName || templateName.trim() === '' || isTemplateNameDuplicate"
+            >
+              淇濆瓨
+            </el-button>
+          </div>
         </el-row>
         <el-table
           :data="productData"
@@ -776,7 +828,7 @@
 import pagination from "@/components/PIMTable/Pagination.vue";
 import { ref, onMounted, reactive, toRefs, getCurrentInstance, nextTick } from "vue";
 import { Search } from "@element-plus/icons-vue";
-import { ElMessageBox } from "element-plus";
+import { ElMessageBox,ElMessage } from "element-plus";
 import { userListNoPage } from "@/api/system/user.js";
 import FileList from "./fileList.vue";
 import {
@@ -795,6 +847,8 @@
   getPurchaseById,
   getOptions,
   createPurchaseNo,
+  getPurchaseTemplateList,
+  addPurchaseTemplate,
 } from "@/api/procurementManagement/procurementLedger.js";
 import useFormData from "@/hooks/useFormData.js";
 import QRCode from "qrcode";
@@ -825,6 +879,103 @@
 const qrCodeDialogVisible = ref(false);
 const qrCodeUrl = ref("");
 
+// 璁㈠崟瀹℃壒鐘舵�佹樉绀烘枃鏈�
+const approvalStatusText = {
+  0: '瀹℃壒涓�',
+  1: '瀹℃壒閫氳繃',
+  2: '瀹℃壒澶辫触'
+};
+
+
+const templateName = ref('');
+const filterInputValue = ref('');
+const templateList = ref([]);
+const isTemplateNameDuplicate = ref(false); // 鏍囪妯℃澘鍚嶇О鏄惁閲嶅
+
+// 妫�鏌ユā鏉垮悕绉版槸鍚﹂噸澶�
+const checkTemplateNameDuplicate = (name) => {
+  if (!name || name.trim() === '') {
+    isTemplateNameDuplicate.value = false;
+    return false;
+  }
+  const isDuplicate = templateList.value.some(item => item.templateName === name.trim());
+  isTemplateNameDuplicate.value = isDuplicate;
+  return isDuplicate;
+};
+
+// 闃叉姈瀹氭椂鍣�
+let duplicateCheckTimer = null;
+const onTemplateFilterChange = (val) => {
+  filterInputValue.value = val ?? '';
+  // 娓呴櫎涔嬪墠鐨勫畾鏃跺櫒
+  if (duplicateCheckTimer) {
+    clearTimeout(duplicateCheckTimer);
+  }
+  // 瀹炴椂妫�鏌ユā鏉垮悕绉版槸鍚﹂噸澶嶏紙闃叉姈澶勭悊锛岄伩鍏嶉绻佹彁绀猴級
+  if (val && val.trim()) {
+    duplicateCheckTimer = setTimeout(() => {
+      const isDuplicate = checkTemplateNameDuplicate(val);
+      if (isDuplicate) {
+        ElMessage({
+          message: '妯℃澘鍚嶇О宸插瓨鍦紝璇锋洿鎹㈡ā鏉垮悕绉�',
+          type: 'warning',
+          duration: 2000
+        });
+      }
+    }, 300); // 300ms 闃叉姈
+  } else {
+    isTemplateNameDuplicate.value = false;
+  }
+};
+
+// allow-create 鏃讹紝杈撳叆涓嶅瓨鍦ㄧ殑鍐呭浼氫綔涓� string 鍊艰繑鍥烇紱杩欓噷鍚屾鍥炶緭鍏ユ浠ョ‘淇濇枃瀛椾笉涓�
+const onTemplateChange = async (val) => {
+  if (typeof val === 'string') {
+    filterInputValue.value = val;
+    // 閫夋嫨鎴栬緭鍏ユ椂妫�鏌ラ噸澶�
+    checkTemplateNameDuplicate(val);
+  }
+
+  // 杩囨护鏁版嵁锛屾煡鎵惧尮閰嶇殑妯℃澘
+  const matchedTemplate = templateList.value.find(item => item.templateName === val);
+
+  if (matchedTemplate?.id) {
+    // 濡傛灉鎵惧埌妯℃澘锛屽姞杞芥ā鏉挎暟鎹�
+    form.value = {
+      ...form.value,
+      ...matchedTemplate,
+    };
+    productData.value = matchedTemplate.productData || [];
+    // 鐢熸垚鏂扮殑閲囪喘鍚堝悓鍙�
+    try {
+      const res = await createPurchaseNo();
+      if (res?.data) {
+        form.value.purchaseContractNumber = res.data;
+      }
+    } catch (error) {
+      console.error('鐢熸垚閲囪喘鍚堝悓鍙峰け璐�:', error);
+    }
+  } else {
+    // 濡傛灉娌℃湁鎵惧埌妯℃澘锛岄噸缃〃鍗曪紙淇濇寔褰撳墠琛ㄥ崟鐘舵�侊級
+    const currentFormData = { ...form.value };
+    const currentProductData = [...productData.value];
+
+    // 濡傛灉瀵硅瘽妗嗘湭鎵撳紑锛屽厛鎵撳紑
+    if (!dialogFormVisible.value) {
+      operationType.value = 'add';
+      dialogFormVisible.value = true;
+    }
+
+    // 绛夊緟涓嬩竴涓� tick 鍚庢仮澶嶆暟鎹�
+    await nextTick();
+    form.value = {
+      ...form.value,
+      ...currentFormData,
+    };
+    productData.value = currentProductData;
+  }
+};
+
 // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁
 const operationType = ref("");
 const dialogFormVisible = ref(false);
@@ -852,7 +1003,8 @@
     purchaseContractNumber: [
       { required: true, message: "璇疯緭鍏�", trigger: "blur" },
     ],
-    supplierId: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
+    approverId:[{ required: true, message: "璇烽�夋嫨瀹℃壒浜�", trigger: "change" }],
+    projectName:[{ required:true, message:"璇疯緭鍏ラ」鐩悕绉�", trigger:"blur"}],
 		entryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
 		executionDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
   },
@@ -933,6 +1085,83 @@
   page.current = 1;
   getList();
 };
+
+// 淇濆瓨妯℃澘
+const handleButtonClick = async () => {
+  // 妫�鏌ユā鏉垮悕绉版槸鍚︿负绌�
+  if (!templateName.value || templateName.value.trim() === '') {
+    ElMessage({
+      message: '璇疯緭鍏ユā鏉垮悕绉�',
+      type: 'warning',
+    });
+    return;
+  }
+
+  // 妫�鏌ユā鏉垮悕绉版槸鍚﹂噸澶�
+  const isDuplicate = checkTemplateNameDuplicate(templateName.value);
+  if (isDuplicate) {
+    ElMessage({
+      message: '妯℃澘鍚嶇О宸插瓨鍦紝璇锋洿鎹㈡ā鏉垮悕绉�',
+      type: 'warning',
+    });
+    return;
+  }
+
+  // 妫�鏌ヤ緵搴斿晢鏄惁閫夋嫨
+  if (!form.value.supplierId) {
+    ElMessage({
+      message: '璇峰厛閫夋嫨渚涘簲鍟�',
+      type: 'warning',
+    });
+    return;
+  }
+
+  // 妫�鏌ユ槸鍚︽湁浜у搧鏁版嵁
+  // if (!productData.value || productData.value.length === 0) {
+  //   ElMessage({
+  //     message: '璇峰厛娣诲姞浜у搧淇℃伅',
+  //     type: 'warning',
+  //   });
+  //   return;
+  // }
+
+  try {
+    let params = {
+      productData: proxy.HaveJson(productData.value),
+      supplierId: form.value.supplierId,
+      paymentMethod: form.value.paymentMethod,
+      recorderId: form.value.recorderId,
+      approverId: form.value.approverId,
+      templateName: templateName.value.trim()
+    };
+    console.log(params);
+    let res = await addPurchaseTemplate(params);
+
+    if (res && res.code === 200) {
+      ElMessage({
+        message: '妯℃澘淇濆瓨鎴愬姛',
+        type: 'success',
+      });
+      // 淇濆瓨鎴愬姛鍚庨噸鏂拌幏鍙栨ā鏉垮垪琛�
+      await getTemplateList();
+      // 娓呯┖妯℃澘鍚嶇О杈撳叆
+      templateName.value = '';
+      filterInputValue.value = '';
+      isTemplateNameDuplicate.value = false;
+    } else {
+      ElMessage({
+        message: res?.msg || '妯℃澘淇濆瓨澶辫触',
+        type: 'error',
+      });
+    }
+  } catch (error) {
+    console.error('淇濆瓨妯℃澘澶辫触:', error);
+    ElMessage({
+      message: '妯℃澘淇濆瓨澶辫触锛岃绋嶅悗閲嶈瘯',
+      type: 'error',
+    });
+  }
+};
 // 瀛愯〃鍚堣鏂规硶
 const summarizeChildrenTable = (param) => {
   return proxy.summarizeTable(
@@ -983,19 +1212,24 @@
 };
 const expandedRowKeys = ref([]);
 // 灞曞紑琛�
-const expandChange = (row, expandedRows) => {
+const expandChange = async (row, expandedRows) => {
   if (expandedRows.length > 0) {
     expandedRowKeys.value = [];
     try {
-      productList({ salesLedgerId: row.id, type: 2 }).then((res) => {
-        const index = tableData.value.findIndex((item) => item.id === row.id);
-        if (index > -1) {
-          tableData.value[index].children = res.data;
-        }
+      const res = await productList({ salesLedgerId: row.id, type: 2 });
+      const index = tableData.value.findIndex((item) => item.id === row.id);
+      if (index > -1) {
+        tableData.value[index].children = res.data || [];
         expandedRowKeys.value.push(row.id);
-      });
+      }
     } catch (error) {
-      console.log(error);
+      console.error('鍔犺浇浜у搧鍒楄〃澶辫触:', error);
+      proxy.$modal.msgError('鍔犺浇浜у搧鍒楄〃澶辫触');
+      // 灞曞紑澶辫触鏃讹紝绉婚櫎灞曞紑鐘舵��
+      const index = expandedRows.findIndex(item => item.id === row.id);
+      if (index > -1) {
+        expandedRows.splice(index, 1);
+      }
     }
   } else {
     expandedRowKeys.value = [];
@@ -1014,40 +1248,63 @@
   ]);
 };
 // 鎵撳紑寮规
-const openForm = (type, row) => {
+const openForm = async (type, row) => {
+  await getTemplateList()
   operationType.value = type;
   form.value = {};
   productData.value = [];
   fileList.value = [];
-  if (operationType.value == "add") {
-    createPurchaseNo().then((res) => {
-      form.value.purchaseContractNumber = res.data;
-    });
-  }
-  userListNoPage().then((res) => {
-    userList.value = res.data;
-  });
-  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) => {
-      form.value = { ...res };
-      productData.value = form.value.productData;
-      if (form.value.salesLedgerFiles) {
-        fileList.value = form.value.salesLedgerFiles;
-      } else {
-        fileList.value = [];
+  templateName.value = '';
+  filterInputValue.value = '';
+  isTemplateNameDuplicate.value = false;
+  try {
+    // 骞惰鍔犺浇鍩虹鏁版嵁
+    const [userRes, salesRes, supplierRes] = await Promise.all([
+      userListNoPage(),
+      getSalesNo(),
+      getOptions()
+    ]);
+
+    userList.value = userRes.data || [];
+    salesContractList.value = salesRes || [];
+    // 渚涘簲鍟嗚繃婊ゅ嚭isWhite=0 鐨勬暟鎹�
+    supplierList.value = (supplierRes.data || []).filter((item) => item.isWhite === 0);
+
+    // 璁剧疆榛樿鍊�
+    form.value.recorderId = userStore.id;
+    form.value.entryDate = getCurrentDate();
+
+    if (type === "add") {
+      // 鏂板鏃剁敓鎴愰噰璐悎鍚屽彿
+      try {
+        const purchaseNoRes = await createPurchaseNo();
+        if (purchaseNoRes?.data) {
+          form.value.purchaseContractNumber = purchaseNoRes.data;
+        }
+      } catch (error) {
+        console.error('鐢熸垚閲囪喘鍚堝悓鍙峰け璐�:', error);
+        proxy.$modal.msgWarning('鐢熸垚閲囪喘鍚堝悓鍙峰け璐�');
       }
-    });
+    } else if (type === "edit" && row?.id) {
+      // 缂栬緫鏃跺姞杞芥暟鎹�
+      currentId.value = row.id;
+      try {
+        const purchaseRes = await getPurchaseById({ id: row.id, type: 2 });
+        form.value = { ...purchaseRes };
+        productData.value = purchaseRes.productData || [];
+        fileList.value = purchaseRes.salesLedgerFiles || [];
+      } catch (error) {
+        console.error('鍔犺浇閲囪喘鍙拌处鏁版嵁澶辫触:', error);
+        proxy.$modal.msgError('鍔犺浇鏁版嵁澶辫触');
+        return;
+      }
+    }
+
+    dialogFormVisible.value = true;
+  } catch (error) {
+    console.error('鎵撳紑琛ㄥ崟澶辫触:', error);
+    proxy.$modal.msgError('鍔犺浇鍩虹鏁版嵁澶辫触');
   }
-  dialogFormVisible.value = true;
 };
 // 涓婁紶鍓嶆牎妫�
 function handleBeforeUpload(file) {
@@ -1586,11 +1843,41 @@
   return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
 }
 
+// 娣诲姞琛岀被鍚嶆柟娉�
+const tableRowClassName = ({ row }) => {
+  return row.isInvalid ? 'invalid-row' : '';
+};
 
+// 鑾峰彇妯℃澘淇℃伅
+const getTemplateList =async ()=>{
+  let res = await getPurchaseTemplateList()
+  if(res && res.code===200 && Array.isArray(res.data)){
+    templateList.value = res.data
+  }
+}
 
 onMounted(() => {
   getList();
+  getTemplateList();
+
 });
 </script>
 
-<style scoped lang="scss"></style>
\ No newline at end of file
+<style scoped lang="scss">
+.invalid-row {
+  opacity: 0.6;
+  background-color: #f5f7fa;
+}
+.el-row{
+  justify-content: space-between;
+  align-items: center
+}
+.no-arrow-select {
+  --el-select-suffix-icon-color: transparent; /* 闅愯棌榛樿涓嬫媺绠ご */
+}
+.select-button-group {
+  display: flex;
+  align-items: center;
+}
+
+</style>

--
Gitblit v1.9.3