detail.vue 9.21 KB
<template>
  <view class="page">
    <scroll-view class="scroll" scroll-y>
      <view class="detail-page">
        <!-- 基础信息 -->
        <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>
    </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 {
  assayApplyDetailApi,
  assayApplySubmitApi,
  assayApplyCancelApi
} from '@/api/procure-manage/assayApply.js'
import { getInfo } from '@/api/login.js'

export default {
  name: 'SampleSubmissionDetail',
  components: { DetailButtons },
  data() {
    return {
      id: '',
      form: {},
      currentUserId: '',
      dicOptions: {
        DEPARTMENT: [],
        AUDIT_STATUS: []
      },
      buttons: [
        { text: '修改', visible: true, variant: 'outline', event: 'edit' },
        { 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' }
      ]
    }
  },
  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
    },
    displayButtons() {
      const status = this.form.approvalStatus || ''
      const isMine = this.form.createById === this.currentUserId
      const isPass = status === 'PASS'
      const isAudit = status === 'AUDIT'
      const canExamine = isAudit && this.form.showExamine === true
      const canExamineDetail = this.form.showExamineDetail === true
      const canEdit = (status === 'DRAFT' || status === 'REFUSE' || !status) && isMine
      return [
        {
          ...this.buttons[0],
          visible: canEdit && this.$auth.hasPermi('warehouse-manage:sample-submission:modify')
        },
        {
          ...this.buttons[1],
          visible: canEdit && this.$auth.hasPermi('warehouse-manage:sample-submission:submit')
        },
        {
          ...this.buttons[2],
          visible: canExamine && this.$auth.hasPermi('warehouse-manage:sample-submission:approve')
        },
        {
          ...this.buttons[3],
          visible: canExamineDetail && this.$auth.hasPermi('warehouse-manage:sample-submission:review')
        },
        {
          ...this.buttons[4],
          visible: (status === 'DRAFT' || status === 'REFUSE') && this.$auth.hasPermi('warehouse-manage:sample-submission:cancel')
        }
      ]
    }
  },
  onLoad(query) {
    this.id = (query && query.id) || ''
    this.loadDicData()
    this.loadDetail()
    this.getUserInfo()
  },
  onShow() {
    let needRefresh = ''
    try { needRefresh = uni.getStorageSync('SAMPLE_SUBMISSION_DETAIL_NEED_REFRESH') } catch (e) {}
    if (!needRefresh) return
    try { uni.removeStorageSync('SAMPLE_SUBMISSION_DETAIL_NEED_REFRESH') } catch (e) {}
    this.loadDetail()
  },
  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: [] }
      }
    },
    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 })
      assayApplyDetailApi({ id: this.id })
        .then(res => {
          const data = res && res.data ? res.data : {}
          this.form = Object.assign({}, data)
        })
        .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 === 'submitAudit') return this.onSubmitAudit()
      if (e === 'audit') return this.onAudit()
      if (e === 'auditDetail') return this.onAuditDetail()
      if (e === 'cancel') return this.onCancel()
    },
    onEdit() {
      uni.navigateTo({ url: '/pages/sample-submission/modify?id=' + this.id })
    },
    onAudit() {
      const id = this.id || (this.form && this.form.id) || ''
      if (!id) return
      uni.setStorageSync('contractType', 'ASSAY_APPLY')
      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_APPLY')
      uni.setStorageSync('sourceBusinessId', id)
      uni.navigateTo({ url: '/pages/flow/audit_detail' })
    },
    refreshListFlags() {
      try {
        uni.setStorageSync('SAMPLE_SUBMISSION_LIST_NEED_REFRESH', '1')
        uni.setStorageSync('SAMPLE_SUBMISSION_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' })
            })
        }
      })
    },
    onSubmitAudit() {
      this.runWithConfirm({
        title: '提交审核',
        content: '确认提交审核吗?',
        loading: '提交中',
        successText: '提交审核成功',
        failText: '提交审核失败',
        run: id => assayApplySubmitApi(id)
      })
    },
    onCancel() {
      this.runWithConfirm({
        title: '取消',
        content: '确认取消该化验送样单吗?',
        loading: '处理中',
        successText: '取消成功',
        failText: '取消失败',
        run: id => assayApplyCancelApi(id)
      })
    },
    safeText(v) {
      const s = v == null ? '' : String(v)
      return s.trim() ? s : '-'
    }
  }
}
</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;
}
.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;
  }
}
</style>