<template>
  <div class="my-receive">
    <div class="search">
      <div class="left" />
      <div class="right">
        <div>
          <el-input v-model="search.contractInfo" placeholder="融资申请编号 / 出口退税申请ID / 支付业务编号" />
        </div>
        <div>
          <el-select v-model="search.contractStatus" placeholder="请选择款项类型" clearable>
            <el-option
              v-for="item in constant.sales_contract_status"
              :key="item.dictCode"
              :label="item.dictLabel"
              :value="item.dictValue"
            />
          </el-select>
        </div>
        <div>
          <el-select v-model="search.agencyCertNo" placeholder="请选择交易对手" clearable>
            <el-option
              v-for="item in counterpartyList"
              :key="item.certNo"
              :label="item.platformName"
              :value="item.certNo"
            />
          </el-select>
        </div>
        <div>
          <el-date-picker
            v-model="addDate"
            type="daterange"
            range-separator="至"
            start-placeholder="收款日期范围"
            end-placeholder="收款日期范围"
          />
        </div>
        <div class="right-btn">
          <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="MyReceive"
    />

  </div>
</template>

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

export default {
  name: 'MyReceive',
  components: {
  },
  data() {
    return {
      count: 0,
      search: {
        customerUserInfo: '',
        importerCertNo: '',
        agencyCertNo: '',
        paymentWay: '',
        contractStatus: ''
      },
      page: 1,
      size: 10,
      addDate: [],
      tableData: [],
      columns: [
        {
          label: '序号',
          index: true
        },
        {
          label: '业务编号',
          prop: 'contractNo',
          showTooltip: true
        },
        {
          label: '款项类型',
          prop: 'paymentWay',
          showTooltip: true,
          render: (h, row) => {
            return <div> <el-tooltip class='item' effect='dark' content={codeChangeName(this.constant.payment_way, row.paymentWay, 'dictValue', 'dictLabel')} placement='top'>
              <div class='one-ellipsis'>
                {codeChangeName(this.constant.payment_way, row.paymentWay, 'dictValue', 'dictLabel')}
              </div>
            </el-tooltip></div>
          }
        },
        {
          label: '收款金额',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ formatMoney(row.contractAmount) }</div>
          }
        },
        {
          label: '收款账户名',
          showTooltip: true,
          prop: 'contractName'
        },
        {
          label: '收款账号',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          label: '销售合同编号',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          label: '交易对手',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          label: '出口商品总金额',
          showTooltip: true,
          render: (h, row) => {
            return <div>{ formatMoney(row.contractAmount) }</div>
          }
        },
        {
          label: '收款日期',
          showTooltip: true,
          prop: 'contractName'
        },
        {
          label: '操作',
          width: 150,
          render: (h, row) => {
            const btnList = [
              {
                msg: '详情',
                icon: 'iconfont icon-a-Group957',
                power: '',
                // rowPower: [4],
                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: []
    }
  },
  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', ['payment_way', 'sales_contract_status'])
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    fetchData(type) {
      this.loading = true
      if (type === 'search') {
        this.page = 1
        this.size = 10
      }
      const params = {
        ...this.search,
        timeStart: this.addDate.length ? this.addDate[0] : '',
        timeEnd: 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)
      })
    },
    getCounterparty() {
      const userId = store.getters.userInfo.id
      getCounterpartyList({ userId: userId }).then(res => {
        this.counterpartyList = res.data || []
      })
    },

    addContract() {
      this.$router.push({
        name: 'SalesContractAdd',
        query: {
          type: 'add'
        }
      })
    }

  }
}
</script>

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

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