outrightPurchaseViewer.vue 10.2 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.incomingUnit) }}</text></view>
        <view class="row"><text class="label">计划单编号</text><text class="value">{{ safeText(form.planCodes) }}</text></view>
        <view class="row"><text class="label">采购处</text><text class="value">{{ safeText(form.purchaseDepartmentName) }}</text></view>
        <view class="row"><text class="label">区域</text><text class="value">{{ safeText(form.regionName) }}</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="!lineList.length" class="empty-tip">暂无明细</view>
          <view v-for="(item, idx) in lineList" :key="'l-' + (item.id || idx)" class="card">
            <view class="card-index">第 {{ idx + 1 }} 行</view>
            <view class="row"><text class="label">买断品种</text><text class="value">{{ safeText(item.buyoutCategory) }}</text></view>
            <view class="row"><text class="label">买断数量</text><text class="value">{{ formatNumber(item.buyoutQuantity) }}</text></view>
            <view class="row"><text class="label">买断单价</text><text class="value">{{ formatNumber(item.buyoutPrice) }}</text></view>
            <view class="row"><text class="label">买断金额</text><text class="value">{{ formatNumber(item.buyoutAmount) }}</text></view>
            <view class="row"><text class="label">入库数量</text><text class="value">{{ formatNumber(item.instockQuantity) }}</text></view>
            <view class="row"><text class="label">入库单价</text><text class="value">{{ formatNumber(item.instockPrice) }}</text></view>
            <view class="row"><text class="label">入库金额</text><text class="value">{{ formatNumber(item.instockAmount) }}</text></view>
            <view class="row"><text class="label">预计吨损耗(元/吨)</text><text class="value">{{ formatNumber(item.expectTonLoss) }}</text></view>
            <view class="row"><text class="label">实际吨损耗(元/吨)</text><text class="value">{{ formatNumber(item.actualTonLoss) }}</text></view>
            <view class="row"><text class="label">吨损耗差异(元/吨)</text><text class="value">{{ formatNumber(item.tonLossDiff) }}</text></view>
            <view class="row"><text class="label">差异金额(元)</text><text class="value">{{ formatNumber(item.diffAmount) }}</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.totalBuyoutQuantity) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">买断金额</text>
            <text class="total-value">{{ formatNumber(form.totalBuyoutAmount) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">入库数量</text>
            <text class="total-value">{{ formatNumber(form.totalInstockQuantity) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">入库金额</text>
            <text class="total-value">{{ formatNumber(form.totalInstockAmount) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">差异金额</text>
            <text class="total-value">{{ formatNumber(form.totalDiffAmount) }}</text>
          </view>
        </view>
      </view>
      <view class="section">
        <view class="row"><text class="label">磅差情况</text><text class="value">{{ formatNumber(form.weighDiff) }}</text></view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import { outrightPurchaseDetailApi } from '@/api/procure-manage/outrightPurchase.js'

export default {
  name: 'OutrightPurchaseViewer',
  props: {
    id: { type: [String, Number], default: '' },
    // 当前审核节点编码(审核页透传,备用)
    nodeCode: { type: String, default: '' }
  },
  data() {
    return {
      // 业务数据全量(详情接口返回,getFormValues 提交 variables 用)
      bizData: {},
      form: {},
      lineList: []
    }
  },
  watch: {
    id: {
      immediate: true,
      handler(val) {
        const v = (val !== undefined && val !== null) ? String(val) : ''
        if (v) this.loadDetail(v)
      }
    }
  },
  methods: {
    loadDetail(id) {
      outrightPurchaseDetailApi({ id })
        .then(res => {
          const data = res && res.data ? (res.data.data || res.data) : {}
          // 保留业务数据全量(getFormValues 提交 variables 用)
          this.bizData = Object.assign({}, data)
          this.form = {
            weighingTicketCode: data.weighingTicketCode || '',
            incomingUnit: data.incomingUnit || '',
            planCodes: data.planCodes || '',
            purchaseDepartmentName: data.purchaseDepartmentName || '',
            regionName: data.regionName || '',
            totalBuyoutQuantity: data.totalBuyoutQuantity == null ? '' : data.totalBuyoutQuantity,
            totalBuyoutAmount: data.totalBuyoutAmount == null ? '' : data.totalBuyoutAmount,
            totalInstockQuantity: data.totalInstockQuantity == null ? '' : data.totalInstockQuantity,
            totalInstockAmount: data.totalInstockAmount == null ? '' : data.totalInstockAmount,
            totalDiffAmount: data.totalDiffAmount == null ? '' : data.totalDiffAmount,
            weighDiff: data.weighDiff == null ? '' : data.weighDiff
          }
          this.lineList = Array.isArray(data.lines) ? data.lines.map(x => ({ ...x })) : []
        })
        .catch(() => {
          uni.showToast({ title: '详情加载失败', icon: 'none' })
        })
    },
    // 供流程审核页获取业务表单数据(variables)
    getFormValues() {
      return { ...this.bizData, lines: this.lineList }
    },
    // 供流程审核页审批通过前校验(审批表单只读,无需校验)
    checkForm() {
      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 {
  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;
  }
}
.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;
        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;
    .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>