From f7cd57455346e4fd7085eae8bcf7b01a75c94d25 Mon Sep 17 00:00:00 2001
From: 周宾 <2802492122@qq.com>
Date: 星期一, 22 十二月 2025 16:35:11 +0800
Subject: [PATCH] 海川开心-协同办公-报销管理金额显示

---
 src/views/inventoryManagement/stockManagement/index.vue |  664 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 446 insertions(+), 218 deletions(-)

diff --git a/src/views/inventoryManagement/stockManagement/index.vue b/src/views/inventoryManagement/stockManagement/index.vue
index ec95b99..00c037c 100644
--- a/src/views/inventoryManagement/stockManagement/index.vue
+++ b/src/views/inventoryManagement/stockManagement/index.vue
@@ -1,154 +1,225 @@
 <template>
   <div class="app-container">
-    <div class="search_form">
-      <div>
-        <span class="search_title">渚涘簲鍟嗗悕绉帮細</span>
-        <el-input v-model="searchForm.customerName" style="width: 240px" placeholder="璇疯緭鍏�" @change="handleQuery"
-          clearable prefix-icon="Search" />
-        <el-button type="primary" @click="handleQuery" style="margin-left: 10px">鎼滅储</el-button>
-      </div>
-      <div>
-        <!-- <el-button type="primary" @click="openForm('add')">鏂板</el-button> -->
-        <el-button @click="handleOut">瀵煎嚭</el-button>
-        <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>
-      </div>
-    </div>
-    <div class="table_list">
-      <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
-        :expand-row-keys="expandedRowKeys" :row-key="row => row.id" show-summary style="width: 100%"
-        :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="salesContractNo" width="100" show-overflow-tooltip />
-        <el-table-column label="鍏ュ簱鏃ユ湡" prop="salesContractNo" width="100" show-overflow-tooltip />
-        <el-table-column label="渚涘簲鍟嗗悕绉�" prop="customerName" width="160" show-overflow-tooltip />
-        <el-table-column label="浜у搧澶х被" prop="salesman" width="100" show-overflow-tooltip />
-        <el-table-column label="瑙勬牸鍨嬪彿" prop="projectName" width="100" show-overflow-tooltip />
-        <el-table-column label="鍗曚綅" prop="contractAmount" width="80" show-overflow-tooltip />
-        <el-table-column label="鍑哄簱鏁伴噺" prop="entryPersonName" width="100" show-overflow-tooltip />
-        <el-table-column label="鍚◣鍗曚环(鍏�)" prop="entryDate" width="100" show-overflow-tooltip />
-        <el-table-column label="鍚◣鎬讳环(鍏�)" prop="executionDate" width="100" show-overflow-tooltip />
-        <el-table-column label="绋庣巼(%)" prop="executionDate" width="100" show-overflow-tooltip />
-        <el-table-column label="涓嶅惈绋庢�讳环(鍏�)" prop="executionDate" width="180" show-overflow-tooltip />
-        <el-table-column label="鍏ュ簱浜�" prop="executionDate" 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>
-          </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%"
-      @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="salesContractNo">
-              <el-input v-model="form.salesContractNo" placeholder="璇疯緭鍏�" clearable />
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="浜у搧澶х被锛�" prop="salesman">
-              <el-select v-model="form.salesman" placeholder="璇烽�夋嫨" clearable>
-                <el-option v-for="item in userList" :key="item.nickName" :label="item.nickName"
-                  :value="item.nickName" />
-              </el-select>
-            </el-form-item>
-          </el-col>
-        </el-row>
-        <el-row :gutter="30">
-          <el-col :span="12">
-            <el-form-item label="瑙勬牸鍨嬪彿锛�" prop="customerContractNo">
-              <el-input v-model="form.customerContractNo" placeholder="璇疯緭鍏�" clearable />
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="鍗曚綅锛�" prop="customerId">
-              <el-input v-model="form.customerContractNo" 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.entryDate" 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="customerContractNo">
-              <el-input v-model="form.customerContractNo" 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.customerContractNo" placeholder="璇疯緭鍏�" clearable />
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="鍚◣鎬讳环锛�" prop="customerContractNo">
-              <el-input v-model="form.customerContractNo" 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.customerContractNo" placeholder="璇疯緭鍏�" clearable />
-            </el-form-item>
-          </el-col>
-          <el-col :span="12">
-            <el-form-item label="涓嶅惈绋庢�讳环锛�" prop="entryDate">
-              <el-input v-model="form.customerContractNo" 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.entryPerson" 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-row>
-      </el-form>
-      <template #footer>
-        <div class="dialog-footer">
-          <el-button type="primary" @click="submitForm">纭</el-button>
-          <el-button @click="closeDia">鍙栨秷</el-button>
+    <el-tabs v-model="activeTab" @tab-change="handleTabChange">
+      <el-tab-pane label="鎴愬搧搴撳瓨" name="production">
+        <div class="search_form">
+          <div>
+            <span class="search_title ml10">鍏ュ簱鏃ユ湡锛�</span>
+            <el-date-picker
+              v-model="searchForm.timeStr"
+              type="date"
+              placeholder="璇烽�夋嫨鏃ユ湡"
+              value-format="YYYY-MM-DD"
+              format="YYYY-MM-DD"
+              clearable
+              @change="handleQuery"
+            />
+							<span class="search_title ml10">浜у搧澶х被锛�</span>
+							<el-input
+								v-model="searchForm.productCategory"
+								style="width: 240px"
+								placeholder="璇疯緭鍏�"
+								clearable
+							/>
+            <el-button type="primary" @click="handleQuery" style="margin-left: 10px">鎼滅储</el-button>
+          </div>
+          <div>
+            <el-button @click="handleOut">瀵煎嚭</el-button>
+<!--            <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>-->
+          </div>
         </div>
-      </template>
-    </el-dialog>
+        <div class="table_list">
+          <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
+            :expand-row-keys="expandedRowKeys" :row-key="row => row.id" show-summary style="width: 100%"
+            :row-class-name="tableRowClassName"
+            :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="createTime" width="100" show-overflow-tooltip />
+						<el-table-column label="閿�鍞悎鍚屽彿" prop="salesContractNo" width="180" show-overflow-tooltip />
+            <el-table-column label="浜у搧澶х被" prop="productCategory" show-overflow-tooltip />
+            <el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" show-overflow-tooltip />
+            <el-table-column label="鍗曚綅" prop="unit" width="80" show-overflow-tooltip />
+            <el-table-column label="宸插嚭搴撴暟閲�" prop="totalInboundNum" width="100" show-overflow-tooltip />
+            <el-table-column label="鍓╀綑搴撳瓨" prop="inboundNum0" width="100" show-overflow-tooltip />
+							<el-table-column label="鍗曚环(鍏�)" prop="unitPrice" width="150"></el-table-column>
+							<el-table-column label="鎬讳环(鍏�)" prop="totalPrice" width="150"></el-table-column>
+            <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>
+              </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-tab-pane>
+
+     <el-tab-pane label="鍘熸枡搴撳瓨" name="purchase">
+       <div class="search_form">
+         <div>
+           <span class="search_title ml10">鍏ュ簱鏃ユ湡锛�</span>
+           <el-date-picker
+             v-model="searchForm.timeStr"
+             type="date"
+             placeholder="璇烽�夋嫨鏃ユ湡"
+             value-format="YYYY-MM-DD"
+             format="YYYY-MM-DD"
+             clearable
+             @change="handleQuery"
+           />
+							<span class="search_title ml10">浜у搧澶х被锛�</span>
+							<el-input
+								v-model="searchForm.productCategory"
+								style="width: 240px"
+								placeholder="璇疯緭鍏�"
+								clearable
+							/>
+           <el-button type="primary" @click="handleQuery" style="margin-left: 10px">鎼滅储</el-button>
+         </div>
+         <div>
+           <el-button @click="handleOut">瀵煎嚭</el-button>
+<!--           <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>-->
+         </div>
+       </div>
+       <div class="table_list">
+         <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
+           :expand-row-keys="expandedRowKeys" :row-key="row => row.id" show-summary style="width: 100%"
+           :row-class-name="tableRowClassName"
+           :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="createTime" width="100" show-overflow-tooltip />
+					 <el-table-column label="閲囪喘鍚堝悓鍙�" prop="purchaseContractNumber" width="180" show-overflow-tooltip />
+           <el-table-column label="浜у搧澶х被" prop="productCategory" show-overflow-tooltip />
+           <el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" show-overflow-tooltip />
+           <el-table-column label="鍗曚綅" prop="unit" width="80" show-overflow-tooltip />
+							<el-table-column label="宸插嚭搴撴暟閲�" prop="totalInboundNum" show-overflow-tooltip />
+							<el-table-column label="鍓╀綑搴撳瓨" prop="inboundNum0" show-overflow-tooltip />
+						 <el-table-column label="鍚◣鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" width="150"></el-table-column>
+						 <el-table-column label="鍚◣鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" width="150"></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-tab-pane>
+
+      <el-tab-pane label="鏉愭枡搴撳瓨" name="manual">
+        <div class="search_form">
+          <div>
+            <span class="search_title ml10">鍏ュ簱鏃ユ湡锛�</span>
+            <el-date-picker
+              v-model="searchForm.timeStr"
+              type="date"
+              placeholder="璇烽�夋嫨鏃ユ湡"
+              value-format="YYYY-MM-DD"
+              format="YYYY-MM-DD"
+              clearable
+              @change="handleQuery"
+            />
+							<span class="search_title ml10">浜у搧澶х被锛�</span>
+							<el-input
+								v-model="searchForm.productCategory"
+								style="width: 240px"
+								placeholder="璇疯緭鍏�"
+								clearable
+							/>
+            <el-button type="primary" @click="handleQuery" style="margin-left: 10px">鎼滅储</el-button>
+          </div>
+          <div>
+            <el-button @click="handleOut">瀵煎嚭</el-button>
+<!--            <el-button type="danger" plain @click="handleDelete">鍒犻櫎</el-button>-->
+          </div>
+        </div>
+        <div class="table_list">
+          <el-table :data="tableData" border v-loading="tableLoading" @selection-change="handleSelectionChange"
+            :expand-row-keys="expandedRowKeys" :row-key="row => row.id" show-summary style="width: 100%"
+            :row-class-name="tableRowClassName"
+            :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="inboundDate" width="100" show-overflow-tooltip />
+						<el-table-column label="鎵规鍙�" prop="code" width="130" show-overflow-tooltip />
+            <el-table-column label="浜у搧澶х被" prop="productCategory" show-overflow-tooltip />
+            <el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" show-overflow-tooltip />
+            <el-table-column label="鍗曚綅" prop="unit" width="80" show-overflow-tooltip />
+            <el-table-column label="鐗╁搧绫诲瀷" prop="itemType" width="120" show-overflow-tooltip />
+							<el-table-column label="宸插嚭搴撴暟閲�" prop="totalInboundNum" width="100" show-overflow-tooltip />
+							<el-table-column label="鍓╀綑搴撳瓨" prop="inboundNum0" width="100" show-overflow-tooltip />
+							<el-table-column label="鍗曚环(鍏�)" prop="taxInclusiveUnitPrice" width="150"></el-table-column>
+							<el-table-column label="鎬讳环(鍏�)" prop="taxInclusiveTotalPrice" width="150"></el-table-column>
+            <el-table-column fixed="right" label="鎿嶄綔" width="100" align="center">
+              <template #default="scope">
+                <el-button link type="primary" size="small" @click="openForm('edit', scope.row);">缂栬緫</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-tab-pane>
+    </el-tabs>
+    
+    <!-- 鎴愬搧搴撳瓨寮规 -->
+    <FormDiaProduction 
+      v-model:dialogFormVisible="productionDialogVisible"
+      :operationType="operationType"
+      :formData="form"
+      @submit="submitForm"
+      @close="closeDia"
+    />
+    
+    <!-- 鍘熸枡搴撳瓨寮规 -->
+    <FormDiaPurchase 
+      v-model:dialogFormVisible="purchaseDialogVisible"
+      :operationType="operationType"
+      :formData="form"
+      @submit="submitForm"
+      @close="closeDia"
+    />
+    
+    <!-- 鏉愭枡搴撳瓨寮规 -->
+    <FormDiaManual 
+      v-model:dialogFormVisible="manualDialogVisible"
+      :operationType="operationType"
+      :formData="form"
+      @submit="submitForm"
+      @close="closeDia"
+    />
   </div>
 </template>
 
 <script setup>
 import pagination from '@/components/PIMTable/Pagination.vue'
-import { ref } from 'vue'
+import { ref, reactive, toRefs, onMounted, getCurrentInstance } 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 {
-  ledgerListPage,
-  customerList,
-  addOrUpdateSalesLedger,
-  getSalesLedgerWithProducts, delLedger
-} from "@/api/salesManagement/salesLedger.js";
+  getStockManagePage,
+  getStockManagePageByProduction,
+  getStockManagePageByCustom,
+  delStockManage,
+} from "@/api/inventoryManagement/stockManage.js";
+import {
+	updateManagement, updateManagementByCustom, updateStockIn
+} from "@/api/inventoryManagement/stockIn.js";
+
+// 瀵煎叆涓変釜鐙珛鐨勫脊妗嗙粍浠�
+import FormDiaProduction from './components/FormDiaProduction.vue'
+import FormDiaPurchase from './components/FormDiaPurchase.vue'
+import FormDiaManual from './components/FormDiaManual.vue'
+
 const userStore = useUserStore()
 const { proxy } = getCurrentInstance()
 const tableData = ref([])
 const productData = ref([])
 const selectedRows = ref([])
 const userList = ref([])
-const customerOption = ref([])
+const productList = ref([])
+const productModelList = ref([])
+// const customerOption = ref([])
 const tableLoading = ref(false)
 const page = reactive({
   current: 1,
@@ -156,34 +227,61 @@
 })
 const total = ref(0)
 const fileList = ref([])
-
+const loading = ref(false);
 // 鐢ㄦ埛淇℃伅琛ㄥ崟寮规鏁版嵁
 const operationType = ref('')
-const dialogFormVisible = ref(false)
+const activeTab = ref('production')
+
+// 涓変釜鐙珛鐨勫脊妗嗘樉绀虹姸鎬�
+const productionDialogVisible = ref(false)
+const purchaseDialogVisible = ref(false)
+const manualDialogVisible = ref(false)
+
 const data = reactive({
   searchForm: {
+    // supplierName: '',
+    productCategory:'',
     customerName: '',
+    timeStr: getCurrentDate(),
   },
   form: {
-    salesContractNo: '',
-    salesman: '',
-    customerContractNo: '',
-    customerId: '',
-    projectName: '',
-    entryPerson: '',
-    entryDate: '',
-    maintenanceTime: '',
-    productData: [],
-    executionDate: ''
+    supplierId: null,
+    // supplierName: '',
+    productId: null,
+    productName: '',
+    userId: userStore.userId,
+    nickName: '',
+    productModelId: null,
+    model: '',
+    unit: '',
+    productrecordId: null,
+    unitPrice: '', // 娣诲姞鎴愬搧搴撳瓨鐨勫崟浠峰瓧娈�
+    taxInclusiveUnitPrice: '',
+    taxInclusiveTotalPrice: '',
+    taxRate: '',
+    taxExclusiveTotalPrice: '',
+    inboundTime: '',
+    inboundBatch: '',
+    stockQuantity: '',
+    boundTime: '',
+		warnNum: '', // 鏂板鏈�浣庡簱瀛樺瓧娈�
+    salesLedgerProductId: null,
   },
   rules: {
-    salesman: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
-    customerContractNo: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
-    customerId: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
-    projectName: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" }],
-    entryPerson: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
-    entryDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
-    executionDate: [{ required: true, message: "璇烽�夋嫨", trigger: "change" }],
+    // supplierName: [{ required: true, message: '璇疯緭鍏ヤ緵搴斿晢鍚嶇О', trigger: 'blur' }],
+    productCategory: [{ required: true, message: '璇烽�夋嫨浜у搧澶х被', trigger: 'change' }],
+    specificationModel: [{ required: true, message: '璇疯緭鍏ヨ鏍煎瀷鍙�', trigger: 'blur' }],
+    unit: [{ required: true, message: '璇疯緭鍏ュ崟浣�', trigger: 'blur' }],
+    stockQuantity: [{ required: true, message: '璇疯緭鍏ュ嚭搴撴暟閲�', trigger: 'blur' }],
+    unitPrice: [{ required: true, message: '璇疯緭鍏ュ崟浠�', trigger: 'blur' }], // 娣诲姞鎴愬搧搴撳瓨鍗曚环鐨勯獙璇佽鍒�
+    taxInclusiveUnitPrice: [{ required: true, message: '璇疯緭鍏ュ惈绋庡崟浠�', trigger: 'blur' }],
+    taxInclusiveTotalPrice: [{ required: true, message: '璇疯緭鍏ュ惈绋庢�讳环', trigger: 'blur' }],
+    taxRate: [{ required: true, message: '璇疯緭鍏ョ◣鐜�', trigger: 'blur' }],
+    taxExclusiveTotalPrice: [{ required: true, message: '璇疯緭鍏ヤ笉鍚◣鎬讳环', trigger: 'blur' }],
+    boundTime: [{ required: true, message: '璇烽�夋嫨搴撳瓨鏃堕棿', trigger: 'change' }],
+    inboundTime: [{ required: true, message: '璇烽�夋嫨鍏ュ簱鏃堕棿', trigger: 'change' }],
+    inboundPerson: [{ required: true, message: '璇烽�夋嫨鍑哄簱浜�', trigger: 'change' }],
+		warnNum: [{ required: true, message: '璇疯緭鍏ユ渶浣庡簱瀛�', trigger: 'blur' }], 
   }
 })
 const { searchForm, form, rules } = toRefs(data)
@@ -199,38 +297,84 @@
   page.size = obj.limit;
   getList()
 }
+const buildQueryParams = () => {
+  const params = {
+    ...page,
+    timeStr: searchForm.value.timeStr,
+  }
+  params.productCategory = searchForm.value.productCategory
+  if (activeTab.value === 'production') {
+    params.customerName = searchForm.value.customerName
+  } else {
+    // params.supplierName = searchForm.value.supplierName
+  }
+  return params
+}
+
 const getList = () => {
   tableLoading.value = true
-  ledgerListPage({ ...searchForm.value, ...page }).then(res => {
+  const params = buildQueryParams()
+  let apiCall
+  if (activeTab.value === 'production') {
+    apiCall = getStockManagePageByProduction(params)
+  } else if (activeTab.value === 'manual') {
+    apiCall = getStockManagePageByCustom(params)
+  } else {
+    apiCall = getStockManagePage(params)
+  }
+  apiCall.then(res => {
     tableLoading.value = false
-    tableData.value = res.records
-    tableData.value.map(item => {
-      item.children = []
+    tableData.value = res.data.records
+    
+    // 涓鸿〃鏍兼暟鎹嚜鍔ㄨ绠楁�讳环
+    tableData.value = tableData.value.map(item => {
+      // 璁$畻鍓╀綑搴撳瓨
+      const stockQuantity = parseFloat(item.inboundNum) || 0
+      const outboundQuantity = parseFloat(item.totalInboundNum) || 0
+      const remainingStock = Math.max(stockQuantity - outboundQuantity, 0)
+      
+      // 鏍规嵁鏍囩椤电被鍨嬭绠楁�讳环
+      if (activeTab.value === 'production') {
+        // 鎴愬搧搴撳瓨锛氭�讳环 = 鍗曚环 脳 鍓╀綑搴撳瓨
+        const unitPrice = parseFloat(item.unitPrice) || 0
+        item.totalPrice = (unitPrice * remainingStock).toFixed(2)
+      } else if (activeTab.value === 'purchase') {
+        // 鍘熸枡搴撳瓨锛氬惈绋庢�讳环 = 鍚◣鍗曚环 脳 鍓╀綑搴撳瓨
+        const taxInclusiveUnitPrice = parseFloat(item.taxInclusiveUnitPrice) || 0
+        item.taxInclusiveTotalPrice = (taxInclusiveUnitPrice * remainingStock).toFixed(2)
+      } else if (activeTab.value === 'manual') {
+        // 鏉愭枡搴撳瓨锛氬惈绋庢�讳环 = 鍚◣鍗曚环 脳 鍓╀綑搴撳瓨
+        const taxInclusiveUnitPrice = parseFloat(item.taxInclusiveUnitPrice) || 0
+        item.taxInclusiveTotalPrice = (taxInclusiveUnitPrice * remainingStock).toFixed(2)
+      }
+      
+      return item
     })
-    total.value = res.total
+    
+    total.value = res.data.total
+    // 鏁版嵁鍔犺浇瀹屾垚鍚庢鏌ュ簱瀛�
+    // checkStockAndCreatePurchase();
   }).catch(() => {
     tableLoading.value = false
   })
 }
-const findNodeById = (nodes, productId) => {
-  for (let i = 0; i < nodes.length; i++) {
-    if (nodes[i].value === productId) {
-      return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥炶鑺傜偣
-    }
-    if (nodes[i].children && nodes[i].children.length > 0) {
-      const foundNode = findNodeById(nodes[i].children, productId);
-      if (foundNode) {
-        return foundNode.label; // 鍦ㄥ瓙鑺傜偣涓壘鍒帮紝杩斿洖璇ヨ妭鐐�
-      }
-    }
-  }
-  return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
-};
+
+// 鍒囨崲 tab
+const handleTabChange = () => {
+  page.current = 1
+  // searchForm.value.supplierName = ''
+  searchForm.value.customerName = ''
+  searchForm.value.timeStr = ''
+  selectedRows.value = []
+  searchForm.value.productCategory = ''
+  getList()
+}
+
 // 琛ㄦ牸閫夋嫨鏁版嵁
 const handleSelectionChange = (selection) => {
 
   // 杩囨护鎺夊瓙鏁版嵁
-  selectedRows.value = selection.filter(item => item.children !== undefined);
+  selectedRows.value = selection.filter(item => item.id);
   console.log('selection', selectedRows.value)
 }
 const expandedRowKeys = ref([])
@@ -240,78 +384,145 @@
   return proxy.summarizeTable(param, ['contractAmount', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice']);
 };
 
+// 琛ㄦ牸琛岀被鍚�
+const tableRowClassName = ({ row }) => {
+  const stock = Number(row?.inboundNum0 ?? 0);
+  const warn = Number(row?.warnNum ?? 0);
+  if (!Number.isFinite(stock) || !Number.isFinite(warn)) {
+    return '';
+  }
+  return stock < warn ? 'row-low-stock' : '';
+};
+
 // 鎵撳紑寮规
 const openForm = async (type, row) => {
   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
-  })
-  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;
+          });
+        }
+      })
     })
   }
-  // let userAll = await userStore.getInfo()
-  // userList.value.forEach(element => {
-  //   if(userAll.user.nickName === element.nickName && userAll.user.userName === element.userName) {
-  //     form.value.entryPerson = userAll.user.userId // 璁剧疆榛樿涓氬姟鍛樹负褰撳墠鐢ㄦ埛
-  //   }
-  // });
   form.value.entryDate = getCurrentDate() // 璁剧疆榛樿褰曞叆鏃ユ湡涓哄綋鍓嶆棩鏈�
-  dialogFormVisible.value = true
+  
+  // 鏍规嵁褰撳墠鏍囩椤垫樉绀哄搴旂殑寮规
+  if (activeTab.value === 'production') {
+    productionDialogVisible.value = true
+  } else if (activeTab.value === 'purchase') {
+    purchaseDialogVisible.value = true
+  } else if (activeTab.value === 'manual') {
+    manualDialogVisible.value = true
+  }
 }
 
 // 鎻愪氦琛ㄥ崟
-const submitForm = () => {
-  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 => {
-        proxy.$modal.msgSuccess("鎻愪氦鎴愬姛")
-        closeDia()
-        getList()
-      })
-    }
+const submitForm = (submittedData) => {
+  console.log('瀛愮粍浠舵彁浜ょ殑鏁版嵁:', submittedData)
+  
+  // 浣跨敤瀛愮粍浠舵彁浜ょ殑鏁版嵁锛岃�屼笉鏄埗缁勪欢鐨刦orm瀵硅薄
+  const submitData = { ...submittedData }
+  
+  // 鏍规嵁褰撳墠鏍囩椤电Щ闄ゅ搴旂殑鎬讳环瀛楁
+  if (activeTab.value === 'production') {
+    // 鎴愬搧搴撳瓨锛氱Щ闄ゆ�讳环瀛楁
+    delete submitData.totalPrice
+  } else if (activeTab.value === 'purchase') {
+    // 鍘熸枡搴撳瓨锛氱Щ闄ゅ惈绋庢�讳环瀛楁
+    delete submitData.taxInclusiveTotalPrice
+  } else if (activeTab.value === 'manual') {
+    // 鏉愭枡搴撳瓨锛氱Щ闄ゅ惈绋庢�讳环瀛楁
+    delete submitData.taxInclusiveTotalPrice
+  }
+  
+  // 绉婚櫎鍏朵粬鍙兘鐨勬�讳环瀛楁
+  delete submitData.taxExclusiveTotalPrice
+  
+  console.log('鎻愪氦缁欏悗绔殑鏁版嵁锛堝凡绉婚櫎鎬讳环瀛楁锛�:', submitData)
+  
+  // 鏍规嵁褰撳墠鏍囩椤佃皟鐢ㄤ笉鍚岀殑鎻愪氦鎺ュ彛
+  let apiCall
+  if (activeTab.value === 'production') {
+    // 鎴愬搧搴撳瓨浣跨敤 updateManagement 鎺ュ彛
+    apiCall = updateManagement(submitData)
+  } else if (activeTab.value === 'manual') {
+    // 鏉愭枡搴撳瓨浣跨敤 updateManagementByCustom 鎺ュ彛
+    apiCall = updateManagementByCustom(submitData)
+  } else {
+    // 鍘熸枡搴撳瓨浣跨敤 updateManagementByCustom 鎺ュ彛
+    apiCall = updateManagementByCustom(submitData)
+  }
+  
+  apiCall.then(res => {
+    proxy.$modal.msgSuccess("鎻愪氦鎴愬姛")
+    closeDia()
+    getList()
+    // 鎻愪氦鍚庢鏌ュ簱瀛樺苟灏濊瘯鍒涘缓璇疯喘鍗�
+    // checkStockAndCreatePurchase();
+  }).catch(error => {
+    console.error('鎻愪氦澶辫触:', error)
+    proxy.$modal.msgError("鎻愪氦澶辫触锛岃閲嶈瘯")
   })
 }
+// 妫�鏌ュ簱瀛樺苟鍒涘缓璇疯喘鍗�
+// const checkStockAndCreatePurchase = async () => {
+//   const stockList = tableData.value;
+//   // handList()
+//   for (const item of stockList) {
+//     if (item.inboundNum0 < item.warnNum) {
+//       try {
+// 				const stockInData = {
+// 					id: item.id,
+// 					quantityStock: item.warnNum + item.totalInboundNum,// 浣跨敤鏂版牸寮忓寲鍑芥暟
+// 				};
+// 				loading.value = true
+// 				await updateStockIn(stockInData)
+// 				proxy.$modal.msgSuccess(`浜у搧 ${item.productCategory} 淇敼鍏ュ簱鎴愬姛`)
+// 				loading.value = false
+//       } catch (error) {
+//         proxy.$modal.msgError(`浜у搧 ${item.productCategory} 鐢熸垚璇疯喘鍗曞け璐ワ紝璇锋墜鍔ㄥ鐞哷);
+//
+//       }
+//     }
+//   }
+// };
 // 鍏抽棴寮规
 const closeDia = () => {
   proxy.resetForm("formRef")
-  dialogFormVisible.value = false
+  productionDialogVisible.value = false
+  purchaseDialogVisible.value = false
+  manualDialogVisible.value = false
 }
 
 // 瀵煎嚭
 const handleOut = () => {
   ElMessageBox.confirm(
-    '閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�',
+    '鏄惁纭瀵煎嚭锛�',
     '瀵煎嚭', {
     confirmButtonText: '纭',
     cancelButtonText: '鍙栨秷',
     type: 'warning',
   }
   ).then(() => {
-    proxy.download("/sales/ledger/export", {}, '鍑哄簱鍙拌处.xlsx')
+    const exportParams = buildQueryParams()
+    // 鏍规嵁涓嶅悓鐨� tab 绫诲瀷璋冪敤涓嶅悓鐨勫鍑烘帴鍙�
+    let exportUrl = "/stockin/exportCopy"
+    if (activeTab.value === 'production') {
+      exportUrl = "/stockin/exportCopyOne"
+    } else if (activeTab.value === 'manual') {
+      exportUrl = "/stockin/exportCopyTwo"
+    }
+    proxy.download(exportUrl, exportParams, '搴撳瓨淇℃伅.xlsx')
   }).catch(() => {
     proxy.$modal.msg("宸插彇娑�")
   })
@@ -333,7 +544,7 @@
     type: 'warning',
   }
   ).then(() => {
-    delLedger(ids).then(res => {
+    delStockManage({ids:ids}).then(res => {
       proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛")
       getList()
     })
@@ -351,7 +562,24 @@
 }
 onMounted(() => {
   getList()
+  // checkStockAndCreatePurchase();
+    // 姣忓皬鏃舵鏌ヤ竴娆″簱瀛�
+    // const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000);
+
+// onUnmounted(() => {
+//   // 缁勪欢鍗歌浇鏃舵竻闄ゅ畾鏃跺櫒
+//   clearInterval(intervalId);
+// });
 })
 </script>
 
-<style scoped lang="scss"></style>
+<style scoped lang="scss">
+:deep(.row-low-stock td) {
+  background-color: #fde2e2;
+  color: #c45656;
+}
+
+:deep(.row-low-stock:hover > td) {
+  background-color: #fcd4d4;
+}
+</style>
\ No newline at end of file

--
Gitblit v1.9.3