<template>
  <div>
    <div class="searchbar">
      <el-form :model="formInline" class="demo-form-inline" ref="formInline">
        <el-form-item>
          <span class="text">
            <i class="el-icon-search"></i>
            筛选搜索
          </span>
          <el-button type="primary" size="small">查询搜索</el-button>
          <el-button @click="resetForm('ruleForm')" size="small"
            >重置</el-button
          >
        </el-form-item>

        <el-form-item required>
          <el-col :span="10">
            <el-form-item
              label="藏品名称（套）："
              label-width="140px"
              prop="name"
            >
              <el-input
                v-model="formInline.name"
                placeholder="请输入藏品名称"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="创建时间：" label-width="160px" prop="date">
              <el-date-picker
                v-model="formInline.date"
                type="daterange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
                size="small"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-form-item>
      </el-form>
    </div>
    <div class="total">
      <i class="el-icon-tickets" style="margin-right: 5px"></i>套系列表
      共有<span style="color: #1890ff">{{ mockData.length }}</span
      >条数据
    </div>
    <div class="list">
      <el-radio-group v-model="tabPosition">
        <el-radio-button label="在售">在售</el-radio-button>
        <el-radio-button label="预售">预售</el-radio-button>
        <el-radio-button label="已过期">已过期</el-radio-button>
      </el-radio-group>
      <el-table
        :data="
          mockData.slice((currentPage - 1) * pageSize, pageSize * currentPage)
        "
        border
        style="width: 100%"
        :header-cell-style="{ background: '#ffffff', color: '#919398' }"
      >
        <el-table-column prop="id" label="ID" width="100px" align="center">
        </el-table-column>
        <el-table-column prop="name" label="藏品名称（套）" align="center">
        </el-table-column>
        <el-table-column prop="settime" label="创建时间" align="center">
        </el-table-column>
        <el-table-column prop="showtime" label="展示时间" align="center">
        </el-table-column>
        <el-table-column prop="amount" label="藏品数量" align="center">
        </el-table-column>
        <el-table-column prop="state" label="状态" align="center">
        </el-table-column>
        <el-table-column prop="operate" label="操作" align="center">
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        :current-page="currentPage"
        background
        layout="total,prev, pager, next"
        :total="mockData.length"
        style="margin-right: 10px"
        :page-size.sync="pageSize"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import { reqMockData } from "../../../mockjs/reqMock.js";
export default {
  mounted() {
    reqMockData().then((res) => {
      // console.log(1);
      // console.log(res);
      this.mockData = res.data;
    });
  },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      formInline: { name: "", date: "" },
      tabPosition: "在售",
      mockData: [],

      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  methods: {
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
  },
};
</script>
<style lang="scss" scoped>
.searchbar {
  border: 1px solid #ebebeb;
  margin: 20px 15px 20px 20px;
  padding: 20px;
  border-radius: 4px;

  .text {
    font-size: medium;
  }
  button {
    float: right;
    margin-left: 15px;
  }
}
.total {
  border: 1px solid #ebebeb;
  margin: 20px 15px 20px 20px;
  padding: 20px;
  border-radius: 4px;
}
.list {
  margin: 20px 10px 20px 20px;
}
.el-pagination {
  float: right;
}
</style>
<style>
label.el-form-item__label {
  font-weight: 500;
}
.list .el-radio-button__inner {
  border-bottom-left-radius: 0;
  border-bottom: none;
  font-weight: 600;
}
.el-radio-button:first-child .el-radio-button__inner {
  border-radius: 4px 0 0 0;
}
.el-radio-button:last-child .el-radio-button__inner {
  border-radius: 0 4px 0 0;
}
</style>

  .text {
    font-size: medium;
  }
  button {
    float: right;
    margin-left: 15px;
  }
}
.total {
  border: 1px solid #ebebeb;
  margin: 20px 15px 20px 20px;
  padding: 20px;
  border-radius: 4px;
}
.list {
  margin: 20px 10px 20px 20px;
}
.el-pagination {
  float: right;
}
</style>
<style>
label.el-form-item__label {
  font-weight: 500;
}
.list .el-radio-button__inner {
  border-bottom-left-radius: 0;
  border-bottom: none;
  font-weight: 600;
}
.el-radio-button:first-child .el-radio-button__inner {
  border-radius: 4px 0 0 0;
}
.el-radio-button:last-child .el-radio-button__inner {
  border-radius: 0 4px 0 0;
}
</style>