<template>
  <button class="received-item" @click="handleDetail">
    <view class="cell">
      <text class="cell-left name">
        {{ itemData.number || '' }}
      </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">
      <text class="cell-left text-info">
        回款时间：{{ itemData.returnTime | formatTime }}
      </text>
      <text v-if="hasMoney" class="cell-right money">
        ￥{{ splitNumber(itemData.money) }}
      </text>
    </view>
  </button>
</template>

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

  export default {
    name: 'ReceivedItem',
    filters: {
      formatTime(val) {
        if (!val) return '--'
        return moment(val).format('YYYY-MM-DD')
      }
    },
    props: {
      itemData: {
        type: Object,
        required: true
      }
    },
    data() {
      return {}
    },
    computed: {
    ...mapGetters({
      calcStatus: 'base/calcStatus'
    }),
    statusObj() {
      return this.calcStatus(this.itemData.checkStatus) || {}
    },
    hasMoney() {
      return this.itemData.hasOwnProperty('money')
    }
    },
    methods: {
      splitNumber(num) {
        return splitNumber(num)
      },
      /**
       * 详情跳转
       */
      handleDetail() {
        if (!this.$auth('crm.receivables.read')) {
          this.$toast('权限不足')
          return
        }
        this.$Router.navigateTo({
          url: '/pages_crm/receivables/detail',
          query: {
            id: this.itemData.receivablesId
          }
        })
      }
    }
  }
</script>

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

.received-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>
