快乐的昕的电脑
2025-10-18 0628e0c6f338f937feff00593f8069fd60a178f8
逻辑优化
已修改1个文件
39 ■■■■■ 文件已修改
components/mold.vue 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/mold.vue
@@ -129,7 +129,8 @@
                loadingTools: false,
                loadingForm: false,
                submitting: false,
                _searchTimer: null
                _searchTimer: null,
                workOrderCurrentCjNum: null // 工单当前数采
            };
        },
        computed: {
@@ -179,7 +180,6 @@
                        this.filteredTools = mapped;
                        this.toolList = mapped.slice();
                        // 修正 total 赋值优先级,优先取 res.data.total
                        const totalFromRes = Number(
                            res.data?.total ?? res.data?.totalCount ?? res.total ?? res.totalCount ?? mapped.length
                        );
@@ -197,7 +197,6 @@
                    this.loadingTools = false;
                }
            },
            //翻页
            async prevPage() {
                if (this.pageIndex > 1) {
                    this.pageIndex--;
@@ -211,21 +210,20 @@
                }
            },
            onSearchKeyInput() {
                // 防抖:输入时自动搜索(节省点击)
                clearTimeout(this._searchTimer);
                this._searchTimer = setTimeout(() => {
                    this.searchTool();
                }, 300);
            },
            async searchTool() {
                this.pageIndex = 1; // 搜索时重置到第一页
                this.pageIndex = 1;
                await this.fetchTools(this.searchKey);
            },
            selectTool(tool) {
                this.selectedToolNo = tool.no;
                this.toolName = tool.name;
                this.toolModel = tool.model;
                this.activeToolNo = tool.no; // 记录选中
                this.activeToolNo = tool.no;
            },
            confirmTool() {
                this.showToolDialog = false;
@@ -240,18 +238,16 @@
                    this.$showMessage('请输入有效的使用上限');
                    return;
                }
                // 仅前端更新表格显示(如需持久化请调用后端接口)
                this.toolRecords = this.toolRecords.map(r => {
                    if (r.no === this.selectedToolNo) {
                        return { ...r, useLimit: v };
                    }
                    return r;
                });
                // 同步 toolList 中的模型(可用来展示)
                this.toolList = this.toolList.map(t => t.no === this.selectedToolNo ? { ...t, useLimit: v } : t);
                this.$showMessage('使用上限已设置(仅前端显示)');
            },
            // 上刀时传递 sdjs = 当前 currentCjNum
            // 上刀时传递 sdjs = 工单 currentCjNum
            async handleUpTool() {
                if (!this.workOrderNo) { this.$showMessage('工单号不能为空'); return; }
                if (!this.machineNo) { this.$showMessage('机台号不能为空'); return; }
@@ -260,9 +256,8 @@
                const useLimit = Number(this.useLimitInput);
                if (isNaN(useLimit) || useLimit <= 0) { this.$showMessage('请输入有效的使用上限'); return; }
                // 查找当前刀具的 currentCjNum
                const currentTool = this.toolRecords.find(r => r.no === this.selectedToolNo);
                const sdjs = currentTool && currentTool.currentCjNum != null ? Number(currentTool.currentCjNum) : null;
                // sdjs 使用工单 currentCjNum
                const sdjs = this.workOrderCurrentCjNum != null ? Number(this.workOrderCurrentCjNum) : null;
                const payload = {
                    workOrderNo: this.workOrderNo,
@@ -270,7 +265,7 @@
                    toolNo: this.selectedToolNo,
                    type: '上刀',
                    useLimit,
                    sdjs // 上刀计数(当前数采)
                    sdjs // 上刀计数(工单当前数采)
                };
                try {
                    this.submitting = true;
@@ -301,7 +296,6 @@
                const useLimit = Number(this.useLimitInput);
                if (isNaN(useLimit) || useLimit <= 0) { this.$showMessage('请输入有效的使用上限'); return; }
                // 查找当前刀具的 downCount
                const currentTool = this.toolRecords.find(r => r.no === this.selectedToolNo);
                const xdjs = currentTool && currentTool.downCount != null ? Number(currentTool.downCount) : null;
@@ -379,22 +373,22 @@
                    const formatPercent = n => {
                        if (n === null || n === undefined || isNaN(n)) return '';
                        // 如果是小于等于1的小数,按比例放大
                        if (n <= 1) return `${(n * 100).toFixed(0)}%`;
                        return `${Number(n).toFixed(0)}%`;
                    };
                    // 获取工单 currentCjNum
                    this.workOrderCurrentCjNum = res.data?.currentCjNum ?? null;
                    const mapped = (list || []).map(t => {
                        const upTimeRaw = getField(t, 'uP_TIME', 'UP_TIME', 'uPTime', 'UPTIME', 'UpTime');
                        const downTimeRaw = getField(t, 'dowN_TIME', 'DOWN_TIME', 'downTime', 'DOWNTIME');
                        const lifeWarnRaw = getField(t, 'lifE_WARN', 'LIFE_WARN', 'lifeWarn', 'LIFEWARN');
                        const currentCjNum = getField(t, 'currentCjNum', 'CURRENTCJNUM', 'currentcjnum'); // 当前数采
                        const currentCjNum = getField(t, 'currentCjNum', 'CURRENTCJNUM', 'currentcjnum');
                        // 使用次数和上限
                        const useCount = getField(t, 'usE_COUNT', 'USE_COUNT', 'useCount');
                        const useLimit = getField(t, 'usE_LIMIT', 'USE_LIMIT', 'useLimit');
                        // 计算寿命比(使用次数/使用上限)
                        let percent = '';
                        if (
                            useCount != null && useLimit != null &&
@@ -404,7 +398,6 @@
                            percent = ((Number(useCount) / Number(useLimit)) * 100).toFixed(0) + '%';
                        }
                        // 预警值格式化
                        const parseNumber = v => {
                            if (v === null || v === undefined || v === '') return null;
                            const s = String(v).replace(/[,%%]/g, '').trim();
@@ -418,7 +411,6 @@
                        };
                        const lifeWarnNum = parseNumber(lifeWarnRaw);
                        // 预警规则:当寿命比 >= 预警值时标记 预警
                        let warnStatus = getField(t, 'status', 'STATUS') || '';
                        if (lifeWarnNum !== null && useCount != null && useLimit != null && !isNaN(useCount) && !isNaN(useLimit) && Number(useLimit) > 0) {
                            const percentNum = Number(useCount) / Number(useLimit);
@@ -440,7 +432,7 @@
                            lifePercent: percent,
                            lifeWarn: formatPercent(lifeWarnNum),
                            warnStatus,
                            currentCjNum // 当前数采
                            currentCjNum
                        };
                    });
@@ -457,9 +449,8 @@
                    this.loadingForm = false;
                }
            },
            // 自动带出工单刀具信息
            async fetchDefaultToolFromWorkOrder() {
                if (!this.machineNo) return; // 注意:这里用机台号
                if (!this.machineNo) return;
                try {
                    const res = await this.$post({
                        url: '/Womdaa/GetWomdaasByShow',
@@ -510,7 +501,7 @@
            if (this.machineNo && this.workOrderNo) {
                this.fetchFormData();
                this.fetchDefaultToolFromWorkOrder(); // 自动带出工单刀具
                this.fetchDefaultToolFromWorkOrder();
            } else {
                console.warn('机台号或工单号为空,无法获取表单数据');
            }