<template>
  <page-layout>
    <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>
            <template v-if="toggleSearchStatus">
              <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>
            <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" v-has="'payment:import'">导入</a-button>
      </div>

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

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

          <span slot="paymentCode" slot-scope="text,record">
                  <a @click="toDetail(record)">{{text}}</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">
              <a v-if="record.status === 0" style="color: #D9001B" @click="handleDelete(record)" v-has="'payment:del'">删除</a>
              <a v-if="(record.status === 2 || record.status === 3) && record.requirementName" @click="handleViewRequirementsModal(record)" v-has="'payment:requirement'">查看需求</a>
              <a v-if="(record.status === 2 || record.status === 3) && !record.requirementName" @click="handleRequirement(record)" v-has="'payment:requirement'">关联需求</a>
          </span>

          <span slot="updateBy" slot-scope="text,record">
            <template v-if="record.status === 1 || record.status === 3">
              {{text}}
            </template>
            <template v-else>
              --
            </template>
          </span>

        </a-table>
      </div>

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

<script>

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

  export default {
    name: 'HlgPaymentList',
    mixins: [JeecgListMixin],
    components: {
      HlgPaymentImportModal,
      HlgPaymentReviewModal,
      HlgPaymentRequirementModal,
      PageLayout,
      HlgPaymentViewRequirementsModal
    },
    data() {
      return {
        description: '付款信息表管理页面',
        // 表头
        columns: [
          {
            title: '付款单号',
            align: 'left',
            dataIndex: 'paymentCode',
            scopedSlots: { customRender: 'paymentCode' }
          },
          {
            title: '付款企业',
            align: 'left',
            dataIndex: 'companyName'
          },
          {
            title: '服务商',
            align: 'left',
            dataIndex: 'subcontractorName',
            customRender: (value,record) => {
              return value ? value:'--'
            }
          },
          {
            title: '付款金额',
            align: 'left',
            dataIndex: 'payment'
          },
          {
            title:'服务费',
            align:"left",
            dataIndex: 'serviceFee'
          },
          // （0：待复核 1：付款中 2：复核未通过 3：已付款）
          {
            title: '状态',
            align: 'left',
            dataIndex: 'status_dictText',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '业务处理情况',
            align: 'left',
            dataIndex: 'remark'
          },
          {
            title: '导入时间',
            align: 'left',
            dataIndex: 'createTime'
          },
          {
            title: '导入人',
            align: 'left',
            dataIndex: 'createBy'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'left',
            scopedSlots: { customRender: 'action' }
          }
        ],
        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',query:{ paymentId:record.id } })
      },
      handleImport() {
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '导入付款'
        this.$refs.modalForm.disableSubmit = false
      },
      handleDelete(record) {
        const id = record.id
        let that = this
        const modal = that.$confirm({
          title: '删除付款',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '确定要删除该付款申请吗？',
          okText: '确定删除',
          cancelText: '取消',
          onOk: function() {
            putAction(that.url.delete, { 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()
          }
        })
      },
      //复核
      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
      },
      //查看需求
      handleViewRequirementsModal(record){
        this.$refs.viewRequirementsModal.edit(record)
        this.$refs.viewRequirementsModal.title = '查看需求'
        this.$refs.viewRequirementsModal.disableSubmit = false
      }

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