<!--**Lxh-查询学校下测试量表下的用户-->
<template>
  <div>
    <div class="headerRow">
      <el-date-picker
        v-model="beginTime"
        type="date"
        format="yyyy-MM-dd"
        class="mrr"
        style="width: 160px"
        value-format="yyyy-MM-dd"
        placeholder="选择开始日期"
      >
      </el-date-picker>

      <el-date-picker
        v-model="endTime"
        style="width: 160px"
        class="mrr"
        type="date"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
        placeholder="选择结束日期"
      >
      </el-date-picker>
      <el-select
        v-model="groupValue"
        @change="onSubmit"
        placeholder="年级选择"
        style="width: 120px"
        class=""
      >
        <el-option
          v-for="item in groupOptions"
          :key="item.id"
          :label="item.groupName"
          :value="item.id"
        >
        </el-option>
      </el-select>
      &nbsp;&nbsp;
      <el-input
        placeholder="请输入名称搜索"
        v-model="searchKeyLin"
        class="input-with-select mrr"
        style="width: 240px"
        @keyup.enter.native="onSubmit"
      >
        <el-button
          class="button-pub-select"
          slot="append"
          icon="el-icon-search"
          @click="onSubmit"
          ></el-button>
      </el-input>
      <el-button
        class="ml10 button-pub"
        icon="el-icon-refresh"
        @click="reset"
      ></el-button>
      <el-button
        class="mrl"
        type="primary"
        :disabled="multipleSelection.length == 0"
        @click="listDown()"
      >
        批量下载
      </el-button>
      <el-button class="mrl" type="primary" @click="downloadAll">
        全部下载
      </el-button>
      <el-button
        class="mrl"
        type="primary"
        :disabled="multipleSelection.length == 0"
        @click="rowDataDownload(0)"
      >
        原始数据批量下载
      </el-button>
      <el-button class="mrl" type="primary" @click="rowDataDownload(1)">
        原始数据全部下载
      </el-button>
      <el-button type="primary" @click="goReturn()">返回</el-button>
    </div>
    <div class="headerRow" style="margin-top: 10px">
      <el-button
          class="mrl"
          type="primary"
          :disabled="multipleSelection.length == 0"
          @click="downloadPDF(0)"
      >
        PDF报告批量下载
      </el-button>
      <el-button class="mrl" type="primary" @click="downloadPDF(1)">
        PDF报告全部下载
      </el-button>
    </div>
    <!--记录展示start-->
    <el-table
      :header-cell-style="{ background: '#F6F7FB', color: '#606266' }"
      :data="tableData"
      border
      style="margin-top: 20px"
      class="table-padding"
      :row-key="getRowKeys"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" :reserve-selection="true" width="55">
      </el-table-column>
      <el-table-column
        prop="petName"
        label="用户名称"
        width="auto"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="phone" label="账号" width="auto" align="center">
      </el-table-column>
      <el-table-column
        prop="gender"
        label="性别"
        width="auto"
        align="center"
        :formatter="sexFormat"
      >
      </el-table-column>
      <el-table-column prop="gid" label="年级名称" width="auto" align="center">
      </el-table-column>
      <el-table-column
        prop="profession"
        label="职业"
        width="auto"
        align="center"
      >
      </el-table-column>

      <el-table-column
        prop="testDate"
        label="测试时间"
        width="auto"
        align="center"
      >
      </el-table-column>
      <el-table-column label="操作" width="auto" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="detailP(scope.row.id)"
            >查看测试详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--记录展示end-->

    <!--分页插件start-->
    <el-row>
      <el-col :span="24" style="text-align: right">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-col>
    </el-row>
    <div class="txt-center" style="margin-top: 20px"></div>
    <!--分页插件end-->
  </div>
</template>

<script>
export default {
  name: "SacleUserList",
  data() {
    return {
      //年级过滤条件
      groupValue: "",
      //年级信息
      groupOptions: [],
      userBid: "", //用户唯一标识
      searchKeyLin: "", //查询条件
      searchKey: "", //查询条件
      currentPage: 1,
      total: 200, //记录总数
      pageSize: 10,
      baseUrl: baseUrl,
      tableData: [],
      userId:'',
      institutionNo: "",
      name: "", //学校名称
      multipleSelection: [], //批量导出选中的对象
      time: ["", ""],
      beginTime: "",
      endTime: "",
      getRowKeys(row) {
        return row.id;
      }, //获取row的key值
    };
  },
  /*页面初始化*/
  created() {
    this.institutionNo = sessionStorage.getItem(
      "f7a42fe7211f98ac7a60a285ac3a9527"
    );
    this.userId = sessionStorage.getItem("b80bb7740288fda1f201890375a60c8f");
    this.name = this.$route.query.name;
    //this.getUserBid()
    this.getData();
    this.groupFun();
  },
  methods: {
    //查询年级信息
    groupFun() {
      this.$http.get(
        // "/group/find?institutionNo=" + this.institutionNo,
        `/group/find?institutionNo=${this.institutionNo}&userId=${this.userId}`,
        {},
        (response) => {
          this.groupOptions = response.data;
          // this.tableData = response.data;
          // console.log(response.data)
        }
      );
    },
    /*后台get请求获得数据*/
    goReturn() {
      this.$router.push({
        path: "/ContainerSys/SacleList",
      });
    },
    getData() {
      if (this.endTime == null) {
        this.endTime = "";
      }
      if (this.beginTime == null) {
        this.beginTime = "";
      }
      this.searchKeyLin = this.searchKey;
      this.$http.get(
        "/institution/getTestUser?institutionNo=" +
          this.institutionNo +
          "&name=" +
          this.name +
          "&pageNum=" +
          this.currentPage +
          "&pageSize=" +
          this.pageSize +
          "&searchKey=" +
          this.searchKey +
          "&beginTime=" +
          this.beginTime +
          "&endTime=" +
          this.endTime +
          "&groupId=" +
          this.groupValue + 
          "&userId=" +
          this.userId,
        {},
        (response) => {
          this.total = response.data.allNum;
          this.tableData = response.data.institutionUserRecordingList;
        }
      );
    },
    /*getUserBid(){
        this.userBid = sessionStorage.getItem("f7a42fe7211f98ac7a60a285ac3a9e87");
    },*/
    /*分页start*/
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getData();
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    reset() {
      console.log(this.tableData);
      this.searchKey = "";
      this.currentPage = 1;
      this.beginTime = "";
      this.endTime = "";
      this.groupValue = "";

      this.getData();
    },

    // 性别，状态设置
    sexFormat(row) {
      if (row.gender == 0) {
        return "男";
      } else {
        return "女";
      }
    },
    //查看详情
    detailP(id) {
      this.JumpJudgment(id);
    },
    // 跳转到SCl-90
    JumpJudgment(id) {
      this.$router.push({
        path: "/ContainerSys/SearchScaleRecordSCl",
        query: {
          id: id,
          come: 3,
        }
      });
    },
    onSubmit() {
      this.currentPage = 1;
      this.searchKey = this.searchKeyLin;
      this.getData();
    },
    //批量导出
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    listDown() {
      let str = "";
      this.multipleSelection.forEach((item) => {
        str += item.id + ",";
      });
      window.location.href =
        this.baseUrl +
        `/result/download/userReds?institutionNo=${
          this.institutionNo
        }&ids=${str.substring(0, str.length - 1)}&name=${this.name}`;
    },

    // 全部下载
    downloadAll() {
      window.location.href = `${this.baseUrl}result/download/allUserReds?institutionNo=${this.institutionNo}&userId=${this.userId}&name=${this.name}&searchKey=${this.searchKey}&beginTime=${this.beginTime}&endTime=${this.endTime}&groupId=${this.groupValue}`;
      // this.multipleSelection = val;
    },

    rowDataDownload(i) {
      if (i == 0) {
        let str = "";
        this.multipleSelection.forEach((item) => {
          str += item.id + ",";
        });
        window.location.href =
          this.baseUrl +
          `result/download/planResultBatch?institutionNo=${
            this.institutionNo
          }&ids=${str.substring(0, str.length - 1)}&name=${this.name}`;
      } else {
        window.location.href = `${this.baseUrl}result/download/planResultAll?institutionNo=${this.institutionNo}&userId=${this.userId}&name=${this.name}&searchKey=${this.searchKey}&beginTime=${this.beginTime}&endTime=${this.endTime}&groupId=${this.groupValue}`;
      }
    },
    downloadPDF(i) {
      if (i == 0) {
        let str = "";
        this.multipleSelection.forEach((item) => {
          str += item.id + ",";
        });
        window.location.href =
            this.baseUrl +
            `/result/download/userPDFReds?institutionNo=${
                this.institutionNo
            }&ids=${str.substring(0, str.length - 1)}`;
      } else {
        window.location.href = `${this.baseUrl}result/download/allUserPDFReds?institutionNo=${this.institutionNo}&userId=${this.userId}&name=${this.name}&searchKey=${this.searchKey}&beginTime=${this.beginTime}&endTime=${this.endTime}`;
      }
    }
  },
};
</script>

<style scoped>
.button-pub-select {
  background: #00CDDD !important;
  color: #ffffff !important;
  border-bottom-right-radius: 4px !important;
  border-top-right-radius: 4px !important;
  border-bottom-left-radius: 0px !important;
  border-top-left-radius: 0px !important;
}
.button-pub {
  background: #00CDDD !important;
  color: #ffffff !important;
  border-radius: 4px !important;
}
::v-deep .el-button--primary {
  color: #fff;
  background-color: #00CDDD;
  border-color: #00CDDD;
  border-radius: 4px !important;
}
::v-deep .el-pager li.active {
  color: #ffffff;
  cursor: default;
  background-color: #00CDDD;
}
::v-deep .el-pagination.is-background .el-pager li {
  margin: 0 5px;
  background-color: #ffffff;
  color: #606266;
  min-width: 30px;
  border-radius: 2px;
  border: 1px solid #dfe0e4;
}
</style>
