From 941b7b96eb85d896a47a9457e1deb3aed1937775 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期一, 27 十月 2025 09:21:56 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 src/views/inventoryManagement/stockManagement/index.vue |  197 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 143 insertions(+), 54 deletions(-)

diff --git a/src/views/inventoryManagement/stockManagement/index.vue b/src/views/inventoryManagement/stockManagement/index.vue
index 53680f6..84dc029 100644
--- a/src/views/inventoryManagement/stockManagement/index.vue
+++ b/src/views/inventoryManagement/stockManagement/index.vue
@@ -19,41 +19,42 @@
         :summary-method="summarizeMainTable" height="calc(100vh - 18.5em)">
         <el-table-column align="center" type="selection" width="55" />
         <el-table-column align="center" label="搴忓彿" type="index" width="60" />
-        <el-table-column label="搴撳瓨鏃ユ湡" prop="boundTime" width="100" show-overflow-tooltip />
-        <el-table-column label="鍏ュ簱鏃ユ湡" prop="inboundTime" width="100" show-overflow-tooltip />
-        <el-table-column label="渚涘簲鍟嗗悕绉�" prop="supplierName" width="160" show-overflow-tooltip />
-        <el-table-column label="浜у搧澶х被" prop="productName" width="100" show-overflow-tooltip />
-        <el-table-column label="瑙勬牸鍨嬪彿" prop="model" width="100" show-overflow-tooltip />
+        <el-table-column label="搴撳瓨鏃ユ湡" prop="createTime" width="100" show-overflow-tooltip />
+        <el-table-column label="鍏ュ簱鏃ユ湡" prop="createTime" width="100" show-overflow-tooltip />
+        <el-table-column label="渚涘簲鍟嗗悕绉�" prop="supplierName" width="240" show-overflow-tooltip />
+        <el-table-column label="浜у搧澶х被" prop="productCategory" width="100" show-overflow-tooltip />
+        <el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" width="200" show-overflow-tooltip />
         <el-table-column label="鍗曚綅" prop="unit" width="80" show-overflow-tooltip />
-        <el-table-column label="鍑哄簱鏁伴噺" prop="stockQuantity" width="100" show-overflow-tooltip />
+        <el-table-column label="搴撳瓨鏁伴噺" prop="inboundNum0" width="100" show-overflow-tooltip />
+        <el-table-column label="鏈�浣庡簱瀛樻暟閲�" prop="minStock" width="130" show-overflow-tooltip />
         <el-table-column label="鍚◣鍗曚环" prop="taxInclusiveUnitPrice" width="100" show-overflow-tooltip />
         <el-table-column label="鍚◣鎬讳环" prop="taxInclusiveTotalPrice" width="100" show-overflow-tooltip />
         <el-table-column label="绋庣巼(%)" prop="taxRate" width="100" show-overflow-tooltip />
         <el-table-column label="涓嶅惈绋庢�讳环" prop="taxExclusiveTotalPrice" width="100" show-overflow-tooltip />
-        <el-table-column label="鍏ュ簱浜�" prop="nickName" width="80" show-overflow-tooltip />
+        <el-table-column label="鍏ュ簱浜�" prop="createBy" width="80" show-overflow-tooltip />
         <el-table-column fixed="right" label="鎿嶄綔" min-width="60" align="center">
           <template #default="scope">
-            <el-button link type="primary" size="small" @click="openForm('edit', scope.row);">缂栬緫</el-button>
+            <el-button link type="primary" size="small" @click="openForm('edit', scope.row);" :disabled="scope.row.createUser !== userStore.id">缂栬緫</el-button>
           </template>
         </el-table-column>
       </el-table>
       <pagination v-show="total > 0" :total="total" layout="total, sizes, prev, pager, next, jumper"
         :page="page.current" :limit="page.size" @pagination="paginationChange" />
     </div>
-    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '鏂板鍑哄簱' : '缂栬緫鍑哄簱'" width="70%"
+    <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '鏂板搴撳瓨' : '缂栬緫搴撳瓨'" width="70%"
       @close="closeDia">
       <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="渚涘簲鍟嗗悕绉帮細" prop="supplierName">
-              <el-input v-model="form.supplierName" placeholder="璇疯緭鍏�" clearable />
+              <el-input disabled v-model="form.supplierName" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="浜у搧澶х被锛�" prop="productId">
-              <el-select v-model="form.productId" placeholder="璇烽�夋嫨" clearable filterable @change="handleProductChange">
+              <el-select disabled v-model="form.productCategory" placeholder="璇烽�夋嫨" clearable filterable @change="handleProductChange">
                 <el-option v-for="item in productList" :key="item.id" :label="item.productName"
-                           :value="item.id" />
+                           :value="item.productName" />
               </el-select>
             </el-form-item>
           </el-col>
@@ -61,7 +62,7 @@
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="productManageId">
-              <el-select v-model="form.productModelId" placeholder="璇峰厛閫夋嫨浜у搧澶х被" clearable filterable :disabled="!form.productId"
+              <el-select disabled v-model="form.specificationModel" placeholder="璇峰厛閫夋嫨浜у搧澶х被" clearable filterable :disabled="!form.productCategory"
                          @change="handleModelChange">
                 <el-option v-for="item in productModelList" :key="item.id" :label="item.model"
                            :value="item.id" />
@@ -69,21 +70,21 @@
             </el-form-item>
           </el-col>
           <el-col :span="12">
-            <el-form-item label="鍗曚綅锛�" prop="customerId">
-              <el-input v-model="form.unit" placeholder="璇疯緭鍏�" clearable />
+            <el-form-item  label="鍗曚綅锛�" prop="customerId">
+              <el-input disabled v-model="form.unit" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="30">
           <el-col :span="12">
             <el-form-item label="搴撳瓨鏃堕棿锛�" prop="projectName">
-              <el-date-picker style="width: 100%" v-model="form.boundTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
+              <el-date-picker style="width: 100%" v-model="form.updateTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                 type="date" placeholder="璇烽�夋嫨" clearable />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="鍏ュ簱鏃堕棿锛�" prop="projectName">
-              <el-date-picker style="width: 100%" v-model="form.inboundTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
+              <el-date-picker style="width: 100%" v-model="form.createTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                 type="date" placeholder="璇烽�夋嫨" clearable />
             </el-form-item>
           </el-col>
@@ -91,38 +92,42 @@
         <el-row :gutter="30">
 
           <el-col :span="12">
-            <el-form-item label="鍚◣鍗曚环锛�" prop="customerId">
-              <el-input v-model="form.taxInclusiveUnitPrice" placeholder="璇疯緭鍏�" clearable />
+            <el-form-item  label="鍚◣鍗曚环锛�" prop="customerId">
+              <el-input disabled v-model="form.taxInclusiveUnitPrice" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
           <el-col :span="12">
-            <el-form-item label="鍚◣鎬讳环锛�" prop="customerContractNo">
-              <el-input v-model="form.taxInclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable />
+            <el-form-item  label="鍚◣鎬讳环锛�" prop="customerContractNo">
+              <el-input disabled v-model="form.taxInclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="30">
 
           <el-col :span="12">
-            <el-form-item label="绋庣巼锛�" prop="customerId">
-              <el-input v-model="form.taxRate" placeholder="璇疯緭鍏�" clearable />
+            <el-form-item  label="绋庣巼锛�" prop="customerId">
+              <el-input disabled v-model="form.taxRate" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="涓嶅惈绋庢�讳环锛�" prop="entryDate">
-              <el-input v-model="form.taxExclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable />
+              <el-input disabled v-model="form.taxExclusiveTotalPrice" placeholder="璇疯緭鍏�" clearable />
             </el-form-item>
           </el-col>
         </el-row>
         <el-row :gutter="30">
-
           <el-col :span="12">
             <el-form-item label="鍑哄簱浜猴細" prop="entryPerson">
-              <el-select v-model="form.nickName" placeholder="璇烽�夋嫨" clearable>
+              <el-select v-model="form.createUser" placeholder="璇烽�夋嫨" clearable>
                 <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="minStock">
+            <el-input v-model="form.minStock" placeholder="璇疯緭鍏ユ渶浣庡簱瀛�" clearable />
+          </el-form-item>
+        </el-col>
         </el-row>
       </el-form>
       <template #footer>
@@ -140,19 +145,28 @@
 import { ref } from 'vue'
 import { ElMessageBox } from "element-plus";
 import useUserStore from '@/store/modules/user'
-import { userListNoPage } from "@/api/system/user.js";
+import { userListNoPageByTenantId } from "@/api/system/user.js";
+import { productTreeList,modelList } from "@/api/basicData/product.js"
 import {
   getStockManagePage ,
   updateStockManage,
   delStockManage,
   exportStockManage
 } from "@/api/inventoryManagement/stockManage.js";
+import {
+  updateManagement,addSutockIn,selectProductRecordListByPuechaserId,updateStockIn
+} from "@/api/inventoryManagement/stockIn.js";
+
+
+
 const userStore = useUserStore()
 const { proxy } = getCurrentInstance()
 const tableData = ref([])
 const productData = ref([])
 const selectedRows = ref([])
 const userList = ref([])
+const productList = ref([])
+const productModelList = ref([])
 // const customerOption = ref([])
 const tableLoading = ref(false)
 const page = reactive({
@@ -161,7 +175,7 @@
 })
 const total = ref(0)
 const fileList = ref([])
-
+const loading = ref(false);
 // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁
 const operationType = ref('')
 const dialogFormVisible = ref(false)
@@ -188,6 +202,8 @@
     inboundBatch: '',
     stockQuantity: '',
     boundTime: '',
+    minStock: '', // 鏂板鏈�浣庡簱瀛樺瓧娈�
+    salesLedgerProductId: null,
   },
   rules: {
     supplierName: [{ required: true, message: '璇疯緭鍏ヤ緵搴斿晢鍚嶇О', trigger: 'blur' }],
@@ -201,7 +217,8 @@
     taxExclusiveTotalPrice: [{ required: true, message: '璇疯緭鍏ヤ笉鍚◣鎬讳环', trigger: 'blur' }],
     boundTime: [{ required: true, message: '璇烽�夋嫨搴撳瓨鏃堕棿', trigger: 'change' }],
     inboundTime: [{ required: true, message: '璇烽�夋嫨鍏ュ簱鏃堕棿', trigger: 'change' }],
-    inboundPerson: [{ required: true, message: '璇烽�夋嫨鍑哄簱浜�', trigger: 'change' }]
+    inboundPerson: [{ required: true, message: '璇烽�夋嫨鍑哄簱浜�', trigger: 'change' }],
+    minStock: [{ required: true, message: '璇疯緭鍏ユ渶浣庡簱瀛�', trigger: 'blur' }], 
   }
 })
 const { searchForm, form, rules } = toRefs(data)
@@ -222,11 +239,13 @@
   getStockManagePage({ ...searchForm.value, ...page }).then(res => {
     tableLoading.value = false
     tableData.value = res.data.records
-    console.log('res', res)
+    // console.log('res', res)
     // tableData.value.map(item => {
     //   item.children = []
     // })
-    // total.value = res.total
+    total.value = res.data.total
+    // 鏁版嵁鍔犺浇瀹屾垚鍚庢鏌ュ簱瀛�
+    checkStockAndCreatePurchase();
   }).catch(() => {
     tableLoading.value = false
   })
@@ -251,7 +270,7 @@
   operationType.value = type
   form.value = {}
   productData.value = []
-  let userLists = await userListNoPage()
+  let userLists = await userListNoPageByTenantId()
   userList.value = userLists.data
   // customerList().then(res => {
   //   customerOption.value = res
@@ -259,13 +278,25 @@
   // console.log('userStore.id', userStore.id)
   // form.value.entryPerson = userStore.id
   if (type === 'edit') {
-    currentId.value = row.id;
-    getSalesLedgerWithProducts({ id: row.id, type: 1 }).then(res => {
-      form.value = { ...res }
-      form.value.entryPerson = Number(res.entryPerson)
-      productData.value = form.value.productData
-      fileList.value = form.value.salesLedgerFiles
+    form.value = { ...row }
+    productTreeList().then(res =>{
+      productList.value = res
+      productList.value.forEach(i =>{
+        if (i.label === row.productCategory) {
+          modelList({ id: i.id }).then((res) => {
+            productModelList.value = res;
+          });
+        }
+      })
     })
+
+
+    // getSalesLedgerWithProducts({ id: row.id, type: 1 }).then(res => {
+
+    //   form.value.entryPerson = Number(res.entryPerson)
+    //   productData.value = form.value.productData
+    //   fileList.value = form.value.salesLedgerFiles
+    // })
   }
   form.value.entryDate = getCurrentDate() // 璁剧疆榛樿褰曞叆鏃ユ湡涓哄綋鍓嶆棩鏈�
   dialogFormVisible.value = true
@@ -273,28 +304,72 @@
 
 // 鎻愪氦琛ㄥ崟
 const submitForm = () => {
+  console.log(form.value)
   proxy.$refs["formRef"].validate(valid => {
     if (valid) {
-      if (productData.value.length > 0) {
-        form.value.productData = proxy.HaveJson(productData.value)
-      } else {
-        proxy.$modal.msgWarning('璇锋坊鍔犱骇鍝佷俊鎭�')
-        return
-      }
-      let tempFileIds = []
-      if (fileList.value.length > 0) {
-        tempFileIds = fileList.value.map(item => item.tempId)
-      }
-      form.value.tempFileIds = tempFileIds
-      form.value.type = 1
-      addOrUpdateSalesLedger(form.value).then(res => {
+
+      updateManagement(form.value).then(res => {
         proxy.$modal.msgSuccess("鎻愪氦鎴愬姛")
         closeDia()
         getList()
+        // 鎻愪氦鍚庢鏌ュ簱瀛樺苟灏濊瘯鍒涘缓璇疯喘鍗�
+        checkStockAndCreatePurchase();
       })
     }
   })
 }
+// const handList = () => {
+//   selectProductRecordListByPuechaserId().then(res => {
+//     productModelList.value = res.data.filter(item => item.productName === value)
+//     console.log('productModelList.value', productModelList.value)
+//   })
+// } 
+// 妫�鏌ュ簱瀛樺苟鍒涘缓璇疯喘鍗�
+const checkStockAndCreatePurchase = async () => {
+  const stockList = tableData.value;
+  // handList()
+  for (const item of stockList) {
+    if (item.inboundNum0 < item.minStock) {
+      try {
+        console.log('item', item)
+          // const stockInData = {
+          //   nickName: userStore.nickName,// 浣跨敤鏂版牸寮忓寲鍑芥暟
+          //   details: [{
+          //     id: item.salesLedgerProductId,
+          //     inboundQuantity: item.minStock - item.inboundNum0
+          //   }]
+          // };
+          const stockInData = {
+            id: item.id,
+            quantityStock: item.minStock + item.totalInboundNum,// 浣跨敤鏂版牸寮忓寲鍑芥暟
+          };
+          
+
+        console.log('鍑嗗鎻愪氦鐨勬暟鎹�:', JSON.parse(JSON.stringify(stockInData)));
+
+          loading.value = true
+          // await addSutockIn(stockInData)
+          await updateStockIn(stockInData)
+          proxy.$modal.msgSuccess(`浜у搧 ${item.productCategory} 淇敼鍏ュ簱鎴愬姛`)
+          loading.value = false
+        // // 鐢熸垚璇疯喘鍗�
+        // const createRes = await createPurchaseRequest({
+        //   productId: item.productId,
+        //   requiredQuantity: item.minStock - item.inboundNum0,
+        //   supplierId: item.supplierId
+        // });
+        // if (createRes.code === 200) {
+        //   // 娴佽浆璇疯喘鍗曞埌閲囪喘妯″潡
+        //   await transferPurchaseRequest({ requestId: createRes.data.id });
+        //   proxy.$modal.msgSuccess(`浜у搧 ${item.productName} 璇疯喘鍗曞凡鐢熸垚骞舵祦杞琡);
+        // }
+      } catch (error) {
+        proxy.$modal.msgError(`浜у搧 ${item.productCategory} 鐢熸垚璇疯喘鍗曞け璐ワ紝璇锋墜鍔ㄥ鐞哷);
+
+      }
+    }
+  }
+};
 // 鍏抽棴寮规
 const closeDia = () => {
   proxy.resetForm("formRef")
@@ -304,14 +379,14 @@
 // 瀵煎嚭
 const handleOut = () => {
   ElMessageBox.confirm(
-    '閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�',
+    '鏄惁纭瀵煎嚭锛�',
     '瀵煎嚭', {
     confirmButtonText: '纭',
     cancelButtonText: '鍙栨秷',
     type: 'warning',
   }
   ).then(() => {
-    proxy.download("/stockmanagement/export", {}, '搴撳瓨淇℃伅.xlsx')
+    proxy.download("/stockin/exportCopy", {}, '搴撳瓨淇℃伅.xlsx')
   }).catch(() => {
     proxy.$modal.msg("宸插彇娑�")
   })
@@ -320,6 +395,12 @@
 const handleDelete = () => {
   let ids = []
   if (selectedRows.value.length > 0) {
+		// 妫�鏌ユ槸鍚︽湁浠栦汉缁存姢鐨勬暟鎹�
+		const unauthorizedData = selectedRows.value.filter(item => item.createUser !== userStore.id);
+		if (unauthorizedData.length > 0) {
+			proxy.$modal.msgWarning("涓嶅彲鍒犻櫎浠栦汉缁存姢鐨勬暟鎹�");
+			return;
+		}
     ids = selectedRows.value.map(item => item.id);
   } else {
     proxy.$modal.msgWarning('璇烽�夋嫨鏁版嵁')
@@ -333,7 +414,7 @@
     type: 'warning',
   }
   ).then(() => {
-    delStockManage(ids).then(res => {
+    delStockManage({ids:ids}).then(res => {
       proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛")
       getList()
     })
@@ -351,6 +432,14 @@
 }
 onMounted(() => {
   getList()
+  checkStockAndCreatePurchase();
+    // 姣忓皬鏃舵鏌ヤ竴娆″簱瀛�
+    const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000); 
+
+onUnmounted(() => {
+  // 缁勪欢鍗歌浇鏃舵竻闄ゅ畾鏃跺櫒
+  clearInterval(intervalId); 
+});
 })
 </script>
 

--
Gitblit v1.9.3