<template>
  <view>
    <uni-nav-bar left-icon="back" @clickLeft="back" statusBar fixed title="飞算授信"></uni-nav-bar>
    <view class="card">
      <text class="label">授信额度(元)</text>
      <text class="value">5{{ info.creditLine }}</text>
    </view>
    <qn-form-item label="授信客户信息" type="title"></qn-form-item>
    <qn-form-item label="客户名称" required>
      <text class="item_text">{{ info.name }}</text>
    </qn-form-item>
    <qn-form-item label="结算方式" required>
      <text class="item_text">{{ transformMethod(info.settlementMethod) }}</text>
    </qn-form-item>
    <qn-form-item label="结算周期" required>
      <text class="item_text">{{ transformPeriod(info.settlementPeriod) }}</text>
    </qn-form-item>
    <qn-form-item label="授信状态" required>
      <text class="item_text" style="color: #007aff">{{ transform(info.status) }}</text>
    </qn-form-item>
  </view>
</template>

<script>
import { back } from '@/utils/hook.js'
import { fsSettlementPeriodEnum, fsSettlementMethodEnum, fsAuditStatus } from '@/enums/index.js'
import { getFsCreditDetail } from '@/apis/clientCreditApi.js'
const statusMap = [
  {
    label: '待客户申请',
    value: fsAuditStatus.WAIT_APPLY
  },
  {
    label: '审核中',
    value: fsAuditStatus.AUDITING
  },
  {
    label: '通过',
    value: fsAuditStatus.PASS
  },
  {
    label: '拒绝',
    value: fsAuditStatus.REJECT
  }
]
export default {
  data() {
    return {
      id: null,
      info: {
        creditLine: 0,
        name: '',
        settlementMethod: 1,
        settlementPeriod: null,
        status: null
      }
    }
  },
  methods: {
    back,
    // 获取授信信息
    getCreditInfo() {
      getFsCreditDetail({ id: this.id, mallSupplierId: this.$store.state.supplierInfo.supplierId }).then((res) => {
        if (res) {
          Object.keys(this.info).forEach((key) => {
            this.info[key] = res[key]
          })
        }
      })
    },
    transform(status) {
      return statusMap.find((item) => item.value == status)?.label || ''
    },
    transformPeriod(period) {
      return fsSettlementPeriodEnum.find((item) => item.value == period)?.label || ''
    },
    transformMethod(method) {
      return fsSettlementMethodEnum.find((item) => item.value == method)?.label || ''
    }
  },
  onLoad(option) {
    if (option) {
      this.id = option.id
    } else {
      uni.showToast({
        title: '参数错误',
        icon: 'none',
        complete: () => {
          setTimeout(() => {
            back()
          }, 1500)
        }
      })
    }
  },
  created() {
    this.getCreditInfo()
  }
}
</script>

<style lang="scss" scoped>
.item_text {
  font-size: 28rpx;
  color: #333333;
}
.button_area {
  width: 750rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  padding: 0 32rpx;
  .button__submit {
    flex-grow: 1;
    height: 88rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    background: #007aff;
    border-radius: 10rpx;
    .text {
      font-size: 30rpx;
      color: #ffffff;
    }
  }
  .button__submit--disabled {
    opacity: 0.5;
  }
}
.card {
  width: 750rpx;
  height: 254rpx;
  background: #fff;
  border-radius: 10rpx;
  padding: 50rpx 32rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  .label {
    font-size: 32rpx;
    color: #000000;
    font-weight: 600;
  }
  .value {
    margin-top: 24rpx;
    font-size: 64rpx;
    color: #000000;
    font-weight: 600;
  }
}
</style>
