index.vue 17.1 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 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
<template>
  <div>
    <div v-show="$store.state.app.authorizePage" class="page-container">
      <div class="content-scroll" :class="{ 'has-footer': orderInfo.status == 1 }">
        <!-- 审核状态 -->
        <div v-if="currentStatus" class="status-section">
          <div class="status-badge">
            <van-icon :name="currentStatus.icon" :color="currentStatus.color" />
            <span class="status-text">{{ currentStatus.name }}</span>
          </div>
          <span class="status-tip">{{ currentStatus.tips }}</span>
        </div>

        <!-- 订单信息 -->
        <div class="section">
          <div class="section-title">订单信息</div>
          <div v-for="(item, index) in displayOrderForm" :key="index" class="info-item" :class="{ 'flex-start': item.flexStart }">
            <span class="info-label">{{ item.label }}</span>
            <template v-if="item.format">
              <div class="info-value">{{ getFormattedFieldValue(getOrderFieldValue(item), item.format) }}</div>
            </template>
            <template v-else-if="item.arr">
              <div class="info-value">
                <span class="name text-hide">{{ orderInfo[item.key[0]] }}</span>
                <span class="split">|</span>
                <span class="text-hide">{{ orderInfo[item.key[1]] }}</span>
              </div>
            </template>
            <template v-else-if="item.image">
              <div v-if="orderInfo[item.key] && orderInfo[item.key].length" class="image-value">
                <div v-for="(subItem, subIndex) in orderInfo[item.key]" :key="subIndex" class="image-item" @click="previewImage(orderInfo[item.key], subIndex)">
                  <van-image :src="subItem.payVoucher" fit="cover" width="56" height="56" radius="8" />
                </div>
              </div>
              <span v-else>-</span>
            </template>
            <template v-else>
              <span class="info-value">
                <span v-if="item.unit" class="unit">{{ item.unit }}</span>
                {{ getFieldValue(item) }}
              </span>
            </template>
          </div>
        </div>

        <!-- 原错误订单商品信息 -->
        <goods-order-item v-if="orderInfo.oldOrderCode" title="原错误订单商品信息" :goods-data="orderInfo.oldGoodsOrderDTO || {}" />

        <!-- 新订单 / 普通订单 -->
        <goods-order-item :title="orderInfo.oldOrderCode ? '新订单商品信息' : '商品信息'" :goods-data="orderInfo.goodsOrderDTO || {}" />

        <!-- 审核日志 -->
        <div v-if="orderInfo.status != 1 && orderInfo.applyLogList && orderInfo.applyLogList.length" class="section">
          <div class="section-title">审核日志</div>
          <div v-for="(item, index) in orderInfo.applyLogList" :key="index" class="log-box">
            <div class="timeline">
              <div class="timeline-item">
                <div class="timeline-left">
                  <div class="dot-wrapper">
                    <div class="dot" :class="index == 0 ? 'step-active' : 'step-done'"></div>
                  </div>
                  <div v-if="orderInfo.applyLogList.length > 1 && index != orderInfo.applyLogList.length - 1" class="status-line step-done"></div>
                </div>
                <div class="timeline-content">
                  <div class="log-status-text">
                    <span class="mar-r16">{{ statusForShow[item.beforeStatus] && statusForShow[item.beforeStatus].text }}</span>
                    <span class="status mar-r16" :class="item.afterStatus == 2 || item.afterStatus == 3 ? 'success' : 'error'">
                      {{ statusForShow[item.afterStatus] && statusForShow[item.afterStatus].status }}
                    </span>
                    <template v-if="item.afterStatus == 4">
                      <span class="mar-r16">至</span>
                      <span>驻店销售</span>
                    </template>
                  </div>
                  <div v-if="item.remark" class="log-row">
                    <div class="label">{{ item.afterStatus == 2 || item.afterStatus == 3 ? '备注' : '驳回原因' }}</div>
                    <div class="value">{{ item.remark }}</div>
                  </div>
                  <div class="log-row">
                    <div class="label">审核人</div>
                    <div class="value">{{ item.operatorName }}</div>
                  </div>
                  <div class="log-row">
                    <div class="label">审核时间</div>
                    <div class="value">{{ item.createdDateStr }}</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 底部操作按钮 -->
      <div v-if="orderInfo.status == 2" class="footer-btn">
        <div class="btn cancel" @click="reject">驳回</div>
        <div class="btn confirm" @click="pass">通过</div>
      </div>

      <approval-popup v-if="showPopup" :show="showPopup" :info-data="popupInfo" :reject-remark-required="true" @confirm="handlePopupConfirm" @cancel="hidePopup" />
    </div>
    <div v-show="!$store.state.app.authorizePage" class="loading-box"></div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { ImagePreview } from 'vant'
import orderApprovalApi from '@/api/orderApproval'
import mockOrderDetailRes from './mockData'
import {
  getFormattedFieldValue as formatFieldValue,
  normalizeOrderGoodsPrices
} from './orderApprovalFormat'
import GoodsOrderItem from './components/goodsOrderItem.vue'
import ApprovalPopup from './components/approvalPopup.vue'
import store from '@/store'

export default {
  name: 'OrderApproval',
  components: { GoodsOrderItem, ApprovalPopup },
  data() {
    return {
      orderCode: '',
      phone: '',
      userInfo: {},
      orderInfo: {},
      showPopup: false,
      popupInfo: {},
      submitFlag: false,
      statusMap: {
        2: { name: '待审核', tips: '请尽快处理', icon: 'more-o', color: '#FF9D0A' },
        // 2: { name: '已审核', tips: '订单已流转至线上运营审核', icon: 'passed', color: '#35C376' },
        3: { name: '已审核', tips: '订单已审核', icon: 'passed', color: '#35C376' },
        4: { name: '已驳回', tips: '订单已驳回', icon: 'warning-o', color: '#666666' }
      },
      orderForm: [
        { label: '订单编号', key: 'orderCode' },
        { label: '订单类型', key: 'djOrderType', format: 'djOrderType' },
        { label: '订单归属', sourceKey: 'goodsOrderDTO', key: 'lowPriceFlag', format: 'lowPriceFlag' },
        { label: '总价', key: 'finalPrice', unit: '¥' },
        { label: '提单人', key: ['sellerName', 'merchantName'], arr: true },
        { label: '提单时间', key: 'applyDate' },
        { label: '备注', key: 'orderRemark', flexStart: true },
        { label: '交易流水号', key: 'outTradeNo', flexStart: true },
        { label: '凭证', key: 'payVoucherList', image: true, flexStart: true }
      ],
      statusForShow: {
        1: { text: '区域运营审核' },
        2: { text: '运营审核', status: '通过' },
        3: { status: '通过' },
        4: { status: '驳回' }
      }
    }
  },
  computed: {
    currentStatus() {
      return this.statusMap[this.orderInfo.status]
    },
    displayOrderForm() {
      const form = [...this.orderForm]
      if (this.orderInfo.oldOrderCode) {
        const typeIndex = form.findIndex(f => f.key === 'djOrderType')
        form.splice(typeIndex, 0, {
          label: '原错误订单编号',
          key: 'oldOrderCode'
        })
      }
      return form
    }
  },
  created() {
    // 先缓存链接业务参数,避免 OAuth 跳转后 orderCode 丢失
    this.initPageParams()
    store.dispatch('login')
  },
  watch: {
    '$store.state.app.authorizePage': {
      immediate: true,
      handler(val) {
        if (val && this.orderCode) {
          this.loadOrderDetail(this.orderCode)
          this.loadStaffInfoByPhone()
        }
      }
    }
  },
  methods: {
    getOrderFieldValue(item) {
      const source = item.sourceKey ? this.orderInfo[item.sourceKey] : this.orderInfo
      return source ? source[item.key] : undefined
    },
    getFormattedFieldValue(value, format) {
      return formatFieldValue(value, format)
    },
    initPageParams() {
      const { orderCode } = this.$route.query
      if (orderCode) this.setLocalStorage('ww_orderCode', orderCode)
      // 授权回调后 URL 可能只剩 code,从缓存读取
      this.orderCode = this.getLocalStorage('ww_orderCode') || ''
    },
    getLoginPhone() {
      const phone = this.getLocalStorage('ww_params_phone')
      if (phone) return phone
      const loginUser = this.getLocalStorage('ww_userInfo') || {}
      return loginUser.phone || ''
    },
    loadStaffInfoByPhone() {
      this.phone = this.getLoginPhone()
      if (!this.phone) return
      orderApprovalApi.getStaffInfoByPhone({ phone: this.phone }).then(res => {
        this.userInfo = res.data
      })
    },
    getFieldValue(item) {
      const val = this.getOrderFieldValue(item)
      return val || val === 0 ? val : '-'
    },
    previewImage(urlList, index) {
      const urls = urlList.map(v => v.payVoucher)
      ImagePreview({
        images: urls,
        startPosition: index
      })
    },
    processOrderData(rawOrder) {
      if (!rawOrder) return rawOrder
      const processed = { ...rawOrder }
      if (processed.goodsOrderDTO) {
        processed.goodsOrderDTO = this.addPackagePrice(processed.goodsOrderDTO)
      }
      if (processed.oldGoodsOrderDTO) {
        processed.oldGoodsOrderDTO = this.addPackagePrice(processed.oldGoodsOrderDTO)
      }
      return processed
    },
    addPackagePrice(orderDTO) {
      return normalizeOrderGoodsPrices(orderDTO)
    },
    async loadOrderDetail(orderCode) {
      this.showLoading()
      try {
        // TODO: 联调时切换为真实接口
        // const res = mockOrderDetailRes
        const res = await orderApprovalApi.getOrderApplyDetail({ orderCode })
        this.hideLoading()
        const { code, data, message } = res
        if (code == 0) {
          const processedData = this.processOrderData(data || {})
          if (data?.applyLogList) {
            data.applyLogList.forEach(val => {
              val.createdDateStr = val.createdDate ? dayjs(val.createdDate).format('YYYY-MM-DD HH:mm:ss') : '-'
            })
          }
          this.orderInfo = {
            ...processedData,
            applyDate: data.applyDate ? dayjs(data.applyDate).format('YYYY-MM-DD HH:mm:ss') : '-',
            oldOrderCode: data?.oldGoodsOrderDTO?.orderCode || ''
          }
        } else {
          this.showToast(message)
        }
      } catch (e) {
        this.hideLoading()
      }
    },
    pass() {
      this.showPopup = true
      this.popupInfo = {
        type: '1',
        title: '审核通过',
        label: '通过备注'
      }
    },
    reject() {
      this.showPopup = true
      this.popupInfo = {
        type: '2',
        title: '审核驳回',
        label: '驳回备注'
      }
    },
    hidePopup() {
      this.showPopup = false
    },
    async handlePopupConfirm(remark) {
      if (this.submitFlag) return
      this.submitFlag = true
      this.showLoading()
      try {
        const res = await orderApprovalApi.auditOrderApply({
          auditResult: this.popupInfo?.type,
          orderCode: this.orderInfo.orderCode,
          remark,
          operatorName: this.userInfo.staffName
        })
        this.hideLoading()
        this.submitFlag = false
        const { code, message } = res
        if (code == 0) {
          this.hidePopup()
          this.loadOrderDetail(this.orderInfo.orderCode)
        } else {
          this.showToast(message)
        }
      } catch (e) {
        this.hideLoading()
        this.submitFlag = false
      }
    }
  }
}
</script>

<style scoped lang="scss">
.loading-box {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #999999;
  font-size: 14px;
}
.page-container {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: #f2f3f7;
  padding: 12px;
  box-sizing: border-box;
  .content-scroll {
    height: 100%;
    overflow-y: auto;
    &.has-footer {
      height: calc(100% - 68px);
    }
    .status-section {
      .status-badge {
        display: flex;
        align-items: center;
      }
      .status-text {
        font-size: 18px;
        font-weight: 500;
        color: #222222;
        margin-left: 10px;
      }
      .status-tip {
        display: block;
        font-size: 13px;
        color: #999999;
        margin-left: 26px;
        margin-top: 4px;
      }
    }
    .section {
      border-radius: 16px;
      background: #ffffff;
      margin: 12px 0;
      padding: 12px 16px;
      .section-title {
        font-size: 15px;
        font-weight: 500;
        color: #222222;
        margin-bottom: 12px;
      }
      .info-item {
        display: flex;
        align-items: center;
        font-size: 13px;
        color: #222222;
        margin-bottom: 6px;
        &.flex-start {
          align-items: flex-start;
        }
        &:last-child {
          margin-bottom: 0;
        }
        .info-label {
          width: 92px;
          margin-right: 16px;
          color: #999999;
          flex-shrink: 0;
        }
        .info-value {
          word-break: break-all;
          .unit {
            margin-right: 4px;
          }
          .text-hide {
            max-width: 140px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: inline-block;
            vertical-align: bottom;
            &.name {
              max-width: 60px;
            }
          }
          .split {
            margin: 0 4px;
          }
        }
      }
      .image-value {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        .image-item {
          cursor: pointer;
        }
      }
      .timeline {
        .timeline-item {
          display: flex;
          position: relative;
          overflow: visible;
          .timeline-left {
            width: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-right: 5px;
            position: relative;
            flex-shrink: 0;
            align-self: stretch;
            .dot-wrapper {
              width: 100%;
              height: 22px;
              display: flex;
              align-items: center;
              justify-content: center;
            }
            .dot {
              width: 8px;
              height: 8px;
              border-radius: 50%;
              background: #e5e5e5;
              z-index: 2;
              box-sizing: border-box;
            }
            .step-active {
              background: #ffffff;
              border: 2px solid #d6e4ff;
              width: 14px;
              height: 14px;
              position: relative;
              &::after {
                content: '';
                position: absolute;
                width: 5px;
                height: 5px;
                background: #ffffff;
                border-radius: 50%;
                border: 2px solid #347bff;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
              }
            }
            .step-done {
              background: #8eb2fb;
            }
            .status-line {
              position: absolute;
              top: 19px;
              bottom: -5px;
              left: 50%;
              transform: translateX(-50%);
              width: 1px;
              background: #d8e5fe;
              z-index: 1;
            }
          }
          .timeline-content {
            font-size: 14px;
            color: #333333;
            flex: 1;
            .log-status-text {
              margin-bottom: 8px;
              font-weight: 600;
              .mar-r16 {
                margin-right: 8px;
              }
              .success {
                color: #35c376;
              }
              .error {
                color: #f24724;
              }
            }
            .log-row {
              display: flex;
              align-items: flex-start;
              margin-bottom: 8px;
              .label {
                width: 84px;
                flex-shrink: 0;
                color: #999999;
                margin-right: 8px;
              }
              .value {
                word-wrap: break-word;
                word-break: break-all;
              }
            }
          }
        }
      }
    }
  }
  .footer-btn {
    position: fixed;
    left: 0;
    width: 100%;
    bottom: 0;
    background: #ffffff;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 99;
    padding: 10px 16px;
    .btn {
      width: 160px;
      height: 40px;
      border-radius: 10px;
      text-align: center;
      line-height: 40px;
      font-size: 16px;
    }
    .cancel {
      line-height: 38px;
      border: 1px solid #2c66f7;
      background: #f0f4ff;
      color: #2c66f7;
    }
    .confirm {
      color: #ffffff;
      font-weight: 500;
      background: #347bff;
    }
  }
}
</style>