sampleSubmissionViewer.vue 7.64 KB
<template>
    <view class="detail-page">
        <scroll-view class="scroll" scroll-y>
            <!-- 基础信息 -->
            <view class="section">
                <text class="row company">{{ safeText(form.code) }}</text>
                <view class="row"><text class="label">码单编号</text><text class="value">{{ safeText(form.weighingTicketCode) }}</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">{{ departmentName }}</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">{{ 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="!sampleLines.length" class="empty-tip">暂无明细</view>
                    <view v-for="(item, idx) in sampleLines" :key="'s-' + idx" class="card">
                        <view class="card-index">第 {{ idx + 1 }} 行</view>
                        <view class="row"><text class="label">取样次序</text><text class="value">{{ safeText(item.sampleNo) }}</text></view>
                        <view class="row"><text class="label">取样编号</text><text class="value">{{ safeText(item.sampleCode) }}</text></view>
                    </view>
                </view>
            </view>
        </scroll-view>
    </view>
</template>

<script>
import { assayApplyDetailApi } from '@/api/procure-manage/assayApply.js'
import { getDicByCodes, getDicName } from '@/utils/dic.js'

export default {
    name: 'SampleSubmissionViewer',
    props: { id: { type: [String, Number], default: '' } },
    data() {
        return {
            form: {},
            // 取样明细
            sampleLines: [],
            dicOptions: {
                DEPARTMENT: [],
                AUDIT_STATUS: []
            }
        }
    },
    computed: {
        departmentName() {
            const v = this.form.department == null ? '' : String(this.form.department)
            if (!v) return '-'
            return getDicName('DEPARTMENT', v, this.dicOptions.DEPARTMENT) || v
        },
        approvalStatusName() {
            const v = this.form.approvalStatus == null ? '' : String(this.form.approvalStatus)
            if (!v) return '-'
            return getDicName('AUDIT_STATUS', v, this.dicOptions.AUDIT_STATUS) || v
        }
    },
    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(['DEPARTMENT', 'AUDIT_STATUS'])
                this.dicOptions.DEPARTMENT = (results.DEPARTMENT && results.DEPARTMENT.data) || []
                this.dicOptions.AUDIT_STATUS = (results.AUDIT_STATUS && results.AUDIT_STATUS.data) || []
            } catch (e) {
                this.dicOptions = { DEPARTMENT: [], AUDIT_STATUS: [] }
            }
        },
        loadDetail(id) {
            assayApplyDetailApi({ id })
                .then(res => {
                    const data = res && res.data ? res.data : {}
                    this.form = Object.assign({}, data)
                    // 取样明细回显
                    this.sampleLines = Array.isArray(data.lines) ? data.lines.map(x => ({ ...x })) : []
                })
                .catch(() => {
                    uni.showToast({ title: '详情加载失败', icon: 'none' })
                })
        },
        // 供审批页通过时取业务表单数据(variables,对齐 PC 端 approve.vue getFormData)
        getFormValues() {
            return Object.assign({}, this.form)
        },
        // 审批表单只读,无需校验
        checkForm() {
            return true
        },
        safeText(v) {
            const s = v == null ? '' : String(v)
            return s.trim() ? s : '-'
        }
    }
}
</script>

<style lang="scss" scoped>
.detail-page {
    background: #f3f3f3;
    min-height: 100%;
}
.scroll {
    height: 100%;
}
.section {
    padding: 32rpx;
    background: #fff;
    margin-bottom: 20rpx;
}
.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;
    }
}
.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;

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

        .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>