<template>
  <div class="export-tax">
    <div class="search">
      <div class="left" />
      <div class="right">
        <div>
          <el-input v-model="search.contractInfo" placeholder="申报批次" />
        </div>
        <div>
          <el-input v-model="search.contractInfo" placeholder="报关单号" />
        </div>
        <div>
          <el-input v-model="search.contractInfo" placeholder="销售订单ID" />
        </div>
        <div>
          <el-input v-model="search.contractInfo" placeholder="出口发票号" />
        </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-date-picker
            v-model="addDate"
            type="daterange"
            range-separator="至"
            start-placeholder="申报年月日期范围"
            end-placeholder="申报年月日期范围"
          />
        </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>
          <el-button type="primary" @click="addContract">添加合同</el-button>
        </div>
      </div>
    </div>
    <cy-comm-table
      ref="commTable"
      v-loading="loading"
      :columns="columns"
      :data="tableData"
      :count="count"
      parent-component="ExportTax"
    />

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import {
  getList
} from '@/api/myTrade/salesContract'
import { formatMoney, codeChangeName } from '@/utils'

export default {
  name: 'ExportTax',
  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: '申报批次',
          showTooltip: true,
          prop: 'contractName'
        },
        {
          label: '报关单号',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          label: '销售订单ID',
          showTooltip: true,
          prop: 'importerEnterpriseName'
        },
        {
          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: '退税状态',
          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>
          }
        }

      ],
      loading: false,
      platformList: [],
      commodityList: [],
      uploadDialogVisible: false,
      curContractId: ''
    }
  },
  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)
      })
    },

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

  }
}
</script>

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

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