<template>
  <page-layout>
    <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">
            <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 type="primary" icon="import" @click="handleImport">导入</a-button>
        <!--        <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
        <!--                  @change="handleImportExcel">-->
        <!--       -->
        <!--        </a-upload>-->
        <!--        <a-button @click="handleAdd" type="primary" icon="plus">关联需求</a-button>-->
      </div>

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

        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :scroll="{ x: 2300 }"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          @change="handleTableChange">
          <span slot="paymentCode" slot-scope="text,record">
                  <a-button type="link" @click="toDetail(record)">{{text}}</a-button>
          </span>

          <span slot="action" slot-scope="text, record">
              <a-button type="link" v-if="record.status === 0" @click="handleReview(record)">复核</a-button>
              <a-divider v-if="record.status === 0" type="vertical"/>
              <a-button type="link" v-if="record.status === 0 || record.status === 2"
                        style="color: #D9001B"
                        @click="handleDelete(record)">删除</a-button>
              <a-button type="link" v-if="record.status === 3" @click="handleEdit(record)">查看需求</a-button>
              <a-button type="link" v-if="record.status === 0" @click="handleRequirement(record)">关联需求</a-button>
        </span>

        </a-table>
      </div>

      <HlgPaymentImportModal ref="modalForm" @ok="modalFormOk"></HlgPaymentImportModal>
      <HlgPaymentReviewModal ref="reviewModal"></HlgPaymentReviewModal>
      <HlgPaymentRequirementModal ref="requirementModal"></HlgPaymentRequirementModal>
    </a-card>
  </page-layout>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlgPaymentImportModal from './modules/HlgPaymentImportModal'
  import HlgPaymentReviewModal from './modules/HlgPaymentReviewModal'
  import HlgPaymentRequirementModal from './modules/HlgPaymentRequirementModal'
  import PageLayout from '@/components/page/PageLayout'
  import { httpAction, getAction, putAction } from '@/api/manage'

  export default {
    name: 'HlgPaymentList',
    mixins: [JeecgListMixin],
    components: {
      HlgPaymentImportModal,
      HlgPaymentReviewModal,
      HlgPaymentRequirementModal,
      PageLayout
    },
    data() {
      return {
        description: '付款信息表管理页面',
        // 表头
        columns: [
          {
            title: '付款单号',
            align: 'center',
            width: 200,
            dataIndex: 'paymentCode',
            scopedSlots: { customRender: 'paymentCode' }
          },
          {
            title: '付款企业',
            align: 'center',
            width: 300,
            dataIndex: 'companyName'
          },
          {
            title: '服务商',
            align: 'center',
            width: 300,
            dataIndex: 'subcontractorName'
          },
          {
            title: '实发金额',
            align: 'center',
            width: 200,
            dataIndex: 'payment'
          },
          // （0：待复核 1：付款中 2：复核未通过 3：已付款）
          {
            title: '状态',
            align: 'center',
            width: 200,
            dataIndex: 'status_dictText'
          },
          {
            title: '业务处理情况',
            align: 'center',
            width: 500,
            dataIndex: 'situation',
            customRender: function(text, record) {
              let _message = ''
              if (record.status === 0) {
                _message = '总笔数18笔， 共计80100元。'
              }
              if (record.status === 1) {
                _message = '总笔数18笔，等待返回结果。'
              }
              if (record.status === 2) {
                _message = '拒绝原因：********'
              }
              if (record.status === 3) {
                _message = '总笔数18笔，18笔成功， 80100元 ，0笔失败， 0元。'
              }
              return _message
            }
          },
          {
            title: '导入时间',
            align: 'center',
            width: 200,
            dataIndex: 'createTime',
            customRender: function(text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '导入人',
            align: 'center',
            width: 200,
            dataIndex: 'createBy'
          },
          {
            title: '付款人',
            align: 'center',
            width: 200,
            dataIndex: 'updateBy'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width: 240,
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
          // {
          //   title:'所属需求',
          //   align:"center",
          //   dataIndex: 'requirementId'
          // },
          //
          //
          // {
          //   title:'税率（付款时从税率表同步过来）',
          //   align:"center",
          //   dataIndex: 'taxRate'
          // },
          // {
          //   title:'计税方式（0：应付计税 1：实付计税）（付款时从税率表同步过来）',
          //   align:"center",
          //   dataIndex: 'taxType'
          // },
          // {
          //   title:'需求名称',
          //   align:"center",
          //   dataIndex: 'requirementName'
          // },
          // {
          //   title:'需求描述',
          //   align:"center",
          //   dataIndex: 'requirementDescription'
          // },
          // {
          //   title:'需求时间',
          //   align:"center",
          //   dataIndex: 'requirmentTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'数据权限',
          //   align:"center",
          //   dataIndex: 'sysOrgCode'
          // },
          //
          //
          // {
          //   title:'更新时间',
          //   align:"center",
          //   dataIndex: 'updateTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          //
          //
          // {
          //   title:'复核未通过原因',
          //   align:"center",
          //   dataIndex: 'refuseReason'
          // },
          // {
          //   title:'是否删除（0：否 1：是）',
          //   align:"center",
          //   dataIndex: 'delFlag'
          // },
        ],
        url: {
          list: '/hlgpayment/hlgPayment/list',
          delete: '/hlgpayment/hlgPayment/deleteByLogic',
          deleteBatch: '/hlgpayment/hlgPayment/deleteBatch',
          exportXlsUrl: '/hlgpayment/hlgPayment/exportXls',
          importExcelUrl: 'hlgpayment/hlgPayment/importExcel'
        },
        loading:false,
        dictOptions: {}
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      initDictConfig() {
      },
      toDetail(record) {
        this.$router.push({ path: '/hlgpayment/hlgPaymentDetail/list' })
      },
      handleImport() {
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '导入付款'
        this.$refs.modalForm.disableSubmit = false
      },
      handleDelete(record) {
        const id = record.id
        this.loading = true
        putAction(this.url.delete, { id }).then(res => {
          if (res.success) {
            this.$message.success(res.message)
          } else {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      handleReview(record) {
        this.$refs.reviewModal.edit(record)
        this.$refs.reviewModal.title = '复核'
        this.$refs.reviewModal.disableSubmit = false
      },
      handleRequirement(record) {
        this.$refs.requirementModal.edit(record)
        this.$refs.requirementModal.title = '关联需求'
        this.$refs.requirementModal.disableSubmit = false
      }

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