<template>
  <div class="page-header-index-wide">
    <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.paymentCode"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="付款企业">
                <a-input placeholder="请输入付款企业" v-model="queryParam.companyName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="状态">
                <j-dict-select-tag :triggerChange="false" v-model="queryParam.status" placeholder="请选择状态查询"
                                   dictCode="payment_status" v-decorator="['status', {}]"/>
              </a-form-item>
            </a-col>
<!--            <template v-if="toggleSearchStatus">-->
<!--            </template>-->
            <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<!--              <a @click="handleToggleSearch">-->
<!--                {{ toggleSearchStatus ? '取消' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
              <a-button ghost type='primary' @click="searchQuery" icon="search">查询</a-button>
              <a-button ghost type='primary' @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a class="ant-btn ant-btn-primary" @click="handleImportExcel1()" icon="import" type="primary"
           v-has="'payment:import'">导入付款</a>
      </div>

      <!-- table区域-begin -->
      <div>

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="deloading"
          :scroll="{ x: 1730}"
          class="j-table-force-nowrap"
          @change="handleTableChange">

          <span slot="paymentCode" slot-scope="text, record">
            <a @click="handleEdit(record)">{{record.paymentCode}}</a>
          </span>

          <span slot="status" slot-scope="text,record">
            <template v-if="record.isAllSuccess === 0">
              <span style="color: #D9001B">{{text}}</span>
            </template>
            <template v-else>
              {{text}}
            </template>
          </span>

          <span slot="action" slot-scope="text, record">
            <template v-if="record.status === 0">
              <a style="color: #D9001B" @click="handleDelete(record.id)" v-has="'payment:del'">删除</a>
            </template>
            <template v-else>
              --
            </template>
        </span>

        </a-table>
      </div>

      <hwPayment-modal ref="modalForm"></hwPayment-modal>
      <hw-payment-export-modal ref="modalSelectRequireForm" @ok="modalFormOk"></hw-payment-export-modal>
    </a-card>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HwPaymentModal from './modules/HwPaymentModal'
  import { filterObj } from '@/utils/util'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  import HwPaymentExportModal from './modules/HwPaymentExportModal'
  import qs from 'qs';
  const deletePayment = (params) => deleteAction('/hwpayment/hwPayment/delete', params)

  export default {
    name: 'HwPaymentList',
    mixins: [JeecgListMixin],
    components: {
      HwPaymentModal,
      HwPaymentExportModal,
    },
    data() {
      return {
        description: 'hw_payment管理页面',
        // 查询条件
        queryParam: {
          createTimeRange: []
        },
        // 表头
        columns: [
          {
            title: '付款单号',
            align: 'left',
            dataIndex: 'paymentCode',
            scopedSlots: { customRender: 'paymentCode' }
          },
          {
            title: '服务商',
            align: 'left',
            dataIndex: 'subcontractorName',
            customRender: (value,record) => {
              return value ? value:'--'
            }
          },
          {
            title: '付款总额',
            align: 'left',
            dataIndex: 'totalPayment'
          },
          {
            title: '付款金额',
            align: 'left',
            dataIndex: 'payment'
          },
          {
            title:'服务费',
            align:"left",
            dataIndex: 'serviceFee'
          },
          {
            title:'服务费率',
            align:"left",
            dataIndex: 'serviceRate',
            customRender: (value,record) => {
              return value ? value + '%':'--'
            }
          },
          {
            title: '业务处理情况',
            align: 'left',
            dataIndex: 'remark'
          },
          // （0：待复核 1：付款中 2：复核未通过 3：已付款）
          {
            title: '状态',
            align: 'left',
            dataIndex: 'status_dictText',
            // scopedSlots: { customRender: 'status' }
          },
          {
            title: '导入时间',
            align: 'left',
            dataIndex: 'createTime'
          },
          {
            title: '付款企业',
            align: 'left',
            dataIndex: 'companyName'
          },
          // {
          //   title: '导入人',
          //   align: 'left',
          //   dataIndex: 'createBy'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'left',
            fixed: 'right',
            width: 160,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/hwpayment/hwPayment/list',
          delete: '/hwpayment/hwPayment/delete',
          deleteBatch: '/hwpayment/hwPayment/deleteBatch',
          exportXlsUrl: '/hwpayment/hwPayment/exportXls',
          importExcelUrl: 'hwpayment/hwPayment/importExcel'
        },
        dictOptions: {},
        //自定义加载层
        deloading:{
          spinning:false,
          tip:''
        },
        allowClear:false,
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      getQueryParams() {
        console.log(this.queryParam)
        var param = Object.assign({}, this.queryParam, this.isorter)
        param.field = this.getQueryField()
        param.pageNo = this.ipagination.current
        param.pageSize = this.ipagination.pageSize
        delete param.createTimeRange // 时间参数不传递后台
        return filterObj(param)
      },
      initDictConfig() {
      },
      onDateChange: function(value, dateString) {
        console.log(dateString[0], dateString[1])
        this.queryParam.createTime_begin = dateString[0] + ' 00:00:00'
        this.queryParam.createTime_end = dateString[1] + ' 23:59:59'
      },
      onDateOk(value) {
        console.log(value)
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.deloading.spinning = true
        this.deloading.tip = '';
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records;
            this.ipagination.total = res.result.total;
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.deloading.spinning = false
        })
      },
      handleDelete(id) {
        let that = this
        const modal = that.$confirm({
          title: '删除付款',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '确定要删除该付款吗？',
          okText: '确定删除',
          cancelText: '取消',
          onOk: function() {
            deletePayment({ id: id }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData(1)
              } else {
                that.$error({
                  title: '删除失败',
                  content: res.message,
                  okText: '确定'
                })
              }
            })
          },
          onCancel(e) {
            modal.destroy()
          }
        })
      },
      handleEdit(record) {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '付款详情'
        this.$refs.modalForm.disableSubmit = false
      },
      handleImportExcel1() {
        this.$refs.modalSelectRequireForm.edit()
        this.$refs.modalSelectRequireForm.title = '导入付款'
        this.$refs.modalSelectRequireForm.disableSubmit = false
      },
      modalFormOk(){
        this.loadData(1);
        this.onClearSelected();
      },
      handleLink(id){

      },
      handleReview(id){

      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  ::v-deep .ant-table-pagination{
    float: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>