<template>
  <div class="my-receive">
    <div class="search">
      <div class="left" />
      <div class="right">
        <div>
          <el-input v-model="search.businessNumber" style="width: 320px;" placeholder="业务编号 / 融资申请编号 / 报关单号 / 收款凭证号" />
        </div>
        <div>
          <el-select v-model="search.paymentType" placeholder="请选择款项类型" clearable>
            <el-option
              v-for="item in constant.ledger_type"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictValue"
            />
          </el-select>
        </div>
        <div>
          <el-input v-model="search.salesContractNo" placeholder="销售合同编号" />
        </div>
        <!-- <div>
          <el-select v-model="search.importerCertNo" placeholder="请选择进口商" clearable>
            <el-option
              v-for="item in entryComList"
              :key="item.certNo"
              :label="item.entityName"
              :value="item.certNo"
            />
          </el-select>
        </div> -->
        <div>
          <el-select v-model="search.payerType" placeholder="请选择付款方类型" clearable>
            <el-option
              v-for="item in constant.payer_type"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictValue"
            />
          </el-select>
        </div>
        <div>
          <el-input v-model="search.payerName" placeholder="付款方名称" />
        </div>
        <div>
          <el-date-picker
            v-model="addDate"
            type="daterange"
            range-separator="至"
            start-placeholder="收款日期范围"
            end-placeholder="收款日期范围"
            value-format="yyyy-MM-dd"
          />
        </div>
        <div class="right-btn">
          <el-button type="primary" @click="fetchData('reset')">重置</el-button>
          <el-button type="primary" @click="fetchData('search')">查询</el-button>
        </div>
      </div>
    </div>
    <cy-comm-table
      ref="commTable"
      v-loading="loading"
      :columns="columns"
      :data="tableData"
      :count="count"
      parent-component="Receive"
    />

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
// import store from '@/store'
import { getList } from '@/api/myAccounts/receive'
import { formatMoney, codeChangeName } from '@/utils'
// import { entryEntityList } from '@/api/myTrade/salesBill'

export default {
  name: 'Receive',
  components: {
  },
  data() {
    return {
      count: 0,
      search: {
        businessNumber: '',
        paymentType: '',
        salesContractNo: '',
        importerCertNo: '',
        payerName: '',
        payerType: ''
      },
      page: 1,
      size: 10,
      addDate: [],
      tableData: [],
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '收款业务编号',
          prop: 'businessNumber',
          showTooltip: true
        },
        {
          label: '款项类型',
          prop: 'paymentWay',
          showTooltip: true,
          render: (h, row) => {
            return <div> <el-tooltip class='item' effect='dark' content={codeChangeName(this.constant.ledger_type, row.paymentWay, 'dictValue', 'dictLabel')} placement='top'>
              <div class='one-ellipsis'>
                {codeChangeName(this.constant.ledger_type, row.paymentWay, 'dictValue', 'dictLabel')}
              </div>
            </el-tooltip></div>
          }
        },
        {
          label: '收款金额',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ row.receivePaymentCurrency + ' ' + formatMoney(row.receivePaymentAmount) }</div>
          }
        },
        {
          label: '收款账号',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          label: '销售合同编号',
          showTooltip: true,
          prop: 'salesContractNo'
        },
        {
          label: '付款方类型',
          prop: 'paymentWay',
          showTooltip: true,
          render: (h, row) => {
            return <div> <el-tooltip class='item' effect='dark' content={codeChangeName(this.constant.payer_type, row.payerType, 'dictValue', 'dictLabel')} placement='top'>
              <div class='one-ellipsis'>
                {codeChangeName(this.constant.payer_type, row.payerType, 'dictValue', 'dictLabel')}
              </div>
            </el-tooltip></div>
          }
        },
        // {
        //   label: '进口商名称',
        //   showTooltip: true,
        //   prop: 'importerEnterpriseName'
        // },
        {
          label: '付款方名称',
          showTooltip: true,
          prop: 'payerName'
        },
        {
          label: '付款日期',
          showTooltip: true,
          prop: 'paymentDate',
          render: (h, row) => {
            return <div> <el-tooltip class='item' effect='dark' content={row.paymentDate ? row.paymentDate.split(' ')[0] : '--'} placement='top'>
              <div class='one-ellipsis'>
                {row.paymentDate ? row.paymentDate.split(' ')[0] : '--'}
              </div>
            </el-tooltip></div>
          }
        },
        {
          label: '操作',
          width: 150,
          render: (h, row) => {
            const btnList = [
              {
                msg: '详情',
                icon: 'iconfont icon-a-Group957',
                power: '',
                category: 'see'
              }
            ]
            const options = btnList.map(item => {
              return (
                this.tablePower({ item, row }) && <el-tooltip class='item' effect='dark' content={item.msg} placement='top'>
                  <span class='table-icon-box'>
                    <i class={item.icon} style={item.style} onClick={() => { this.handlerOperate(item.category, row) }}></i>
                  </span>
                </el-tooltip>
              )
            })
            return <div>{ options }</div>
          }
        }

      ],
      loading: false,
      counterpartyList: [],
      entryComList: []
    }
  },
  computed: {
    ...mapGetters(['constant']),
    tablePower() {
      return ({ item, row }) => {
        const { rowPower } = item
        if (rowPower) {
          if (rowPower.includes(row.status)) {
            return true
          }
        } else {
          return true
        }
      }
    }
  },
  created() {
    this.$store.dispatch('getConstant', ['ledger_type', 'payer_type'])
    // const userId = store.getters.userInfo.id
    // entryEntityList({ userId: userId }).then(res => {
    //   this.entryComList = res.data || []
    // })
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData(type) {
      this.loading = true
      if (type) {
        this.page = 1
        this.size = 10
        if (type === 'reset') {
          for (const key in this.search) {
            this.search[key] = ''
          }
          this.addDate = []
        }
      }
      const params = {
        ...this.search,
        beginTime: this.addDate && this.addDate.length ? this.addDate[0] : '',
        endTime: this.addDate && this.addDate.length ? this.addDate[1] : '',
        page: this.page || 1,
        rows: this.size || 10
      }
      getList(params).then(({ data }) => {
        this.loading = false
        this.tableData = data.rows
        this.count = Number(data.records)
      })
    },
    handlerOperate(type, row) {
      if (type === 'see') {
        this.$router.push({
          name: 'ReceiveView',
          query: {
            type: 'view',
            id: row.id
          }
        })
      }
    }
  }
}
</script>

  <style lang="scss" scoped>
      .export-tax {

      }
  </style>
  <style lang="scss">
      .my-receive {
          .icon-a-Group957, .icon-a-Group1087 {
              font-size: 28px;
          }
      }
  </style>
