detail.vue 5.77 KB
<template>
  <view class="page">
    <scroll-view class="scroll" scroll-y>
      <view class="detail-page">
        <view class="section">
          <text class="row company">{{ form.deptName }}</text>
          <view :class="['status', `status_${form.status}`]" />
          <view class="row"><text class="label">要车日期</text><text class="value">{{ form.applyDate }}</text></view>
        </view>

        <!-- 产品 -->
        <view class="section2">
          <Product mode="view" :list="form.delayedShipmentDetailList"
             />
        </view>
      </view>
    </scroll-view>
    <detail-buttons :buttons="displayButtons" @click="handleButtonClick" />
  </view>
</template>

<script>
import { getDetailApi, cancelApi } from '@/api/delay_invoice.js'
import Product from './product.vue'
import DetailButtons from '@/components/detail-buttons/index.vue'

export default {
  name: 'DelayInvoiceDetail',
  components: { Product, DetailButtons },
  data() {
    return {
      form: {},
      buttons: [
        { text: '编辑', visible: true, variant: 'outline', event: 'edit' },
        { text: '审核详情', visible: true, variant: 'outline', event: 'auditDetail' },
        { text: '审核', visible: true, variant: 'primary', event: 'audit' },
        { text: '取消', visible: true, variant: 'outline', event: 'cancel', style: { color: 'rgba(0,0,0,0.9)', border: '1px solid #DCDCDC' } },
      ]
    }
  },
  computed: {
    statusFlags() {
      const m = this.form || {}
      const e = String(m.status || '')
      return {
        isRefuse: e === 'REFUSE' || false,
        isAudit: e === 'AUDIT' || false,
        canEdit: e === 'REFUSE' && m.delayedCreateBy || false,
        canAudit: e === 'AUDIT' && m.showExamine || false,
        canCancel: e === 'REFUSE' && m.delayedCreateBy || false,
      }
    },
    displayButtons() {
      const f = this.statusFlags
      return [
        { ...this.buttons[0], visible: f.canEdit && this.$auth.hasPermi('shipping-plan-manage:delay-invoice:modify') },
        { ...this.buttons[1], visible: this.$auth.hasPermi('shipping-plan-manage:delay-invoice:review') },
        { ...this.buttons[2], visible: f.canAudit && this.$auth.hasPermi('shipping-plan-manage:delay-invoice:approve') },
        { ...this.buttons[3], visible: f.canCancel && this.$auth.hasPermi('shipping-plan-manage:delay-invoice:cancel') },
      ]
    }
  },
  onLoad(query) {
    const id = (query && (query.id || query.code)) || ''
    if (id) this.loadDetail(id)
  },
  methods: {
    async loadDetail(id) {
      try {
        const res = await getDetailApi(id)
        this.form = res.data || {}
      } catch (e) {
        this.form = {}
      }
    },
    handleButtonClick(btn) {
      if (!btn || btn.disabled) return
      const map = {
        edit: () => this.onEdit(),
        auditDetail: () => this.onAuditDetail(),
        audit: () => this.onAudit(),
        fill: () => this.onFill(),
        cancel: () => this.onCancel(),
      }
      const fn = map[btn.event]
      if (typeof fn === 'function') fn()
    },
    onEdit() {
      const id = this.form.id || this.form.code
      if (id) uni.navigateTo({ url: `/pages/delay_invoice/modify?id=${id}` })
    },
    onAuditDetail() {
      uni.setStorageSync('sourceBusinessId', this.form.id)
      uni.navigateTo({ url: '/pages/flow/audit_detail' })
    },
    onAudit() {
      uni.setStorageSync('sourceBusinessId', this.form.id)
      uni.navigateTo({ url: '/pages/flow/audit' })
    },
    onCancel() {
      const id = this.form.id || this.form.code
      if (!id) return
      uni.showModal({
        title: '提示',
        content: '确定要取消该延迟发货单吗?',
        success: async (res) => {
          if (res.confirm) {
            try {
              await cancelApi(id)
              uni.showToast({ title: '取消成功', icon: 'success' })
              setTimeout(() => { uni.redirectTo({ url: '/pages/delay_invoice/index' }) }, 300)
            } catch (e) {
              uni.showToast({ title: (e && e.msg) || '取消失败', icon: 'none' })
            }
          }
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.page {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.scroll {
  flex: 1;
  background: #f3f3f3;
}

.detail-page {
  padding-bottom: 150rpx;
}

.section {
  padding: 32rpx;
  background: #fff;
  margin-bottom: 20rpx;
  position: relative;

  .status {
    position: absolute;
    top: 16rpx;
    right: 52rpx;
    width: 180rpx;
    height: 146rpx;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;

   &_AUDIT {
      background-image: url('~@/static/images/dev_manage/status_1.png');
    }

    &_PASS {
      background-image: url('~@/static/images/dev_manage/status_2.png');
    }

    &_REFUSE {
      background-image: url('~@/static/images/dev_manage/status_3.png');
    }

    &_CANCEL {
      background-image: url('~@/static/images/dev_manage/status_4.png');
    }

  }
}

.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: 10rpx;
    margin-bottom: 32rpx;
    line-height: 50rpx;
  }

  .label {
    width: 240rpx;
    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;
  }
}

.title-header {
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 32rpx 32rpx 22rpx;
  border-bottom: 1rpx dashed #f0f0f0;

  &_icon {
    width: 32rpx;
    height: 28rpx;
    margin-right: 16rpx;
  }

  span {
    color: rgba(0, 0, 0, 0.9);
    font-size: 32rpx;
    line-height: 44rpx;
    font-weight: 600;
  }
}
</style>