<template>
  <view style="background-color: rgb(246, 247, 250); height: 100%">
    <view class="flex-col group_2" v-if="step == 0">
      <u-navbar title="教师认证"></u-navbar>
      <view class="form">
        <view class="flex-col group">
          <view class="flex-col section_2">
            <!-- 教职工 -->
            <view v-if="roleId === '2'" class="flex-col group_5 jzg-box">
              <!-- 头像 -->
              <view class="flex-col items-center img-box">
                <u-avatar
                  mode="circle"
                  :src="headerImg"
                  @click="chooseAvatar"
                />
                <text class="text_4">请上传头像</text>
              </view>
              <!-- 真实姓名 -->
              <view class="flex-row group_6">
                <text class="text_15">真实姓名</text>
                <u-input
                  v-model="form.realName"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'text'"
                  textAlign="right"
                  class="input"
                  placeholder="请输入真实姓名"
                />
              </view>
              <!-- 性别 -->
              <view class="justify-between group_7" @click="sex = true">
                <view class="flex-row u-col-center">
                  <text class="text_15">性别</text>
                  <view v-if="form.sex">{{ form.sex }}</view>
                  <view v-else style="color: #cbcacd">请选择性别</view>
                </view>
                <image
                  class="image_3 image_5"
                  src="/static/common/img/row_right.png"
                />
              </view>
              <!-- <view class="flex-row group_6">
              <text class="text_15">申请人姓名</text>
              <u-input v-model="form.name" :border="false" :custom-style="inputStyle" :type="'text'"
                       class="input" disabled placeholder="请输入" />
            </view> -->
              <view class="group_9 flex-row">
                <text class="text_15">联系方式</text>
                <u-input
                  v-model="form.phone"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'number'"
                  textAlign="right"
                  class="input"
                  disabled
                  placeholder="请输入"
                />
              </view>

              <!-- 任职学校 -->
              <view class="justify-between group_7" @click="shoolShow = true">
                <view class="flex-row u-col-center">
                  <text class="text_15">任职学校</text>
                  <view v-if="shoolName">{{ shoolName }}</view>
                  <view v-else style="color: #cbcacd">请选择任职学校</view>
                  <!--                <u-input class="input" :custom-style="inputStyle" :type="'text'" :border="false"-->
                  <!--                         v-model="shoolName" placeholder="请输入" disabled />-->
                  <!--                    <u-input-->
                  <!--            v-model="shoolName"-->
                  <!--            :border="false"-->
                  <!--            :custom-style="inputStyle"-->
                  <!--            :readonly="true"-->
                  <!--            :type="'text'"-->
                  <!--            class="input"-->
                  <!--            placeholder="请选择任职学校"-->
                  <!--            @click="shoolShow = true"-->
                  <!--          />-->
                </view>
                <image
                  class="image_3 image_5"
                  src="/static/common/img/row_right.png"
                />
              </view>
              <view class="justify-between group_7" @click="schoolPost = true">
                <view class="flex-row u-col-center">
                  <text class="text_15">校内职务</text>
                  <view v-if="form.schoolJob">{{ form.schoolJob }}</view>
                  <view v-else style="color: #cbcacd">请选择校内职务</view>
                  <!--                <u-input v-model="form.schoolJob" :border="false" :custom-style="inputStyle" :type="'text'"-->
                  <!--                         aria-readonly class="input" placeholder="请选择" @click="schoolPost = true" />-->
                </view>
                <image
                  class="image_3 image_5"
                  src="/static/common/img/row_right.png"
                />
              </view>
              <view
                v-if="isDisabled"
                class="justify-between group_13"
                @click="college = true"
              >
                <view class="flex-row u-col-center">
                  <text class="text_15">所属院系</text>
                  <view v-if="form.faculty">{{ form.faculty }}</view>
                  <view v-else style="color: #cbcacd">请选择所属院系</view>
                  <!--                <u-input v-model="form.faculty" :border="false" :custom-style="inputStyle" :type="'text'"-->
                  <!--                         class="input" placeholder="请选择" @click="college=true" />-->
                  <!-- @click="address = true" -->
                </view>
                <image
                  class="image_3 image_8"
                  src="/static/common/img/row_right.png"
                />
              </view>

              <view
                v-if="isDisabled"
                class="justify-between group_13"
                style="border: none"
                @click="job = true"
              >
                <view class="flex-row u-col-center">
                  <text class="text_15">具体职位</text>
                  <view v-if="form.job">{{ form.job }}</view>
                  <view v-else style="color: #cbcacd">请选择具体职位</view>
                </view>
                <image
                  class="image_3 image_8"
                  src="/static/common/img/row_right.png"
                />
              </view>
            </view>
            <!-- 企业 -->
            <view v-if="roleId === '0'" class="flex-col group_5">
              <view class="flex-row group_6">
                <text class="text_15">企业名称</text>
                <u-input
                  v-model="form.businessName"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'text'"
                  class="input"
                  placeholder="请输入"
                />
              </view>
              <view class="flex-row group_6">
                <text class="text_15">企业地址</text>
                <u-input
                  v-model="form.businessAddress"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'text'"
                  class="input"
                  placeholder="请选择"
                  @click="address = true"
                />
              </view>

              <view class="justify-between group_7">
                <view class="flex-row">
                  <text class="text_15">企业申请人姓名</text>
                  <u-input
                    v-model="form.businessUser"
                    :border="false"
                    :custom-style="inputStyle"
                    :type="'text'"
                    class="input"
                    disabled
                  />
                  <!-- placeholder="请选择"
         @click="sex = true" -->
                </view>
                <!-- <image
                src="/static/common/img/row_right.png"
                class="image_3 image_5"
              /> -->
              </view>
              <view class="group_9 flex-row">
                <text class="text_15">联系方式</text>
                <u-input
                  v-model="form.phone"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'number'"
                  class="input"
                  disabled
                  placeholder="请输入"
                />
              </view>
              <view class="justify-between group_13" style="border: none">
                <view class="flex-row">
                  <text class="text_15">申请人职务</text>
                  <u-input
                    v-model="form.job"
                    :border="false"
                    :custom-style="inputStyle"
                    :type="'text'"
                    class="input"
                    placeholder="请输入"
                  />
                  <!-- @click="WorkArea = true"
        disabled -->
                </view>
                <!--  <image
                src="/static/common/img/row_right.png"
                class="image_3 image_8"
              /> -->
              </view>
            </view>
            <!-- 管理员 -->
            <view v-if="roleId === '1'" class="flex-col group_5">
              <view class="flex-row group_6">
                <text class="text_15">申请人姓名</text>
                <u-input
                  v-model="form.name"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'text'"
                  class="input"
                  disabled
                  placeholder="请输入"
                />
              </view>
              <view class="group_9 flex-row">
                <text class="text_15">联系方式</text>
                <u-input
                  v-model="form.phone"
                  :border="false"
                  :custom-style="inputStyle"
                  :type="'number'"
                  class="input"
                  disabled
                  placeholder="请输入"
                />
              </view>
              <view class="justify-between group_7">
                <!-- {{form.schoolName}} -->
                <view class="flex-row">
                  <text class="text_15">学校</text>
                  <u-input
                    v-model="shoolName"
                    :border="false"
                    :custom-style="inputStyle"
                    :type="'text'"
                    class="input"
                    disabled
                    placeholder="请输入"
                  />
                  <!-- <u-input
                  class="input"
                  :custom-style="inputStyle"
                  :type="'text'"
                  :border="false"
                  placeholder="请选择"
                  v-model="shoolName"
                  @click="shoolShow = true"
                  disabled
                /> -->
                </view>
                <!--   <image
                src="/static/common/img/row_right.png"
                class="image_3 image_5"
              /> -->
              </view>
              <!--            <view class="justify-between group_13" style="border: none">
              <view class="flex-row">
                <text class="text_15">职业</text>
                <u-input
                  class="input"
                  :custom-style="inputStyle"
                  :type="'text'"
                  :border="false"
                  placeholder="请选择"
                  v-model="form.job"
                  @click="WorkArea = true"
                  disabled
                />
              </view>
              <image
                src="/static/common/img/row_right.png"
                class="image_3 image_8"
              />
            </view> -->
            </view>
          </view>
        </view>
      </view>

      <view class="file">
        <view class="flex-col section_4">
          <text class="text_11">申请人身份证</text>
          <view class="equal-division">
            <view class="flex-col equal-division-item">
              <view class="flex-col section_5">
                <u-upload
                  ref="uUpload1"
                  :action="action"
                  :header="header"
                  index="0"
                  max-count="1"
                  width="640"
                  height="396"
                  @on-success="onSuccess"
                  ><template #addBtn>
                    <image
                      :src="idcardPositive"
                      mode="widthFix"
                    ></image> </template
                ></u-upload>
              </view>
            </view>
            <view class="flex-col equal-division-item">
              <u-upload
                ref="uUpload2"
                :action="action"
                :header="header"
                index="1"
                max-count="1"
                width="640"
                height="396"
                @on-success="onSuccess"
                ><template #addBtn>
                  <image :src="idcardBack" mode="widthFix"></image> </template
              ></u-upload>
            </view>
          </view>
        </view>
        <view class="flex-col section_4">
          <text class="text_11">个人工作证</text>
          <view class="equal-division">
            <view class="flex-col equal-division-item">
              <u-upload
                ref="uUpload3"
                :action="action"
                :header="header"
                index="2"
                max-count="1"
                width="640"
                height="396"
                @on-success="onSuccess"
                ><template #addBtn>
                  <image :src="workCard" mode="widthFix"></image> </template
              ></u-upload>
            </view>
            <view v-if="roleId == 0" class="flex-col">
              <text class="text_11">企业营业执照</text>
              <view class="equal-division">
                <view class="flex-col equal-division-item">
                  <u-upload
                    ref="uUpload4"
                    :action="action"
                    :header="header"
                    index="3"
                    max-count="1"
                    width="640"
                    height="396"
                    @on-success="onSuccess"
                    ><template #addBtn>
                      <image
                        :src="enterprisesImg"
                        mode="widthFix"
                      ></image> </template
                  ></u-upload>
                </view>
              </view>
            </view>
          </view>
        </view>
        <view class="flex-col group_9">
          <text class="text_23">*所有上传信息仅供身份的认证</text>
          <u-button
            :disabled="!state"
            :plain="!state"
            :throttle-time="1000"
            class="button"
            type="primary"
            @click="save"
            >{{ state ? "提交认证" : "提交中" }}</u-button
          >
          <!-- <view class="flex-col items-center button" @click="save">
          <text>提交认证</text>
        </view> -->
          <text class="text_25">示例</text>
          <view class="grid">
            <view class="grid-item flex-col items-center">
              <image class="image_14" src="/static/common/img/身份证正面.png" />
              <text style="color: #fff">身份证正面</text>
            </view>
            <view class="flex-col items-center grid-item">
              <image class="image_14" src="/static/common/img/身份证反面.png" />
              <text style="color: #fff">身份证反面</text>
            </view>
            <view class="grid-item flex-col items-center">
              <image class="image_14" src="/static/common/img/个人工作证.png" />
              <text style="color: #fff">个人工作证</text>
            </view>
            <view v-if="roleId == 0" class="grid-item flex-col items-center">
              <image
                class="image_14"
                src="/static/common/img/企业营业执照.png"
              />
              <text style="color: #fff">企业营业执照</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 地址 -->
      <u-picker
        v-model="address"
        :area-code="addressId"
        mode="region"
        @confirm="selectAddress"
      ></u-picker>
      <!-- 性别 -->
      <u-select
        v-model="sex"
        :default-value="sexId"
        :list="sexList"
        mode="single-column"
        @confirm="selectSex"
      >
      </u-select>
      <!--校内职务-->
      <u-select
        v-model="schoolPost"
        :default-value="schoolPostId"
        :list="schoolPostList"
        mode="single-column"
        @confirm="selectScpost"
      ></u-select>
      <!--所属院系-->
      <u-select
        v-model="college"
        :default-value="collegeId"
        :list="CollegeList"
        mode="single-column"
        @confirm="selectCpllege"
      ></u-select>
      <!--具体职位-->
      <u-select
        v-model="job"
        :default-value="jobId"
        :list="jobList"
        mode="single-column"
        @confirm="selectJob"
      >
      </u-select>
      <!-- 学校 -->
      <u-select
        v-model="shoolShow"
        :default-value="shoolId"
        :list="shoolList"
        mode="single-column"
        title="学校选择"
        @confirm="shoolSelect"
      >
      </u-select>
      <!-- 出生日期 -->
      <u-picker
        v-model="birthdays"
        :default-time="birthdaysId"
        :end-year="EndYear"
        mode="time"
        @confirm="selectBirthdays"
      ></u-picker>
      <!-- 籍贯 -->
      <u-picker
        v-model="NativePlace"
        :area-code="NativePlaceId"
        mode="region"
        @confirm="selectNativePlace"
      >
      </u-picker>
      <!-- 工作领域 -->
      <u-select
        v-model="WorkArea"
        :default-value="WorkAreaId"
        :list="WorkAreaList"
        mode="single-column"
        @confirm="selectWorkArea"
      ></u-select>
      <!-- 提示 -->
      <u-top-tips ref="uTips" :navbar-height="0"></u-top-tips>
      <u-toast ref="uToast" />
    </view>
    <view class="flex-col group_3 preference-page" v-if="step == 1">
      <u-navbar
        title="推荐偏好"
        :custom-back="back"
        :border-bottom="false"
      ></u-navbar>
      <view class="selected-count">
        已选择（{{ selectedInterests.length }}/10）
        <text class="desc"
          >您选择的标签将影响系统推荐给你的信息类型，进入系统后可以在我的-个人信息中修改。</text
        >
      </view>

      <view class="selected-tags">
        <view
          v-for="item in selectedInterests"
          :key="item.lableId"
          class="tag selected"
        >
          {{ item.lableName }}
          <image
            class="close-btn"
            src="/static/common/img/handDelete.png"
            @click.stop="removeInterest(item)"
          ></image>
        </view>
      </view>
      <view class="line"></view>
      <view class="all-tags">
        <view class="title">兴趣爱好</view>
        <view class="tags-list">
          <view
            v-for="item in interestList"
            :key="item.lableId"
            class="tag"
            :class="{ selected: selectedInterests.includes(item) }"
            @click="toggleInterest(item)"
            >{{ item.lableName }}</view
          >
        </view>
      </view>
      <view class="line-shadow"></view>
      <view class="btn-box">
        <u-button
          shape="circle"
          class="button"
          type="primary"
          @click="finishPreference"
          >完成</u-button
        >
      </view>
      <u-toast ref="uToast" />
    </view>
  </view>
</template>

<script>
import { Debounce } from "../../common/utils.js";
import idcardPositive from "@/static/common/img/上传身份证正面.png";
import idcardBack from "@/static/common/img/上传身份证反面.png";
import workCard from "@/static/common/img/上传个人工作证.png";
import enterprisesImg from "@/static/common/img/上传营业执照.png";
export default {
  data() {
    return {
      step: 0,
      state: true,
      headerImg: "",
      title: "教职工认证",
      action: "/app/User/File",
      teacherId: "",
      // input 样式
      inputStyle: {
        lineHeight: "0.5rem",
        height: "0.5rem",
        width: "2rem",
      },
      shoolName: "",
      sex: false, //性别选择框的显示/隐藏
      shoolShow: false, //学校选择框的显示/隐藏
      schoolPost: false, //校内职务选择框的显示/隐藏
      sexList: [
        //性别选择框内容
        {
          label: "男",
          value: "0",
        },
        {
          label: "女",
          value: "1",
        },
      ],
      schoolPostList: [
        //校内职务选择框内容
        {
          label: "教师",
          value: "0",
        },
        {
          label: "行政管理",
          value: "1",
        },
        {
          label: "后勤",
          value: "2",
        },
      ],
      jobList: [
        //具体职务
        {
          label: "助教",
          value: "0",
        },
        {
          label: "讲师",
          value: "1",
        },
        {
          label: "副教授",
          value: "2",
        },
        {
          label: "教授",
          value: "3",
        },
      ],
      header: {
        Authorization: "",
      },
      shoolList: [], //学校选择
      CollegeList: [], //院系选择,
      sexId: [0], //记录选择的性别进行数据复现
      shoolId: [0], //默认选择学校
      schoolPostId: [0], //默认选择的校内职务
      jobId: [0], //默认选择具体职务
      collegeId: [0], //默认选择所属院系
      address: false, //现居地址选择框的显示/隐藏
      addressId: [11, 1101, 110101], //记录选择的现居地址进行数据复现
      birthdays: false, //出生日期选择框的显示/隐藏
      birthdaysId: "", //记录选择的出生日期进行数据复现
      EndYear: 2022, //出生日期选择框的最大年份
      NativePlace: false, //籍贯选择框的显示/隐藏
      NativePlaceId: [11, 1101, 110101], //记录选择的籍贯进行数据复现
      WorkArea: false, //工作领域选择框的显示/隐藏
      WorkAreaId: [0], //记录选择的工作领域进行数据复现
      //工作领域选择框内容
      WorkAreaList: [],
      form: {
        name: "",
        realName: "",
        sex: "",
        birthdays: "",
        phone: "",
        NativePlace: "",
        address: "",
        DetailedAddress: "",
        WorkArea: "",
        schoolId: "",
        job: "",
        businessName: "",
        businessAddress: "",
        businessUser: "",
        businessLicense: "",
        schoolJob: "",
        faculty: "",
      },
      job: false,
      roleId: "2",
      college: false,
      isDisabled: false,
      route: "", //判断提交成功之后的页面
      idcardPositive: idcardPositive,
      idcardBack: idcardBack,
      workCard: workCard,
      enterprisesImg: enterprisesImg,
      interestList: [], // 兴趣爱好列表
      selectedInterests: [], // 已选择的兴趣爱好
    };
  },
  onLoad(e) {
    this.imgResFn();
    this.action = this.$u.http.config.baseUrl + this.action;
    this.header.Authorization = "Bearer " + this.vuex_token;
    this.roleId = "2";
    let name = this.vuex_user.name;
    console.log("name-");
    if (this.roleId == 0) {
      this.title = "企业认证";
      this.form.businessUser = name;
    } else if (this.roleId == 2) {
      this.title = "教职工认证";
      this.form.name = name;
    } else if (this.roleId == 1) {
      this.title = "管理员认证";
      this.form.name = name;
    }

    if (this.vuex_userInfo.realName) {
      this.form.realName = this.vuex_userInfo.realName;
    }

    this.EndYear = new Date().getFullYear();
    this.form.phone = this.vuex_user.phone;
    this.getschoolId();
    this.getShool();
    this.getWorkFile();
    this.echoFn();
  },
  created() {},
  methods: {
    back() {
      if (this.step > 0) {
        this.step--;
      } else {
        uni.navigateBack();
      }
    },
    // 回填个人信息  如果已经存在学生身份，教师身份未认证时
    async echoFn() {
      const res = await this.$u.apiList.SelectUserTypeApi();
      console.log(res, "res---");
      const jzgFlag = res.jzgFlag;
      const studentFlag = res.studentFlag;
      if (studentFlag === true && jzgFlag === false) {
        this.form.realName = this.vuex_user.name;
        this.form.sex = this.vuex_user.sex;
        this.headerImg = this.$u.http.config.baseUrl + this.vuex_user.head;
        this.form.path = this.vuex_user.head;
      }
    },
    imgResFn() {
      // 监听从裁剪页发布的事件，获得裁剪结果
      uni.$on("uAvatarCropper", (path) => {
        this.headerImg = path;
        let file = this.common.base64toFile(path, new Date().getTime());
        if (file.type.indexOf("image") < 0) {
          // this.$tips("请选择图片", "error");
          this.$refs.uToast.show({
            title: "请选择图片",
            type: "error",
          });

          return false;
        }
        uni.uploadFile({
          url: this.$u.http.config.baseUrl + "/app/User/File",
          file: file,
          fileType: "image",
          header: {
            Authorization: "Bearer " + this.vuex_token,
          },
          complete: (res) => {
            console.log(res, "res--");
            this.form.path = JSON.parse(res.data).data;
          },
        });
      });
    },
    // 头像裁剪
    chooseAvatar() {
      // 此为uView的跳转方法，详见"文档-JS"部分，也可以用uni的uni.navigateTo
      this.$u.route({
        // 关于此路径，请见下方"注意事项"
        url: "/uview-ui/components/u-avatar-cropper/u-avatar-cropper",
        // 内部已设置以下默认参数值，可不传这些参数
        params: {
          // 输出图片宽度，高等于宽，单位px
          destWidth: 200,
          // 裁剪框宽度，高等于宽，单位px
          rectWidth: 200,
          // 输出的图片类型，如果'png'类型发现裁剪的图片太大，改成"jpg"即可
          fileType: "jpg",
        },
      });
    },
    //获取学校id
    getschoolId() {
      this.$u.apiList.GetUserSchool().then((res) => {
        // 学生时
        if ([0, 2].includes(this.vuex_user.userType)) {
          this.form.schoolId = res.items.schoolId;
          this.shoolName = res.items.school.name;
        }
        // 教师时
        if (this.vuex_user.userType === 1) {
          this.form.schoolId = res.jzgItems.schoolId;
          this.shoolName = res.jzgItems.school.name;
        }

        this.getColleg();
      });
    },
    // 获取学校
    getShool() {
      this.$u.api.GetAllSchool().then((res) => {
        for (let i = 0; i < res.length; i++) {
          this.shoolList.push({
            label: res[i].schoolName + "",
            value: res[i].id + "",
          });
        }
      });

      setTimeout(() => {
        if (this.vuex_userInfo.schoolName) {
          this.shoolName = this.vuex_userInfo.schoolName.name;
          this.form.schoolId = this.vuex_userInfo.schoolName.id;
          this.getColleg(this.form.schoolId, this.shoolName);

          // console.log(this.vuex_userInfo.schoolName.id);
          // console.log('this.form',this.form);
        }
      }, 300);
    },
    //获取学院
    getColleg() {
      const data = {
        schoolid: this.form.schoolId,
        // name:name
      };
      this.form.faculty = "";
      this.$u.apiList.GetCollegeList(data).then((res) => {
        this.CollegeList = [];
        for (let i = 0; i < res.length; i++) {
          this.CollegeList.push({
            label: res[i].name + "",
            value: res[i].id + "",
          });
        }
      });
    },
    //获取工作领域
    getWorkFile() {
      this.$u.apiList.GetWorkFile().then((res) => {
        this.teacherId = res.find((item) => item.workFieldName === "教师").id;
        this.WorkAreaList = res.map((item) => {
          return {
            label: item.workFieldName,
            value: item.id,
          };
        });
      });
    },
    // 提示
    tips(title, type, time) {
      if (this.$refs.uToast) {
        this.$refs.uToast.show({
          title: title ? title : "",
          type: type ? type : "success",
          duration: time ? time + "" : "1000",
        });
      } else {
        uni.showToast({
          title: title,
          icon: type === "error" ? "none" : "success",
          duration: time || 1000,
        });
      }
    },
    // 保存
    save: Debounce(function (e) {
      let data = this.form;
      this.form.userId = this.vuex_user.id;
      if (this.roleId == 1) {
        if (data.name === "") {
          this.tips("请输入用户名", "error");
          return;
        }
        //  var reg = new RegExp("^[1][3,4,5,7,8,9][0-9]{9}$", "g"); //手机号
        //  if (data.phone === "" || !reg.test(data.phone)) {
        // this.tips("请输入正确的手机号码", "error");
        // return;
        //  }
        if (data.schoolId === "") {
          this.tips("请选择学校", "error");
        }
        // if(data.job === ""){
        //  this.tips("请选择职业","error")
        // }
        if (!this.filecheck()) {
          return;
        }
        this.SubmitAttestationGLY();
      } else if (this.roleId == 0) {
        if (data.businessName === "") {
          this.tips("请输入企业名称", "error");
          return;
        }
        if (data.businessAddress === "") {
          this.tips("请输入企业地址", "error");
          return;
        }
        // if(data.phone === ""){
        //  this.tips("请输入联系方式", "error");
        //  return;
        // }
        if (data.job === "") {
          this.tips("请输入申请人职务", "error");
          return;
        }
        if (!this.filecheck()) {
          return;
        }
        this.SubmitAttestationQY();
      } else if (this.roleId == 2) {
        console.log("2022222222222222");
        if (!this.headerImg) {
          this.tips("请上传头像", "error");
          return;
        }
        let reg = new RegExp("^[\u4e00-\u9fa5]{0,}$", "g"); //真实姓名
        if (data.realName === "" || !reg.test(data.realName)) {
          this.tips("请输入正确的真实姓名", "error");
          return;
        }
        if (!data.sex) {
          this.tips("请选择性别", "error");
          return;
        }
        //  var reg1 = new RegExp("^[1][3,4,5,7,8,9][0-9]{9}$", "g"); //手机号
        //  if (data.phone === "" || !reg1.test(data.phone)) {
        // this.tips("请输入正确的手机号码", "error");
        // return;
        //  }
        if (!this.shoolName) {
          this.tips("请选择入职学校", "error");
          return;
        }
        if (data.schoolJob === "") {
          this.tips("请选择校内职务", "error");
          return;
        }
        if (data.schoolJob === "教师") {
          if (data.faculty === "") {
            this.tips("请输入所属院系", "error");
            return;
          }
          if (data.job === "") {
            this.tips("请选择具体职位", "error");
            return;
          }
        }
        if (!this.filecheck()) {
          return;
        }
        this.step = 1;
        this.GetInterestLable();
        // this.SubmitAttestationJZG();
      }
    }, 1000),

    filecheck() {
      let file1 = this.$refs.uUpload1.lists[0];
      let file2 = this.$refs.uUpload2.lists[0];
      let file3 = this.$refs.uUpload3.lists[0];
      if (!file1) {
        this.tips("请上传身份证正面", "error");
        return false;
      }
      if (!file2) {
        this.tips("请上传身份证反面", "error");
        return false;
      }
      if (!file3) {
        this.tips("请上传个人工作证", "error");
        return false;
      }
      if (this.roleId == 0) {
        let file4 = this.$refs.uUpload4.lists[0];
        if (!file4) {
          this.tips("请上传企业营业执照", "error");
          return false;
        }
      }
      return true;
    },
    // 盘判断出生日期
    isBirthday(data) {
      return new Date(data) >= new Date();
    },
    // 选择工作领域
    selectWorkArea(e) {
      this.form.job = e[0].label;
      this.WorkAreaId = [parseInt(e[0].value)];
    },
    // 选择籍贯
    selectNativePlace(e) {
      this.form.NativePlace =
        e.province.label + "-" + e.city.label + "-" + e.area.label;
      var arr = [];
      //   - 0 是转化为隐式转换为数组类型
      arr.push(e.province.value - 0);
      arr.push(e.city.value - 0);
      arr.push(e.area.value - 0);
      this.NativePlaceId = arr;
    },
    // 选择出生日期
    selectBirthdays(e) {
      this.form.birthdays = e.year + "-" + e.month + "-" + e.day;
      this.birthdaysId = e.year + "-" + e.month + "-" + e.day;
    },
    //   选择性别
    selectSex(e) {
      this.form.sex = e[0].label;
      this.sexId = [parseInt(e[0].value)];
    },
    //   选择校内职务
    selectScpost(e) {
      if (e[0].label == "教师") {
        this.isDisabled = true;
      } else {
        this.form.faculty = "";
        this.form.job = "";
        this.isDisabled = false;
      }
      this.form.schoolJob = e[0].label;
      this.schoolPostId = [parseInt(e[0].value)];
    },
    //选择所属院系
    selectCpllege(e) {
      this.form.faculty = e[0].label;
      this.collegeId = [parseInt(e[0].value)];
    },
    //   选择具体职务
    selectJob(e) {
      this.form.job = e[0].label;
      this.jobId = [parseInt(e[0].value)];
    },
    //   选择地址
    selectAddress(e) {
      this.form.businessAddress =
        e.province.label + "-" + e.city.label + "-" + e.area.label;
      var arr = [];
      //   - 0 是转化为隐式转换为数组类型
      arr.push(e.province.value - 0);
      arr.push(e.city.value - 0);
      arr.push(e.area.value - 0);
      this.addressId = arr;
    },
    // 学校选择
    shoolSelect(e) {
      this.shoolName = e[0].label;
      this.form.schoolId = e[0].value;
      this.getColleg(this.form.schoolId, this.shoolName);
    },
    // 提交管理员认证
    SubmitAttestationGLY() {
      this.state = false;
      this.$u.apiList.SubmitAttestationGLY(this.form).then((res) => {
        this.state = true;
        if (this.route == "my") {
          this.$refs.uToast.show({
            title: "提交认证成功",
            type: "success",
          });
          setTimeout(() => {
            uni.switchTab({
              url: "../../my/my/my",
            });
          }, 2000);
        } else {
          this.$refs.uToast.show({
            title: "提交认证成功",
            type: "success",
            url: "pages/my/authentication/authentication",
          });
        }
      });
    },
    //提交企业认证
    SubmitAttestationQY() {
      this.state = false;
      setTimeout(() => {
        this.state = true;
        // uni.showToast({
        //   title: '提交异常,请联系管理员',
        //   icon: 'none'
        // })
      }, 5000);
      this.$u.apiList
        .SubmitAttestationQY(this.form)
        .then((res) => {
          this.state = true;
          this.$refs.uToast.show({
            title: "提交认证成功",
            type: "success",
            url: "pages/my/authentication/authentication",
          });
        })
        .catch((err) => {
          this.state = true;
          this.tips("保存错误", "error");
        });
    },
    //TODO 提交教职工认证
    SubmitAttestationJZG() {
      this.state = false;
      let data = {
        ...this.form,
        userType: 1,
        // 塞字段
        path: this.form.path,
        name: this.form.realName,
        userName: this.form.realName,
        jzgName: this.form.realName,
        workFieldId: this.teacherId,
        list: this.form.list,
      };
      console.log(data, "data--");
      // return
      this.$u.apiList.UpdateUserJZG(data).then(async (res) => {
        console.log(res, "res---认证后返的educationId");
        this.state = true;
        // this.$refs.uToast.show({
        //   title: '提交认证成功',
        //   type: 'success',
        //   // url: 'pages/my/authentication/authentication'
        // })
        this.$refs.uToast.show({
          title: "提交认证成功",
          type: "success",
        });
        // return
        // 选中这个学校
        const req = {
          userId: this.vuex_user.id,
          educationId: res,
        };
        const result = await this.$u.apiList.SelectJZGApi(req);
        this.$u.vuex("vuex_token", result.token);
        this.$u.vuex("vuex_glyType", result.glyType);
        this.$u.vuex("vuex_user", result.user);
        //  把这个改成true
        this.$u.vuex("vuex_user.isFill", true);
        setTimeout(() => {
          uni.switchTab({
            url: "/pages/main/index/index",
          });
        }, 800);
      });
    },
    //图片上传成功
    onSuccess(data, index, lists, name) {
      if (name == 0) {
        this.form.imgFront = data.data;
      } else if (name == 1) {
        this.form.imgReverse = data.data;
      } else if (name == 2) {
        this.form.imgWork = data.data;
      } else if (name == 3) {
        this.form.businessLicense = data.data;
      }
    },
    async GetInterestLable() {
      const res = await this.$u.apiList.GetInterestLable();
      console.log("获取标签", res);
      this.interestList = res;
    },
    toggleInterest(item) {
      // 先判断是否已达到最大选择数量
      if (this.selectedInterests.length >= 10) {
        // uni.showToast({
        //   title: "最多选择10个",
        //   icon: "none",
        //   duration: 2000
        // });
        this.$refs.uToast.show({
          title: "最多选择10个",
          type: "error",
        });
        return;
      }

      // 从 interestList 中查找并移除标签
      const interestIndex = this.interestList.findIndex(
        (i) => i.lableId === item.lableId
      );
      if (interestIndex > -1) {
        this.interestList.splice(interestIndex, 1);
        // 添加到已选择列表
        this.selectedInterests.push(item);
      }
    },
    removeInterest(item) {
      // 从已选择列表中移除
      const selectedIndex = this.selectedInterests.findIndex(
        (i) => i.lableId === item.lableId
      );
      if (selectedIndex > -1) {
        this.selectedInterests.splice(selectedIndex, 1);
        // 添加回 interestList
        this.interestList.push(item);
      }
    },
    async finishPreference() {
      if (this.selectedInterests.length === 0) {
        this.$refs.uToast.show({
            title: "请至少选择一个标签",
            type: "error",
          });
        return;
      }

      try {
        // 构建标签列表
        const interestList = this.selectedInterests.map((item) => ({
          lableId: item.lableId,
        }));

        this.form.list = interestList;
        await this.SubmitAttestationJZG();
      } catch (error) {
        uni.showToast({
          title: "保存失败，请重试",
          icon: "none",
          duration: 2000,
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.file {
  .group_9 {
    padding: 0.14rem 0.25rem 0;
    background-color: rgb(246, 247, 250);
    padding-bottom: 0.2rem;

    .text_23 {
      color: rgb(46, 155, 255);
      font-size: 0.12rem;
      line-height: 0.16rem;
      white-space: nowrap;
    }

    .button {
      margin: 0.14rem 0.07rem 0 0.08rem;
      padding: 0.12rem 0;
      color: rgb(255, 255, 255);
      font-size: 0.15rem;
      line-height: 0.16rem;
      letter-spacing: 0.03rem;
      white-space: nowrap;
      background-color: rgb(46, 155, 255);
      border-radius: 0.1rem;
    }

    .text_25 {
      margin-left: 0.025rem;
      margin-top: 0.21rem;
      color: rgb(164, 174, 183);
      font-size: 0.15rem;
      line-height: 0.14rem;
      letter-spacing: 0.03rem;
      white-space: nowrap;
    }

    .grid {
      margin: 0.1rem 0.03rem 0 0.02rem;
      height: 1.61rem;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-row-gap: 0.11rem;
      grid-column-gap: 0.11rem;

      .grid-item {
        background-color: rgb(176, 191, 205);
        border-radius: 0.05rem;
      }

      .grid-item_1 {
        padding: 0.23rem 0 0.29rem;
        background-color: rgb(176, 191, 205);
        border-radius: 0.05rem;
      }

      .image_14 {
        width: 100%;
        height: 0.8rem;
      }
    }
  }

  .section_4 {
    width: calc(100% - 60rpx);
    margin: 20rpx auto;
    background: #fff;
    border-radius: 20rpx;
    padding: 30rpx;

    .text_11 {
      color: #191919;
      font-size: 32rpx;
      white-space: nowrap;
    }

    .equal-division {
      margin-top: 0.13rem;
      color: rgb(46, 155, 255);
      font-size: 0.12rem;
      line-height: 0.16rem;
      white-space: nowrap;

      .equal-division-item {
        display: flex;
        flex-direction: row;
        justify-content: center;
        margin-bottom: 20rpx;

        .text_11 {
          color: #191919;
          font-size: 32rpx;
          white-space: nowrap;
        }

        .section_5 {
          // padding: 0.17rem 0.22rem 0.14rem 0.22rem;
          border-radius: 0.05rem;
          // border: 1px dotted #66b5ff;
        }

        .text_16 {
          margin-top: 0.055rem;
          align-self: center;
        }
      }

      .equal-division-item_1 {
        max-width: 48.5%;
        margin-left: 0.14rem;
        flex: 1 1 1.6rem;

        .text_11 {
          color: #191919;
          font-size: 32rpx;
          white-space: nowrap;
        }

        .section_6 {
          padding: 0.17rem 0.22rem 0.14rem 0.22rem;
          border-radius: 0.05rem;
          border: 1px dotted #66b5ff;
        }

        .text_19 {
          margin-top: 0.05rem;
          align-self: center;
        }
      }

      .top-section {
        padding: 0.12rem 0 0.1rem;
        border-radius: 0.05rem;
        background: #eff7ff;

        .image_6 {
          width: 0.22rem;
          height: 0.17rem;
        }

        .text_12 {
          margin-left: 0.075rem;
          margin-top: 0.015rem;
        }
      }

      .bottom-section {
        margin-top: 0.1rem;
        padding: 0.09rem 0.17rem 0.13rem;
        border-radius: 0.05rem;
        background: #eff7ff;

        .image_8 {
          margin-right: 0.08rem;
          width: 0.23rem;
          height: 0.17rem;
        }

        .text_14 {
          margin-top: 0.015rem;
        }
      }
    }
  }
}

.form {
  // border: 1px solid red;
  // margin-top: -0.3rem;
  .headerImg {
    padding-bottom: 0.05rem;
  }

  .section_2 > view > view {
    margin-left: 0.21rem;
    padding: 0 !important;
    border-bottom: 0.01rem solid #edeeef;
    position: relative;
  }

  .section_2 > view > view .input,
  .section_2 > view > view text {
    line-height: 0.5rem;
  }

  .section_2 > view > view .input {
    padding-right: 0.2rem !important;
  }

  .section_2 > view > view text {
    margin-right: 0.1rem;
    min-width: 0.91rem;
    white-space: nowrap;
  }

  .section_2 > view > view image {
    position: absolute;
    top: 50%;
    right: 0.14rem;
    transform: translateY(-50%);
  }

  .image_3 {
    width: 0.075rem;
    height: 0.13rem;
  }

  .group {
    flex: 1 1 auto;
    overflow-y: auto;
  }

  .section_2 {
    padding: 0.055rem 0 0 0;
    background-color: rgb(255, 255, 255);
  }

  .group_16 {
    margin-top: 0.21rem;
    padding: 0 0.02rem;
  }

  .button_1,
  .button {
    padding: 0.13rem 0;
    color: rgb(255, 255, 255);
    font-size: 0.15rem;
    line-height: 0.14rem;
    letter-spacing: 0.03rem;
    white-space: nowrap;
    background-color: rgb(46, 155, 255);
    border-radius: 0.1rem;
    width: 3.1rem;
    margin: 0 auto;
  }

  .button_1 {
    margin-top: 0.1rem;
    color: rgb(55, 59, 72);
    background-color: rgb(255, 255, 255);
    border: solid 0.01rem rgba(160, 162, 172, 0.33);
    margin-bottom: 0.2rem;
  }

  .view_1 {
    margin-left: 0.02rem;
  }

  .text_15 {
    color: rgb(55, 59, 72);
    font-size: 0.15rem;
    line-height: 0.16rem;
    white-space: nowrap;
  }

  .image_2 {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    overflow: hidden;
  }

  .image_4 {
    margin-right: 0.15rem;
    margin-top: 0.28rem;
  }
}
.jzg-box {
  // margin-top:-0.5rem;
  .img-box {
    .text_4 {
      text-align: center;
      margin-top: 0.15rem;
      margin-bottom: 0.15rem;
      color: rgb(153, 153, 153);
      font-size: 0.14rem;
      font-family: PingFang;
      line-height: 0.13rem;
    }
  }
}
::v-deep .u-add-wrap {
  display: none !important;
}

.preference-page {
  background: #fff;
  // height: 100%;
  // height: calc(100vh - 300rpx);
  display: flex;
  flex-direction: column;

  .selected-count {
    padding: 24rpx;
    font-weight: bold;
    font-size: 32rpx;
    line-height: 48rpx;
    color: rgba(0, 0, 0, 0.9);
    .desc {
      display: block;
      font-weight: 400;
      font-size: 24rpx;
      color: rgba(0, 0, 0, 0.6);
      line-height: 40rpx;
      margin-top: 8rpx;
    }
  }
  .selected-tags {
    padding: 0 24rpx;
    display: flex;
    flex-wrap: wrap;
    gap: 24rpx 24rpx;

    .tag {
      display: flex;
      align-items: center;
      background: #3cb5fb;
      color: #fff;
      border-radius: 64rpx;
      padding: 20rpx;
      font-size: 28rpx;
      position: relative;
      margin-right: 0;
      margin-bottom: 0;
      box-sizing: border-box;
      justify-content: flex-start;
      gap: 6rpx;
    }

    .close-btn {
      font-size: 28rpx;
      margin-right: 8rpx;
      cursor: pointer;
      color: #fff;
      font-weight: bold;
      line-height: 1;
      display: inline-block;
      width: 32rpx;
      height: 32rpx;
      text-align: center;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.18);
    }
  }
  .line {
    width: 100%;
    height: 4rpx;
    background: #f6f8f9;
    margin-top: 24rpx;
    margin-bottom: 44rpx;
  }
  .line-shadow {
    width: 100%;
    height: 2rpx;
    background: #ffffff;
    box-shadow: 0rpx -6rpx 12rpx 0rpx rgba(0, 0, 0, 0.05);
    margin-top: 56rpx;
  }
  .all-tags {
    padding: 0 24rpx;
    .title {
      font-weight: bold;
      font-size: 32rpx;
      color: rgba(0, 0, 0, 0.9);
      margin-bottom: 18rpx;
    }
    .tags-list {
      display: flex;
      flex-wrap: wrap;
      gap: 24rpx 24rpx;
      margin-bottom: 32rpx;
      padding-bottom: 100rpx;
      .tag {
        background: #f6f8f9;
        color: #333;
        border-radius: 200rpx;
        padding: 20rpx 32rpx;
        font-size: 28rpx;
        &.selected {
          background: #3cb5fb;
          color: #fff;
        }
      }
    }
  }
  .btn-box {
    position: fixed;
    bottom: 62rpx;
    left: 0;
    right: 0;
    padding: 0 24rpx;
  }
  .button {
    margin: 48rpx 0 0 0;
    width: 100%;
  }
}
</style>
