<template>
  <div>
    <div>
      <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="organId">
          <el-select
            class="multiple"
            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>
          <el-select
            class="multiple"
            v-model.trim="searchForm.audit"
            filterable
            clearable
            placeholder="请选择审核人"
          >
            <el-option
              v-for="(item, index) in userList"
              :key="index"
              :label="item.auditName"
              :value="item.audit"
            ></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-select
            class="multiple"
            v-model.trim="searchForm.status"
            filterable
            clearable
            placeholder="审核状态"
          >
            <el-option label="审核中" value="AUDITING"></el-option>
            <el-option label="拒绝" value="REJECT"></el-option>
            <el-option label="开启缴费" value="OPEN"></el-option>
          </el-select>
        </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="left"
            prop="id"
            label="续费编号"
          ></el-table-column>
          <el-table-column align="left" prop="organName" label="分部名称">
          </el-table-column>
          <el-table-column align="left" prop="name" label="学练宝">
            <template slot-scope="scope">
              <div>
                <p>
                  学练宝版本：
                  {{ scope.row.memberRankSettingName ? scope.row.memberRankSettingName : "--" }}
                </p>
                <p>
                  续费周期：
                  {{ scope.row.memberNum ? scope.row.memberNum : "--"
                  }}{{ scope.row.period | memberEnumType }}
                </p>
                <p>
                  缴费金额： {{ scope.row.actualAmount | moneyFormat(true) }}
                </p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column align="left" prop="memberNum" label="周期数">
          </el-table-column> -->
          <!-- <el-table-column align="left" prop="subjectName" label="缴费金额(元)">
            <template slot-scope="scope">
              {{ scope.row.actualAmount | moneyFormat(true) }}
            </template>
          </el-table-column> -->
          <el-table-column align="left" prop="type" label="人数">
            <template slot-scope="scope">
              <p>已缴费： {{ scope.row.paymentUserNum }}人</p>
              <p>总人数： {{ scope.row.userNum }}人</p>
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            label="创建人"
            prop="operatorName"
            width="200px"
          >
            <template slot-scope="scope">
              <div>
                <p>
                  {{ scope.row.operatorName ? scope.row.operatorName : "--" }}
                </p>
                <p>{{ scope.row.createTime ? scope.row.createTime : "--" }}</p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            prop="createTime"
            label="审核人"
            width="140px"
          >
            <template slot-scope="scope">
              <div>
                <p>{{ scope.row.auditName ? scope.row.auditName : "--" }}</p>
                <p>
                  {{
                    scope.row.auditTime
                      ? scope.row.auditTime
                      : "--" | dateForMinFormat
                  }}
                </p>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            prop="remark"
            label="备注"
          ></el-table-column>
          <el-table-column align="left" prop="memo" label="审核意见">
            <template slot-scope="scope">
              <overflow-text width="80px" :text="scope.row.memo" />
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            prop="operatorName"
            label="申请人"
          ></el-table-column>
          <el-table-column
            align="left"
            prop="status"
            label="状态"
            width="100px"
          >
            <template slot-scope="scope">
              <div>
                {{ scope.row.status | auditType }}
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            align="left"
            prop="createTime"
            label="创建时间"
          ></el-table-column> -->
          <!-- </el-table-column> -->
          <el-table-column align="left" label="操作">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="
                  scope.row.status == 'AUDITING' &&
                    $helpers.permission('cloudCoachPaymentProgram/audit')
                "
                @click="onDetail(scope.row)"
                >审核</el-button
              >
              <el-button
                type="text"
                v-if="
                  scope.row.status != 'AUDITING' &&
                    $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="800px"
      v-if="recordVisible"
      append-to-body
    >
      <member-model
        :detail="selectDetail"
        @getList="getList"
        @close="recordVisible = false"
      />
    </el-dialog>
  </div>
</template>
<script>
import pagination from "@/components/Pagination/index";
import memberModel from "./memberModel";
import { cloudCoachPaymentProgramQueryPage } from "../studentManager/api";
import { getTimes } from "@/utils";
import { auditTypeList } from "@/utils/searchArray";
import { getCalenderUser } from "./api";
export default {
  components: { pagination, memberModel },
  data() {
    return {
      recordVisible: false,
      searchForm: {
        visitTime: [],
        period: null,
        organId: null,
        status: "AUDITING",
        audit: null
      },
      tableList: [],
      userList: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },
      selectDetail: null,
      statusList: auditTypeList
    };
  },
  async mounted() {
    await this.$store.dispatch("setBranchs");
    this.getList();
    this.getCalenderList();
  },

  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;
    },
    async getCalenderList() {
      try {
        const res = await getCalenderUser({ type: "CLOUD" });
        this.userList = res.data;
      } catch (e) {
        console.log(e);
      }
    }
  }
};
</script>
