| | |
| | | loadingTools: false, |
| | | loadingForm: false, |
| | | submitting: false, |
| | | _searchTimer: null |
| | | _searchTimer: null, |
| | | workOrderCurrentCjNum: null // 工单当前数采 |
| | | }; |
| | | }, |
| | | computed: { |
| | |
| | | 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 |
| | | ); |
| | |
| | | this.loadingTools = false; |
| | | } |
| | | }, |
| | | //翻页 |
| | | async prevPage() { |
| | | if (this.pageIndex > 1) { |
| | | this.pageIndex--; |
| | |
| | | } |
| | | }, |
| | | 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; |
| | |
| | | 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 |
| | | async handleUpTool() { |
| | | if (!this.workOrderNo) { this.$showMessage('工单号不能为空'); return; } |
| | | if (!this.machineNo) { this.$showMessage('机台号不能为空'); return; } |
| | |
| | | const useLimit = Number(this.useLimitInput); |
| | | if (isNaN(useLimit) || useLimit <= 0) { this.$showMessage('请输入有效的使用上限'); return; } |
| | | |
| | | // sdjs 使用工单 currentCjNum |
| | | const sdjs = this.workOrderCurrentCjNum != null ? Number(this.workOrderCurrentCjNum) : null; |
| | | |
| | | const payload = { |
| | | workOrderNo: this.workOrderNo, |
| | | machineNo: this.machineNo, |
| | | toolNo: this.selectedToolNo, |
| | | type: '上刀', |
| | | useLimit |
| | | useLimit, |
| | | sdjs // 上刀计数(工单当前数采) |
| | | }; |
| | | try { |
| | | this.submitting = true; |
| | |
| | | this.submitting = false; |
| | | } |
| | | }, |
| | | // 下刀时传递 xdjs = 工单 currentCjNum |
| | | async handleDownTool() { |
| | | if (!this.workOrderNo) { this.$showMessage('工单号不能为空'); return; } |
| | | if (!this.machineNo) { this.$showMessage('机台号不能为空'); return; } |
| | |
| | | const useLimit = Number(this.useLimitInput); |
| | | if (isNaN(useLimit) || useLimit <= 0) { this.$showMessage('请输入有效的使用上限'); return; } |
| | | |
| | | // 下刀计数同样取工单最新采集数 |
| | | const xdjs = this.workOrderCurrentCjNum != null ? Number(this.workOrderCurrentCjNum) : null; |
| | | |
| | | const payload = { |
| | | workOrderNo: this.workOrderNo, |
| | | machineNo: this.machineNo, |
| | | toolNo: this.selectedToolNo, |
| | | type: '下刀', |
| | | useLimit |
| | | useLimit, |
| | | xdjs // 下刀计数 |
| | | }; |
| | | try { |
| | | this.submitting = true; |
| | |
| | | |
| | | 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)}%`; |
| | | }; |
| | |
| | | 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 useCount = getField(t, 'usE_COUNT', 'USE_COUNT', 'useCount'); |
| | | const useLimit = getField(t, 'usE_LIMIT', 'USE_LIMIT', 'useLimit'); |
| | | |
| | | // 计算寿命比(使用次数/使用上限) |
| | | let percent = ''; |
| | | if ( |
| | | useCount != null && useLimit != null && |
| | |
| | | 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(); |
| | |
| | | }; |
| | | 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); |
| | |
| | | useLimit: useLimit ?? '', |
| | | lifePercent: percent, |
| | | lifeWarn: formatPercent(lifeWarnNum), |
| | | warnStatus |
| | | warnStatus, |
| | | currentCjNum |
| | | }; |
| | | }); |
| | | |
| | |
| | | this.loadingForm = false; |
| | | } |
| | | }, |
| | | // 自动带出工单刀具信息 |
| | | async fetchDefaultToolFromWorkOrder() { |
| | | if (!this.machineNo) return; // 注意:这里用机台号 |
| | | try { |
| | | const res = await this.$post({ |
| | | url: '/Womdaa/GetWomdaasByShow', |
| | | data: JSON.stringify({ machineNo: this.machineNo }), |
| | | headers: { 'Content-Type': 'application/json' } |
| | | }); |
| | | if (res.status === 0 && Array.isArray(res.data?.tbBillList) && res.data.tbBillList.length > 0) { |
| | | const tool = res.data.tbBillList[0]; |
| | | this.selectedToolNo = tool.cutterId || tool.cutteR_ID || ''; |
| | | this.toolName = tool.cutterName || tool.cutteR_NAME || ''; |
| | | this.toolModel = tool.cutterModel || tool.cutteR_MODEL || ''; |
| | | } |
| | | } catch (e) { |
| | | console.warn('自动带出工单刀具失败', e); |
| | | } |
| | | }, |
| | | // 自动带出工单刀具信息,并获取工单最新采集数 |
| | | async fetchDefaultToolFromWorkOrder() { |
| | | if (!this.machineNo) return; |
| | | try { |
| | | const res = await this.$post({ |
| | | url: '/Womdaa/GetWomdaasByShow', |
| | | data: JSON.stringify({ machineNo: this.machineNo }), |
| | | headers: { 'Content-Type': 'application/json' } |
| | | }); |
| | | if (res.status === 0 && Array.isArray(res.data?.tbBillList) && res.data.tbBillList.length > 0) { |
| | | const order = res.data.tbBillList[0]; |
| | | this.selectedToolNo = order.cutterId || order.cutteR_ID || ''; |
| | | this.toolName = order.cutterName || order.cutteR_NAME || ''; |
| | | this.toolModel = order.cutterModel || order.cutteR_MODEL || ''; |
| | | // 关键:获取工单最新采集数 |
| | | this.workOrderCurrentCjNum = order.CurrentCjNum ?? order.currentCjNum ?? null; |
| | | } else { |
| | | this.workOrderCurrentCjNum = null; |
| | | } |
| | | } catch (e) { |
| | | console.warn('自动带出工单刀具失败', e); |
| | | this.workOrderCurrentCjNum = null; |
| | | } |
| | | }, |
| | | formatDateTime(dateTimeStr) { |
| | | if (!dateTimeStr) return ''; |
| | | try { |
| | |
| | | |
| | | if (this.machineNo && this.workOrderNo) { |
| | | this.fetchFormData(); |
| | | this.fetchDefaultToolFromWorkOrder(); // 自动带出工单刀具 |
| | | this.fetchDefaultToolFromWorkOrder(); |
| | | } else { |
| | | console.warn('机台号或工单号为空,无法获取表单数据'); |
| | | } |