<template>
  <view class="invoice-item" @click="handleDetail">
    <view class="cell">
      <text class="cell-left name">
        {{ itemData.invoiceApplyNumber || '' }}
      </text>
      <view
        :style="{
          color: statusObj.color,
          backgroundColor: statusObj.bg,
        }"
        class="cell-right status">
        {{ statusObj.label }}
      </view>
    </view>
    <view class="cell">
      <text class="cell-left text-info">
        {{ itemData.customerName || '' }}
      </text>
    </view>
    <view class="cell">
      <view class="cell-left text-info">
        开票日期：{{ itemData.invoiceDate }}
      </view>
      <view class="cell-right money">
        ￥{{ splitNumber(itemData.invoiceMoney) }}
      </view>
    </view>
  </view>
</template>

<script>
  import { splitNumber } from '@/utils/lib.js'
  import { mapGetters } from 'vuex'

  export default {
    name: 'InvoiceItem',
    props: {
      itemData: {
        type: Object,
        required: true
      }
    },
    data() {
      return {
        auth: 'crm.invoice.read'
      }
    },
    computed: {
    ...mapGetters({
      calcStatus: 'base/calcStatus'
    }),
    statusObj() {
      return this.calcStatus(this.itemData.checkStatus) || {}
    }
    },
    methods: {
      splitNumber(num) {
        return splitNumber(num)
      },

      handleDetail() {
        if (!this.$auth(this.auth)) {
          this.$toast('权限不足')
          return
        }
        this.$Router.navigateTo({
          url: '/pages_crm/invoice/detail',
          query: {
            id: this.itemData.invoiceId
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
@import "../../style/listItem";

.invoice-item {
  border-bottom: 1rpx solid $border-color;
  background-color: white;
  padding: 20rpx 32rpx;

  .cell {
    .name {
      font-size: 32rpx;
      color: #212121;
      @include ellipsis;
    }
    .status {
      width: 116rpx;
      height: 46rpx;
      font-size: 24rpx;
      border-radius: 4rpx;
      @include center;
    }

    .text-info {
      font-size: 26rpx;
      color: $gray;
    }

    .money {
      color: #FF7300;
      font-size: 28rpx;
      font-weight: bold;
    }
  }
}
</style>
