gaoluyang
5 天以前 d16397e58995f4acbd5e8a715ff9186a59258bd7
湟水峡
1.仓储物流逻辑修改
2.生产订单组件调整
已添加3个文件
已修改12个文件
2935 ■■■■■ 文件已修改
src/api/productionManagement/productionOrder.js 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/assets/styles/index.scss 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/PageHeader/index.vue 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/dispatchLog/index.vue 497 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/issueManagement/index.vue 817 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/stockManagement/components/FormDiaProduction.vue 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/stockManagement/components/FormDiaPurchase.vue 147 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/stockManagement/index.vue 950 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/inventoryManagement/stockWarning/index.vue 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/login.vue 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productStructure/Detail/index.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/productionManagement/productionOrder/index.vue 222 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/fileList.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/salesManagement/salesLedger/index.vue 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/productionManagement/productionOrder.js
@@ -113,4 +113,21 @@
    method: "post",
    data: data,
  });
}
// æ‰‹åŠ¨æ–°å¢žç”Ÿäº§è®¢å•
export function addProductOrder(data) {
  return request({
    url: "/productOrder/add",
    method: "post",
    data: data,
  });
}
// ç”Ÿäº§è®¢å•-批量删除(传 id æ•°ç»„)
export function deleteProductOrder(ids) {
  return request({
    url: "/productOrder/delete",
    method: "delete",
    data: ids,
  });
}
src/assets/styles/index.scss
@@ -137,7 +137,6 @@
}
.table_list {
  height: calc(100vh - 11em);
  margin-top: 20px;
  background: #fff;
  padding: 18px
}
src/components/PageHeader/index.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,53 @@
<template>
  <div class="page-header-wrapper">
    <el-page-header @back="handleBack" :content="content">
      <template #icon v-if="$slots.icon">
        <slot name="icon"></slot>
      </template>
      <template #title v-if="$slots.title">
        <slot name="title"></slot>
      </template>
      <template #content v-if="$slots.content">
        <slot name="content"></slot>
      </template>
      <template #extra>
        <slot name="extra">
          <slot name="right-button"></slot>
        </slot>
      </template>
    </el-page-header>
  </div>
</template>
<script setup>
import { useRouter } from 'vue-router'
const props = defineProps({
  content: {
    type: String,
    default: ''
  }
})
const emit = defineEmits(['back'])
const router = useRouter()
const handleBack = () => {
  emit('back')
  // é»˜è®¤è¿”回到上一级
  router.back()
}
</script>
<style scoped>
.page-header-wrapper {
  margin-bottom: 16px;
}
.page-header-wrapper :deep(.el-page-header__extra) {
  display: flex;
  align-items: center;
  gap: 8px;
}
</style>
src/main.js
@@ -52,6 +52,8 @@
import DictTag from "@/components/DictTag";
// è¡¨æ ¼ç»„ä»¶
import PIMTable from "@/components/PIMTable/PIMTable.vue";
// é¡µé¢å¤´éƒ¨ç»„ä»¶
import PageHeader from "@/components/PageHeader/index.vue";
import { getToken } from "@/utils/auth";
import {
@@ -93,6 +95,7 @@
app.component("RightToolbar", RightToolbar);
app.component("Editor", Editor);
app.component("PIMTable", PIMTable);
app.component("PageHeader", PageHeader);
app.use(router);
app.use(store);
src/views/inventoryManagement/dispatchLog/index.vue
@@ -1,145 +1,196 @@
<template>
    <div class="app-container">
        <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"
                />
                <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>
                <el-button type="primary" plain @click="handlePrint">打印</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="createTime"
                    min-width="250"
                    show-overflow-tooltip
                />
                <el-table-column
                    label="供应商名称"
                    prop="supplierName"
                    width="250"
                    show-overflow-tooltip
                />
                <el-table-column
                    label="产品大类"
                    prop="productCategory"
                    width="100"
                    show-overflow-tooltip
                />
                <el-table-column
                    label="规格型号"
                    prop="specificationModel"
                    width="100"
                    show-overflow-tooltip
                />
                <el-table-column
                    label="单位"
                    prop="unit"
                    width="80"
                    show-overflow-tooltip
                />
                <el-table-column
                    label="出库数量"
                    prop="inboundNum"
                    width="100"
                    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="180"
                    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
                        >
                    </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-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>
                        <el-button type="primary" plain @click="handlePrint">打印</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="createTime" width="120" 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="inboundNum" 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 label="出库人" prop="createBy" width="80" show-overflow-tooltip />
                    </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>
                        <el-button type="primary" plain @click="handlePrint">打印</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="createTime" width="120" 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="inboundNum" 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 label="出库人" prop="createBy" width="80" show-overflow-tooltip />
                    </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="semiProduct">
        <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>
            <el-button type="primary" plain @click="handlePrint">打印</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="createTime" width="220" 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="100" show-overflow-tooltip />
            <el-table-column label="出库数量" prop="inboundNum" width="220" show-overflow-tooltip />
            <el-table-column label="出库人" prop="createBy" width="220" show-overflow-tooltip />
          </el-table>
          <pagination
              v-show="total > 0"
              :total="total"
              layout="total, sizes, prev, pager, next, jumper"
              :page="page.current"
              :limit="page.size"
              @pagination="paginationSemiProductChange"
          />
        </div>
      </el-tab-pane>
        </el-tabs>
        <!-- æ‰“印预览弹窗 -->
        <el-dialog
            v-model="printPreviewVisible"
@@ -163,10 +214,10 @@
                    <div v-for="(item, index) in printData" :key="index" class="print-page">
                        <div class="delivery-note">
                            <div class="header">
                                <div class="company-name">鼎诚瑞实业有限责任公司</div>
                                <div class="company-name">军泰伟业(天津)有限公司</div>
                                <div class="document-title">零售发货单</div>
                            </div>
                            <div class="info-section">
                                <div class="info-row">
                                    <div>
@@ -174,7 +225,7 @@
                                        <span class="value">{{ formatDate(item.createTime) }}</span>
                                    </div>
                                    <div>
                                        <span class="label">客户名称:</span>
                                        <span class="value">{{ item.supplierName || '张爱有' }}</span>
                                    </div>
@@ -184,7 +235,7 @@
                                    <span class="value">{{ item.code }}</span>
                                </div>
                            </div>
                            <div class="table-section">
                                <table class="product-table">
                                    <thead>
@@ -219,7 +270,7 @@
                                    </tfoot>
                                </table>
                            </div>
                            <div class="footer-section">
                                <div class="footer-row">
                                    <div class="footer-item">
@@ -251,25 +302,29 @@
                </div>
            </div>
        </el-dialog>
    </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 { getCurrentDate } from "@/utils/index.js";
import {
    getStockOutPage,
    delStockOut,
  getStockOutSemiProductPage,
} from "@/api/inventoryManagement/stockOut.js";
import {
    getStockInPageByProduct,
} from "@/api/inventoryManagement/stockIn.js";
const userStore = useUserStore();
const { proxy } = getCurrentInstance();
const tableData = ref([]);
const activeTab = ref('production');
const selectedRows = ref([]);
const tableLoading = ref(false);
const page = reactive({
@@ -286,7 +341,9 @@
const data = reactive({
    searchForm: {
        supplierName: "",
        timeStr: "",
        customerName: "",
        productCategory:'',
        timeStr: '',
    },
    form: {
        supplierId: null,
@@ -321,20 +378,71 @@
    page.size = obj.limit;
    getList();
};
const paginationSemiProductChange = (obj) => {
  page.current = obj.page;
  page.size = obj.limit;
  getList();
};
const getList = () => {
    tableLoading.value = true;
    getStockOutPage({ ...searchForm.value, ...page })
        .then((res) => {
            tableLoading.value = false;
            tableData.value = res.data.records;
            tableData.value.map((item) => {
                item.children = [];
            });
            total.value = res.data.total;
        })
        .catch(() => {
            tableLoading.value = false;
        });
    const params = { ...page }
    if (activeTab.value === 'production') {
        params.customerName = searchForm.value.customerName
        params.timeStr = searchForm.value.timeStr
    } else {
        params.supplierName = searchForm.value.supplierName
        params.timeStr = searchForm.value.timeStr
    }
    params.productCategory = searchForm.value.productCategory
    // æ ¹æ®ä¸åŒçš„ tab ç±»åž‹è°ƒç”¨ä¸åŒçš„æŽ¥å£\
  if (activeTab.value === 'semiProduct') {
    const apiCall = getStockOutSemiProductPage(params)
    apiCall
        .then((res) => {
          tableLoading.value = false;
          tableData.value = res.data.records;
        })
  }else {
    const apiCall = activeTab.value === 'production'
        ? getStockInPageByProduct(params)
        : getStockOutPage(params)
    apiCall
        .then((res) => {
          tableLoading.value = false;
          tableData.value = res.data.records;
          tableData.value.map((item) => {
            item.children = [];
            // å‰ç«¯è®¡ç®—总价
            const inboundNum = Number(item.inboundNum) || 0;
            if (activeTab.value === 'production') {
              // æˆå“å‡ºåº“:总价 = unitPrice Ã— inboundNum
              const unitPrice = Number(item.unitPrice) || 0;
              item.totalPrice = (unitPrice * inboundNum).toFixed(2);
            } else {
              // åŽŸæ–™å‡ºåº“ï¼šæ€»ä»· = taxInclusiveUnitPrice Ã— inboundNum
              const taxInclusiveUnitPrice = Number(item.taxInclusiveUnitPrice) || 0;
              item.taxInclusiveTotalPrice = (taxInclusiveUnitPrice * inboundNum).toFixed(2);
            }
          });
          total.value = res.data.total;
        })
        .catch(() => {
          tableLoading.value = false;
        });
  }
};
const handleTabChange = () => {
    page.current = 1
    searchForm.value.supplierName = ''
    searchForm.value.customerName = ''
    searchForm.value.timeStr = ''
    selectedRows.value = []
      searchForm.value.productCategory = ''
    getList()
};
// è¡¨æ ¼é€‰æ‹©æ•°æ®
@@ -362,7 +470,12 @@
        type: "warning",
    })
        .then(() => {
            proxy.download("/stockmanagement/export", {}, "出库台账.xlsx");
            // æ ¹æ®ä¸åŒçš„ tab ç±»åž‹è°ƒç”¨ä¸åŒçš„导出接口
            let exportUrl = "/stockmanagement/export"
            if (activeTab.value === 'production') {
                exportUrl = "/stockmanagement/exportone"
            }
            proxy.download(exportUrl, {}, "出库台账.xlsx");
        })
        .catch(() => {
            proxy.$modal.msg("已取消");
@@ -409,10 +522,10 @@
const executePrint = () => {
    console.log('开始执行打印,数据条数:', printData.value.length);
    console.log('打印数据:', printData.value);
    // åˆ›å»ºä¸€ä¸ªæ–°çš„æ‰“印窗口
    const printWindow = window.open('', '_blank', 'width=800,height=600');
    // æž„建打印内容
    let printContent = `
    <!DOCTYPE html>
@@ -548,14 +661,14 @@
    </head>
    <body>
  `;
    // ä¸ºæ¯æ¡æ•°æ®ç”Ÿæˆæ‰“印页面
    printData.value.forEach((item, index) => {
        printContent += `
      <div class="print-page">
        <div class="delivery-note">
          <div class="header">
            <div class="company-name">鼎诚瑞实业有限责任公司</div>
            <div class="company-name">军泰伟业(天津)有限公司</div>
            <div class="document-title">零售发货单</div>
          </div>
          
@@ -641,16 +754,16 @@
      </div>
    `;
    });
    printContent += `
    </body>
    </html>
  `;
    // å†™å…¥å†…容到新窗口
    printWindow.document.write(printContent);
    printWindow.document.close();
    // ç­‰å¾…内容加载完成后打印
    printWindow.onload = () => {
        setTimeout(() => {
@@ -683,6 +796,14 @@
    const seconds = String(date.getSeconds()).padStart(2, "0");
    return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
};
// èŽ·å–å½“å‰æ—¥æœŸå¹¶æ ¼å¼åŒ–ä¸º 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}`;
}
onMounted(() => {
    getList();
});
@@ -702,12 +823,12 @@
        padding: 15px;
        border-bottom: 1px solid #e4e7ed;
        text-align: center;
        .el-button {
            margin: 0 10px;
        }
    }
    .print-preview-content {
        padding: 20px;
        background-color: #f5f5f5;
@@ -739,13 +860,13 @@
.header {
    text-align: center;
    margin-bottom: 8px;
    .company-name {
        font-size: 18px;
        font-weight: bold;
        margin-bottom: 4px;
    }
    .document-title {
        font-size: 16px;
        font-weight: bold;
@@ -757,16 +878,16 @@
    display: flex;
    justify-content: space-between;
    align-items: center;
    .info-row {
        line-height: 20px;
        .label {
            font-weight: bold;
            width: 60px;
            font-size: 14px;
        }
        .value {
            margin-right: 20px;
            min-width: 80px;
@@ -778,12 +899,12 @@
.table-section {
    margin-bottom: 4px;
    flex: 1;
    .product-table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid #000;
        th, td {
            border: 1px solid #000;
            padding: 6px;
@@ -791,16 +912,16 @@
            font-size: 14px;
            line-height: 1.4;
        }
        th {
            font-weight: bold;
        }
        .total-label {
            text-align: right;
            font-weight: bold;
        }
        .total-value {
            font-weight: bold;
        }
@@ -813,22 +934,22 @@
        margin-bottom: 3px;
        line-height: 20px;
        justify-content: space-between;
        .footer-item {
            display: flex;
            margin-right: 20px;
            .label {
                font-weight: bold;
                width: 80px;
                font-size: 14px;
            }
            .value {
                min-width: 80px;
                font-size: 14px;
            }
            &.address-item {
                .address-value {
                    min-width: 200px;
@@ -842,7 +963,7 @@
    .app-container {
        display: none;
    }
    .print-page {
        box-shadow: none;
        margin: 0;
@@ -856,3 +977,5 @@
    }
}
</style>
src/views/inventoryManagement/issueManagement/index.vue
@@ -1,74 +1,276 @@
<template>
  <div class="app-container">
    <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"
                />
        <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="createTime" width="100" show-overflow-tooltip />
        <el-table-column label="入库批次" prop="inboundBatches" width="160" 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="70" show-overflow-tooltip />
        <el-table-column label="入库数量" prop="inboundNum" width="90" show-overflow-tooltip />
        <el-table-column label="库存数量" prop="inboundNum0" width="90" 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="80" show-overflow-tooltip />
        <el-table-column label="不含税总价" prop="taxExclusiveTotalPrice" width="100" 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(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="'新增出库'" width="40%" @close="closeDia">
      <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef">
        <el-form-item label="出库数量:" prop="salesContractNo">
          <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="form.inboundQuantity" placeholder="请输入" clearable />
    <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-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"
                    :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"
                             label="序号"
                             type="index"
                             width="60" />
            <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="70"
                             show-overflow-tooltip />
            <el-table-column label="剩余库存"
                             prop="inboundNum0"
                             width="90"
                             show-overflow-tooltip />
            <el-table-column fixed="right"
                             label="操作"
                             min-width="60"
                             align="center">
              <template #default="scope">
                <el-button :disabled="scope.row.inboundNum0 <= 0"
                           link
                           type="primary"
                           size="small"
                           @click="openForm(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-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%"
                    :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="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="70"
                             show-overflow-tooltip />
            <el-table-column label="剩余库存"
                             prop="inboundNum0"
                             width="90"
                             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="操作"
                             min-width="60"
                             align="center">
              <template #default="scope">
                <el-button link
                           :disabled="scope.row.inboundNum0 <= 0"
                           type="primary"
                           size="small"
                           @click="openForm(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="product">
        <div class="search_form">
          <div>
            <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%"
                    :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="productCategory"
                             show-overflow-tooltip />
            <el-table-column label="规格型号"
                             prop="specificationModel"
                             show-overflow-tooltip />
            <el-table-column label="单位"
                             prop="unit"
                             width="70"
                             show-overflow-tooltip />
            <el-table-column label="剩余库存"
                             prop="inboundNum0"
                             width="90"
                             show-overflow-tooltip />
            <el-table-column fixed="right"
                             label="操作"
                             min-width="60"
                             align="center">
              <template #default="scope">
                <el-button link
                           :disabled="scope.row.inboundNum0 <= 0"
                           type="primary"
                           size="small"
                           @click="openForm(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>
    <el-dialog v-model="dialogFormVisible"
               :title="getDialogTitle()"
               width="40%"
               @close="closeDia">
      <el-form :model="form"
               label-width="140px"
               label-position="top"
               :rules="rules"
               ref="formRef">
        <div>{{getAvailableQuantityText()}}:{{currentRowNum}}</div>
        <el-form-item :label="getQuantityLabel()"
                      prop="salesContractNo">
          <el-input-number :step="0.01"
                           :min="0"
                           style="width: 100%"
                           v-model="form.inboundQuantity"
                           placeholder="请输入"
                           clearable />
        </el-form-item>
        <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"
            type="date" placeholder="请选择" clearable />
        <el-form-item :label="getDateLabel()"
                      prop="projectName">
          <el-date-picker style="width: 100%"
                          v-model="form.inboundTime"
                          value-format="YYYY-MM-DD"
                          format="YYYY-MM-DD"
                          type="date"
                          placeholder="请选择"
                          clearable />
        </el-form-item>
        <el-form-item label="出库人:" prop="entryPerson">
          <el-select v-model="form.nickName" placeholder="请选择" clearable>
            <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
        <el-form-item :label="getPersonLabel()"
                      prop="entryPerson">
          <el-select v-model="form.nickName"
                     filterable
                     default-first-option
                     :reserve-keyword="false"
                     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>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确认</el-button>
          <el-button type="primary"
                     @click="submitForm">确认</el-button>
          <el-button @click="closeDia">取消</el-button>
        </div>
      </template>
@@ -77,209 +279,314 @@
</template>
<script setup>
import pagination from '@/components/PIMTable/Pagination.vue'
import { ref } from 'vue'
import { ElMessageBox } from "element-plus";
import useUserStore from '@/store/modules/user'
import { userListNoPageByTenantId } from "@/api/system/user.js";
import {
  getStockInPage
} from "@/api/inventoryManagement/stockIn.js";
import {
  getStockManagePage,
  import pagination from "@/components/PIMTable/Pagination.vue";
  import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue";
  import { ElMessageBox } from "element-plus";
  import useUserStore from "@/store/modules/user";
  import { userListNoPageByTenantId } from "@/api/system/user.js";
  import {
    getStockInPage,
    getStockInPageByProduction,
    getStockInPageByProductProduction,
  } from "@/api/inventoryManagement/stockIn.js";
  import {
    getStockManagePage,
    delStockManage,
    stockOut,
} from "@/api/inventoryManagement/stockManage.js";
  } from "@/api/inventoryManagement/stockManage.js";
const userStore = useUserStore()
const { proxy } = getCurrentInstance()
const tableData = ref([])
const selectedRows = ref([])
const userList = ref([])
const tableLoading = ref(false)
const page = reactive({
  current: 1,
  size: 100,
})
const total = ref(0)
const fileList = ref([])
  const userStore = useUserStore();
  const { proxy } = getCurrentInstance();
  const tableData = ref([]);
  const selectedRows = ref([]);
  const userList = ref([]);
  const tableLoading = ref(false);
  const page = reactive({
    current: 1,
    size: 100,
  });
  const total = ref(0);
  const fileList = ref([]);
// ç”¨æˆ·ä¿¡æ¯è¡¨å•弹框数据
const dialogFormVisible = ref(false)
const data = reactive({
  searchForm: {
    supplierName: '',
    inboundQuantity:'',
    inboundTime:'',
    nickName: '',
    userId: '',
        timeStr: '',
  },
  form: {
    productrecordId: '',
  },
  rules: {
    inboundTime: [{ required: true, message: "请选择", trigger: "change" }],
    inboundQuantity: [{ required: true, message: "请输入", trigger: "blur" }],
    nickname: [{ required: true, message: "请选择", trigger: "change" }]
  }
})
const { searchForm, form, rules } = toRefs(data)
  // ç”¨æˆ·ä¿¡æ¯è¡¨å•弹框数据
  const dialogFormVisible = ref(false);
  const activeTab = ref("production");
  const data = reactive({
    searchForm: {
      supplierName: "",
      customerName: "",
      inboundQuantity: "",
      inboundTime: "",
      nickName: "",
      userId: "",
      productCategory: "",
      timeStr: "",
    },
    form: {
      productrecordId: "",
    },
    rules: {
      inboundTime: [{ required: true, message: "请选择", trigger: "change" }],
      inboundQuantity: [{ required: true, message: "请输入", trigger: "blur" }],
      nickname: [{ required: true, message: "请选择", trigger: "change" }],
    },
  });
  const { searchForm, form, rules } = toRefs(data);
// æŸ¥è¯¢åˆ—表
/** æœç´¢æŒ‰é’®æ“ä½œ */
const handleQuery = () => {
  page.current = 1
  getList()
}
const paginationChange = (obj) => {
  page.current = obj.page;
  page.size = obj.limit;
  getList()
}
const getList = () => {
  tableLoading.value = true
  getStockInPage({ ...searchForm.value, ...page }).then(res => {
    tableLoading.value = false
    tableData.value = res.data.records
    total.value = res.data.total
    console.log('res', res.data.records)
  }).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; // æ‰¾åˆ°èŠ‚ç‚¹ï¼Œè¿”å›žè¯¥èŠ‚ç‚¹
  // æŸ¥è¯¢åˆ—表
  /** æœç´¢æŒ‰é’®æ“ä½œ */
  const handleQuery = () => {
    page.current = 1;
    getList();
  };
  const paginationChange = obj => {
    page.current = obj.page;
    page.size = obj.limit;
    getList();
  };
  const getList = () => {
    tableLoading.value = true;
    const params = { ...page };
    if (activeTab.value === "production") {
      params.customerName = searchForm.value.customerName;
      params.timeStr = searchForm.value.timeStr;
    } else {
      params.supplierName = searchForm.value.supplierName;
      params.timeStr = searchForm.value.timeStr;
    }
    if (nodes[i].children && nodes[i].children.length > 0) {
      const foundNode = findNodeById(nodes[i].children, productId);
      if (foundNode) {
        return foundNode.label; // åœ¨å­èŠ‚ç‚¹ä¸­æ‰¾åˆ°ï¼Œè¿”å›žè¯¥èŠ‚ç‚¹
      }
    params.productCategory = searchForm.value.productCategory;
    let apiCall;
    if (activeTab.value === "production") {
      apiCall = getStockInPageByProduction(params);
    } else if (activeTab.value === "product") {
      apiCall = getStockInPageByProductProduction(params);
    }else {
      apiCall = getStockInPage(params);
    }
  }
  return null; // æ²¡æœ‰æ‰¾åˆ°èŠ‚ç‚¹ï¼Œè¿”å›žnull
};
// è¡¨æ ¼é€‰æ‹©æ•°æ®
const handleSelectionChange = (selection) => {
  // è¿‡æ»¤æŽ‰å­æ•°æ®
  selectedRows.value = selection.filter(item => item.id);
  console.log('selection', selectedRows.value)
}
const expandedRowKeys = ref([])
// ä¸»è¡¨åˆè®¡æ–¹æ³•
const summarizeMainTable = (param) => {
  return proxy.summarizeTable(param, ['contractAmount', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice']);
};
const currentRowId = ref(null) // æ–°å¢žï¼šå­˜å‚¨å½“前操作的行ID
const currentRowNum = ref(0)
const salesLedgerProductId = ref(null);
// æ‰“开弹框
const openForm = async (row) => {
  dialogFormVisible.value = true
  currentRowId.value = row.id
  currentRowNum.value = row.inboundNum0
  salesLedgerProductId.value = row.salesLedgerProductId
  form.value = {}
  // åˆå§‹åŒ–表单数据
  form.value = {
    productrecordId: '',
    inboundQuantity: '', // å‡ºåº“数量清空
    inboundTime: getCurrentDate(), // é»˜è®¤å½“前日期
    nickName: '', // é»˜è®¤å½“前用户
  }
  console.log('form',form.value)
  // åŠ è½½ç”¨æˆ·åˆ—è¡¨
  try {
    const userLists = await userListNoPageByTenantId()
    userList.value = userLists.data
  } catch (error) {
    console.error('加载用户列表失败:', error)
  }
}
// æäº¤è¡¨å•
const submitForm = () => {
  let num = Number(form.value.inboundQuantity)
  if(num <= 0 || num > currentRowNum.value){
    return proxy.$modal.msgWarning("请填入有效数字")
  }
  proxy.$refs["formRef"].validate(valid => {
    if (valid && currentRowId.value) {
      const outData = {
        id: currentRowId.value, // åŽŸå§‹è®°å½•ID
        salesLedgerProductId: salesLedgerProductId.value,
        quantity: form.value.inboundQuantity, // å‡ºåº“数量
        time: form.value.inboundTime, // å‡ºåº“æ—¶é—´
        userId: form.value.nickName // æ“ä½œäºº
      }
      console.log(outData)
      stockOut(outData).then(res => {
        proxy.$modal.msgSuccess("提交成功")
        closeDia()
        getList()
      }).catch(err => {
        proxy.$modal.msgError("出库失败")
    apiCall
      .then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
        total.value = res.data.total;
      })
    }
  })
}
// å…³é—­å¼¹æ¡†
const closeDia = () => {
  proxy.resetForm("formRef")
  dialogFormVisible.value = false
}
      .catch(() => {
        tableLoading.value = false;
      });
  };
// å¯¼å‡º
const handleOut = () => {
  ElMessageBox.confirm(
    '是否确认导出?',
    '导出', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  }
  ).then(() => {
    proxy.download("/stockin/export", {}, '入库台账.xlsx')
  }).catch(() => {
    proxy.$modal.msg("已取消")
  })
}
// åˆ é™¤
const handleDelete = () => {
  let ids = []
  if (selectedRows.value.length > 0) {
    ids = selectedRows.value.map(item => item.id);
  } else {
    proxy.$modal.msgWarning('请选择数据')
    return
  }
  ElMessageBox.confirm(
    '选中的内容将被删除,是否确认删除?',
    '导出', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  }
  ).then(() => {
    delStockManage(ids).then(res => {
      proxy.$modal.msgSuccess("删除成功")
      getList()
  const handleTabChange = () => {
    page.current = 1;
    searchForm.value.supplierName = "";
    searchForm.value.customerName = "";
    searchForm.value.timeStr = "";
    selectedRows.value = [];
    searchForm.value.productCategory = "";
    getList();
  };
  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; // æ²¡æœ‰æ‰¾åˆ°èŠ‚ç‚¹ï¼Œè¿”å›žnull
  };
  // è¡¨æ ¼é€‰æ‹©æ•°æ®
  const handleSelectionChange = selection => {
    // è¿‡æ»¤æŽ‰å­æ•°æ®
    selectedRows.value = selection.filter(item => item.id);
    console.log("selection", selectedRows.value);
  };
  const expandedRowKeys = ref([]);
  // ä¸»è¡¨åˆè®¡æ–¹æ³•
  const summarizeMainTable = param => {
    return proxy.summarizeTable(param, [
      "contractAmount",
      "taxInclusiveTotalPrice",
      "taxExclusiveTotalPrice",
    ]);
  };
  const currentRowId = ref(null); // æ–°å¢žï¼šå­˜å‚¨å½“前操作的行ID
  const currentRowNum = ref(0);
  const salesLedgerProductId = ref(null);
const productModelId = ref(null);
  // æ‰“开弹框
  const openForm = async row => {
    dialogFormVisible.value = true;
    currentRowId.value = row.id;
    currentRowNum.value = row.inboundNum0;
    salesLedgerProductId.value = row.salesLedgerProductId;
    productModelId.value = row.productModelId;
    form.value = {};
    // åˆå§‹åŒ–表单数据
    form.value = {
      productrecordId: "",
      inboundQuantity: "", // å‡ºåº“数量清空
      inboundTime: getCurrentDate(), // é»˜è®¤å½“前日期
      nickName: "", // é»˜è®¤å½“前用户
    };
    console.log("form", form.value);
    // åŠ è½½ç”¨æˆ·åˆ—è¡¨
    try {
      const userLists = await userListNoPageByTenantId();
      userList.value = userLists.data;
    } catch (error) {
      console.error("加载用户列表失败:", error);
    }
  };
  // æäº¤è¡¨å•
  const submitForm = () => {
    let num = Number(form.value.inboundQuantity);
    if (num <= 0 || num > currentRowNum.value) {
      return proxy.$modal.msgWarning("请填入有效数字");
    }
    if (!form.value.nickName) {
      return proxy.$modal.msgWarning("请选择操作人");
    }
    proxy.$refs["formRef"].validate(valid => {
      if (valid && currentRowId.value) {
        const typeMap = { production: 2, purchase: 1, product: 4 };
        const outData = {
          id: currentRowId.value, // åŽŸå§‹è®°å½•ID
          salesLedgerProductId: salesLedgerProductId.value,
          quantity: form.value.inboundQuantity, // å‡ºåº“数量
          time: form.value.inboundTime, // å‡ºåº“æ—¶é—´
          userId: form.value.nickName, // æ“ä½œäºº
          type: typeMap[activeTab.value], // å‡ºåº“类型:采购1,生产2
          productModelId: productModelId.value,
        };
        console.log(outData);
        stockOut(outData)
          .then(res => {
            proxy.$modal.msgSuccess("提交成功");
            closeDia();
            getList();
          })
          .catch(err => {
            proxy.$modal.msgError("出库失败");
          });
      }
    });
  };
  // å…³é—­å¼¹æ¡†
  const closeDia = () => {
    proxy.resetForm("formRef");
    dialogFormVisible.value = false;
  };
  // å¯¼å‡º
  const handleOut = () => {
    ElMessageBox.confirm("是否确认导出?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
  }).catch(() => {
    proxy.$modal.msg("已取消")
  })
}
onMounted(() => {
  getList()
})
      .then(() => {
        // æ ¹æ®ä¸åŒçš„ tab ç±»åž‹è°ƒç”¨ä¸åŒçš„导出接口
        let exportUrl = "/stockin/export";
        if (activeTab.value === "production") {
          exportUrl = "/stockin/exportOne";
        }
        proxy.download(exportUrl, {}, "入库台账.xlsx");
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
  // åˆ é™¤
  const handleDelete = () => {
    let ids = [];
    if (selectedRows.value.length > 0) {
      ids = selectedRows.value.map(item => item.id);
    } else {
      proxy.$modal.msgWarning("请选择数据");
      return;
    }
    ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        delStockManage(ids).then(res => {
          proxy.$modal.msgSuccess("删除成功");
          getList();
        });
      })
      .catch(() => {
        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}`;
  }
  // æ ¹æ®tab类型获取弹框标题
  const getDialogTitle = () => {
    const titleMap = {
      production: "新增发货",
      purchase: "新增领用",
    };
    return titleMap[activeTab.value] || "新增出库";
  };
  // æ ¹æ®tab类型获取可出库数量文本
  const getAvailableQuantityText = () => {
    const textMap = {
      production: "可发货数量",
      purchase: "可领用数量",
    };
    return textMap[activeTab.value] || "可出库数量";
  };
  // æ ¹æ®tab类型获取数量字段标签
  const getQuantityLabel = () => {
    const labelMap = {
      production: "发货数量:",
      purchase: "领用数量:",
    };
    return labelMap[activeTab.value] || "出库数量:";
  };
  // æ ¹æ®tab类型获取日期字段标签
  const getDateLabel = () => {
    const labelMap = {
      production: "发货日期:",
      purchase: "领用日期:",
    };
    return labelMap[activeTab.value] || "出库日期:";
  };
  // æ ¹æ®tab类型获取人员字段标签
  const getPersonLabel = () => {
    const labelMap = {
      production: "发货人:",
      purchase: "领用人:",
    };
    return labelMap[activeTab.value] || "出库人:";
  };
  onMounted(() => {
    getList();
  });
</script>
<style scoped lang="scss"></style>
src/views/inventoryManagement/stockManagement/components/FormDiaProduction.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,147 @@
<template>
  <el-dialog :model-value="dialogFormVisible" :title="operationType === 'add' ? '新增成品库存' : '编辑成品库存'" width="70%"
    @update:model-value="$emit('update:dialogFormVisible', $event)" @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="productCategory">
            <el-input disabled v-model="form.productCategory" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格型号:" prop="specificationModel">
            <el-input disabled v-model="form.specificationModel" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="单位:" prop="unit">
            <el-input disabled v-model="form.unit" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库时间:" prop="createTime">
            <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>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="库存数量:" prop="inboundNum">
            <el-input v-model="form.inboundNum" placeholder="请输入" clearable @input="calculateTotalPrice" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="已出库数量:" prop="totalInboundNum">
            <el-input disabled v-model="form.totalInboundNum" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="待出库数量:" prop="inboundNum0">
            <el-input disabled v-model="form.inboundNum0" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单价(元):" prop="unitPrice">
            <el-input v-model="form.unitPrice" placeholder="请输入" clearable @input="calculateTotalPrice" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="总价(元):" prop="totalPrice">
            <el-input disabled v-model="form.totalPrice" placeholder="自动计算" clearable />
          </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>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, toRefs, watch } from 'vue'
const props = defineProps({
  dialogFormVisible: Boolean,
  operationType: String,
  formData: Object
})
const emit = defineEmits(['update:dialogFormVisible', 'submit', 'close'])
const formRef = ref()
const data = reactive({
  form: {
    productCategory: '',
    specificationModel: '',
    unit: '',
    createTime: '',
    inboundNum: '',
    totalInboundNum: '',
    inboundNum0: '',
    unitPrice: '',
    totalPrice: ''
  },
  rules: {
    productCategory: [{ required: true, message: '请输入产品大类', trigger: 'blur' }],
    specificationModel: [{ required: true, message: '请输入规格型号', trigger: 'blur' }],
    unit: [{ required: true, message: '请输入单位', trigger: 'blur' }],
    createTime: [{ required: true, message: '请选择入库时间', trigger: 'change' }],
    inboundNum: [{ required: true, message: '请输入库存数量', trigger: 'blur' }],
    unitPrice: [{ required: true, message: '请输入单价', trigger: 'blur' }]
  }
})
const { form, rules } = toRefs(data)
// è®¡ç®—总价:总价 = å•ä»· Ã— å‰©ä½™åº“å­˜
const calculateTotalPrice = () => {
  const unitPrice = parseFloat(form.value.unitPrice) || 0
  const stockQuantity = parseFloat(form.value.inboundNum) || 0 // åº“存数量
  const outboundQuantity = parseFloat(form.value.totalInboundNum) || 0 // å·²å‡ºåº“数量
  const remainingStock = stockQuantity - outboundQuantity // å‰©ä½™åº“å­˜
  form.value.totalPrice = (unitPrice * remainingStock).toFixed(2)
}
// ç›‘听formData变化
watch(() => props.formData, (newVal) => {
  if (newVal) {
    form.value = { ...newVal }
    // æ•°æ®å˜åŒ–后重新计算总价
    calculateTotalPrice()
  }
}, { immediate: true })
// æäº¤è¡¨å•
const submitForm = () => {
  formRef.value.validate(valid => {
    if (valid) {
      emit('submit', form.value)
    }
  })
}
// å…³é—­å¼¹æ¡†
const closeDia = () => {
  emit('close')
  emit('update:dialogFormVisible', false)
}
</script>
<style scoped lang="scss">
.dialog-footer {
  text-align: center;
}
</style>
src/views/inventoryManagement/stockManagement/components/FormDiaPurchase.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,147 @@
<template>
  <el-dialog :model-value="dialogFormVisible" :title="operationType === 'add' ? '新增原料库存' : '编辑原料库存'" width="70%"
    @update:model-value="$emit('update:dialogFormVisible', $event)" @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="productCategory">
            <el-input disabled v-model="form.productCategory" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格型号:" prop="specificationModel">
            <el-input disabled v-model="form.specificationModel" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="单位:" prop="unit">
            <el-input disabled v-model="form.unit" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库时间:" prop="createTime">
            <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>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="库存数量:" prop="inboundNum">
            <el-input v-model="form.inboundNum" placeholder="请输入" clearable @input="calculateTotalPrice" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="已出库数量:" prop="totalInboundNum">
            <el-input disabled v-model="form.totalInboundNum" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="待出库数量:" prop="inboundNum0">
            <el-input disabled v-model="form.inboundNum0" placeholder="请输入" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="含税单价(元):" prop="taxInclusiveUnitPrice">
            <el-input v-model="form.taxInclusiveUnitPrice" placeholder="请输入" clearable @input="calculateTotalPrice" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="30">
        <el-col :span="12">
          <el-form-item label="含税总价(元):" prop="taxInclusiveTotalPrice">
            <el-input disabled v-model="form.taxInclusiveTotalPrice" placeholder="自动计算" clearable />
          </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>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, toRefs, watch } from 'vue'
const props = defineProps({
  dialogFormVisible: Boolean,
  operationType: String,
  formData: Object
})
const emit = defineEmits(['update:dialogFormVisible', 'submit', 'close'])
const formRef = ref()
const data = reactive({
  form: {
    productCategory: '',
    specificationModel: '',
    unit: '',
    createTime: '',
    inboundNum: '',
    totalInboundNum: '',
    inboundNum0: '',
    taxInclusiveUnitPrice: '',
    taxInclusiveTotalPrice: ''
  },
  rules: {
    productCategory: [{ required: true, message: '请输入产品大类', trigger: 'blur' }],
    specificationModel: [{ required: true, message: '请输入规格型号', trigger: 'blur' }],
    unit: [{ required: true, message: '请输入单位', trigger: 'blur' }],
    createTime: [{ required: true, message: '请选择入库时间', trigger: 'change' }],
    inboundNum: [{ required: true, message: '请输入库存数量', trigger: 'blur' }],
    taxInclusiveUnitPrice: [{ required: true, message: '请输入含税单价', trigger: 'blur' }]
  }
})
const { form, rules } = toRefs(data)
// è®¡ç®—总价:含税总价 = å«ç¨Žå•ä»· Ã— å‰©ä½™åº“å­˜
const calculateTotalPrice = () => {
  const unitPrice = parseFloat(form.value.taxInclusiveUnitPrice) || 0
  const stockQuantity = parseFloat(form.value.inboundNum) || 0 // åº“存数量
  const outboundQuantity = parseFloat(form.value.totalInboundNum) || 0 // å·²å‡ºåº“数量
  const remainingStock = stockQuantity - outboundQuantity // å‰©ä½™åº“å­˜
  form.value.taxInclusiveTotalPrice = (unitPrice * remainingStock).toFixed(2)
}
// ç›‘听formData变化
watch(() => props.formData, (newVal) => {
  if (newVal) {
    form.value = { ...newVal }
    // æ•°æ®å˜åŒ–后重新计算总价
    calculateTotalPrice()
  }
}, { immediate: true })
// æäº¤è¡¨å•
const submitForm = () => {
  formRef.value.validate(valid => {
    if (valid) {
      emit('submit', form.value)
    }
  })
}
// å…³é—­å¼¹æ¡†
const closeDia = () => {
  emit('close')
  emit('update:dialogFormVisible', false)
}
</script>
<style scoped lang="scss">
.dialog-footer {
  text-align: center;
}
</style>
src/views/inventoryManagement/stockManagement/index.vue
@@ -1,419 +1,591 @@
<template>
  <div class="app-container">
    <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"
                />
        <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%"
        :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="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="inboundNum0" width="100" show-overflow-tooltip />
        <el-table-column label="库存预警数量" prop="warnNum" 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="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>
          </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="supplierName">
              <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 disabled v-model="form.productCategory" placeholder="请选择" clearable filterable>
                <el-option v-for="item in productList" :key="item.id" :label="item.productName"
                           :value="item.productName" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="规格型号:" prop="productManageId">
              <el-select disabled v-model="form.specificationModel" placeholder="请先选择产品大类" clearable filterable :disabled="!form.productCategory">
                <el-option v-for="item in productModelList" :key="item.id" :label="item.model"
                           :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <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.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.createTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD"
                type="date" 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 disabled v-model="form.taxInclusiveUnitPrice" placeholder="请输入" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <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 disabled v-model="form.taxRate" placeholder="请输入" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不含税总价:" prop="entryDate">
              <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.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="warnNum">-->
<!--            <el-input v-model="form.warnNum" placeholder="请输入最低库存" clearable />-->
<!--          </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="120">
              <template #default="scope">
                {{ parseTime(scope.row.createTime, '{y}-{m}-{d}') || '-' }}
              </template>
            </el-table-column>
            <el-table-column label="产品名称"
                             prop="productName"
                             width="180"
                             show-overflow-tooltip />
            <el-table-column label="产品规格"
                             prop="model"
                             show-overflow-tooltip />
            <el-table-column label="单位"
                             prop="unit"
                             width="80"
                             show-overflow-tooltip />
            <el-table-column label="已出库数量"
                             prop="outboundNum"
                             show-overflow-tooltip />
            <el-table-column label="剩余库存"
                             prop="stockQuantity"
                             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-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="120"
                             show-overflow-tooltip>
              <template #default="scope">
                {{ parseTime(scope.row.createTime, '{y}-{m}-{d}') || '-' }}
              </template>
            </el-table-column>
            <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-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" />
  </div>
</template>
<script setup>
import pagination from '@/components/PIMTable/Pagination.vue'
import { ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue'
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 { getCurrentDate } from "@/utils/index.js";
import {
  getStockManagePage,
  delStockManage,
} from "@/api/inventoryManagement/stockManage.js";
import {
  updateManagement,updateStockIn
} from "@/api/inventoryManagement/stockIn.js";
  import pagination from "@/components/PIMTable/Pagination.vue";
  import { ref, reactive, toRefs, onMounted, getCurrentInstance } from "vue";
  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 {
    getStockManagePage,
    getStockManagePageByProduction,
    delStockManage, getStockManageProduction,
  } 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";
  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({
    current: 1,
    size: 100,
  });
  const total = ref(0);
  const fileList = ref([]);
  const loading = ref(false);
  // ç”¨æˆ·ä¿¡æ¯è¡¨å•弹框数据
  const operationType = ref("");
  const activeTab = ref("production");
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({
  current: 1,
  size: 100,
})
const total = ref(0)
const fileList = ref([])
const loading = ref(false);
// ç”¨æˆ·ä¿¡æ¯è¡¨å•弹框数据
const operationType = ref('')
const dialogFormVisible = ref(false)
const data = reactive({
  searchForm: {
    supplierName: '',
        timeStr: '',
  },
  form: {
    supplierId: null,
    supplierName: '',
    productId: null,
    productName: '',
    userId: userStore.userId,
    nickName: '',
    productModelId: null,
    model: '',
    unit: '',
    productrecordId: null,
    taxInclusiveUnitPrice: '',
    taxInclusiveTotalPrice: '',
    taxRate: '',
    taxExclusiveTotalPrice: '',
    inboundTime: '',
    inboundBatch: '',
    stockQuantity: '',
    boundTime: '',
        warnNum: '', // æ–°å¢žæœ€ä½Žåº“存字段
    salesLedgerProductId: null,
  },
  rules: {
    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' }],
    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)
  // å¼¹æ¡†æ˜¾ç¤ºçŠ¶æ€
  const productionDialogVisible = ref(false);
  const purchaseDialogVisible = ref(false);
// æŸ¥è¯¢åˆ—表
/** æœç´¢æŒ‰é’®æ“ä½œ */
const handleQuery = () => {
  page.current = 1
  getList()
}
const paginationChange = (obj) => {
  page.current = obj.page;
  page.size = obj.limit;
  getList()
}
const getList = () => {
  tableLoading.value = true
  getStockManagePage({ ...searchForm.value, ...page }).then(res => {
    tableLoading.value = false
    tableData.value = res.data.records
    total.value = res.data.total
    // æ•°æ®åŠ è½½å®ŒæˆåŽæ£€æŸ¥åº“å­˜
    // checkStockAndCreatePurchase();
  }).catch(() => {
    tableLoading.value = false
  })
}
  const data = reactive({
    searchForm: {
      // supplierName: '',
      productCategory: "",
      customerName: "",
      timeStr: "",
    },
    form: {
      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: {
      // 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);
// è¡¨æ ¼é€‰æ‹©æ•°æ®
const handleSelectionChange = (selection) => {
  // æŸ¥è¯¢åˆ—表
  /** æœç´¢æŒ‰é’®æ“ä½œ */
  const handleQuery = () => {
    page.current = 1;
    getList();
  };
  const paginationChange = obj => {
    page.current = obj.page;
    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;
  };
  // è¿‡æ»¤æŽ‰å­æ•°æ®
  selectedRows.value = selection.filter(item => item.id);
  console.log('selection', selectedRows.value)
}
const expandedRowKeys = ref([])
  const getList = () => {
    tableLoading.value = true;
    const params = buildQueryParams();
    const apiCall =
      activeTab.value === "production"
        ? getStockManageProduction(params)
        : getStockManagePage(params);
    apiCall
      .then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
// ä¸»è¡¨åˆè®¡æ–¹æ³•
const summarizeMainTable = (param) => {
  return proxy.summarizeTable(param, ['contractAmount', 'taxInclusiveTotalPrice', 'taxExclusiveTotalPrice']);
};
        // ä¸ºè¡¨æ ¼æ•°æ®è‡ªåŠ¨è®¡ç®—æ€»ä»·
        // 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);
        //   }
        //
        //   return item;
        // });
// è¡¨æ ¼è¡Œç±»å
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 userListNoPageByTenantId()
  userList.value = userLists.data
  if (type === 'edit') {
    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;
          });
        }
        total.value = res.data.total;
        // æ•°æ®åŠ è½½å®ŒæˆåŽæ£€æŸ¥åº“å­˜
        // checkStockAndCreatePurchase();
      })
    })
  }
  form.value.entryDate = getCurrentDate() // è®¾ç½®é»˜è®¤å½•入日期为当前日期
  dialogFormVisible.value = true
}
      .catch(() => {
        tableLoading.value = false;
      });
  };
// æäº¤è¡¨å•
const submitForm = () => {
  console.log(form.value)
  proxy.$refs["formRef"].validate(valid => {
    if (valid) {
  // åˆ‡æ¢ tab
  const handleTabChange = () => {
    page.current = 1;
    // searchForm.value.supplierName = ''
    searchForm.value.customerName = "";
    searchForm.value.timeStr = "";
    selectedRows.value = [];
    searchForm.value.productCategory = "";
    getList();
  };
      updateManagement(form.value).then(res => {
        proxy.$modal.msgSuccess("提交成功")
        closeDia()
        getList()
  // è¡¨æ ¼é€‰æ‹©æ•°æ®
  const handleSelectionChange = selection => {
    // è¿‡æ»¤æŽ‰å­æ•°æ®
    selectedRows.value = selection.filter(item => item.id);
    console.log("selection", selectedRows.value);
  };
  const expandedRowKeys = ref([]);
  // ä¸»è¡¨åˆè®¡æ–¹æ³•
  const summarizeMainTable = param => {
    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 userListNoPageByTenantId();
    userList.value = userLists.data;
    if (type === "edit") {
      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;
            });
          }
        });
      });
    }
    form.value.entryDate = getCurrentDate(); // è®¾ç½®é»˜è®¤å½•入日期为当前日期
    // æ ¹æ®å½“前标签页显示对应的弹框
    if (activeTab.value === "production") {
      productionDialogVisible.value = true;
    } else if (activeTab.value === "purchase") {
      purchaseDialogVisible.value = true;
    }
  };
  // æäº¤è¡¨å•
  const submitForm = submittedData => {
    console.log("子组件提交的数据:", submittedData);
    // ä½¿ç”¨å­ç»„件提交的数据,而不是父组件的form对象
    const submitData = { ...submittedData };
    // æ ¹æ®å½“前标签页移除对应的总价字段
    if (activeTab.value === "production") {
      // æˆå“åº“存:移除总价字段
      delete submitData.totalPrice;
    } else if (activeTab.value === "purchase") {
      // åŽŸæ–™åº“å­˜ï¼šç§»é™¤å«ç¨Žæ€»ä»·å­—æ®µ
      delete submitData.taxInclusiveTotalPrice;
    }
    // ç§»é™¤å…¶ä»–可能的总价字段
    delete submitData.taxExclusiveTotalPrice;
    console.log("提交给后端的数据(已移除总价字段):", submitData);
    // æ ¹æ®å½“前标签页调用不同的提交接口
    let apiCall;
    if (activeTab.value === "production") {
      // æˆå“åº“存使用 updateManagement æŽ¥å£
      apiCall = updateManagement(submitData);
    } else {
      // åŽŸæ–™åº“å­˜ä½¿ç”¨ updateManagementByCustom æŽ¥å£
      apiCall = updateManagementByCustom(submitData);
    }
    apiCall
      .then(res => {
        proxy.$modal.msgSuccess("提交成功");
        closeDia();
        getList();
        // æäº¤åŽæ£€æŸ¥åº“存并尝试创建请购单
        // checkStockAndCreatePurchase();
      })
    }
  })
}
// æ£€æŸ¥åº“存并创建请购单
// 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
}
      .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");
    productionDialogVisible.value = false;
    purchaseDialogVisible.value = false;
  };
// å¯¼å‡º
const handleOut = () => {
  ElMessageBox.confirm(
    '是否确认导出?',
    '导出', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  }
  ).then(() => {
    proxy.download("/stockin/exportCopy", {}, '库存信息.xlsx')
  }).catch(() => {
    proxy.$modal.msg("已取消")
  })
}
// åˆ é™¤
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('请选择数据')
    return
  }
  ElMessageBox.confirm(
    '选中的内容将被删除,是否确认删除?',
    '导出', {
    confirmButtonText: '确认',
    cancelButtonText: '取消',
    type: 'warning',
  }
  ).then(() => {
    delStockManage({ids:ids}).then(res => {
      proxy.$modal.msgSuccess("删除成功")
      getList()
  // å¯¼å‡º
  const handleOut = () => {
    ElMessageBox.confirm("是否确认导出?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
  }).catch(() => {
    proxy.$modal.msg("已取消")
  })
}
onMounted(() => {
  getList()
  // checkStockAndCreatePurchase();
      .then(() => {
        const exportParams = buildQueryParams();
        // æ ¹æ®ä¸åŒçš„ tab ç±»åž‹è°ƒç”¨ä¸åŒçš„导出接口
        let exportUrl = "/stockin/exportCopy";
        if (activeTab.value === "production") {
          exportUrl = "/stockin/exportCopyOne";
        }
        proxy.download(exportUrl, exportParams, "库存信息.xlsx");
      })
      .catch(() => {
        proxy.$modal.msg("已取消");
      });
  };
  // åˆ é™¤
  const handleDelete = () => {
    let ids = [];
    if (selectedRows.value.length > 0) {
      ids = selectedRows.value.map(item => item.id);
    } else {
      proxy.$modal.msgWarning("请选择数据");
      return;
    }
    ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "导出", {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
    })
      .then(() => {
        delStockManage({ ids: ids }).then(res => {
          proxy.$modal.msgSuccess("删除成功");
          getList();
        });
      })
      .catch(() => {
        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}`;
  }
  onMounted(() => {
    getList();
    // checkStockAndCreatePurchase();
    // æ¯å°æ—¶æ£€æŸ¥ä¸€æ¬¡åº“å­˜
    // const intervalId = setInterval(checkStockAndCreatePurchase, 60 * 60 * 1000);
// onUnmounted(() => {
//   // ç»„件卸载时清除定时器
//   clearInterval(intervalId);
// });
})
    // onUnmounted(() => {
    //   // ç»„件卸载时清除定时器
    //   clearInterval(intervalId);
    // });
  });
</script>
<style scoped lang="scss">
:deep(.row-low-stock td) {
  background-color: #fde2e2;
  color: #c45656;
}
  :deep(.row-low-stock td) {
    background-color: #fde2e2;
    color: #c45656;
  }
:deep(.row-low-stock:hover > td) {
  background-color: #fcd4d4;
}
</style>
  :deep(.row-low-stock:hover > td) {
    background-color: #fcd4d4;
  }
</style>
src/views/inventoryManagement/stockWarning/index.vue
@@ -306,8 +306,9 @@
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeDialog">取消</el-button>
          <el-button type="primary" @click="submitForm">确认</el-button>
          <el-button @click="closeDialog">取消</el-button>
        </div>
      </template>
    </el-dialog>
src/views/login.vue
@@ -10,7 +10,6 @@
          size="large"
          auto-complete="off"
          placeholder="账号"
          @input="getUserLoginFacotryList"
        >
          <template #prefix><el-icon><User /></el-icon></template>
        </el-input>
@@ -28,11 +27,6 @@
          <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
        </el-input>
      </el-form-item>
<!--      <el-form-item prop="currentFatoryId">-->
<!--        <el-select v-model="loginForm.currentFatoryId" placeholder="请选择公司" filterable>-->
<!--          <el-option  v-for="item in factoryList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item prop="code" v-if="captchaEnabled">-->
<!--        <el-input-->
<!--          v-model="loginForm.code"-->
@@ -77,7 +71,6 @@
import Cookies from "js-cookie"
import { encrypt, decrypt } from "@/utils/jsencrypt"
import useUserStore from '@/store/modules/user'
import {userLoginFacotryList} from "@/api/system/user.js"
const title = import.meta.env.VITE_APP_TITLE
const userStore = useUserStore()
@@ -104,8 +97,6 @@
// æ³¨å†Œå¼€å…³
const register = ref(false)
const redirect = ref(undefined)
const factoryList = ref([])
watch(route, (newRoute) => {
    redirect.value = newRoute.query && newRoute.query.redirect
@@ -160,20 +151,8 @@
  }
}
function getUserLoginFacotryList() {
  if(loginForm.value.username){
    userLoginFacotryList({userName:loginForm.value.username}).then(res => {
      console.log('res', res)
      factoryList.value = res.data
    })
  }else {
    factoryList.value = []
  }
}
getCode()
getCookie()
getUserLoginFacotryList()
</script>
<style lang='scss' scoped>
src/views/productionManagement/productStructure/Detail/index.vue
@@ -1,4 +1,4 @@
<template>
<template xmlns="">
  <div class="app-container">
    <PageHeader content="产品结构详情">
      <template #right-button>
src/views/productionManagement/productionOrder/index.vue
@@ -41,7 +41,9 @@
        </el-form-item>
      </el-form>
      <div>
        <el-button type="primary" @click="openCreateOrder">新增订单</el-button>
        <el-button @click="handleOut">导出</el-button>
        <el-button type="danger" plain :disabled="selectedRows.length === 0" @click="handleBatchDelete">批量删除</el-button>
      </div>
    </div>
    <div class="table_list">
@@ -50,6 +52,8 @@
                :tableData="tableData"
                :page="page"
                :tableLoading="tableLoading"
                :isSelection="true"
                @selection-change="handleSelectionChange"
                @pagination="pagination">
        <template #completionStatus="{ row }">
          <el-progress
@@ -85,20 +89,79 @@
        </span>
      </template>
    </el-dialog>
    <el-dialog v-model="orderFormVisible"
               title="新增生产订单"
               width="520px"
               @close="() => proxy?.resetForm?.('orderFormRef')">
      <el-form ref="orderFormRef"
               :model="orderForm"
               :rules="orderRules"
               label-width="120px"
               label-position="top">
        <el-form-item label="产品大类" prop="productId">
          <el-tree-select v-model="orderForm.productId"
                          placeholder="请选择"
                          clearable
                          check-strictly
                          :data="productOptions"
                          :render-after-expand="false"
                          style="width: 100%"
                          @change="getModels" />
        </el-form-item>
        <el-form-item label="规格型号" prop="productModelId">
          <el-select v-model="orderForm.productModelId"
                     placeholder="请选择"
                     clearable
                     style="width: 100%"
                     @change="getProductModel">
            <el-option v-for="item in modelOptions"
                       :key="item.id"
                       :label="item.model"
                       :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="orderForm.unit"
                    placeholder="请输入"
                    clearable />
        </el-form-item>
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item label="数量" prop="quantity">
              <el-input-number v-model="orderForm.quantity"
                               :step="0.1"
                               :min="0"
                               :precision="2"
                               placeholder="请输入"
                               style="width: 100%"
                               @change="calculateFromQuantity" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="submitCreateOrder">ç¡® è®¤</el-button>
          <el-button @click="orderFormVisible = false">取 æ¶ˆ</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
  import { onMounted, ref } from "vue";
  import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue";
  import { ElMessageBox } from "element-plus";
  import dayjs from "dayjs";
  import { useRouter } from "vue-router";
  import {
    productOrderListPage,
    addProductOrder,
    listProcessRoute,
    bindingRoute,
    listProcessBom,
    deleteProductOrder,
  } from "@/api/productionManagement/productionOrder.js";
  import { productTreeList, modelList } from "@/api/basicData/product.js";
  import { listMain as getOrderProcessRouteMain } from "@/api/productionManagement/productProcessRoute.js";
  const { proxy } = getCurrentInstance();
@@ -111,22 +174,12 @@
      width: '120px',
    },
    {
      label: "销售合同号",
      prop: "salesContractNo",
      width: '150px',
    },
    {
      label: "客户名称",
      prop: "customerName",
      width: '200px',
    },
    {
      label: "产品名称",
      label: "产品大类",
      prop: "productCategory",
      width: '120px',
    },
    {
      label: "规格",
      label: "规格型号",
      prop: "specificationModel",
      width: '120px',
    },
@@ -196,6 +249,7 @@
  ]);
  const tableData = ref([]);
  const tableLoading = ref(false);
  const selectedRows = ref([]);
  const page = reactive({
    current: 1,
    size: 100,
@@ -212,6 +266,30 @@
    },
  });
  const { searchForm } = toRefs(data);
  // æ–°å¢žè®¢å•弹框数据
  const orderFormVisible = ref(false);
  const orderFormRef = ref(null);
  const orderFormState = reactive({
    orderForm: {
      productId: null,
      productCategory: "",
      productModelId: "",
      specificationModel: "",
      unit: "",
      quantity: null,
    },
    orderRules: {
      productId: [{ required: true, message: "请选择产品大类", trigger: "change" }],
      productModelId: [{ required: true, message: "请选择规格型号", trigger: "change" }],
      specificationModel: [{ required: true, message: "请选择规格型号", trigger: "change" }],
      unit: [{ required: true, message: "请输入单位", trigger: "blur" }],
      quantity: [{ required: true, message: "请输入数量", trigger: "blur" }],
    },
  });
  const { orderForm, orderRules } = toRefs(orderFormState);
  const productOptions = ref([]);
  const modelOptions = ref([]);
  const toProgressPercentage = val => {
    const n = Number(val);
@@ -378,8 +456,124 @@
      });
  };
  // è¡¨æ ¼é€‰æ‹©æ•°æ®
  const handleSelectionChange = (selection) => {
    selectedRows.value = selection || [];
  };
  // æ‰¹é‡åˆ é™¤
  const handleBatchDelete = async () => {
    if (selectedRows.value.length === 0) {
      proxy.$modal.msgWarning("请选择要删除的数据");
      return;
    }
    const ids = selectedRows.value.map(item => item.productModelId).filter(Boolean);
    if (ids.length === 0) {
      proxy.$modal.msgWarning("选中数据缺少ID,无法删除");
      return;
    }
    try {
      await ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      });
      await deleteProductOrder(ids);
      proxy.$modal.msgSuccess("删除成功");
      selectedRows.value = [];
      getList();
    } catch (e) {
      // å–消或失败
      if (e !== 'cancel' && e !== 'close') {
        console.error("批量删除失败:", e);
        proxy.$modal.msgError("删除失败,请重试");
      }
    }
  };
  const handleConfirmRoute = () => {};
  const openCreateOrder = async () => {
    orderForm.value = {
      productId: null,
      productCategory: "",
      productModelId: "",
      specificationModel: "",
      unit: "",
      quantity: null,
    };
    await loadProductOptions();
    orderFormVisible.value = true;
  };
  const loadProductOptions = async () => {
    const tree = await productTreeList();
    productOptions.value = Array.isArray(tree?.data) ? convertIdToValue(tree.data) : convertIdToValue(tree || []);
  };
  const convertIdToValue = data => {
    return (data || []).map(item => {
      const { id, children, ...rest } = item;
      const newItem = { ...rest, value: id };
      if (children && children.length > 0) {
        newItem.children = convertIdToValue(children);
      }
      return newItem;
    });
  };
  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;
        }
      }
    }
    return null;
  };
  const getModels = async value => {
    orderForm.value.productId = value;
    orderForm.value.productCategory = findNodeById(productOptions.value, value);
    const res = await modelList({ id: value });
    modelOptions.value = res || [];
  };
  const getProductModel = value => {
    const index = modelOptions.value.findIndex(item => item.id === value);
    if (index !== -1) {
      orderForm.value.specificationModel = modelOptions.value[index].model;
      orderForm.value.unit = modelOptions.value[index].unit;
    } else {
      orderForm.value.specificationModel = null;
      orderForm.value.unit = null;
    }
  };
  const calculateFromQuantity = () => {
    // å ä½ï¼šæ•°é‡å˜æ›´æ—¶å¯åœ¨æ­¤æ‰©å±•逻辑
  };
  const submitCreateOrder = async () => {
    proxy.$refs["orderFormRef"]?.validate(async valid => {
      if (!valid) return;
      try {
        await addProductOrder(orderForm.value);
        proxy.$modal.msgSuccess("新增成功");
        orderFormVisible.value = false;
        getList();
      } catch (e) {
        console.error("新增生产订单失败", e);
        proxy.$modal.msgError("新增失败,请稍后重试");
      }
    });
  };
  onMounted(() => {
    getList();
  });
src/views/salesManagement/salesLedger/fileList.vue
@@ -14,7 +14,7 @@
</template>
<script setup>
import { ref } from 'vue'
import { ref, getCurrentInstance } from 'vue'
import filePreview from '@/components/filePreview/index.vue'
const dialogVisible = ref(false)
src/views/salesManagement/salesLedger/index.vue
@@ -55,33 +55,11 @@
                  <el-tag v-if="scope.row.approveStatus === 4" type="danger">审核失败</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="发货车牌" minWidth="100px" align="center">
                <template #default="scope">
                  <div>
                    <el-tag type="success" v-if="scope.row.shippingCarNumber">{{ scope.row.shippingCarNumber }}</el-tag>
                    <el-tag v-else type="info">未发货</el-tag>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="发货日期" minWidth="100px" align="center">
                <template #default="scope">
                  <div>
                    <div v-if="scope.row.shippingDate">{{ scope.row.shippingDate }}</div>
                    <el-tag v-else type="info">未发货</el-tag>
                  </div>
                </template>
              </el-table-column>
              <el-table-column label="数量" prop="quantity" />
              <el-table-column label="税率(%)" prop="taxRate" />
              <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 Width="60px" label="操作" align="center">
                <template #default="scope">
                  <el-button :disabled="scope.row.approveStatus!==2 || scope.row.approveStatus!==5" link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</el-button>
                </template>
              </el-table-column>
            </el-table>
          </template>
        </el-table-column>
@@ -95,12 +73,13 @@
        <el-table-column label="录入人" prop="entryPersonName" width="100" show-overflow-tooltip />
        <el-table-column label="录入日期" prop="entryDate" width="120" show-overflow-tooltip />
        <el-table-column label="签订日期" prop="executionDate" width="120" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" min-width="100" align="center">
        <el-table-column label="发货车牌" prop="shippingCarNumber" width="140" align="center" show-overflow-tooltip />
        <el-table-column label="发货日期" prop="shippingDate" width="140" align="center" show-overflow-tooltip />
        <el-table-column fixed="right" label="操作" min-width="140" 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('view', scope.row)">详情</el-button>-->
            <el-button link type="primary" size="small" @click="downLoadFile(scope.row)">附件</el-button>
<!--            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</el-button>-->
            <el-button link type="primary" size="small" @click="openDeliveryForm(scope.row)">发货</el-button>
          </template>
        </el-table-column>
      </el-table>
@@ -492,7 +471,7 @@
import { UploadFilled } from "@element-plus/icons-vue";
import useUserStore from "@/store/modules/user";
import { userListNoPage } from "@/api/system/user.js";
import FileListDialog from '@/components/Dialog/FileListDialog.vue';
import FileList from '@/views/salesManagement/salesLedger/fileList.vue';
import FormDialog from '@/components/Dialog/FormDialog.vue';
import { getQuotationList } from "@/api/salesManagement/salesQuotation.js";
import {
@@ -1622,16 +1601,18 @@
// æ‰“开发货弹框
const openDeliveryForm = (row) => {
  getProductInventory({ salesLedgerId: row.id, type:1 }).then((res) => {
    currentDeliveryRow.value = row;
    deliveryForm.value = {
      shippingDate: getCurrentDate(),
      shippingCarNumber: "",
    };
    deliveryFormVisible.value = true;
  }).catch(err => {
    ElMessage.error(err.msg);
  });
  // getProductInventory({ salesLedgerId: row.id, type:1 }).then((res) => {
  //   currentDeliveryRow.value = row;
  //   deliveryForm.value = {
  //     shippingDate: getCurrentDate(),
  //     shippingCarNumber: "",
  //   };
  //   deliveryFormVisible.value = true;
  // }).catch(err => {
  //   ElMessage.error(err.msg);
  // });
    currentDeliveryRow.value = row;
    deliveryFormVisible.value = true;
};
// æäº¤å‘货表单