materialTestViewer.vue 12.8 KB
<template>
    <view class="detail-page">
        <scroll-view class="scroll" scroll-y>
            <!-- 基础信息 -->
            <view class="section">
                <text class="row company">{{ safeText(form.weighingTicketCode) }}</text>
                <view class="row"><text class="label">日期</text><text class="value">{{ safeText(form.reportDate) }}</text></view>
                <view class="row"><text class="label">客户名称</text><text class="value">{{ safeText(form.supplierName) }}</text></view>
                <view class="row"><text class="label">分厂</text><text class="value">{{ safeText(form.workshopName) }}</text></view>
                <view class="row"><text class="label">计划编号</text><text class="value">{{ safeText(form.planCode) }}</text></view>
                <view class="row"><text class="label">过磅品种</text><text class="value">{{ safeText(form.productName) }}</text></view>
                <view class="row"><text class="label">审核状态</text><text class="value">{{ approvalStatusName }}</text></view>
                <view class="row"><text class="label">流程节点</text><text class="value">{{ flowNodeName }}</text></view>
                <view class="row"><text class="label">创建人</text><text class="value">{{ safeText(form.createBy) }}</text></view>
                <view class="row"><text class="label">创建时间</text><text class="value">{{ safeText(form.createTime) }}</text></view>
            </view>

            <!-- 化验明细(只读) -->
            <view class="sub-table">
                <view class="sub-header">
                    <image class="sub-bar" src="/static/images/title.png" />
                    <text class="sub-title">化验明细</text>
                </view>
                <view class="sub-body">
                    <view v-if="!lines.length" class="empty-tip">暂无明细</view>
                    <view v-for="(item, idx) in lineRows" :key="'l-' + (item.assayApplyId || idx)" class="card">
                        <view class="card-index">第 {{ idx + 1 }} 行</view>
                        <view class="row"><text class="label">样品</text><text class="value">{{ safeText(item.productName) }}</text></view>
                        <view class="row"><text class="label">数量</text><text class="value">{{ formatNumber(item.quantity) }}</text></view>
                        <view class="row"><text class="label">样号</text><text class="value">{{ safeText(item.testCode) }}</text></view>
                        <view class="row"><text class="label">送样编号</text><text class="value">{{ safeText(item.assayApplyCode) }}</text></view>
                        <view v-for="key in componentKeys" :key="key" class="row">
                            <text class="label">{{ componentLabels[key] || key }}</text>
                            <text class="value">{{ formatNumber(item[key]) }}</text>
                        </view>
                    </view>
                </view>
            </view>

            <!-- 修改意向(有值时展示,对齐 PC 端 detail-form) -->
            <template v-if="hasQualityProblemName">
                <view class="title-header">
                    <image class="title-header_icon" src="/static/images/title.png" />
                    <span>修改意向</span>
                </view>
                <view class="section">
                    <view class="row"><text class="label">是否有质量问题</text><text class="value">{{ hasQualityProblemName }}</text></view>
                    <view v-if="hasQualityProblemBool" class="row"><text class="label">处理意见</text><text class="value">{{ safeText(form.processOpinion) }}</text></view>
                </view>
            </template>

            <!-- 是否继续审批(assay_report_yfcckzg 节点必填) -->
            <view v-if="showContinueApproval" class="section">
                <view class="field-row">
                    <view class="field-label"><text class="required">*</text><text>是否继续审批</text></view>
                    <uni-data-checkbox
                        mode="tag"
                        :multiple="false"
                        :value-field="'value'"
                        :text-field="'text'"
                        v-model="continueApproval"
                        :localdata="continueApprovalOptions"
                    />
                </view>
            </view>
        </scroll-view>
    </view>
</template>

<script>
import { getDicByCodes, getDicName } from '@/utils/dic.js'
import { COMPONENT_LABELS, getComponentKeys } from './component-config.js'
import { assayReportDetailApi } from '@/api/procure-manage/assayReport.js'

export default {
    name: 'MaterialTestViewer',
    props: {
        id: { type: [String, Number], default: '' },
        // 当前审核节点编码(flow/audit 透传,flow/instance/getByBusinessId 返回)
        nodeCode: { type: String, default: '' }
    },
    data() {
        return {
            form: {},
            lines: [],
            componentLabels: COMPONENT_LABELS,
            // 是否继续审批(assay_report_yfcckzg 节点必填)
            continueApproval: undefined,
            continueApprovalOptions: [
                { value: true, text: '是' },
                { value: false, text: '否' }
            ],
            dicOptions: {
                AUDIT_STATUS: [],
                FLOW_NODE: []
            }
        }
    },
    computed: {
        // assay_report_gyglkzg2 节点需填写 是否继续审批
        showContinueApproval() {
            return this.nodeCode === 'assay_report_gyglkzg2'
        },
        componentKeys() {
            // 按 workshopCode 匹配成分项,名称兜底
            return getComponentKeys(this.form.workshopCode, this.form.workshopName)
        },
        // 是否有质量问题名称(兼容 1/0、true/false、'1'/'0' 返回,无值返回空不展示)
        hasQualityProblemName() {
            const v = this.form.hasQualityProblem
            if (v === true || v === 1 || v === '1') return '是'
            if (v === false || v === 0 || v === '0') return '否'
            return ''
        },
        // 是否有质量问题-是
        hasQualityProblemBool() {
            const v = this.form.hasQualityProblem
            return v === true || v === 1 || v === '1'
        },
        approvalStatusName() {
            const v = this.form.approvalStatus == null ? '' : String(this.form.approvalStatus)
            if (!v) return '-'
            return getDicName('AUDIT_STATUS', v, this.dicOptions.AUDIT_STATUS) || v
        },
        flowNodeName() {
            const v = this.form.flowNode == null ? '' : String(this.form.flowNode)
            if (!v) return '-'
            return getDicName('FLOW_NODE', v, this.dicOptions.FLOW_NODE) || v
        },
        // 化验明细展示行(样号按行序编号展示)
        lineRows() {
            return (this.lines || []).map((item, index) => ({
                ...item,
                testCode: item.testCode || String(index + 1)
            }))
        }
    },
    created() {
        this.loadDicData()
    },
    watch: {
        id: {
            immediate: true,
            handler(val) {
                const v = (val !== undefined && val !== null) ? String(val) : ''
                if (v) this.loadDetail(v)
            }
        }
    },
    methods: {
        async loadDicData() {
            try {
                const results = await getDicByCodes(['AUDIT_STATUS', 'FLOW_NODE'])
                this.dicOptions.AUDIT_STATUS = (results.AUDIT_STATUS && results.AUDIT_STATUS.data) || []
                this.dicOptions.FLOW_NODE = (results.FLOW_NODE && results.FLOW_NODE.data) || []
            } catch (e) {
                this.dicOptions = { AUDIT_STATUS: [], FLOW_NODE: [] }
            }
        },
        // 按业务 id 加载化验报告单详情
        loadDetail(id) {
            assayReportDetailApi({ id })
                .then(res => {
                    const data = (res && res.data) || {}
                    this.form = Object.assign({}, data)
                    this.lines = Array.isArray(data.lines) ? data.lines.map(x => ({ ...x })) : []
                })
                .catch(() => {
                    uni.showToast({ title: '详情加载失败', icon: 'none' })
                })
        },
        // 供审批页通过时取业务表单数据(variables,对齐 PC 端 viewer.vue getFormData)
        getFormValues() {
            const vals = Object.assign({}, this.form)
            // assay_report_yfcckzg 节点:审批意见 是否继续审批 随 variables 提交
            if (this.showContinueApproval) {
                vals.continueApproval = this.continueApproval
            }
            return vals
        },
        // 审批表单校验:assay_report_yfcckzg 节点 是否继续审批 必填
        checkForm() {
            if (this.showContinueApproval && this.continueApproval !== true && this.continueApproval !== false) {
                uni.showToast({ title: '请选择是否继续审批', icon: 'none' })
                return false
            }
            return true
        },
        safeText(v) {
            const s = v == null ? '' : String(v)
            return s.trim() ? s : '-'
        },
        formatNumber(v) {
            if (v === null || v === undefined || v === '') return '-'
            const n = Number(v)
            if (isNaN(n)) return String(v)
            return n.toLocaleString('zh-CN', { maximumFractionDigits: 4 })
        }
    }
}
</script>

<style lang="scss" scoped>
.detail-page {
    background: #f3f3f3;
    min-height: 100%;
}
.scroll {
    height: 100%;
}
.section {
    padding: 32rpx;
    background: #fff;
    margin-bottom: 20rpx;
}
.title-header {
    display: flex;
    align-items: center;
    padding: 24rpx 32rpx 12rpx;
    background-color: #ffffff;
    .title-header_icon { width: 36rpx; height: 36rpx; margin-right: 12rpx; }
    span { font-size: 34rpx; font-weight: 600; color: rgba(0, 0, 0, 0.9); }
}
.row {
    display: flex;
    margin-bottom: 28rpx;

    &:last-child {
        margin-bottom: 0;
    }

    &.company {
        font-size: 36rpx;
        font-weight: 600;
        color: rgba(0, 0, 0, 0.9);
        padding-top: 8rpx;
        line-height: 50rpx;
    }

    .label {
        max-width: 420rpx;
        margin-right: 20rpx;
        line-height: 32rpx;
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.6);
    }

    .value {
        flex: 1;
        line-height: 32rpx;
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.9);
        text-align: right;
        word-break: break-all;
    }
}

.field-row {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .field-label {
        flex: none;
        font-size: 32rpx;
        color: rgba(0, 0, 0, 0.9);
        position: relative;
        padding-left: 16rpx;

        .required {
            color: red;
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            left: 0;
        }
    }
}
.sub-table {
    background: #fff;
    margin-bottom: 20rpx;
}
.sub-header {
    display: flex;
    align-items: center;
    padding: 16rpx 0 16rpx 32rpx;
    .sub-bar { width: 6rpx; height: 32rpx; margin-right: 14rpx; }
    .sub-title { font-size: 30rpx; font-weight: 600; color: rgba(0, 0, 0, 0.9); flex: 1; line-height: 42rpx; }
}
.sub-body {
    padding: 0 32rpx 24rpx;
    .empty-tip {
        text-align: center;
        padding: 60rpx 0;
        color: rgba(0, 0, 0, 0.4);
        font-size: 28rpx;
    }
    .card {
        position: relative;
        background: #fafafa;
        border-radius: 12rpx;
        padding: 32rpx 28rpx 20rpx;
        margin-bottom: 24rpx;
        .card-index {
            position: absolute;
            top: 0;
            right: 0;
            background: rgba(24, 144, 255, 0.08);
            color: $theme-primary;
            font-size: 22rpx;
            line-height: 36rpx;
            padding: 0 16rpx;
            border-bottom-left-radius: 12rpx;
            border-top-right-radius: 12rpx;
        }
        .row {
            align-items: center;
            justify-content: space-between;
            padding: 14rpx 0;
            margin-bottom: 0;
            border-bottom: 1rpx dashed #f2f2f2;
            &:last-child { border-bottom: none; }
            .label {
                flex-shrink: 0;
                width: 220rpx;
                max-width: none;
                margin-right: 0;
                font-size: 28rpx;
                color: rgba(0, 0, 0, 0.6);
                line-height: 40rpx;
            }
            .value {
                flex: 1;
                text-align: right;
                font-size: 28rpx;
                color: rgba(0, 0, 0, 0.9);
                line-height: 40rpx;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
    }
}
</style>