<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      团练宝缴费记录
    </h2>
    <div class="m-core">
      <el-form :inline="true" :model="searchForm">
        <el-form-item prop="period">
          <el-select
            placeholder="团练宝单位"
            clearable
            v-model.trim="searchForm.period"
            style="width: 100% !important"
          >
            <el-option label="月度" value="MONTH"></el-option>
            <el-option label="季度" value="QUARTERLY"></el-option>
            <el-option label="半年" value="YEAR_HALF"></el-option>
            <el-option label="年度" value="YEAR"></el-option>
            <!-- <el-option label="固定天数" value="DAY"></el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item prop="visitTime">
            <el-date-picker
              v-model.trim="searchForm.visitTime"
              style="width: 410px"
              type="daterange"
              :picker-options="{
                firstDayOfWeek: 1,
              }"
              :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 @click="search" type="danger">搜索</el-button>
          <el-button @click="onReSet" type="primary">重置</el-button>
        </el-form-item>
      </el-form>

      <div class="tableWrap">
        <el-table
          style="width: 100%"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
          :data="tableList"
        >
          <el-table-column
            align="center"
            prop="id"
            label="续费编号"
          ></el-table-column>
          <el-table-column align="center" prop="name" label="团练宝单位">
            <template slot-scope="scope">
              {{ scope.row.period | memberEnumType }}
            </template>
          </el-table-column>
          <el-table-column align="center" prop="memberNum" label="周期数">
          </el-table-column>
          <el-table-column
            align="center"
            prop="subjectName"
            label="缴费金额(元)"
          >
            <template slot-scope="scope">
              {{ scope.row.actualAmount | hasMoneyFormat }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="type"
            label="已缴费人数/总人数"
          >
            <template slot-scope="scope">
              {{ scope.row.paymentUserNum }}/{{ scope.row.userNum }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="创建人"
            prop="operatorName"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            label="创建时间"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="remark"
            label="备注"
          ></el-table-column>
          <el-table-column align="center"
                          label="操作">
            <template slot-scope="scope">
              <el-button type="text" v-if="$helpers.permission('studentCloudCoachPaymentDetails/queryPage')" @click="onDetail(scope.row)">详情</el-button>
            </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>

    <el-dialog
      title="激活会员"
      :visible.sync="recordVisible"
      width="1000px"
      v-if="recordVisible"
      append-to-body
    >
      <recordDetail :detail="selectDetail"  @close="recordVisible = false" />
    </el-dialog>
  </div>
</template>
<script>
import pagination from "@/components/Pagination/index";
import { queryInactive } from '@/views/resetTeaming/api'
import recordDetail from '@/views/studentManager/modals/recordDetail'
import { cloudCoachPaymentProgramQueryPage } from './api'
import { getTimes } from "@/utils";
export default {
  components: { pagination, recordDetail },
  data() {
    return {
      recordVisible: false,
      searchForm: {
        visitTime: [],
        period: null,
      },
      tableList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      selectDetail: null,
    };
  },
  mounted() {
    this.getList()
  },
  methods: {
    async getList() {
      try {
        const { visitTime, ...search } = this.searchForm
        const res = await cloudCoachPaymentProgramQueryPage({
          ...search,
          ...getTimes(visitTime, ["startTime", "endTime"]),
          page: this.rules.page,
          rows: this.rules.limit,
        });
        this.rules.total = res.data.total;
        this.tableList = res.data.rows;
      } catch (e) { }
    },
    search() {
      this.rules.page = 1;
      this.getList();
    },
    onReSet() {
      this.searchForm = {
        visitTime: [],
        period: null,
      }
      this.search()
    },
    onDetail(row) {
      this.selectDetail = row
      this.recordVisible = true
    }
  },
};
</script>