<!--  -->
<template>
  <div class="m-container">
    <el-page-header @back="onCancel" :content="title"></el-page-header>
    <div class="m-core">
      <save-form
        :inline="true"
        :model="searchForm"
        @submit="search"
        @reset="onReSet"
      >
        <el-form-item prop="search">
          <el-input v-model="searchForm.search" placeholder="学员编号/姓名/订单号" clearable> </el-input>
        </el-form-item>

        <!-- <el-form-item prop="organId">
          <el-select
            class="multiple"
            style="width: 180px !important"
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="(item, index) in selects.branchs"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item prop="type" v-if="!$route.query.year">
          <el-select
            v-model.trim="searchForm.type"
            filterable
            clearable
            placeholder="购买课程"
          >
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="type" v-else>
          <el-select
            v-model.trim="searchForm.type"
            filterable
            clearable
            placeholder="购买课程"
          >
            <el-option
              v-for="item in typeListBase"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="giveMemberFlag" v-if="!$route.query.year">
          <el-select
            class="multiple"
            style="width: 180px !important"
            v-model.trim="searchForm.giveMemberFlag"
            filterable
            clearable
            placeholder="是否赠送会员"
          >
            <el-option label="是" value="true"></el-option>
            <el-option label="否" value="false"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="getTime">
          <el-date-picker
            style="width: 100%"
            v-model="searchForm.getTime"
            :picker-options="{ firstDayOfWeek: 1 }"
            type="datetimerange"
            :default-time="['00:00:00', '23:59:59']"
            range-separator="-"
            start-placeholder="交易开始日期"
            end-placeholder="交易结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="primary">搜索</el-button>
          <el-button native-type="reset" type="danger">重置</el-button>
          <auth auths="export/doubleEleven2021OrderDetail"></auth>
          <!-- <el-button type="primary" @click="onExport">导出</el-button> -->
        </el-form-item>
      </save-form>
      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="studentId"
            label="学生姓名(编号)"
          >
            <template slot-scope="scope">
              <div>{{ scope.row.username }}({{ scope.row.userId }})</div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderNo"
            label="订单号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="payTime"
            label="交易时间"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="type"
            label="购买课程"
          ></el-table-column>
          <el-table-column
          v-if="!$route.query.year"
            align="center"
            prop="giveMember"
            label="是否赠送会员"
          >
          <template slot-scope="scope">
            <div>
              {{scope.row.giveMember?'是':'否'}}
            </div>
          </template></el-table-column>
        </el-table>
        <pagination
          sync
          :total.sync="rules.total"
          :page.sync="rules.page"
          :limit.sync="rules.limit"
          :page-sizes="rules.page_size"
          @pagination="getList"
        />
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import { getToken } from "@/utils/auth";
import pagination from "@/components/Pagination/index";
import load from "@/utils/loading";
import {courseViewTypeList } from "@/utils/searchArray";
import { getDoubleElevenDetail,  } from "./api";
import { Export } from "@/utils/downLoadFile";

import { getTimes } from "@/utils";
import cleanDeep from "clean-deep";
import qs from "qs";
const typeListBase = [
{ value: 1, label: "1v1 20节" },
  { value: 2, label: "1v1 40节" },
  { value: 3, label: "1v2 20节" },
  { value: 4, label: "1v2 40节" },
];
const typeList = [
  ...typeListBase,
  { value: 5, label: "乐理课" },
];
export default {
  components: { pagination },
  data() {
    return {
      searchForm: {
        search: null,
        getTime: [],
        giveMemberFlag: null,
        type: null,
      },
      courseViewTypeList,
      tableList: [],
      organList: [],
      typeListBase,
      typeList: typeList,
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      organId: "",
      title: "",
      gradeList: {},
    };
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  async mounted() {
    this.organId = this.$route.query.organId;
    if (this.$route.query.organName) {
      this.title = `${this.$route.query.organName}双十一活动详情`;
    } else {
      this.title = `分部会员活动详情`;
    }
    // await this.$store.dispatch("setBranchs");
    await this.$store.dispatch("setSubjects");

    this.init();
  },
  methods: {
    init() {
      this.getList();
    },
    async getList() {
      let { getTime, ...rest } = this.searchForm;
      let params = {
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(getTime, ["startTime", "endTime"],'YYYY-MM-DD HH:mm:ss'),
      };
      try {
        const res = await getDoubleElevenDetail({
          organId: this.organId,
          ...params,
          year: this.$route.query.year,
          page: this.rules.page,
          rows: this.rules.limit,
        });
        this.tableList = res.data.rows;
        this.rules.total = res.data.total;
      } catch (e) {
        console.log(e);
      }
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.$nextTick(() => {
        this.search();
      });
    },
    onCancel() {
      this.$store.dispatch("delVisitedViews", this.$route);
      this.$router.push({
        path: "/2021double11List",
        query: {
          year: this.$route.query.year
        }
      });
    },
    async onExport() {
        let { getTime, ...rest } = this.searchForm;
      let params = {
        ...rest,
        page: this.rules.page,
        rows: this.rules.limit,
        ...getTimes(getTime, ["startTime", "endTime"]),
      };
      let obj = {
        organId: this.organId,
        ...params,
      };
      await Export(
        this,
        {
          url: "/api-web/export/doubleEleven2021OrderDetail",
          fileName: this.$route.query.year === "" ? "2022双十一活动.xls" : "2021双十一活动.xls",
          method: "post",
          params: qs.stringify(cleanDeep(obj)),
        },
        "您确定导出双十一活动详情列表?"
      );
    },
  },
};
</script>
<style lang='scss' scoped>
</style>
