
<template>
  <div class="m-container">
    <h2>
      <div class="squrt"></div>
      考级报名
    </h2>
    <div class="m-core">
      <!-- 搜索标题 -->
      <save-form
        :inline="true"
        class="searchForm"
        ref="searchForm"
        @submit="onSearch"
        @reset="onReSet"
        :model="searchForm"
      >
        <el-form-item prop="name">
          <el-input
            v-model.trim="searchForm.name"
            clearable
            placeholder="请输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="orderNo">
          <el-input
            v-model.trim="searchForm.orderNo"
            clearable
            placeholder="请输入订单编号"
          ></el-input>
        </el-form-item>
        <el-form-item prop="transNo">
          <el-input
            v-model.trim="searchForm.transNo"
            clearable
            placeholder="请输入交易流水号"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
          <el-input v-model.trim="searchForm.city"
                    @keyup.enter.native="city"
                    placeholder="请输入城市名"></el-input>
        </el-form-item> -->
        <el-form-item prop="organId">
          <el-select
            v-model.trim="searchForm.organId"
            filterable
            clearable
            placeholder="请选择分部"
          >
            <el-option
              v-for="item in selects.branchs"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            class="multiple"
            v-model.trim="searchForm.degreeType"
            filterable
            clearable
            placeholder="请选择考级类型"
          >
            <el-option :value="2" label="2022级考级"></el-option>
            <el-option :value="1" label="2021级考级"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            class="multiple"
            v-model.trim="searchForm.status"
            filterable
            clearable
            placeholder="请选择缴费状态"
          >
            <el-option value="reg" label="未缴费"></el-option>
            <el-option value="pay" label="已缴费"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="orderDate">
          <el-date-picker
            v-model.trim="searchForm.orderDate"
            style="width: 410px"
            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-button
            @click="onExport"
            v-permission="'export/degreeRegistration/825'"
            type="primary"
            >导出</el-button
          >
        </el-form-item>
      </save-form>
      <div style="font-size: 14px; color: #f85043; padding-bottom: 10px">
        报考总人数：{{ totalNumber }}人
        <i style="width: 10px; display: inline-block"></i>
        实收总金额：{{ totalAmount }}元
      </div>
      <div class="tableWrap">
        <el-table
          :data="tableList"
          :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
        >
          <el-table-column width="90px" align="center" prop="id" label="编号">
            <template slot-scope="scope">
              <copy-text>{{ scope.row.id }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="name" label="姓名">
            <template slot-scope="scope">
              <copy-text>{{ scope.row.name }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="orderNo" label="订单编号">
            <template slot-scope="scope">
              <copy-text>{{ scope.row.orderNo }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="transNo" label="交易流水号">
            <template slot-scope="scope">
              <el-tooltip placement="top-start">
                <div slot="content">{{ scope.row.transNo }}</div>
              </el-tooltip>
                <copy-text>{{ scope.row.transNo }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="city"
            label="分部"
          >
              <template slot-scope="scope">
              <copy-text>{{ scope.row.city }}</copy-text>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="gender" label="性别">
            <template slot-scope="scope">{{
              scope.row.gender == 1 ? "男" : "女"
            }}</template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="idcard"
            label="身份证号"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="mobile"
            label="联系电话"
            width="110px"
          ></el-table-column>

          <el-table-column
            align="center"
            prop="subject"
            label="报考乐器"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="level"
            label="报考级别"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="theoryLevel"
            label="乐理级别"
          ></el-table-column>
          <el-table-column align="center" label="缴费状态">
            <template slot-scope="scope">{{
              scope.row.status == 2 ? "已缴费" : "未缴费"
            }}</template>
          </el-table-column>
          <el-table-column align="center" prop="money" label="报考级别费用">
            <template slot-scope="scope"
              >{{ scope.row.money | moneyFormat }}元</template
            >
          </el-table-column>
          <el-table-column
            align="center"
            prop="theoryMoney"
            label="乐理级别费用"
          >
            <template slot-scope="scope"
              >{{ scope.row.theoryMoney | moneyFormat }}元</template
            >
          </el-table-column>
          <el-table-column align="center" label="证书">
            <template slot-scope="scope">
              <div v-if="scope.row.theoryCert">
                <el-image
                  fit="cover"
                  style="width: 100px; height: 100px"
                  :src="scope.row.theoryCert"
                  :preview-src-list="[scope.row.theoryCert]"
                ></el-image>
              </div>
              <div v-else>--</div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="createTime"
            label="报名时间"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="memo"
            label="备注"
          ></el-table-column>
          <!-- <el-table-column align="center" label="操作">
                    <template slot-scope="scope">
                    <el-button @click="onTypeDelOpeation(scope.row)"
                        v-permission="'helpCenterContent/delete'" type="text">删除</el-button>
                    </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 axios from "axios";
import cleandeep from "clean-deep";
// import store from '@/store'
import { degreeQueryPage } from "./levelManageApi";
import { getToken } from "@/utils/auth";
import { getTimes } from "@/utils";
import load from "@/utils/loading";
export default {
  components: { pagination },
  name: "helpCategory",
  data() {
    return {
      searchForm: {
        name: null,
        orderNo: null,
        transNo: null,
        city: null,
        status: "pay",
        startTime: null,
        organId: null,
        endTime: null,
        orderDate: [],
        degreeType: 2
      },
      totalNumber: 0,
      totalAmount: 0,
      tableList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
      tempTreeList: [],
    };
  },
  mounted() {
    this.getList();
    this.__init();
  },
  methods: {
    __init() {
      this.$store.dispatch("setBranchs");
    },
    onSearch() {
      this.pageInfo.page = 1;
      this.getList();
    },
    onReSet() {
      // 重置搜索

      this.orderDate = null;
      // this.searchForm = {
      //   orderNo: null,
      //   transNo: null,
      //   city: null,
      //   status: null,
      //   startTime: null,
      //   organId: null,
      //   endTime: null,
      // };
      this.$refs.searchForm.resetFields();
      //  this.$set(this.searchForm,'status','pay')
      this.searchForm.status = 'pay'
      this.onSearch();
    },
    getList() {
      // let searchForm = this.searchForm;
      // let params = cleandeep(searchForm);
      // params.page = this.pageInfo.page;
      // params.rows = this.pageInfo.limit;
      let { orderDate, ...rest } = this.searchForm;
      let params = {
        ...rest,
        page: this.pageInfo.page,
        rows: this.pageInfo.limit,
        ...getTimes(orderDate, ["startTime", "endTime"]),
      };
      degreeQueryPage(params).then((res) => {
        let result = res.data;
        if (res.code == 200) {
          this.totalNumber = result.applyNum;
          this.totalAmount = result.totalAmount;
          this.tableList = result.rows;
          this.pageInfo.total = result.total;
        }
      });
    },
    // searchOrderDate(value) {
    //   if (value) {
    //     this.searchForm.startTime = value[0];
    //     this.searchForm.endTime = value[1];
    //   } else {
    //     this.searchForm.startTime = null;
    //     this.searchForm.endTime = null;
    //   }
    // },
    // 导出
    onExport() {
      let url = "/api-web/export/degreeRegistration";
          let { orderDate, ...rest } = this.searchForm;
      let params = {
        ...rest,
        ...getTimes(orderDate, ["startTime", "endTime"]),
      };

     params = cleandeep(params);
      // {
      //   orderNo: searchForm.orderNo ? searchForm.orderNo : null,
      //   transNo: searchForm.transNo ? searchForm.transNo : null,
      //   city: searchForm.city ? searchForm.city : null,
      //   status: searchForm.status ? searchForm.status : null,
      //   startTime: searchForm.startTime ? searchForm.startTime : null,
      //   endTime: searchForm.endTime ? searchForm.endTime : null,
      // };
      const options = {
        method: "get",
        headers: {
          Authorization: getToken(),
        },
        url,
        params: params,
        responseType: "blob",
      };

      this.$confirm("您确定导出列表?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          load.startLoading();
          axios(options)
            .then((res) => {
              let blob = new Blob([res.data], {
                // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
                type: "application/vnd.ms-excel;charset=utf-8",
                //word文档为application/msword,pdf文档为application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8
              });
              let text = new Response(blob).text();
              text.then((res) => {
                // 判断是否报错
                if (res.indexOf("code") != -1) {
                  let json = JSON.parse(res);
                  this.$message.error(json.msg);
                } else {
                  let objectUrl = URL.createObjectURL(blob);
                  let link = document.createElement("a");
                  let nowTime = new Date();
                  let ymd =
                    nowTime.getFullYear() +
                    "" +
                    (nowTime.getMonth() + 1) +
                    "" +
                    nowTime.getDate() +
                    "" +
                    nowTime.getHours() +
                    "" +
                    nowTime.getMinutes();
                  let fname = ymd + "考级报名列表.xls";
                  link.href = objectUrl;
                  link.setAttribute("download", fname);
                  document.body.appendChild(link);
                  link.click();
                }
              });
              load.endLoading();
            })
            .catch((error) => {
              this.$message.error("导出数据失败，请联系管理员");
              load.endLoading();
            });
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.el-button--primary {
  background: #14928a;
  border-color: #14928a;
  color: #fff;
  &:hover,
  &:active,
  &:focus {
    background: #14928a;
    border-color: #14928a;
    color: #fff;
  }
}
/deep/.el-image-viewer__close {
  color: #fff;
  opacity: 1;
}
/deep/.el-date-editor.el-input {
  width: 100% !important;
}
/deep/.el-select {
  width: 100% !important;
}
/deep/.el-table .cell {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
</style>
