warehouseMaterialViewer.vue 15.8 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 493 494 495 496 497 498 499 500 501 502 503 504 505 506
<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(form.materialSource) }}</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.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="!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.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">{{ safeText(item.specModel) }}</text></view>
            <view class="row"><text class="label">单位</text><text class="value">{{ safeText(item.unit) }}</text></view>
            <view class="row"><text class="label">数量(采购数kg)</text><text class="value">{{ formatNumber(item.purchaseQuantity) }}</text></view>
            <view class="row actual-row">
              <view class="label"><text v-if="canEditActualQuantity" class="required">*</text><text>数量(实收数kg)</text></view>
              <view class="actual-value">
                <uni-easyinput v-if="canEditActualQuantity" v-model="item.actualQuantity" type="digit"
                  :inputBorder="false" placeholder="请输入实收数" />
                <text v-else class="value">{{ formatNumber(item.actualQuantity) }}</text>
              </view>
            </view>
            <view class="row"><text class="label">含税价格(单价)</text><text class="value">{{ formatNumber(item.taxPrice) }}</text></view>
            <view class="row"><text class="label">含税价格(金额)</text><text class="value">{{ formatNumber(item.taxAmount) }}</text></view>
            <view class="row"><text class="label">不含税价格(单价)</text><text class="value">{{ formatNumber(item.noTaxPrice) }}</text></view>
            <view class="row"><text class="label">不含税价格(金额)</text><text class="value">{{ formatNumber(item.noTaxAmount) }}</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">采购数(kg)</text>
            <text class="total-value">{{ purchaseQuantityCap }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">实收数(kg)</text>
            <text class="total-value">{{ formatNumber(form.totalActualQuantity) }}</text>
          </view>
          <view class="total-item">
            <text class="total-label">含税金额</text>
            <text class="total-value">{{ formatNumber(form.totalTaxAmount) }}</text>
          </view>
        </view>
      </view>
      <view class="section">
        <view class="remark-label">备注</view>
        <text class="remark-text">{{ safeText(form.remark) }}</text>
        <view class="remark-label">附件</view>
        <view v-if="!fileList.length" class="empty-tip">暂无附件</view>
        <view v-for="(file, idx) in fileList" :key="file.fileId || idx" class="file-item"
          @click="downloadAttachment(file)">
          <text class="file-name">{{ file.fileName || '未命名文件' }}</text>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import { warehouseReceiveDetailApi } from '@/api/procure-manage/warehouseMaterial.js'
import { getInstanceByBusinessIdApi } from '@/api/flow.js'
import { downloadFile } from '@/utils/downloadFile.js'

// 数量(实收数)可修改的流程节点 code(各分厂仓库统计员环节,对齐 PC 端 viewer.vue)
const EDITABLE_ACTUAL_QUANTITY_NODE_CODES = [
  'receive_order_yfccktjy',
  'receive_order_efccktjy',
  'receive_order_sfccktjy',
  'receive_order_ztfccktjy'
]

export default {
  name: 'WarehouseMaterialViewer',
  props: {
    id: { type: [String, Number], default: '' },
    // 当前审核节点编码(审核页透传,备用;可编辑判断以按业务ID查询流程实例结果为准)
    nodeCode: { type: String, default: '' }
  },
  data() {
    return {
      // 业务数据全量(详情接口返回,getFormValues 提交 variables 用)
      bizData: {},
      form: {},
      lineList: [],
      // 当前审核节点是否允许修改数量(实收数)
      canEditActualQuantity: false
    }
  },
  computed: {
    // 合计-采购数(明细行采购数求和后转中文大写+公斤)
    purchaseQuantityCap() {
      if (!(this.lineList || []).length) return '-'
      const total = (this.lineList || []).reduce(
        (sum, row) => sum + Number(row.purchaseQuantity || 0), 0
      )
      return numberToChineseUpper(Number(total.toFixed(2))) + '公斤'
    },
    // 附件列表(ids 与 names 按位置一一对应)
    fileList() {
      const ids = splitCsv(this.bizData.attachmentFileIds)
      const names = splitCsv(this.bizData.attachmentFileNames)
      const len = Math.max(ids.length, names.length)
      const list = []
      for (let i = 0; i < len; i++) {
        list.push({ fileId: ids[i] || '', fileName: names[i] || '' })
      }
      return list
    }
  },
  created() {
    if (this.nodeCode && EDITABLE_ACTUAL_QUANTITY_NODE_CODES.includes(this.nodeCode)) {
      this.canEditActualQuantity = true
    }
  },
  watch: {
    id: {
      immediate: true,
      handler(val) {
        const v = (val !== undefined && val !== null) ? String(val) : ''
        if (v) this.loadDetail(v)
      }
    }
  },
  methods: {
    loadDetail(id) {
      warehouseReceiveDetailApi({ 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 || '',
            ticketDate: data.ticketDate || '',
            materialSource: data.materialSource || '',
            planCode: data.planCode || '',
            workshopName: data.workshopName || '',
            totalActualQuantity: data.totalActualQuantity == null ? '' : data.totalActualQuantity,
            totalTaxAmount: data.totalTaxAmount == null ? '' : data.totalTaxAmount,
            remark: data.remark || ''
          }
          this.lineList = Array.isArray(data.lines) ? data.lines.map(x => ({ ...x })) : []
          // 按流程实例当前节点判断数量(实收数)是否可修改
          this.loadFlowNode()
        })
        .catch(() => {
          uni.showToast({ title: '详情加载失败', icon: 'none' })
        })
    },
    // 查询流程实例:当前审核节点为各分厂仓库统计员环节时,数量(实收数)可修改
    loadFlowNode() {
      this.canEditActualQuantity = false
      const id = this.id == null ? '' : String(this.id)
      if (!id) return
      getInstanceByBusinessIdApi({ businessId: id, operateType: 'AUDIT' })
        .then(res => {
          const data = res && res.data ? res.data : {}
          const nodeCode = data.nodeCode || this.nodeCode || ''
          this.canEditActualQuantity = EDITABLE_ACTUAL_QUANTITY_NODE_CODES.includes(nodeCode)
        })
        .catch(() => {
          // 查询失败时退回审核页透传的节点编码
          this.canEditActualQuantity = EDITABLE_ACTUAL_QUANTITY_NODE_CODES.includes(this.nodeCode || '')
        })
    },
    // 附件下载
    downloadAttachment(file) {
      const id = file && file.fileId
      const fileName = file && file.fileName
      if (!id) return
      downloadFile(id, fileName)
    },
    // 供流程审核页获取业务表单数据(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 })
    }
  }
}

// 逗号分隔字符串转数组
function splitCsv(val) {
  if (!val) return []
  if (Array.isArray(val)) return val
  return String(val).split(',').filter(Boolean)
}

// 数字转中文大写(对齐 PC 端 useReceiveForm.ts,保留位权读法,不含货币单位)
function numberToChineseUpper(num) {
  if (num === null || num === undefined || num === '' || isNaN(Number(num))) return '零'
  const n = Number(num)
  if (!isFinite(n)) return '零'

  const digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
  const smallUnits = ['', '拾', '佰', '仟']
  const bigUnits = ['', '万', '亿', '兆']

  const negative = n < 0
  const abs = Math.abs(n)
  const parts = abs.toString().split('.')
  const intStrRaw = parts[0]
  const decStrRaw = parts[1] || ''
  const s = intStrRaw
  const len = s.length

  let intPart = ''
  let zeroFlag = false
  for (let i = 0; i < len; i++) {
    const d = parseInt(s[i], 10)
    const pos = len - 1 - i
    const unitIdx = pos % 4
    const groupIdx = Math.floor(pos / 4)
    if (d !== 0) {
      if (zeroFlag) {
        intPart += digit[0]
        zeroFlag = false
      }
      intPart += digit[d] + smallUnits[unitIdx]
    } else {
      zeroFlag = true
    }
    if (unitIdx === 0) {
      const start = Math.max(0, len - (groupIdx + 1) * 4)
      const end = len - groupIdx * 4
      const groupDigits = s.slice(start, end)
      if (!/^0+$/.test(groupDigits)) {
        intPart += bigUnits[groupIdx] || ''
      }
    }
  }
  if (intPart === '') intPart = digit[0]

  let result = intPart
  if (decStrRaw) {
    const decChars = decStrRaw
      .split('')
      .map(c => digit[parseInt(c, 10)])
      .join('')
    result += '点' + decChars
  }
  return (negative ? '负' : '') + result
}
</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;
  }
  &.actual-row {
    align-items: center;
    justify-content: space-between;
    .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;
      position: relative;
      .required {
        color: red;
        position: absolute;
        left: -16rpx;
      }
    }
    .actual-value {
      flex: 1;
      min-height: 48rpx;
      .value { font-size: 28rpx; }

      ::v-deep .uni-easyinput {
        display: flex;
      }

      ::v-deep .uni-easyinput__content {
        border: none;
        background-color: transparent !important;
      }

      ::v-deep .uni-input-input {
        text-align: right;
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.9);
      }
    }
  }
  .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-label {
  display: flex;
  align-items: center;
  font-size: 32rpx;
  color: rgba(0, 0, 0, 0.9);
  margin-bottom: 16rpx;
}
.remark-text {
  font-size: 28rpx;
  color: rgba(0, 0, 0, 0.9);
  line-height: 1.6;
  white-space: pre-wrap;
  margin-bottom: 32rpx;
}
.empty-tip {
  text-align: center;
  padding: 24rpx 0;
  color: rgba(0, 0, 0, 0.4);
  font-size: 28rpx;
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx 24rpx;
  margin-bottom: 16rpx;
  background: #fafafa;
  border-radius: 8rpx;

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

  .file-name {
    flex: 1;
    font-size: 28rpx;
    color: $theme-primary;
    word-break: break-all;
    margin-right: 20rpx;
  }
}
.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>