周宾
2 天以前 cd17315666ec8099678c55329d3e5889efb23c1e
src/views/inventoryManagement/stockManagement/index.vue
@@ -47,202 +47,165 @@
              <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-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>
         </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="productCategory" show-overflow-tooltip />
                  <el-table-column label="产品高度" prop="specificationModel" width="100" show-overflow-tooltip>
                  <template #default="scope">
                     <div>{{ scope.row.specificationModel }}{{ scope.row.unit }}</div>
                  </template>
                  </el-table-column>
                  <el-table-column label="每件数量/支" prop="boxNum" width="100" show-overflow-tooltip />
                  <el-table-column label="入库数量" prop="inboundNum" width="100" 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="cartonSpecifications" 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">
      <el-tab-pane label="采购库存" name="purchase">
        <div class="search_form">
          <div>
<!--            <span class="search_title">供应商名称:</span>-->
<!--            <el-input v-model="searchForm.supplierName" style="width: 240px" placeholder="请输入" @change="handleQuery"-->
<!--              clearable prefix-icon="Search" />-->
            <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-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)">
            :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="productCategory" show-overflow-tooltip />
            <el-table-column label="产品高度" prop="specificationModel" width="100" show-overflow-tooltip>
              <template #default="scope">
                <div>{{ scope.row.specificationModel }}{{ scope.row.unit }}</div>
              </template>
            </el-table-column>
            <el-table-column label="每件数量/支" prop="boxNum" width="100" show-overflow-tooltip />
            <el-table-column label="入库数量" prop="inboundNum" width="100" show-overflow-tooltip />
            <el-table-column label="单价(元)/件" prop="taxInclusiveUnitPrice" width="150"></el-table-column>
            <el-table-column label="单价(美元)/件" prop="dollarPrice" width="150"></el-table-column>
            <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="cartonSpecifications" 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">供应商名称:</span>-->
            <!--            <el-input v-model="searchForm.supplierName" style="width: 240px" placeholder="请输入" @change="handleQuery"-->
            <!--              clearable prefix-icon="Search" />-->
            <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="产品图片" width="100" align="center">
                     <template #default="scope">
                        <img class="barcode-img" :src="javaApiUrl+scope.row.url"></img>
                     </template>
                  </el-table-column>
                  <el-table-column label="入库时间" prop="inboundDate" width="100" show-overflow-tooltip />
                  <el-table-column label="产品名称" prop="productCategory" show-overflow-tooltip />
                  <el-table-column label="产品高度" prop="specificationModel" width="100" show-overflow-tooltip>
                  <template #default="scope">
                     <div>{{ scope.row.specificationModel }}{{ scope.row.unit }}</div>
                  </template>
                  </el-table-column>
                  <el-table-column label="每件数量/支" prop="boxNum" width="100" show-overflow-tooltip />
                  <el-table-column label="入库数量" prop="inboundNum" width="100" 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 />
              <template #default="scope">
                <img class="barcode-img" :src="javaApiUrl + scope.row.url"></img>
              </template>
            </el-table-column>
            <el-table-column label="入库时间" prop="inboundDate" width="100" show-overflow-tooltip />
            <el-table-column label="产品名称" prop="productCategory" show-overflow-tooltip />
            <el-table-column label="产品高度" prop="specificationModel" width="100" show-overflow-tooltip>
              <template #default="scope">
                <div>{{ scope.row.specificationModel }}{{ scope.row.unit }}</div>
              </template>
            </el-table-column>
            <el-table-column label="单价(元)/件" prop="taxInclusiveUnitPrice" width="150"></el-table-column>
            <el-table-column label="单价(美元)/件" prop="dollarPrice" width="150"></el-table-column>
            <el-table-column label="每件数量/支" prop="boxNum" width="100" show-overflow-tooltip />
            <el-table-column label="入库数量" prop="inboundNum" width="100" 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="cartonSpecifications" width="150"></el-table-column>
            <el-table-column fixed="right" label="操作" width="100" align="center">
            <!-- <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-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"
    />
    <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"
    />
    <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"
    />
    <FormDiaManual v-model:dialogFormVisible="manualDialogVisible" :operationType="operationType" :formData="form"
      @submit="submitForm" @close="closeDia" />
  </div>
  <el-dialog v-model="barcodeDia" title="产品信息" width="70%" @close="closeBarcodeDia">
      <div>
        <el-row :gutter="30">
          <el-col :span="12">
            <div class="barcode-item">
              <div class="barcode-label">名称</div>
              <div class="barcode-value">{{barcodeDetail.barcode}}</div>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="barcode-item">
              <div class="barcode-label">单价</div>
              <div class="barcode-value">xxx元</div>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <div class="barcode-item">
              <div class="barcode-label">产品高度</div>
              <div class="barcode-value">222cm</div>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="barcode-item">
              <div class="barcode-label">数量/件</div>
              <div class="barcode-value">120</div>
            </div>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <div class="barcode-item">
              <div class="barcode-label">规格</div>
              <div class="barcode-value">12*20*30</div>
            </div>
          </el-col>
        </el-row>
    <div>
      <el-row :gutter="30">
        <el-col :span="12">
          <div class="barcode-item">
            <div class="barcode-label">名称</div>
            <div class="barcode-value">{{ barcodeDetail.barcode }}</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="barcode-item">
            <div class="barcode-label">单价</div>
            <div class="barcode-value">xxx元</div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <div class="barcode-item">
            <div class="barcode-label">产品高度</div>
            <div class="barcode-value">222cm</div>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="barcode-item">
            <div class="barcode-label">数量/件</div>
            <div class="barcode-value">120</div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <div class="barcode-item">
            <div class="barcode-label">规格</div>
            <div class="barcode-value">12*20*30</div>
          </div>
        </el-col>
      </el-row>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeBarcodeDia">关闭</el-button>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeBarcodeDia">关闭</el-button>
        </div>
      </template>
    </el-dialog>
    </template>
  </el-dialog>
</template>
<script setup>
@@ -251,7 +214,7 @@
import { ElMessageBox } from "element-plus";
import useUserStore from '@/store/modules/user'
import { userListNoPageByTenantId } from "@/api/system/user.js";
import { productTreeList,modelList } from "@/api/basicData/product.js"
import { productTreeList, modelList } from "@/api/basicData/product.js"
import {
  getStockManagePage,
  getStockManagePageByProduction,
@@ -259,8 +222,9 @@
  delStockManage,
} from "@/api/inventoryManagement/stockManage.js";
import {
   updateManagement, updateManagementByCustom, updateStockIn
  updateManagement, updateManagementByCustom, updateStockIn
} from "@/api/inventoryManagement/stockIn.js";
const javaApiUrl = __BASE_API__;
// 导入三个独立的弹框组件
import FormDiaProduction from './components/FormDiaProduction.vue'
@@ -296,7 +260,7 @@
const data = reactive({
  searchForm: {
    // supplierName: '',
    productCategory:'',
    productCategory: '',
    customerName: '',
    timeStr: getCurrentDate(),
  },
@@ -320,7 +284,7 @@
    inboundBatch: '',
    stockQuantity: '',
    boundTime: '',
      warnNum: '', // 新增最低库存字段
    warnNum: '', // 新增最低库存字段
    salesLedgerProductId: null,
  },
  rules: {
@@ -337,7 +301,7 @@
    boundTime: [{ required: true, message: '请选择库存时间', trigger: 'change' }],
    inboundTime: [{ required: true, message: '请选择入库时间', trigger: 'change' }],
    inboundPerson: [{ required: true, message: '请选择出库人', trigger: 'change' }],
      warnNum: [{ required: true, message: '请输入最低库存', trigger: 'blur' }],
    warnNum: [{ required: true, message: '请输入最低库存', trigger: 'blur' }],
  }
})
const { searchForm, form, rules } = toRefs(data)
@@ -381,14 +345,14 @@
  apiCall.then(res => {
    tableLoading.value = false
    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') {
        // 成品库存:总价 = 单价 × 剩余库存
@@ -403,10 +367,10 @@
        const taxInclusiveUnitPrice = parseFloat(item.taxInclusiveUnitPrice) || 0
        item.taxInclusiveTotalPrice = (taxInclusiveUnitPrice * remainingStock).toFixed(2)
      }
      return item
    })
    total.value = res.data.total
    // 数据加载完成后检查库存
    // checkStockAndCreatePurchase();
@@ -459,9 +423,9 @@
  userList.value = userLists.data
  if (type === 'edit') {
    form.value = { ...row }
    productTreeList().then(res =>{
    productTreeList().then(res => {
      productList.value = res
      productList.value.forEach(i =>{
      productList.value.forEach(i => {
        if (i.label === row.productCategory) {
          modelList({ id: i.id }).then((res) => {
            productModelList.value = res;
@@ -471,7 +435,7 @@
    })
  }
  form.value.entryDate = getCurrentDate() // 设置默认录入日期为当前日期
  // 根据当前标签页显示对应的弹框
  if (activeTab.value === 'production') {
    productionDialogVisible.value = true
@@ -485,10 +449,10 @@
// 提交表单
const submitForm = (submittedData) => {
  console.log('子组件提交的数据:', submittedData)
  // 使用子组件提交的数据,而不是父组件的form对象
  const submitData = { ...submittedData }
  // 根据当前标签页移除对应的总价字段
  if (activeTab.value === 'production') {
    // 成品库存:移除总价字段
@@ -500,12 +464,12 @@
    // 材料库存:移除含税总价字段
    delete submitData.taxInclusiveTotalPrice
  }
  // 移除其他可能的总价字段
  delete submitData.taxExclusiveTotalPrice
  console.log('提交给后端的数据(已移除总价字段):', submitData)
  submitData.inboundNum = parseFloat(submitData.inboundNum) || 0
  // 根据当前标签页调用不同的提交接口
  let apiCall
  if (activeTab.value === 'production') {
@@ -518,7 +482,7 @@
    // 原料库存使用 updateManagementByCustom 接口
    apiCall = updateManagementByCustom(submitData)
  }
  apiCall.then(res => {
    proxy.$modal.msgSuccess("提交成功")
    closeDia()
@@ -600,7 +564,7 @@
    type: 'warning',
  }
  ).then(() => {
    delStockManage({ids:ids}).then(res => {
    delStockManage({ ids: ids }).then(res => {
      proxy.$modal.msgSuccess("删除成功")
      getList()
    })
@@ -623,7 +587,7 @@
const barcodeDetail = ref({})
// 扫码函数
const scanBarcode = (e) => {
  if(!e||!e.target||!e.target.tagName){
  if (!e || !e.target || !e.target.tagName) {
    return;
  }
  if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
@@ -637,9 +601,9 @@
    scanBarcodeInput.value += e.key
  }
}
const getDetail = (barcode)=>{
const getDetail = (barcode) => {
  barcodeDetail.value = {
    barcode:barcode
    barcode: barcode
  }
  barcodeDia.value = true
}
@@ -652,13 +616,13 @@
  // document.addEventListener('keypress', scanBarcode)
  getList()
  // checkStockAndCreatePurchase();
    // 每小时检查一次库存
    // const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000);
  // 每小时检查一次库存
  // const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000);
// onUnmounted(() => {
//   // 组件卸载时清除定时器
//   clearInterval(intervalId);
// });
  // onUnmounted(() => {
  //   // 组件卸载时清除定时器
  //   clearInterval(intervalId);
  // });
})
onUnmounted(() => {
  // 移除键盘监听事件
@@ -676,9 +640,17 @@
:deep(.row-low-stock:hover > td) {
  background-color: #fcd4d4;
}
.barcode-item{
.barcode-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
}
.barcode-img {
  width: 80px;
  height: 80px;
  border-radius: 5px;
  background-color: #F5F5F5;
}
</style>