<template>
  <div class="forecastName">
    <div class="m-core">
      <save-form
        :inline="true"
        @reset="onReSet"
        @submit="search"
        :model="searchForm"
        ref="searchForm"
      >
        <el-form-item>
          <el-input
            v-model.trim="searchForm.search"
            clearable
            @keyup.enter.native="search"
            placeholder="学生编号/姓名/手机号"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" native-type="seach">搜索</el-button>
          <!-- <el-button native-type="reset" type="primary">重置</el-button> -->
          <el-button @click="exporOrPreList" type="primary" v-permission="'studentRegistration/registerOrPreListExport'">导出</el-button>
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
          @sort-change="changePayTime"
        >
          <!--    :default-sort="{prop: 'perRegisterTime', order: 'payTime'}" -->
          <el-table-column align="center" prop="userId" label="学员编号">
            <template slot-scope="scope">
              <copy-text>{{ scope.row.userId }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="studentName"
            label="学员姓名"
          ></el-table-column>
          <el-table-column align="center" prop="actualSubjectName" label="声部">
          </el-table-column>
          <el-table-column
            align="center"
            prop="perRegisterTime"
            label="预报名时间"
            sortable="custom"
          >
            <template slot-scope="scope">
              <div>
                <p>{{ scope.row.perRegisterTime | formatTimer }}</p>
                <p>{{ scope.row.perRegisterTime | formatSecondTimer }}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" label="预报名时间差">
            <template slot-scope="scope">
              {{ formatterTimes(scope.row.perRegInterval) }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="缴费时间"
            sortable="custom"
            prop="payTime"
          >
            <template slot-scope="scope">
              <div>
                <p>{{ scope.row.payTime | formatTimer }}</p>
                <p>{{ scope.row.payTime | formatSecondTimer }}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="isRegistered"
            label="缴费时间差"
          >
            <template slot-scope="scope">
              {{ formatterTimes(scope.row.payInterval) }}
            </template>
          </el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="pageInfo.total"
          :page.sync="pageInfo.page"
          :limit.sync="pageInfo.limit"
          :page-sizes="pageInfo.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import pagination from "@/components/Pagination/index";
import { getRegisterOrPreList } from "../api";
import cleandeep from "clean-deep";
import moment from "moment";
import{Export}  from "@/utils/downLoadFile";

export default {
  name: "forecastName",
  components: { pagination },
  data() {
    const query = this.$route.query;
    return {
      musicGroupId: query.id,
      searchForm: {
        search: null,
        orderByPayTime: null,
        orderByPerRegister: null,
      },
      tableList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
    };
  },
  mounted() {
    this.searchForm.orderByPerRegister = null;
    this.searchForm.orderByPayTime = null;
    this.$store.dispatch("setSubjects");
    this.getList();
  },
  methods: {
    onReSet() {
      this.$refs["searchForm"].resetFields();
      this.search();
    },
    search() {
      this.pageInfo.page = 1;
      this.getList();
    },
    async getList() {
      try {
        const result = await getRegisterOrPreList({
          ...this.searchForm,
          musicGroupId: this.musicGroupId,
          page: this.pageInfo.page,
          rows: this.pageInfo.limit,
        });
        this.tableList = result.data.rows;
        this.pageInfo.total = result.data.total;
      } catch (error) {}
    },
    changePayTime(row) {
      // console.log(row);
      this.searchForm.orderByPerRegister = null;
      this.searchForm.orderByPayTime = null;
      let obj = {
        perRegisterTime: "orderByPerRegister",
        payTime: "orderByPayTime",
        ascending: "ASC",
        descending: "DESC",
      };
      this.searchForm[obj[row.prop]] = obj[row.order];
      this.search();
    },
    formatterTimes(second) {
      if (second < 60) {
        return second + "秒";
      } else if (60 < second && second < 3600) {
        return moment(second * 1000).format("mm分钟");
      } else if (3600 < second && second < 86400) {
        return moment(second * 1000).format("HH小时mm分钟");
      } else if (second > 86400) {
        return moment(second * 1000).format("DD天HH小时mm分钟");
      } else {
        return "--";
      }
    },
    exporOrPreList(){
       let params = this.searchForm;
      Export(
        this,
        {
          method: "get",
          url: "/api-web/studentRegistration/registerOrPreListExport",
          params:{...params, musicGroupId: this.musicGroupId,}
        },
        "是否导出时间数据统计？"
      );
    }
  },
};
</script>

<style lang="less" scoped>
</style>
