detail.vue 17.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
<template>
  <view class="page">
    <scroll-view class="scroll" scroll-y>
      <view class="detail-page">
        <!-- 基础信息 -->
        <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 class="sub-toggle" @click="collapse = !collapse">
              <image class="sub-toggle_icon" :src="collapse ? '/static/images/down.png' : '/static/images/up.png'" />
              <text class="sub-toggle_text">{{ collapse ? '展开' : '收起' }}</text>
            </view>
          </view>
          <view v-if="!collapse" 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">数量(kg)</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 class="row"><text class="label">取样编号</text><text class="value">{{ safeText(item.sampleCode) }}</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>
      </view>
    </scroll-view>
    <detail-buttons :buttons="displayButtons" @click="handleButtonClick" />
  </view>
</template>

<script>
import DetailButtons from '@/components/detail-buttons/index.vue'
import { getDicByCodes, getDicName } from '@/utils/dic.js'
import { COMPONENT_LABELS, getComponentKeys } from './component-config.js'
import {
  assayReportDetailApi,
  assayReportSubmitAuditApi,
  assayReportSubmitApproveApi,
  assayReportCancelApi,
  assayReportInvalidApi
} from '@/api/procure-manage/assayReport.js'
import { getInfo } from '@/api/login.js'

export default {
  name: 'MaterialTestDetail',
  components: { DetailButtons },
  data() {
    return {
      id: '',
      form: {},
      lines: [],
      collapse: false,
      currentUserId: '',
      componentLabels: COMPONENT_LABELS,
      dicOptions: {
        AUDIT_STATUS: [],
        FLOW_NODE: []
      },
      buttons: [
        { text: '修改', visible: true, variant: 'outline', event: 'edit' },
        { text: '提交', visible: true, variant: 'outline', event: 'submit' },
        { text: '修改意见', visible: true, variant: 'outline', event: 'quality' },
        { text: '提交审核', visible: true, variant: 'outline', event: 'submitAudit' },
        { text: '审核', visible: true, variant: 'primary', event: 'audit' },
        { text: '审核详情', visible: true, variant: 'outline', event: 'auditDetail' },
        { text: '取消', visible: true, variant: 'outline', event: 'cancel' },
        { text: '作废', visible: true, variant: 'outline', event: 'invalid' }
      ]
    }
  },
  computed: {
    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)
      }))
    },
    displayButtons() {
      const status = this.form.approvalStatus || ''
      // 已删除单据仅可查看(对齐 PC 端 createActions)
      if (this.form.deleted === true) return []
      const isMine = this.form.createById === this.currentUserId
      const isDraft = status === 'DRAFT'
      const isRefuse = status === 'REFUSE'
      const isAudit = status === 'AUDIT'
      const isPass = status === 'PASS';
      const flowNode = this.form.flowNode || ''
      const showExamine = this.form.showExamine === true
      const showExamineDetail = this.form.showExamineDetail === true
      // 工艺考核意见节点(或无节点):修改/提交由创建人操作
      const canEditMine = (isDraft || isRefuse) && (flowNode === 'GYKHYY' || !flowNode) && isMine
      // 仓库质检意见节点:修改意向/提交审核
      const canQuality = (isDraft || isRefuse) && flowNode === 'CKZJY'

      return [
        {
          ...this.buttons[0],
          visible: canEditMine && this.$auth.hasPermi('warehouse-manage:material-test:modify')
        },
        {
          ...this.buttons[1],
          visible: canEditMine && this.$auth.hasPermi('warehouse-manage:material-test:submit')
        },
        {
          ...this.buttons[2],
          visible: canQuality && this.$auth.hasPermi('warehouse-manage:material-test:updateOption')
        },
        {
          ...this.buttons[3],
          visible: canQuality && this.$auth.hasPermi('warehouse-manage:material-test:submitApprove')
        },
        {
          ...this.buttons[4],
          visible: isAudit && showExamine && this.$auth.hasPermi('warehouse-manage:material-test:approve')
        },
        {
          ...this.buttons[5],
          visible: showExamineDetail && this.$auth.hasPermi('warehouse-manage:material-test:review')
        },
        {
          ...this.buttons[6],
          visible: (isDraft || isRefuse) && this.$auth.hasPermi('warehouse-manage:material-test:cancel')
        },
        {
          ...this.buttons[7],
          visible: isPass && this.$auth.hasPermi('warehouse-manage:material-test:invalid')
        }
      ]
    }
  },
  onLoad(query) {
    this.id = (query && query.id) || ''
    this.loadDicData()
    this.loadDetail()
    this.getUserInfo()
  },
  onShow() {
    let needRefresh = ''
    try { needRefresh = uni.getStorageSync('MATERIAL_TEST_DETAIL_NEED_REFRESH') } catch (e) {}
    if (!needRefresh) return
    try { uni.removeStorageSync('MATERIAL_TEST_DETAIL_NEED_REFRESH') } catch (e) {}
    this.loadDetail()
  },
  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: [] }
      }
    },
    async getUserInfo() {
      try {
        const res = await getInfo()
        this.currentUserId = (res && (res.id || (res.data && res.data.id))) || ''
      } catch (e) {
        this.currentUserId = ''
      }
    },
    loadDetail() {
      if (!this.id) {
        uni.showToast({ title: '缺少单据ID', icon: 'none' })
        return
      }
      uni.showLoading && uni.showLoading({ title: '加载中...', mask: true })
      assayReportDetailApi({ id: this.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' })
        })
        .finally(() => {
          uni.hideLoading && uni.hideLoading()
        })
    },
    handleButtonClick(btn) {
      if (!btn || btn.disabled || !btn.visible) return
      const e = btn.event || ''
      if (e === 'edit') return this.onEdit()
      if (e === 'submit') return this.onSubmitApprove()
      if (e === 'quality') return this.onQuality()
      if (e === 'submitAudit') return this.onSubmitAudit()
      if (e === 'audit') return this.onAudit()
      if (e === 'auditDetail') return this.onAuditDetail()
      if (e === 'cancel') return this.onCancel()
      if (e === 'invalid') return this.onInvalid()
    },
    onEdit() {
      uni.navigateTo({ url: '/pages/material-test/modify?id=' + this.id })
    },
    onQuality() {
      uni.navigateTo({ url: '/pages/material-test/quality?id=' + this.id })
    },
    onAudit() {
      const id = this.id || (this.form && this.form.id) || ''
      if (!id) return
      uni.setStorageSync('contractType', 'ASSAY_REPORT')
      uni.setStorageSync('sourceBusinessId', id)
      uni.navigateTo({ url: '/pages/flow/audit' })
    },
    onAuditDetail() {
      const id = this.id || (this.form && this.form.id) || ''
      if (!id) return
      uni.setStorageSync('contractType', 'ASSAY_REPORT')
      uni.setStorageSync('sourceBusinessId', id)
      uni.navigateTo({ url: '/pages/flow/audit_detail' })
    },
    refreshListFlags() {
      try {
        uni.setStorageSync('MATERIAL_TEST_LIST_NEED_REFRESH', '1')
        uni.setStorageSync('MATERIAL_TEST_DETAIL_NEED_REFRESH', '1')
      } catch (e) {}
    },
    runWithConfirm(opts) {
      const title = opts.title || '提示'
      const content = opts.content || ''
      const run = opts.run
      const loading = opts.loading || '处理中'
      const successText = opts.successText || '操作成功'
      const failText = opts.failText || '操作失败'
      if (!this.id) {
        uni.showToast({ title: '缺少单据ID', icon: 'none' })
        return
      }
      uni.showModal({
        title,
        content,
        confirmText: '确定',
        cancelText: '取消',
        success: res => {
          if (!res || !res.confirm) return
          uni.showLoading({ title: loading, mask: true })
          Promise.resolve(run(this.id))
            .then(() => {
              uni.hideLoading()
              uni.showToast({ title: successText, icon: 'none' })
              this.refreshListFlags()
              this.loadDetail()
            })
            .catch(e => {
              uni.hideLoading()
              uni.showToast({ title: (e && (e.msg || e.message)) || failText, icon: 'none' })
            })
        }
      })
    },
    onInvalid() {
      this.runWithConfirm({
        title: '作废确认',
        content: '继续作废则对关联结算详情单作废,是否继续?',
        loading: '处理中',
        successText: '作废成功',
        failText: '作废失败',
        run: id => assayReportInvalidApi(id)
      })
    },
    onSubmitApprove() {
      this.runWithConfirm({
        title: '提交确认',
        content: '确认提交吗?',
        loading: '提交中',
        successText: '提交成功',
        failText: '提交失败',
        run: id => assayReportSubmitApproveApi(id)
      })
    },
    onSubmitAudit() {
      this.runWithConfirm({
        title: '提交审核确认',
        content: '确认提交审核吗?',
        loading: '提交中',
        successText: '提交审核成功',
        failText: '提交审核失败',
        run: id => assayReportSubmitAuditApi(id)
      })
    },
    onCancel() {
      this.runWithConfirm({
        title: '取消确认',
        content: '确认取消该原料化验报告单吗?',
        loading: '处理中',
        successText: '取消成功',
        failText: '取消失败',
        run: id => assayReportCancelApi(id)
      })
    },
    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>
.page {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.scroll {
  flex: 1;
  padding: 8rpx 0 144rpx;
}
.detail-page {
  background: #f3f3f3;
}
.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;
  }
}
.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-toggle {
    display: flex;
    align-items: center;
    padding: 0 12rpx;
    height: 56rpx;
    .sub-toggle_icon { width: 24rpx; height: 24rpx; margin-right: 8rpx; }
    .sub-toggle_text { font-size: 26rpx; color: rgba(0, 0, 0, 0.6); }
  }
}
.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>