<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="时间" prop="countDate">
        <el-date-picker clearable
                        v-model="queryParams.countDate"
                        type="date"
                        @keyup.enter.native="handleQuery"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="通道" prop="appid">
        <el-input
            v-model="queryParams.appid"
            placeholder="请输入最低次数"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </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>

    <el-table v-loading="loading" :data="ipRecordList" @selection-change="handleSelectionChange">
      <el-table-column label="时间" align="center" prop="countDate" />
      <el-table-column label="通道" align="center" prop="appid" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="次数" align="center" prop="totalNum" />
    </el-table>

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

<script>
import {totalPageRechargeOrder} from "@/api/cai/rechargeOrder";

export default {
  name: "OrderTotal",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // ip访问记录表格数据
      ipRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 30,
        countDate: this.getCurrentDateFormatted(),
        appid: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getCurrentDateFormatted() {
      const nowDate = new Date();
      const year = nowDate.getFullYear();
      // 月份和日期需要补零处理
      const month = String(nowDate.getMonth() + 1).padStart(2, '0');
      const day = String(nowDate.getDate()).padStart(2, '0');
      return `${year}-${month}-${day}`;
    },
    /** 查询ip访问记录列表 */
    getList() {
      this.loading = true;
      totalPageRechargeOrder(this.queryParams).then(response => {
        this.ipRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
