<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">
        <!-- 查询区域 -->
        <a-row>
          <a-button type="primary" @click="topUpRefund" v-has="'account:uprefund'">充值退款</a-button>
        </a-row>
        <!-- 查询区域-END -->

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

        </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-button type="link" @click="changeDisplay(scope,index)">
                     <a-icon type="eye" v-show="scope.isDisplay"/>
                     <a-icon type="eye-invisible" :style="{color:'#8e8e8e'}" v-show="!scope.isDisplay"/>
                  </a-button>
                </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>
                  <!--开心可见-->
                  <template v-if="scope.companyId">
                    <a style="float: right;margin-right: 5px" v-if="scope.type === 0 && scope.isDrawback === 0" @click="editServiceFee(scope)">调整</a>
                  </template>
                </span>
          </a-table>
        </div>
      </a-card>
      <HlgAccountTopUpRefundModal ref="topUpRefundModalForm" @ok="modalFormOk"></HlgAccountTopUpRefundModal>
      <HlgAccountEditServiceFeeModal ref="editServiceFeeModal" @ok="modalFormOk"></HlgAccountEditServiceFeeModal>
    </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 HlgAccountTopUpRefundModal from './HlgAccountTopUpRefundListModal'
  import HlgAccountEditServiceFeeModal from './HlgAccountEditServiceFeeModal'

  export default {
    name: 'HlgAccountPaymentDetailsModal',
    mixins: [JeecgListMixin, Arithmetic],
    components: {
      JDate,
      HlgAccountTopUpRefundModal,
      HlgAccountEditServiceFeeModal
    },
    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: '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: '/hlgaccount/hlgAccountDetail/list',
          edit: '/hlgaccount/hlgAccountDetail/edit',
        }

      }
    },
    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
        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);
      },
      //调整服务费
      editServiceFee(scope){
        this.$refs.editServiceFeeModal.edit(scope)
        this.$refs.editServiceFeeModal.title = '调整服务费'
        this.$refs.editServiceFeeModal.disableSubmit = false
      }

    }
  }
</script>