<template>
  <a-card :bordered="false">

    <!-- table区域-begin -->
    <div>
      <div class="" style="margin-bottom: 16px;">
        <h2>{{model.companyName}}</h2>
      </div>

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

           <span slot="action" slot-scope="text, record">
             <a @click="handleMoney(record)" v-has="'company:account:recharge'">充值</a>
             <a-divider type="vertical" v-has="'company:account:withdrow'"/>
             <a @click="handleWithDrow(record)" v-has="'company:account:withdrow'">提现</a>
             <a-divider type="vertical" v-has="'company:account:detail'"/>
             <a @click="handleDetail(record)" v-has="'company:account:detail'">收支明细</a>
           </span>

      </a-table>
    </div>
    <HlwCompanyAccountRechargeModal ref="rechargeModalForm" @ok="modalFormOk"></HlwCompanyAccountRechargeModal>
    <HlwCompanyAccountDetailsModal ref="paymentDetailsModalForm" @ok="modalFormOk"></HlwCompanyAccountDetailsModal>
    <HlwCompanyAccountWithdrawModal ref="withdrawModalForm" @ok="modalFormOk"></HlwCompanyAccountWithdrawModal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction, getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import HlwCompanyAccountRechargeModal from './HlwCompanyAccountRechargeModal'
  import HlwCompanyAccountDetailsModal from './HlwCompanyAccountDetailsModal'
  import HlwCompanyAccountWithdrawModal from './HlwCompanyAccountWithdrawModal'

  export default {
    name: 'HlgAccountModal',
    mixins: [JeecgListMixin],
    components: {
      JDate,
      HlwCompanyAccountRechargeModal,
      HlwCompanyAccountDetailsModal,
      HlwCompanyAccountWithdrawModal
    },
    data() {
      return {
        title: '',
        bodyStyle: {
          padding: '0px',
          height: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '76%',
          style: { top: '20px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        // 表头
        columns: [
          {
            title: '资金账户',
            align: 'left',
            dataIndex: 'subcontractorName'
          },
          {
            title: '账户余额',
            align: 'left',
            dataIndex: 'balance'
          },
          {
            title: '充值总额',
            align: 'left',
            dataIndex: 'totalDeposit'
          },
          {
            title: '付款总额',
            align: 'left',
            dataIndex: 'totalPayment'
          },
          {
            title: '支付服务费',
            align: 'left',
            dataIndex: 'totalServiceFee'
          },
          {
            title: '操作',
            align: 'left',
            scopedSlots: { customRender: 'action' }
          }
        ],
        loading: false,
        companyId: 0,
        url: {
          list: '/wisdom/hlwCompanyAccount/companyList',
          add: '/wisdom/hlwCompanyAccount/add',
          edit: '/wisdom/hlwCompanyAccount/edit'
        }

      }
    },
    created() {

    },
    methods: {
      resetData() {
        this.model = {};
      },
      edit(record) {

      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        this.companyId = this.$route.query.companyId;
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        this.resetData()
        this.loading = true
        this.model = Object.assign({}, this.$route.query);
        var params = this.getQueryParams()//查询条件
        params.companyId = this.companyId
        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.loading = false
        })
      },
      handleMoney(record) {
        this.$refs.rechargeModalForm.edit(record,this.model.companyName)
        this.$refs.rechargeModalForm.title = '充值'
        this.$refs.rechargeModalForm.disableSubmit = false
      },
      handleWithDrow(record){
        this.$refs.withdrawModalForm.edit(record,this.model.companyName)
        this.$refs.withdrawModalForm.title = '提现'
        this.$refs.withdrawModalForm.disableSubmit = false
      },
      handleDetail(record) {
        this.$refs.paymentDetailsModalForm.edit({ ...record, companyName: this.model.companyName })
        this.$refs.paymentDetailsModalForm.title =  this.model.companyName + ' ---- ' + record.subcontractorName
        this.$refs.paymentDetailsModalForm.disableSubmit = false
      }
    }
  }
</script>