<template>
  <div class="disFlex">
    <NavLeft navIf="consumer" />
    <div class="consumer">
      <div class="pull-title">
        <ul class="title-item">
          <li class="cur">用户管理</li>
        </ul>
      </div>
      <div class="consumer-seach">
        <ul class="consumer-seach-item">
          <li>
            <el-input
              v-model="consumerData.keyword"
              placeholder="请输入手机号"
              class="input-with-select"
              style="width: 340px"
            >
              <template #prepend>
                <el-select
                  v-model="consumerData.type"
                  placeholder="手机号"
                  style="width: 88px"
                >
                  <el-option label="手机号" value="手机号"></el-option>
                  <el-option label="微信号" value="微信号"></el-option>
                  <el-option label="钉钉号" value="钉钉号"></el-option>
                </el-select>
              </template>
            </el-input>
          </li>
          <li>
            <el-date-picker
              v-model="consumerData.Time"
              type="daterange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </li>
          <el-button class="seach-btn" @click="queryConsumer()"
            ><img src="../assets/search-btn.png" alt="" />查询
          </el-button>
        </ul>
      </div>
      <div class="consumer-list">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column align="center" prop="name" label="用户姓名" />
          <el-table-column align="center" prop="phone" label="手机号" />
          <el-table-column align="center" prop="wxMiniShowname" label="微信" />
          <el-table-column
            align="center"
            prop="dingdingShowname"
            label="钉钉"
          />
          <el-table-column align="center" prop="createTime" label="注册时间" />
          <el-table-column align="center" #default="scope" label="操作">
            <el-button type="text" size="small" @click="queryName(scope)"
              >用户详情</el-button
            >
            <el-button type="text" size="small" @click="queryNamea(scope)"
              >测试列表</el-button
            >
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="consumer-pagination">
        <el-pagination
          background
          v-model:currentPage="currentPage3"
          :page-size="100"
          layout="prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        >
        </el-pagination>
      </div>
    </div>

    <el-drawer
      v-model="drawer"
      :direction="direction"
      :before-close="handleClose"
    >
      <div class="elementUl">
        <div class="usernameDatatit">
          <p
            @click="usernameDatatitIf(true)"
            :class="usernameDataIf ? 'usernameDatatitIf' : ''"
          >
            用户信息
          </p>
          <p
            @click="usernameDatatitIf(fales)"
            :class="usernameDataIf ? '' : 'usernameDatatitIf'"
          >
            测评报告
          </p>
        </div>

        <div v-if="usernameDataIf" class="usernameData">
          <p class="p">
            用户ID：<span>{{ usernameData.id }}</span>
          </p>
          <p class="p">
            手机号：<span>{{ usernameData.phone }}</span>
          </p>
          <p class="p">
            身份证号：<span>{{ usernameData.idCard }}</span>
          </p>
          <div class="wxDd">
            <p>微信</p>
            <div class="wxDdCon">
              <img :src="usernameData.wxMiniHeader" alt="" />
              <p>{{ usernameData.wxMiniShowname }}</p>
            </div>
            <p>钉钉</p>
            <div class="wxDdCon">
              <img :src="usernameData.dingdingHeader" alt="" />
              <p>{{ usernameData.dingdingShowname }}</p>
            </div>
          </div>
        </div>

        <div v-else class="reportList">
          <div class="reportListCon" v-for="item in ReportListData" :key="item">
            <p>{{item.testName}}</p>
            <p><span> 测试时间</span> <span> {{item.createTime}}</span></p>
            <p><span> 创建部门</span> <span> {{item.companyName}}</span></p>
            <P>
              <span>允许面试人员查看结果</span>
          
              <el-switch v-model="item.isAllowViewResultIf" @change="isAllowViewResultIf(item)" class="mb-2"> </el-switch>
              </P>
          </div>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import NavLeft from "../components/nav.vue";
export default {
  components: {
    NavLeft,
  },
  props: {
    msg: String,
  },
  data() {
    return {
      input: "",
      select: "",
      value1:true,
      drawer: false,
      value: "",
      Time: "",
      usernameData: {},
      tableData: [],
      ReportListData: [],
      total: 1,
      usernameDataIf: true,
      consumerData: {
        current: 1,
        keyword: "",
        type: "",
        size: 10,
        endTime: "",
        startTime: "",
      },
    };
  },
  mounted() {
    // 初始化获取数据
    this.getConsumer();
  },
  methods: {
    // 时间格式转换
    newDate(data) {
      let yy = new Date(data).getFullYear();
      let mm = new Date(data).getMonth() + 1;
      let dd = new Date(data).getDate();
      return yy + "-" + mm + "-" + dd;
    },
    usernameDatatitIf(ifS) {
      this.usernameDataIf = ifS;
    },
    // 查看用户信息
    queryName(data) {
      this.drawer = true;
      this.getReportList(data.row.id);
      this.usernameData = data.row;
      console.log(this.usernameData);

      this.usernameDataIf = true;
    },
    // 查看测试列表
    queryNamea(data) {
      this.drawer = true;
      this.getReportList(data.row.id);
      this.usernameData = data.row;
      this.usernameDataIf = false;
    },
    handleCurrentChange(data) {
      this.consumerData.current = data;
      this.getConsumer();
    },
    handleClose() {
      this.drawer = false;
    },
    phonetest(data) {
      const reg = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
      if (data == "" || data.length <= 10 || !reg.test(data)) {
        return false;
      } else {
        return true;
      }
    },

    // 获取列表数据
    getConsumer() {
      let param = new URLSearchParams();

      param.append("current", this.consumerData.current);
      param.append("keyword", this.consumerData.keyword);
      param.append("size", this.consumerData.size);
      param.append("type", this.consumerData.type);
      param.append("endTime", this.consumerData.endTime);
      param.append("startTime", this.consumerData.startTime);
      let that = this;
      this.axios
        .get("/hysc/member/getMemberPage", {
          params: param,
        })
        .then(function (response) {
          that.tableData = response.data.data.records;
          that.total = response.data.data.total;
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    getReportList(id) {
      let param = new URLSearchParams();
      param.append("memberId", id);

      let that = this;
      this.axios
        .get("/hysc/member/getMemberTestList", {
          params: param,
        })
        .then(function (response) {
          console.log(response.data);
          that.ReportListData = response.data.data;
          for (let index = 0; index <  that.ReportListData.length; index++) {
            console.log(that.ReportListData[index].isAllowViewResult);
            if (  that.ReportListData[index].isAllowViewResult=="1") {
              that.ReportListData[index].isAllowViewResultIf=true
            }else{
               that.ReportListData[index].isAllowViewResultIf=false
            }
            
          }
          console.log(  response.data.data,"123");
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    isAllowViewResultIf(data){
           console.log(data);
            console.log(data.isAllowViewResultIf);
       if (data.isAllowViewResultIf) {
         data.isAllowViewResult="1"
       }else{
            data.isAllowViewResult="0"
       }

      this.axios
        .post("/hysc/test/allowViewResult",  {id:this.usernameData.id,
        isAllowViewResult:data.isAllowViewResult
        })
        .then(function (response) {
          console.log(response.data, "213123");
        
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    queryConsumer() {
      // 	   consumerData: {
      //     current: 1,
      //     keyword: "",
      //     type: "",
      //     size: 10,
      //     endTime: "",
      //     startTime: "",
      //   },

      console.log(this.consumerData.type);
      if (this.consumerData.keyword&&this.consumerData.type == "") {
        this.consumerData.type="手机号"
      }

      if (this.consumerData.type == "手机号" ) {
        if (!this.phonetest(this.consumerData.keyword)) {
          this.$alert("请正确输入手机号", "手机号错误", {
            confirmButtonText: "确定",
          });
          return;
        }
      }

      if (this.consumerData.Time) {
        this.consumerData.startTime = this.newDate(this.consumerData.Time[0]);
        this.consumerData.endTime = this.newDate(this.consumerData.Time[1]);
      }else{
           this.consumerData.startTime = ""
        this.consumerData.endTime =""
      }
      this.getConsumer();
    },
  },
};
</script>
<style scoped>
.disFlex {
  display: flex;
}
.usernameDatatit {
  display: flex;
  position: absolute;
  width: 80%;
  top: 0px;
  border-bottom: 1px solid #e4eaee;
  padding-left: 40px;
  padding-top: 23px;
  left: 0px;
}
.usernameData > .p {
  width: 93%;
  padding: 16px 20px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8e8e8e;
  display: flex;
  justify-content: space-between;
  line-height: 20px;
  border-bottom: 1px solid #e4eaee;
  margin-bottom: 18px;
}

.usernameData > .p span {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #515151;
  line-height: 20px;
}
.usernameDatatit > p {
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #454d67;
  margin-right: 30px;
  line-height: 22px;
}
.consumer {
  width: calc(100% - 260px);
  padding: 50px 60px;
}
.reportListCon {
  background: #f8fafb;
  padding: 20px;
}
.reportListCon > p {
  width: 93%;
  padding-bottom: 16px;
  padding-left: 10px;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #515151;
  margin-bottom: 20px;

  border-bottom: 1px solid #e4eaee;
  line-height: 22px;
  display: flex;
  justify-content: space-between;
}
.reportListCon > p > :nth-child(1) {
  width: 144px;
  height: 19px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8e8e8e;
  line-height: 20px;
}
.reportListCon > p > :nth-child(2) {
  width: 138px;
  height: 19px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8e8e8e;
  text-align: right;
  line-height: 20px;
  width: 206px;
  height: 19px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #515151;
  line-height: 20px;
}
/* 搜索 */
.consumer-seach {
  margin: 60px 0 50px;
}

.consumer-seach-item {
  display: flex;
}

.consumer-seach-item li {
  margin-right: 10px;
}

.consumer-seach-item >>> .el-input__inner {
  height: 40px;
}

.consumer-seach-item .seach-btn,
.consumer-seach-item .seach-btn:hover {
  width: 90px;
  height: 40px;
  background-color: #0544a4;
  color: #ffffff;
  border: 0;
}
.consumer-seach-item .seach-btn img {
  height: 18px;
  margin-right: 8px;
  font-size: 15px;
}
/* 列表 */
.consumer-list >>> .el-table .cell {
  padding: 0;
}

/* 分页 */
.consumer-pagination {
  display: flex;
  justify-content: flex-end;
  margin-top: 120px;
}

.consumer-pagination >>> .el-pager li {
  color: #666666;
  font-weight: normal;
}

.consumer-pagination >>> .el-input__inner {
  width: 48px;
}

.consumer-pagination >>> .el-pagination__jump {
  margin-left: 0;
}
.wxDd > p {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #8e8e8e;
  padding-bottom: 16px;
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 16px;
  width: 93%;
  border-bottom: 1px solid #e4eaee;
  line-height: 20px;
}
.wxDdCon {
  display: flex;
  align-items: center;
  padding: 20px 30px;
}
.wxDdCon img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 1px solid #c1c1c1;
}
.wxDdCon p {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #515151;
  line-height: 20px;
  margin-left: 20px;
}
.usernameDatatit > .usernameDatatitIf {
  color: #0544a4;
  font-weight: 600;
  padding-bottom: 20px;
  border-bottom: 2px solid #0544a4;
}
</style>
