<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" style="height: 100%;">
        <a-row :gutter="24">
          <a-col :md="8" :sm="8">
            <a-form-item label="">
              <span style="font-size: 18px;">{{cpCompanyName}}</span>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8" >
            <a-form-item label="账目余额">
              <span style="font-size: 18px;">{{balanceMoney}}元</span>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8" >
            <a-form-item label="服务费余额">
              <span style="font-size: 18px;">{{serviceBalanceMoney}}元</span>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="9" :sm="12">
            <a-form-item label="业务时间">
              <a-range-picker
                style="width: 100%"
                v-model="queryParam.createTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onDateChange"
                @ok="onDateOk"
                :allowClear="allowClear"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <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>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">-->
                <!--{{ toggleSearchStatus ? '收起' : '展开' }}-->
                <!--<a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--</a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
      <a-row :gutter="24">
        <a-col :md="6" :sm="6">
          <div style="display: flex;flex-direction: column"><i class="anticon anticon-info-circle ant-alert-icon"></i> 收入合计 <a style="font-weight: 600">{{rechargeMoney}}元</a></div>
        </a-col>
        <a-col :md="6" :sm="6">
          <div style="display: flex;flex-direction: column;"><i class="anticon anticon-info-circle ant-alert-icon"></i> 支出合计 <a style="font-weight: 600">{{paymentMoney}}元</a></div>
        </a-col>
        <a-col :md="6" :sm="6">
          <div style="display: flex;flex-direction: column;"><i class="anticon anticon-info-circle ant-alert-icon"></i> 服务费收入合计 <a style="font-weight: 600">{{serviceMoney}}元</a></div>
        </a-col>
        <a-col :md="6" :sm="6">
          <div style="display: flex;flex-direction: column;"><i class="anticon anticon-info-circle ant-alert-icon"></i> 服务费支出合计 <a style="font-weight: 600">{{paymentServiceMoney}}元</a></div>
        </a-col>
      </a-row>

    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('平台账目统计')" v-has="'cpaccountDetail:export'">导出</a-button>
    </div>

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

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


      </a-table>
    </div>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { Arithmetic } from '@/mixins/Arithmetic'
  import JDate from '@/components/jeecg/JDate.vue'
  import { filterObj } from '@/utils/util';
  import { getAction } from '@/api/manage'

  export default {
    name: "HlgCpAccountDetailList",
    mixins:[JeecgListMixin,Arithmetic],
    components: {
      JDate
    },
    data () {
      return {
        description: 'hlg_cp_account_detail管理页面',
        // 查询条件
        queryParam: {
          createTimeRange:[],
        },
        // 表头
        columns: [
          {
            title:'企业名称',
            align:"left",
            width: 200,
            dataIndex: 'companyName'
          },
          {
            title:'平台',
            align:"left",
            width: 200,
            dataIndex: 'platformName'
          },
          {
            title:'收支方向',
            align:"left",
            width: 150,
            dataIndex: 'type_dictText'
          },
          {
            title:'金额',
            align:"left",
            width: 150,
            dataIndex: 'amount',
            customRender: (value,record) => {
              if(record.isDrawback === 1){
                return value ? value +'(已退款)': value === 0 ? value+'(已退款)':'--'
              }
              return value ? value:value === 0 ? value:'--'
            }
          },
          {
            title:'服务费',
            align:"left",
            width: 150,
            dataIndex: 'serviceFee',
            customRender: (value,record) => {
              if(record.isDrawback === 1){
                return value ? value +'(已退款)': value === 0 ? value+'(已退款)':'--'
              }
              return value ? value:value === 0 ? value:'--'
            }
          },
          {
            title:'支出服务费',
            align:"left",
            width: 150,
            dataIndex: 'paymentServiceFee',
            customRender: (value,record) => {
              if(record.isDrawback === 1){
                return value ? value +'(已退款)': value === 0 ? value+'(已退款)':'--'
              }
              return value ? value:value === 0 ? value:'--'
            }
          },
          {
            title:'备注',
            align:"left",
            dataIndex: 'remark',
            width: 500
          },
          {
            title:'业务时间',
            align:"left",
            width: 200,
            dataIndex: 'generateTime'
          },
          {
            title: '操作人',
            align: 'left',
            width: 150,
            dataIndex: 'generateBy',
          }
        ],
        url: {
          list: "/hlgcpmanager/hlgCpAccountDetail/allList",
          delete: "/hlgcpmanager/hlgCpAccountDetail/delete",
          deleteBatch: "/hlgcpmanager/hlgCpAccountDetail/deleteBatch",
          exportXlsUrl: "/hlgcpmanager/hlgCpAccountDetail/exportXls",
          importExcelUrl: "hlgcpmanager/hlgCpAccountDetail/importExcel",
          cpAccount: '/hlgcpmanager/hlgCpAccountDetail/cpAccount'
        },
        allowClear:false,
        rechargeMoney: '0.00',
        paymentMoney: '0.00',
        serviceMoney: '0.00',
        paymentServiceMoney: '0.00',
        cpCompanyName: '江苏开心工作科技有限公司',
        balanceMoney: '0.00',
        serviceBalanceMoney: '0.00',
        dictOptions:{
        }
      }
    },
    created() {
      //获取平台服务商数据
      this.loadCpAccount();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      loadCpAccount(){
        getAction(this.url.cpAccount, {}).then((res) => {
          if (res.success) {
            this.cpCompanyName = res.result.cpCompanyName;
            this.balanceMoney = this.returnFloat(res.result.balanceMoney) || '0.00';
            this.serviceBalanceMoney = this.returnFloat(res.result.serviceFeeBalanceMoney) || '0.00';
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }

        })
      },
      getQueryParams(){
        console.log(this.queryParam.createTimeRange)
        var param = Object.assign({}, this.queryParam,this.isorter);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        delete param.createTimeRange; // 时间参数不传递后台
        return filterObj(param);
      },

      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        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.result.records.length >0){
              this.rechargeMoney = this.returnFloat(res.result.records[0].rechargeMoney) || '0.00'
              this.paymentMoney = this.returnFloat(res.result.records[0].paymentMoney) || '0.00'
              this.serviceMoney = this.returnFloat(res.result.records[0].serviceMoney) || '0.00'
              this.paymentServiceMoney = this.returnFloat(res.result.records[0].paymentServiceMoney) || '0.00'
            } else {
              this.rechargeMoney = '0.00'
              this.paymentMoney = '0.00'
              this.serviceMoney = '0.00'
              this.paymentServiceMoney = '0.00'
            }
          }
          if(res.code===510){
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },

      onDateChange: function (value, dateString) {
        console.log(dateString[0],dateString[1]);
        this.queryParam.createTime_begin=dateString[0]+" 00:00:00";
        this.queryParam.createTime_end=dateString[1] +" 23:59:59";
      },
      onDateOk(value) {
        console.log(value);
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>