<template>
  <a-card class="j-address-list-right-card-box" :loading="cardLoading" :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业名称">
              <a-input placeholder="请输入企业名称" v-model="queryParam.companyName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <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>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 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="action" slot-scope="text, record">
          <a @click="handleDetail(record)">{{record.companyName}}</a>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'

  export default {
    name: "HlwCompanyAccountList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {

    },
    props: ['value'],
    data () {
      return {
        description: '平台企业账户表管理页面',
        cardLoading: true,
        // 表头
        columns: [
          {
            title:'企业名称',
            align:"center",
            dataIndex: 'companyName',
            scopedSlots: { customRender: 'action' }
          },
          {
            title:'账户余额',
            align:"center",
            dataIndex: 'balance'
          },
          {
            title:'充值金额',
            align:"center",
            dataIndex: 'totalDeposit'
          },
          {
            title:'付款总额',
            align:"center",
            dataIndex: 'totalPayment'
          },
          {
            title:'支付服务费',
            align:"center",
            dataIndex: 'totalServiceFee'
          }
        ],
        url: {
          list: "/wisdom/hlwCompanyAccount/list",
          delete: "/wisdom/hlwCompanyAccount/delete",
          deleteBatch: "/wisdom/hlwCompanyAccount/deleteBatch",
          exportXlsUrl: "/wisdom/hlwCompanyAccount/exportXls",
          importExcelUrl: "wisdom/hlwCompanyAccount/importExcel",
        },
        dictOptions:{},
      }
    },
    watch: {
      value: {
        immediate: true,
        handler(applicationId) {
          this.dataSource = []
          this.loadData(1, applicationId)
        }
      },
    },
    methods: {
      loadData(pageNum, applicationId) {
        this.loading = true
        if (pageNum === 1) {
          this.ipagination.current = 1
        }
        // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
        if (!applicationId) {
          // getAction(this.url.list, {
          //   ...this.getQueryParams()
          // }).then((res) => {
          //   if (res.success) {
          //     this.dataSource = res.result.records
          //     this.ipagination.total = res.result.total
          //   }
          // }).finally(() => {
          //   this.loading = false
          //   this.cardLoading = false
          // })
          this.loading = false
          this.cardLoading = false
          // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
        }else{
          //加载数据 若传入参数1则加载第一页的内容
          getAction(this.url.list, {
            applicationId,
            ...this.getQueryParams()
          }).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records
              this.ipagination.total = res.result.total
            }
          }).finally(() => {
            this.loading = false
            this.cardLoading = false
          })
        }
      },
      searchQuery() {
        this.loadData(1, this.value)
      },
      searchReset() {
        this.queryParam = {}
        this.loadData(1, this.value)
      },

      handleTableChange(pagination, filters, sorter) {
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field
          this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
        }
        this.ipagination = pagination
        this.loadData(null, this.value)
      },
      handleDetail(record){
        this.$router.push({ path: '/wisdom/hlwCompanyAccount/companyList',query:{ companyId:record.companyId,companyName:record.companyName }})
      }
    }
  }
</script>
<style>
  .j-address-list-right-card-box .ant-table-placeholder {
    min-height: 46px;
  }
</style>
<style scoped>
  .j-address-list-right-card-box {
    height: 100%;
    min-height: 300px;
  }
</style>