materialSettlementViewer.vue 10.3 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.ticketDate) }}</text></view>
        <view class="row"><text class="label">计划编号</text><text class="value">{{ safeText(planCodeText) }}</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>

      <!-- 申请净重明细 -->
      <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="!applyList.length" class="empty-tip">暂无明细</view>
          <view v-for="(item, idx) in applyList" :key="'a-' + (item.id || idx)" class="card">
            <view class="card-index">第 {{ idx + 1 }} 行</view>
            <view class="row"><text class="label">类别</text><text class="value">{{ safeText(item.category) }}</text></view>
            <view class="row"><text class="label">数量</text><text class="value">{{ formatNumber(item.quantity) }}</text></view>
          </view>
        </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="!detailList.length" class="empty-tip">暂无明细</view>
          <view v-for="(item, idx) in detailList" :key="'d-' + (item.id || idx)" class="card">
            <view class="card-index">第 {{ idx + 1 }} 行</view>
            <view class="row"><text class="label">计划编号</text><text class="value">{{ safeText(item.planCode) }}</text></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">{{ safeText(item.category) }}</text></view>
            <view class="row"><text class="label">名称</text><text class="value">{{ safeText(item.name) }}</text></view>
            <view class="row"><text class="label">过磅数</text><text class="value">{{ formatNumber(item.weighQuantity) }}</text></view>
            <view class="row"><text class="label">杂率(%)</text><text class="value">{{ formatNumber(item.impurityRate) }}</text></view>
            <view class="row"><text class="label">折斤</text><text class="value">{{ formatNumber(item.foldWeight) }}</text></view>
            <view class="row"><text class="label">退料</text><text class="value">{{ formatNumber(item.returnWeight) }}</text></view>
            <view class="row"><text class="label">入库净重</text><text class="value">{{ formatNumber(item.netWeight) }}</text></view>
            <view class="row"><text class="label">备注</text><text class="value">{{ safeText(item.remark) }}</text></view>
          </view>
        </view>
      </view>

      <!-- 其他信息 -->
      <view class="title-header">
        <image class="title-header_icon" src="/static/images/title.png" />
        <span>其他信息</span>
      </view>
      <view class="total-card">
        <view class="total-title">合计</view>
        <view class="total-body">
          <view class="total-item">
            <text class="total-label">过磅数</text>
            <text class="total-value">{{ formatNumber(form.totalWeighQuantity) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">折斤</text>
            <text class="total-value">{{ formatNumber(form.totalFoldWeight) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">退料</text>
            <text class="total-value">{{ formatNumber(form.totalReturnWeight) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">入库净重</text>
            <text class="total-value">{{ formatNumber(form.totalNetWeight) }}</text>
          </view>
        </view>
      </view>
      <view class="section">
        <view class="row"><text class="label">类型</text><text class="value">{{ settleTypeName }}</text></view>
      </view>
      <view class="section">
        <text class="remark-text">{{ safeText(form.remark) }}</text>
      </view>
    </scroll-view>
  </view>
</template>

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

export default {
  name: 'MaterialSettlementViewer',
  props: { id: { type: [String, Number], default: '' } },
  data() {
    return {
      form: {},
      applyList: [],
      detailList: [],
      dicOptions: {
        SETTLE_TYPE: []
      }
    }
  },
  computed: {
    settleTypeName() {
      const v = this.form.settleType == null ? '' : String(this.form.settleType)
      if (!v) return '-'
      return getDicName('SETTLE_TYPE', v, this.dicOptions.SETTLE_TYPE) || v
    },
    planCodeText() {
      const codes = Array.from(new Set((this.detailList || []).map(it => it.planCode).filter(Boolean)))
      return codes.join(',')
    }
  },
  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(['SETTLE_TYPE'])
        this.dicOptions.SETTLE_TYPE = (results.SETTLE_TYPE && results.SETTLE_TYPE.data) || []
      } catch (e) {
        this.dicOptions = { SETTLE_TYPE: [] }
      }
    },
    loadDetail(id) {
      materialSettleDetailApi({ id })
        .then(res => {
          const data = res && res.data ? (res.data.data || res.data) : {}
          this.form = Object.assign({}, data)
          this.applyList = Array.isArray(data.applyLines) ? data.applyLines.map(x => ({ ...x })) : []
          this.detailList = Array.isArray(data.lines) ? data.lines.map(x => ({ ...x })) : []
        })
        .catch(() => {
          uni.showToast({ title: '详情加载失败', icon: 'none' })
        })
    },
    // 供流程审核页获取业务表单数据(variables)
    getFormValues() {
      return this.form
    },
    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 {
  flex: 1;
  padding: 8rpx 0;
}
.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;
  }
}
.remark-text {
  font-size: 28rpx;
  color: rgba(0, 0, 0, 0.9);
  line-height: 1.6;
  white-space: pre-wrap;
}
.total-card {
  background: #fff;
  margin-bottom: 20rpx;
  padding: 24rpx 32rpx;
  .total-title {
    font-size: 32rpx;
    font-weight: 600;
    color: rgba(0, 0, 0, 0.9);
    margin-bottom: 20rpx;
  }
  .total-body {
    display: flex;
    flex-wrap: wrap;
    .total-item {
      width: 50%;
      display: flex;
      align-items: center;
      margin-bottom: 20rpx;
      &:nth-last-child(-n + 2) { margin-bottom: 0; }
      .total-label {
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.6);
        margin-right: 16rpx;
      }
      .total-value {
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.9);
        font-weight: 500;
      }
    }
  }
}
.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>