<template>
  <div class="record-warp">
    <div class="record-main">
      <el-row>
        <el-col :span="24">

          <div class="search-head">
            <el-input
                v-model="keyword"
                clearable
                placeholder="请输入游戏名称"
            ></el-input>&nbsp;&nbsp;
            <el-button type="primary" @click="searchTarget">搜索</el-button>
          </div>

        </el-col>
      </el-row>

      <div class="table-content">
        <el-table
          :data="tableData"
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '5px' }"
        >
          <el-table-column prop="name" label="游戏名称" align="center" width="">
          </el-table-column>

          <el-table-column label="操作" width="" align="center">
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="view(scope.$index, scope.row)"
                type="primary"
                size="small"
              >
                查看
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <el-pagination
        small
        background
        @current-change="handleCurrentChange"
        :current-page.sync="pageNum"
        layout="total, prev, pager, next"
        :page-size="pageSize"
        :total="total"
      >
      </el-pagination>
      <!-- <el-pagination small background layout="total prev, pager, next" :total="36">
      </el-pagination> -->
    </div>
  </div>
</template>

<script>
import { oSessionStorage } from "../../utils/utils";

export default {
  name: "gameRecord",
  components: {},
  data() {
    return {
      total: 0,
      pageSize: 10,
      pageNum: 1,
      keyword: "",
      tableData: [
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
      ],
      userInfo: {}, //用户信息
      userId: "", //用户id
    };
  },
  created() {},
  mounted() {
    this.searchTarget();
  },
  methods: {
    view(val, value) {
      //跳转页面
      sessionStorage.setItem("gameManageId", value.flag);
      this.$router.push({ path: "/manage/gameRecord/detail" });
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.searchList();
    },
    //根据现有情况进行搜索
    searchList() {
      this.$http.get(
        `game/findAll?pageNum=${this.pageNum}&pageSize=${this.pageSize}&name=${this.keyword}`,
        {},
        (res) => {
          // console.log(res,'用户测试记录')
          if (res && res.code == 200) {
            this.tableData = res.data.gameInfos;
            this.total = res.data.num;
          } else {
            // this.$toast.fail(res.msg);
            this.$message.error(res.msg);
          }
        }
      );
    },
    searchTarget() {
      this.pageNum = 1;
      this.searchList();
    },
    //跳转首页
    goHome() {
      this.$router.push({ path: "/home" });
    },
    //跳转记录页
    goRecord() {
      this.$router.push({ path: "/record" });
    },
    //退出登陆
    logout() {
      oSessionStorage.removeItem("userInfo");
      oSessionStorage.removeItem("token");
      this.$router.push({ path: "/" });
    },
    //点击日历获取日期
    getDate(param) {
      // console.log(param,"日期。。。")
      this.userRecord(param.dateStr);
    },
    //点击获取月出勤次数
    getTimes(param) {
      this.monthTimes = param;
    },
    // 用户测试记录显示
    userRecord(date) {
      this.$http.get(
        `gameRecord/findListByUserIdAndDate/${this.userId}/${date}`,
        {},
        (res) => {
          // console.log(res,'用户测试记录')
          if (res && res.code == 200) {
            this.listData = res.data;
          } else {
            this.$toast.fail(res.msg);
          }
        }
      );
    },
  },
};
</script>


<style lang="less" scoped>
@import "../../styles/theme.less";

.record-warp {
  width: 100%;
  height: 100%;
  //background: url(../../assets/img/index/19.png) no-repeat center;
  //background-size: 100% 100%;
  position: relative;

  .record-main {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
    .search-head {
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
    }
    .table-content {
      margin: 10px 0;
    }
  }
}
</style>
