<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.userName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="身份证号">
              <a-input placeholder="请输入身份证号" v-model="queryParam.idcardNumber"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="状态（0：待付款 1：付款中 2：付款成功 3：付款失败）">
                <a-input placeholder="请输入状态（0：待付款 1：付款中 2：付款成功 3：付款失败）" v-model="queryParam.status"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleReissue" type="primary">补发</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio',getCheckboxProps:getCheckboxProps}"
        @change="handleTableChange">

        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在"
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="status" slot-scope="text, record">
            {{text}}
            <a type="link" v-if="record.status === 3" style="margin-left: 8px" @click="checkCause(record)"> 原因</a>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <HlgPaymentReissueModal ref="modalForm" @ok="modalFormOk"></HlgPaymentReissueModal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlgPaymentReissueModal from './modules/HlgPaymentReissueModal'

  const statusMessage = {
    0: '待付款', 1: '付款中', 2: '付款成功', 3: '付款失败'
  }
  export default {
    name: 'HlgPaymentDetailList',
    mixins: [JeecgListMixin],
    components: {
      HlgPaymentReissueModal
    },
    data() {
      return {
        statusMessage,
        description: '付款明细表管理页面',
        // 表头
        columns: [
          {
            title: '账户姓名',
            align: 'center',
            dataIndex: 'userName'
          },
          {
            title: '身份证号',
            align: 'center',
            dataIndex: 'idcardNumber'
          },
          {
            title: '银行卡号',
            align: 'center',
            dataIndex: 'cardNumber'
          },
          // Y：开户行是招商银行 N：开户行是他行
          {
            title: '开户行',
            align: 'center',
            dataIndex: 'bnkflg',
            customRender: function(text, record) {
              return text === 'Y' ? '招商银行' : record.eacbnk
            }
          },
          // {
          //   title: '他行开户行（他行时必填）',
          //   align: 'center',
          //   dataIndex: 'eacbnk'
          // },
          {
            title: '开户地',
            align: 'center',
            dataIndex: 'rcveaa',
            customRender: function(text, record) {
              return record.bnkflg === 'Y' ? '--' : text
            }
          },
          {
            title: '实付金额',
            align: 'center',
            dataIndex: 'payment'
          },
          // （0：待付款 1：付款中 2：付款成功 3：付款失败）
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status_dictText',
            scopedSlots: { customRender: 'status' }
          },

          {
            title: '返回结果时间',
            align: 'center',
            dataIndex: 'paymentResultTime',
            customRender: function(text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          }


          // {
          //   title: '#',
          //   dataIndex: '',
          //   key:'rowIndex',
          //   width:60,
          //   align:"center",
          //   customRender:function (t,r,index) {
          //     return parseInt(index)+1;
          //   }
          // },
          // {
          //   title:'支付id',
          //   align:"center",
          //   dataIndex: 'paymentId'
          // },
          // {
          //   title:'用户',
          //   align:"center",
          //   dataIndex: 'userId'
          // },
          // {
          //   title:'付款时间（向银行提交付款按钮的时间）',
          //   align:"center",
          //   dataIndex: 'paymentTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'付款者',
          //   align:"center",
          //   dataIndex: 'paymentBy'
          // },
          //
          // {
          //   title:'创建时间',
          //   align:"center",
          //   dataIndex: 'createTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'创建者',
          //   align:"center",
          //   dataIndex: 'createBy'
          // },
          // {
          //   title:'更新时间',
          //   align:"center",
          //   dataIndex: 'updateTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'更新者',
          //   align:"center",
          //   dataIndex: 'updateBy'
          // },
          // {
          //   title:'数据权限',
          //   align:"center",
          //   dataIndex: 'sysOrgCode'
          // },
          //
          // {
          //   title:'是否补发（0：不是 1：是）',
          //   align:"center",
          //   dataIndex: 'isSupplementPayment'
          // },
          // {
          //   title:'付款失败原因',
          //   align:"center",
          //   dataIndex: 'failureReason'
          // },
          // {
          //   title:'是否删除（0：未删除 1：已删除）',
          //   align:"center",
          //   dataIndex: 'delFlag'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   scopedSlots: { customRender: 'action' },
          // }
        ],
        url: {
          list: '/hlgpayment/hlgPaymentDetail/list',
          delete: '/hlgpayment/hlgPaymentDetail/delete',
          deleteBatch: '/hlgpayment/hlgPaymentDetail/deleteBatch',
          exportXlsUrl: '/hlgpayment/hlgPaymentDetail/exportXls',
          importExcelUrl: 'hlgpayment/hlgPaymentDetail/importExcel'
        },
        dictOptions: {}
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    mounted() {
      if (this.$route.query.record) {
        console.log(JSON.parse(this.$route.query.record))
      }
    },
    methods: {
      initDictConfig() {
      },
      checkCause(record) {
        this.$error({
          title: '失败原因',
          content: record.failureReason,
          okText: '确定',
          centered: true
        })
      },
      getCheckboxProps: (record) => ({
        props: {
          disabled: record.status === 3 // Column configuration not to be checked
        }
      }),
      handleReissue() {
        if (this.selectionRows.length) {
          this.$refs.modalForm.edit(this.selectionRows[0])
          this.$refs.modalForm.title = '补发'
          this.$refs.modalForm.disableSubmit = false
        } else {
          this.$message.warning('请选择付款单')
        }
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>