<template>
  <div>
    <div class="gva-search-box">
      <div class="gva-btn-list">
        <el-form ref="searchForm" :inline="true" :model="searchInfo">
          <el-form-item label="平台">
            <el-select v-model="searchInfo.name" size="small">
              <el-option label="浪潮" value="浪潮" />
              <el-option label="海马" value="海马" />
            </el-select>
          </el-form-item>
          <el-form-item label="日期" prop="new_date">
            <el-date-picker
              v-model="searchInfo.new_date"
              popper-class="picker-popovers"
              class="timefilter"
              type="date"
              :disabled-date="disabledDate"
              :shortcuts="shortcuts"
              placeholder="选择日期时间"
              value-format="YYYY-MM-DD"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              size="small"
              type="primary"
              icon="search"
              @click="onSubmit"
              >查询</el-button
            >
            <el-button size="small" icon="refresh" @click="onReset"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="gva-table-box">
      <!-- <el-scrollbar height="550px"> -->
      <el-table
        height="500px"
        :data="tableData"
        @sort-change="sortChange"
        @selection-change="handleSelectionChange"
        border
      >
        <el-table-column type="selection" width="55" />
        <el-table-column
          align="left"
          label="日期"
          min-width="100"
          prop="new_date"
        />
        <el-table-column
          align="left"
          label="更新时间"
          min-width="150"
          prop="update_time"
        />
        <el-table-column
          align="left"
          label="平台名"
          min-width="100"
          prop="name"
        />
        <el-table-column
          align="left"
          label="平台余额"
          min-width="100"
          prop="balance"
        />
      </el-table>
      <!-- </el-scrollbar> -->
      <div class="gva-pagination">
        <el-pagination
          :current-page="page"
          :page-size="pageSize"
          :page-sizes="[10, 20, 30, 50, 100]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "wechat_scanner_api",
};
</script>

<script setup>
import { getWeChatScannerApiList } from "@/api/data_abnormal_rate";
import { toSQLLine } from "@/utils/stringFun";
import { ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { formatDate } from "@/utils/format";

const page = ref(1);
const total = ref(0);
const pageSize = ref(20);
const tableData = ref([]);
let spanArr = [];
const searchInfo = ref({});
const shortcuts = [
  {
    text: "今日",
    value: new Date(),
  },
  {
    text: "昨日",
    value: () => {
      const date = new Date();
      date.setTime(date.getTime() - 3600 * 1000 * 24);
      return date;
    },
  },
];

const disabledDate = (time) => {
  return time.getTime() > Date.now();
};


// 分页
const handleSizeChange = (val) => {
  pageSize.value = val;
  getTableData();
};
const onReset = () => {
  searchInfo.value = {};
};
const handleCurrentChange = (val) => {
  page.value = val;
  getTableData();
};

// 排序
const sortChange = ({ prop, order }) => {
  if (prop) {
    if (prop === "id") {
      prop = "id";
    }
    searchInfo.value.orderKey = toSQLLine(prop);
    searchInfo.value.desc = order === "descending";
  }
  getTableData();
};

// 搜索
const onSubmit = () => {
  page.value = 1;
  pageSize.value = 10;

  // if (typeof searchInfo.value.name != "undefined") {
  //   searchInfo.value.name = Number(searchInfo.value.name);
  // }
  // searchInfo.value.new_date = String(searchInfo.value.new_date);

  getTableData();
};

// 查询
const getTableData = async () => {
  const table = await getWeChatScannerApiList({
    page: page.value,
    pageSize: pageSize.value,
    ...searchInfo.value,
  });
  if (table.code === 0) {
    tableData.value = table.data.list;
    total.value = table.data.total;
    page.value = table.data.page;
    pageSize.value = table.data.pageSize;
  }
};
getTableData();
</script>

<style scoped lang="scss">
.button-box {
  padding: 10px 20px;
  .el-button {
    float: right;
  }
}
.warning {
  color: #dc143c;
}
</style>
