<template>
  <a-modal
    :title="title"
    :width="modelStyle.width"
    :visible="visible"
    :bodyStyle="bodyStyle"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-card :bordered="false">
        <!-- 查询区域 -->

        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">

        </div>

        <!-- table区域-begin -->
        <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 ,index">
              <template v-if="record.isDrawback === 0 && !model.cpSettingId">
                <a @click="handleMoney(record,index)" v-has="'account:refund'">退款</a>
              </template>
              <template v-else>
                --
              </template>
            </span>
          </a-table>
        </div>
      </a-card>
      <HlgAccountRefundModal ref="refundModalForm" @ok="changeItem"></HlgAccountRefundModal>
    </a-spin>
  </a-modal>
</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 HlgAccountRefundModal from './HlgAccountRefundModal'

  export default {
    name: 'HlgAccountTopUpRefundModal',
    mixins: [JeecgListMixin],
    components: {
      JDate,
      HlgAccountRefundModal
    },
    data() {
      return {
        title: '',
        bodyStyle: {
          padding: '0',
          height: (window.innerHeight * 0.62) + 'px',
          'overflow-y': 'auto'
        },
        modelStyle: {
          width: '76%',
          style: { top: '10px' },
          fullScreen: false
        },
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        // 表头
        columns: [
          {
            title: '充值时间',
            align: 'left',
            dataIndex: 'generateTime'
          },
          {
            title: '充值金额',
            align: 'left',
            dataIndex: 'totalAmount'
          },
          {
            title: '服务费比例',
            align: 'left',
            dataIndex: 'serviceRate',
            customRender: (value,record) => {
              if(record.isEditServiceFee === 1){
                return '--'
              }
              return value + '%'
            }
          },
          {
            title: '服务费',
            align: 'left',
            dataIndex: 'serviceFee',
            customRender: (value) => {
              return value ? value:value === 0 ? value:'--'
            }
          },
          {
            title: '到账金额',
            align: 'left',
            dataIndex: 'amount'
          },
          {
            title: '状态',
            align: 'left',
            dataIndex: 'isDrawback',
            customRender: (value) => {
              if(value === 1){
                return '已退款'
              }
              return '充值成功';
            }
          },
          {
            title: '操作',
            align: 'left',
            scopedSlots: { customRender: 'action' }
          }
        ],
        confirmLoading: false,
        dataSource: [],
        companyName: '',
        companyId: 0,
        accountId: 0,
        url: {
          list: '/hlgaccount/hlgAccountDetail/refundList'
        }

      }
    },
    created() {
    },
    methods: {
      resetData() {
        this.model = {};
      },
      add() {
        this.edit({})
      },
      edit(record) {
        this.resetData();
        this.model = Object.assign({}, record)
        this.companyId = record.companyId
        this.visible = true
        this.companyName = record.companyName
        this.accountId = record.id
        this.loadData(1)
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1
        }
        var params = this.getQueryParams()//查询条件
        params.accountId = this.accountId
        params.type = 0
        this.loading = true
        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
        })
      },
      close() {
        this.visible = false
      },
      handleOk() {
        this.close()
      },
      handleCancel() {
        this.close()
      },
      changeItem() {
        this.$emit('ok')
        this.loadData()
      },
      handleMoney(record, index) {
        this.$refs.refundModalForm.edit(record)
        this.$refs.refundModalForm.changeIndex = index
        this.$refs.refundModalForm.title = '退款'
        this.$refs.refundModalForm.disableSubmit = false
      },

    }
  }
</script>
