<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">
        <!-- 查询区域 -->
        <!--<div class="table-page-search-wrapper">-->
          <!--<a-form layout="inline" @keyup.enter.native="searchQuery">-->
            <!--<a-row :gutter="24">-->
              <!--<a-col :md="8" :sm="8">-->
                <!--<a-form-item label="注册时间">-->
                  <!--<a-range-picker-->
                    <!--style="width: 100%"-->
                    <!--v-model="queryParam.generateTimeRange"-->
                    <!--format="YYYY-MM-DD"-->
                    <!--:placeholder="['开始时间', '结束时间']"-->
                    <!--@change="onDateChange"-->
                    <!--@ok="onDateOk"-->
                    <!--:allowClear="allowClear"-->
                  <!--/>-->
                <!--</a-form-item>-->
              <!--</a-col>-->
            <!--</a-row>-->
          <!--</a-form>-->
        <!--</div>-->
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button type="primary" @click="topUpRefund" v-has="'account:uprefund'">充值退款</a-button>
          <!--<a-button type="primary" icon="download" @click="handleExportXls('收支记录')" v-has="'account:export'">导出</a-button>-->
        </div>

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

          <a-table
            ref="table"
            size="middle"
            bordered
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            @change="handleTableChange">
                <span slot="type" slot-scope="text,scope,index">
                  {{text}}
                   <a-icon type="eye" :style="{color:'#1890FF',float:'right'}" v-show="scope.isDisplay" @click="changeDisplay(scope,index)" v-has="'account:display'"/>
                   <a-icon type="eye-invisible" :style="{color:'#8e8e8e',float:'right'}" v-show="!scope.isDisplay" @click="changeDisplay(scope,index)" v-has="'account:display'"/>
                </span>
                <span slot="serviceFee" slot-scope="text,scope,index">
                  <template v-if="scope.isDrawback === 1">
                    {{text?text+'(已退款)':text===0?text+'(已退款)':'--'}}
                  </template>
                  <template v-else>
                    {{text?text:text===0?text:'--'}}
                  </template>
                </span>
          </a-table>
        </div>
      </a-card>
      <HwAccountTopUpRefundListModal ref="topUpRefundModalForm" @ok="modalFormOk"></HwAccountTopUpRefundListModal>
    </a-spin>
  </a-modal>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { Arithmetic } from '@/mixins/Arithmetic'
  import { httpAction, getAction, putAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import HwAccountTopUpRefundListModal from './HwAccountTopUpRefundListModal'

  export default {
    name: 'HlgAccountPaymentDetailsModal',
    mixins: [JeecgListMixin, Arithmetic],
    components: {
      JDate,
      HwAccountTopUpRefundListModal
    },
    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,
        allowClear: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: 'type_dictText',
            scopedSlots: { customRender: 'type' }
          },
          {
            title: '金额',
            align: 'left',
            dataIndex: 'amount',
            customRender: (value,record) => {
              if(record.isDrawback === 1){
                return value ? value +'(已退款)': value === 0 ? value+'(已退款)':'--'
              }
              return value ? value:value === 0 ? value:'--'
            }
          },
          {
            title: '服务费',
            align: 'left',
            dataIndex: 'serviceFee',
            scopedSlots: { customRender: 'serviceFee' },

          },
          {
            title: '备注',
            align: 'left',
            dataIndex: 'remark'
          },
          {
            title: '操作人',
            align: 'left',
            dataIndex: 'generateBy',
            scopedSlots: { customRender: 'action' }
          }
        ],
        confirmLoading: false,
        companyName: '',
        companyId: 0,
        url: {
          list: '/saasmanager/hwPlatformCompanyAccountDetail/companyList',
          edit: '/saasmanager/hwPlatformCompanyAccountDetail/edit',
        }

      }
    },
    created() {
    },
    methods: {
      resetData() {
        this.model = {};
      },
      add() {
        this.edit({})
      },
      edit(record) {
        this.resetData();
        this.model = Object.assign({}, record)
        this.visible = true
        this.companyName = record.companyName
        this.platformCompanyAccountId = 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.platformCompanyAccountId = this.platformCompanyAccountId
        this.loading = true
        getAction(this.url.list, params).then((res) => {
          console.log(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()
      },
      //可见/不可见
      changeDisplay(scope, index) {
        this.loading = true
        const isDisplay = Number(!Number(scope.isDisplay))
        let url = ''
        url = this.url.edit
        putAction(url, { id: scope.id, isDisplay }).then(data => {
          if (data.success) {
            this.$set(this.dataSource[index], 'isDisplay', isDisplay)
          }
          if (data.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },
      topUpRefund() {
        this.$refs.topUpRefundModalForm.edit(this.model)
        this.$refs.topUpRefundModalForm.title = '充值退款'
        this.$refs.topUpRefundModalForm.disableSubmit = false
      },
      modalFormOk(){
        this.$emit('ok')
        this.loadData(1);
      },
    }
  }
</script>