<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      团练宝激活记录
    </h2>
    <div class="m-core">
      <save-form
        :inline="true"
        class="searchForm"
        ref="searchForm"
        @submit="search"
        @reset="reset"
        :saveKey="'tenantTradeManager'"
        :model.sync="searchForm"
      >
        <el-form-item prop="queryCondition">
          <el-input
            placeholder="学员编号/姓名/手机号"
            clearable
            type="text"
            v-model.trim="searchForm.queryCondition"
          ></el-input>
        </el-form-item>
        <el-form-item prop="orderNo">
          <el-input
            placeholder="订单号"
            clearable
            type="text"
            v-model.trim="searchForm.orderNo"
          ></el-input>
        </el-form-item>
        <el-form-item prop="createTimer">
          <el-date-picker
            v-model.trim="searchForm.createTimer"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="订单开始时间"
            end-placeholder="订单结束时间"
            :picker-options="{ firstDayOfWeek: 1 }"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="danger">搜索</el-button>
          <el-button native-type="reset" type="primary">重置</el-button>
        </el-form-item>
      </save-form>
      <!-- 列表 -->
      <div class="tableWrap">
        <el-table
          :data="tableList"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        >
          <el-table-column align="center" label="交易流水号" prop="transNo">
          </el-table-column>
          <el-table-column align="center" label="订单号" prop="orderNo">
          </el-table-column>
          <el-table-column align="center" label="订单时间" prop="orderTime">
          </el-table-column>
          <el-table-column align="center" label="学员编号" prop="studentId">
          </el-table-column>
          <el-table-column align="center" label="学员名称" prop="name">
          </el-table-column>
          <el-table-column align="center" label="手机号码" prop="phone">
          </el-table-column>
          <!-- <el-table-column align="center" label="交易类型">
            <template slot-scope="scope">
              {{ scope.row.type | tenantStatus }}
            </template>
          </el-table-column> -->
          <el-table-column align="center" label="团练宝类型">
            <template slot-scope="scope">
              {{ scope.row.type | memberEnumType }}
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" label="网络教室剩余时长" prop="productName">
          </el-table-column> -->
          <el-table-column align="center" label="数量">
            <template slot-scope="scope">
              {{ scope.row.time }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="激活费用(元)">
            <template slot-scope="scope">
              {{ scope.row.amount | moneyFormat }}
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :saveKey="'tenantTradeManager'"
          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 { queryActiveRecord } from "./api";
import { dealStatus } from "@/utils/searchArray";
import { getTimes } from "@/utils";
const initSearch = {
  queryCondition: null,
  orderNo: null,
  createTimer: [],
};
export default {
  components: { pagination },
  data() {
    return {
      dealStatus,
      tableList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      searchForm: { ...initSearch }
    };
  },
  async mounted() {
    this.getList();
  },
  methods: {
    async getList() {
      try {
        let { createTimer, ...reset } = this.searchForm;
        const res = await queryActiveRecord({
          ...reset,
          ...getTimes(createTimer, ["startDate", "endDate"], "YYYY-MM-DD"),
          page: this.pageInfo.page,
          rows: this.pageInfo.limit
        });
        console.log(res)
        this.pageInfo.total = res.data.total;
        this.tableList = res.data.rows;
      } catch (e) {}
    },
    search() {
      this.pageInfo.page = 1;
      this.$refs.searchForm.save(this.searchForm);
      this.$refs.searchForm.save(this.pageInfo, "page");
      this.getList();
    },
    reset() {
      this.searchForm = { ...initSearch };
      this.search();
    },
    openService(row) {
      this.orderVisible = true
    },
  },
  filters: {
    tenantOrderStatus(val) {
      const template = {
        0: "待支付",
        1: "已支付",
        2: "支付失败"
      }
      return template[val]
    }
  }
};
</script>
<style lang="scss" scoped>
.courseMask .el-dialog__body {
  padding-bottom: 0;
}
</style>
