<template>
  <view class="contact-main">
    <view class="todo-list">
      <u-empty mode="list" v-if="list.length == 0"></u-empty>
      <view v-else v-for="(v, i) in list" :key="i">
        <view class="contact-item">
          <view class="flex_l">
            <view class="label">合同编号：</view>
            <view class="val">{{ v.contractCode }}</view>
          </view>
          <view class="flex_l">
            <view class="label">开票金额：</view>
            <view class="val">{{ formatPrice(v.invoiceAmount) }}</view>
          </view>
          <view class="flex_l">
            <view class="label">开票日期：</view>
            <view class="val">{{ v.invoiceDate }}</view>
          </view>
          <view class="flex_l">
            <view class="label">开票类型：</view>
            <view class="val">{{ invoiceTypeData.filter((item) => item.key == v.invoiceType)[0].value || '-' }}</view>
          </view>
          <view class="flex_l">
            <view class="label">审核状态：</view>
            <view class="val"> {{
              v.approStatus == '10'
                ? '待提交审核'
                : v.approStatus == '20'
                ? '待审核'
                : v.approStatus == '30'
                ? '审核已同意'
                : v.approStatus == '40'
                ? '审核已拒绝'
                : v.approStatus == '50'
                ? '审核已撤销'
                : ''
            }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import to from 'await-to-js'
  import api from '@/api/contract'
  export default {
    name: 'OmsContractInvoice',
    props: {
      contractId: {
        type: [String, Number],
        default: '0',
      },
    },
    data() {
      return {
        invoiceTypeData: [], //发票类型
        list: []
      }
    },
    mounted() {
      this.getOptions()
      this.fetchData()
    },
    methods: {
      getOptions() {
        Promise.all([this.getDicts('invoice_type')])
          .then(([invoiceType]) => {
            this.invoiceTypeData = invoiceType.data.values || []
          })
          .catch((err) => console.log(err))
      },
      async fetchData() {
        const [err, res] = await to(api.getInvoice({
          contractId: this.contractId,
          pageNum: 0
        }))
        if (err) return
        this.list = res.data.list || []
      }
    }
  }
</script>

<style lang="scss" scoped>
  .contact-main {
    height: 100%;

    .todo-list {
      height: 100%;
      overflow: auto;
      padding: 20rpx 20rpx 0;

      .contact-item {
        padding: 20rpx;
        margin-bottom: 20rpx;
        box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
        border-radius: 8px;

        .label,
        .val {
          font-size: 28rpx;
          padding-bottom: 14rpx;
        }

        .label {
          color: #646464;
        }
      }
    }
  }
</style>
