<template>
  <div class="app-container withdrawalApp-table" :style="{'--q-height':qHeight}">
    <div class="app-container-query" ref="queryFormBox">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <el-form-item label="团队名称" prop="teamName">
          <el-input
            v-model="queryParams.teamName"
            placeholder="请输入团队名称"
            clearable
            style="width: 220px;"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="日期">
          <el-date-picker
            style="width: 240px"
            v-model="dateRange"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    
    <div class="app-container-table-box">
      <div class="app-container-table-info">
        <el-table ref="tables" v-loading="loading" height="100%" :data="dataList" border>
          <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
          <el-table-column label="团队名称" align="center" prop="teamName"  width="100" />
          <el-table-column label="银企直连交易金额" align="center" prop="transAmt" />
          <el-table-column label="订单笔数" align="center" prop="orderNum" width="120" />
          <el-table-column label="下单人数" align="center" prop="touristNum" width="150" />
          <el-table-column label="订单交易总额" align="center" prop="realTotalPrice" />
          <el-table-column label="核销金额" align="center" prop="usedPrice" />
          <el-table-column label="退款人数" align="center" prop="refundNum" />
          <el-table-column label="退款金额" align="center" prop="refundPrice" />
          <el-table-column label="储值额度" align="center" prop="regTotalAmount	" />
          <el-table-column label="储值余额" align="center" prop="balance" />
          <el-table-column label="授信额度" align="center" prop="grantQuota" />
          <el-table-column label="授信余额" align="center" prop="grantSurplus" />
          <el-table-column label="操作" align="center" width="100" fixed="right" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="viewOrderInfo(scope.row)"
              >订单详情</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>

    <!--  修改凭证  -->
    <!-- <imgAduit ref="imgAduit" @getList="getList" /> -->
     <!-- 订单详情 -->
    <orderInfo ref="orderInfo" @getList="getList" />


  </div>
</template>

<script>

import { 
  pageList
} from '@/api/financeMr/reconciliation'
import orderInfo from "./dialog/orderInfo.vue";
import moment from "moment"
// import html2canvas from 'html2canvas'

export default {
  name: "Reconciliation",
  dicts: ['distribution_type'],
  components: { orderInfo },
  data() {
    return {
      qHeight: '0px',
      resizeObserver: null,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teamName: ""
      },
    };
  },
  created() {
    this.setDateRange();
    this.getList();
  },
  mounted() {
    this.resizeObserver = new ResizeObserver(entries => {
      for (let entry of entries) {
        const { width, height } = entry.contentRect;
        this.qHeight = height + 'px'
      }
    });
    this.resizeObserver.observe(this.$refs.queryFormBox);
  },
  methods: {
    // 日期处理
    setDateRange() {
      const today = moment();
      const firstDayOfMonth = moment().startOf('month');
      this.dateRange = [
        firstDayOfMonth.format("YYYY-MM-DD"),
        today.format("YYYY-MM-DD")
      ];
    },
    /** 查询列表 */
    getList() {
      this.dataList = []
      this.loading = true;
       if(this.dateRange && this.dateRange.length > 0){
         this.queryParams.startDate = this.dateRange[0];
         this.queryParams.endDate = this.dateRange[1];
       } else {
         if(this.queryParams.startDate) {
           delete this.queryParams.startDate
           delete this.queryParams.endDate
         }
       }
      pageList(this.queryParams)
      .then(response => {
          let list = response.data.rows
          list.forEach(item =>{
            item.switchValue = item.status;
          })
          this.dataList = list
          this.total = response.data.total;
          this.loading = false;
        }
      ).catch(()=>{
        this.dataList = []
        this.loading = false;
      })
    },
    // 订单详情
    viewOrderInfo(row) {
      this.$refs["orderInfo"].openDialog("订单详情", row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'teamName', '');

      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    
  },
  beforeDestroy() {
    this.resizeObserver.unobserve(this.$refs.queryFormBox);
    this.resizeObserver.disconnect();
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  height: calc( 100vh - 110px );
  box-sizing: border-box;
}
.app-container-table-box {
  height: calc( 100% - var(--q-height) );
  .app-container-table-info {
    height: calc( 100% - 100px );
  }
}
</style>