快乐的昕的电脑
2025-10-23 8a3c9928a60ed4ed3e96873c8d71384eb57e5953
components/mold.vue
@@ -11,6 +11,14 @@
                <label class="form-label">设置使用上限:</label>
                <input class="input" type="number" v-model="useLimitInput" placeholder="每次换刀后手填" :disabled="!selectedToolNo || loadingForm" />
            </view>
            <!-- 新增:寿命比预警值输入框 -->
            <view class="form-cell">
                <label class="form-label">寿命比预警值:</label>
                <input class="input"
                       v-model="lifeWarnInput"
                       placeholder="如0.9或90(%)"
                       :disabled="!selectedToolNo || loadingForm" />
            </view>
            <view class="form-cell">
                <label class="form-label">刀具名称:</label>
                <input class="input" v-model="toolName" placeholder="刀具带出" disabled />
@@ -125,6 +133,7 @@
                searchKey: '',
                filteredTools: [],
                useLimitInput: '',
                lifeWarnInput: '', // 新增:寿命比预警值原始输入
                toolRecords: [],
                loadingTools: false,
                loadingForm: false,
@@ -139,6 +148,15 @@
            }
        },
        methods: {
            // 新增:寿命比预警值归一化 (返回 0~1 或 null)
            normalizeLifeWarn(v) {
                if (v == null) return null;
                const raw = String(v).trim().replace(/[%%]/g, '');
                if (raw === '') return null;
                const num = Number(raw);
                if (!isFinite(num) || num <= 0) return null;
                return num > 1 ? (num / 100) : num;
            },
            openToolDialog() {
                this.showToolDialog = true;
                this.pageIndex = 1;
@@ -259,14 +277,15 @@
                // sdjs 使用工单 currentCjNum
                const sdjs = this.workOrderCurrentCjNum != null ? Number(this.workOrderCurrentCjNum) : null;
                const lifeWarnRatio = this.normalizeLifeWarn(this.lifeWarnInput);
                const payload = {
                    workOrderNo: this.workOrderNo,
                    machineNo: this.machineNo,
                    toolNo: this.selectedToolNo,
                    type: '上机',
                    useLimit,
                    sdjs // 上刀计数(工单当前数采)
                    sdjs,// 上刀计数(工单当前数采)
                    modlLifeWorning: lifeWarnRatio // 新增
                };
                try {
                    this.submitting = true;
@@ -309,14 +328,15 @@
                // 下刀计数同样取工单最新采集数
                const xdjs = this.workOrderCurrentCjNum != null ? Number(this.workOrderCurrentCjNum) : null;
                const lifeWarnRatio = this.normalizeLifeWarn(this.lifeWarnInput);
                const payload = {
                    workOrderNo: this.workOrderNo,
                    machineNo: this.machineNo,
                    toolNo: this.selectedToolNo,
                    type: '下机',
                    useLimit,
                    xdjs // 下刀计数
                    xdjs,// 下刀计数
                    modlLifeWorning: lifeWarnRatio // 新增
                };
                try {
                    this.submitting = true;
@@ -353,6 +373,7 @@
                this.toolName = '';
                this.toolModel = '';
                this.useLimitInput = '';
                this.lifeWarnInput = ''; // 新增:清空
            },
            async fetchFormData() {
                if (!this.workOrderNo || !this.machineNo) {
@@ -385,19 +406,6 @@
                        return null;
                    };
                    const parseNumber = v => {
                        if (v === null || v === undefined || v === '') return null;
                        const s = String(v).replace(/[,%%]/g, '').trim();
                        const n = parseFloat(s);
                        return Number.isFinite(n) ? n : null;
                    };
                    const formatPercent = n => {
                        if (n === null || n === undefined || isNaN(n)) return '';
                        if (n <= 1) return `${(n * 100).toFixed(0)}%`;
                        return `${Number(n).toFixed(0)}%`;
                    };
                    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');
@@ -408,11 +416,7 @@
                        const useLimit = getField(t, 'usE_LIMIT', 'USE_LIMIT', 'useLimit');
                        let percent = '';
                        if (
                            useCount != null && useLimit != null &&
                            !isNaN(useCount) && !isNaN(useLimit) &&
                            Number(useLimit) > 0
                        ) {
                        if (useCount != null && useLimit != null && !isNaN(useCount) && !isNaN(useLimit) && Number(useLimit) > 0) {
                            percent = ((Number(useCount) / Number(useLimit)) * 100).toFixed(0) + '%';
                        }
@@ -519,9 +523,8 @@
            this.fetchTools('');
            this.machineNo = uni.getStorageSync('machineNo') || '';
            this.workOrderNo = uni.getStorageSync('daa001') || '';
            console.log('机台号:', this.machineNo);
            console.log('工单号:', this.workOrderNo);
            // 默认预警值 (90% -> 0.9)
            this.lifeWarnInput = '90';
            if (this.machineNo && this.workOrderNo) {
                this.fetchFormData();
@@ -534,16 +537,17 @@
</script>
<style scoped>
    /* 原样保持,未改动样式,只插入了一个输入框 */
    .top-section-grid {
        display: flex;
        justify-content: center;
        align-items: flex-end;
        gap: 32px;
        margin-bottom: 2vh;
        width: 95vw; /* 新增,和表格宽度一致 */
        max-width: 1600px; /* 新增,和表格一致 */
        margin-left: auto; /* 新增,居中 */
        margin-right: auto; /* 新增,居中 */
        width: 95vw;
        max-width: 1600px;
        margin-left: auto;
        margin-right: auto;
    }
    .form-cell {
@@ -666,7 +670,7 @@
    }
    .tool-btn {
        flex: 0 0 24%; /* 每行4个按钮 */
        flex: 0 0 24%;
        box-sizing: border-box;
        margin: 5px 1% 5px 0;
        padding: 12px 18px;
@@ -722,7 +726,6 @@
        box-shadow: none;
    }
    /* 表格整体居中,宽度限制,内容居中 */
    .table-section {
        display: flex;
        justify-content: center;
@@ -731,8 +734,8 @@
    }
    table.styled-table {
        max-width: 1600px; /* 原为1400px,调宽 */
        width: 95vw; /* 原为90vw,调宽 */
        max-width: 1600px;
        width: 95vw;
        margin: 0 auto;
        border-collapse: separate;
        border-spacing: 0;
@@ -760,13 +763,11 @@
            text-align: center;
        }
    .table-section table th:first-child,
    .table-section table td:first-child {
    .table-section table th:first-child, .table-section table td:first-child {
        border-left: 2px solid #bfbfbf;
    }
    .table-section table th:last-child,
    .table-section table td:last-child {
    .table-section table th:last-child, .table-section table td:last-child {
        border-right: 2px solid #bfbfbf;
    }