<template>
  <div class="referInfo">
    <el-form
      ref="referRef"
      :model="referForm"
      label-position="top"
      class="checkForm"
      :rules="referInfoRules"
    >
      <div class="cont_title">个人信息</div>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input
              v-model="referForm.name"
              placeholder="填写真实姓名"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="sex">
            <el-radio-group v-model="referForm.sex" size="small">
              <el-radio label="0">男</el-radio>
              <el-radio label="2">女</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="身份证号" prop="id_card ">
            <el-input
              v-model="referForm.id_card"
              placeholder="填写真实姓名身份证号"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <!-- <el-col :span="4">
          <el-form-item label="出生日期" prop="birthday">
            <el-select v-model="referForm.birthday" clearable placeholder="年">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label=" ">
            <el-select v-model="value" clearable placeholder="月">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="4">
          <el-form-item label=" ">
            <el-select v-model="value" clearable placeholder="日">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="6">
          <el-form-item label="籍贯" prop="jiguan_code">
            <el-select
              v-model="referForm.jiguan_code"
              placeholder="省"
              clearable
              @keyup.enter.native="selsectProvince"
              @change="changeProvince(1, $event)"
            >
              <el-option
                v-for="item in selectProvince"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label=" " prop="">
            <el-select v-model="jiguan_city" clearable placeholder="市">
              <el-option
                v-for="item in selectCityJiguan"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="民族" prop="nation">
            <el-input
              v-model="referForm.nation"
              placeholder="填写民族"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入学年份(高中)" prop="start_school_date ">
            <el-input
              v-model="referForm.startSchoolDate"
              placeholder="填写入学年份(高中)"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="政治面貌" prop="political_status ">
            <el-input
              v-model="referForm.political_status"
              placeholder="填写政治面貌"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号" prop="phone ">
            <el-input
              v-model="referForm.phone"
              placeholder="填写手机号"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="电子邮箱" prop="email">
            <el-input
              v-model="referForm.email"
              placeholder="填写电子邮箱"
              size="small"
              clearable
            />
          </el-form-item>
        </el-col>
      </el-row>

      <div class="cont_title">学校信息</div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form-item label="就读中学" prop="school_province ">
            <el-select
              v-model="referForm.school_province"
              clearable
              placeholder="省"
              @change="changeProvince(2, $event)"
            >
              <el-option
                v-for="item in selectProvince"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label=" " prop="school_city">
            <el-select v-model="referForm.school_city" clearable placeholder="市">
              <el-option
                v-for="item in selectCitySchool"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label=" " prop="school">
            <el-select v-model="referForm.school" clearable placeholder="中学">
              <el-option
                v-for="item in schoolName"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中学联系人" clearable prop="school_contacts ">
            <el-input
              v-model="referForm.school_contacts"
              placeholder="填写中学联系人"
              size="small"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="中学联系电话" clearable prop="school_phone ">
            <el-input
              v-model="referForm.school_phone"
              placeholder="填写中学联系电话"
              size="small"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <div class="cont_title">学习成绩证明材料</div>
      <el-form-item
        label="上传申请资料图片"
        prop="backgroundPicture"
        class="bgPic"
      >
        <div class="bgInfo">1、资料包括：XXXXXXXXXXXXX；</div>
        <div class="bgInfo">
          2、请上传1-10张图片，支持JPG、JPEG、PNG等格式，每张图片不超过10M
        </div>
        <div class="image_add">
          <div class="image_in">
            <i style="font-size: 44px" class="el-icon-circle-plus"> </i>
            <div class="text">上传材料</div>
          </div>

          <img :src="referForm.backgroundPicture" class="avatar" />
        </div>
      </el-form-item>

      <el-form-item class="btn">
        <el-button @click="confirm()">提交资料</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
/* eslint-disable */
import {
  getAccount,
  getAchievementOss,
  setAccount,
  getProAndCity,
  getSchool,
} from "r/index/signUp";
import validator from "common/validator";

export default {
  name: "CheckForm",

  data() {
    return {
      referForm: {
        name: "",
        sex: "",
        id_card: "",
        birthday: "",
        jiguan_code: "",
        nation: "",
        start_school_date: "",
        political_status: "",
        phone: "",
        email: "",
        school_province: "",
        school_city: "",
        school: "",
        school_contacts: "",
        school_phone: "",
      },
      schoolName: [],
      referInfoRules: {
        name: [
          { required: true, message: "真实姓名不能为空！", trigger: "blur" },
        ],
        sex: [{ required: true, message: "性别不能为空！", trigger: "change" }],
        id_card: [
          { required: true, message: "身份证号码不能为空！", trigger: "blur" },
          { validator: validator.validateid_card, trigger: "blur" },
        ],
        birthday: [
          { required: true, message: "出生日期不能为空！", trigger: "change" },
        ],
        jiguan_code: [
          { required: true, message: "籍贯不能为空！", trigger: "change" },
        ],
        nation: [
          { required: true, message: "民族不能为空！", trigger: "blur" },
        ],
        start_school_date: [
          {
            required: true,
            message: "高中入学年份不能为空！",
            trigger: "change",
          },
        ],
        political_status: [
          { required: true, message: "政治面貌不能为空！", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "手机号不能为空！", trigger: "blur" },
          { validator: validator.validatePhone, trigger: "blur" },
        ],
        email: [
          { required: true, message: "邮箱不能为空！", trigger: "blur" },
          { validator: validator.validateEmail, trigger: "blur" },
        ],
        schoolprovince: [
          {
            required: true,
            message: "请选择所在学校省份！",
            trigger: "change",
          },
        ],
        schoolcity: [
          {
            required: true,
            message: "请选择所在学校城市！",
            trigger: "change",
          },
        ],
        school: [
          { required: true, message: "请选择所在学校！", trigger: "change" },
        ],
        school_contacts: [
          { required: true, message: "请选择所在学校！", trigger: "blur" },
        ],
        school_phone: [
          { required: true, message: "请选择所在学校！", trigger: "blur" },
        ],
      },
      selectProvince: [],
      CityName: {},
      selectCityJiguan: [],
      selectCitySchool: [],
      jiguan_city: null,
    };
  },
  created() {
    this.getAccount();
    this.getProAndCity();
    this.getSchool();
    this.getTenYear();
  },

  methods: {
    //获取近10年的年份
    getTenYear() {
      let nowDate = new Date();
      let currentYear = nowDate.getFullYear();
      console.log(nowDate, currentYear);
      let yearArr = [];
      let rxYearArr = [];
      for (let i = 0; i < 22; i++) {
        let year = currentYear - i;
        yearArr.push(year);
      }
      console.log(yearArr);
      for (let i = 0; i < 10; i++) {
        let year = currentYear - i;
        rxYearArr.push(year);
      }
      this.yearArrs = yearArr;
      this.rxYearArrs = rxYearArr;
    },
    // 页面信息个人获取
    getAccount() {
      getAccount({}).then((res) => {
        console.log(res, "getAccount");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
      });
    },
    // 获取省份城市
    getProAndCity() {
      getProAndCity({}).then((res) => {
        console.log(res, "getProAndCity");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
        this.selectProvince = res.data.province_list;
        this.CityName = res.data.city_list;
      });
    },
    changeProvince(type, value) {
      console.log(value, "value");
      let selectCity = [];
      for (const key in this.CityName) {
        if (this.CityName[key].parent_id == value) {
          selectCity.push(this.CityName[key]);
        }
      }
      if(type == 1){
        this.selectCityJiguan = selectCity;
      }else{
         this.selectCitySchool = selectCity;
      }
      
   
    },

    // 获取学校
    getSchool() {
      getSchool({}).then((res) => {
        console.log(res, "getSchool");
        if (res.data.code != 200) {
          return this.$message.error(res.data.message);
        }
        this.schoolName = res.data.school_list;
      });
    },
    confirm() {
      this.$refs["referRef"].validate((valid) => {
        if (!valid) return;
        setAccount({
          name: this.formData.name,
          sex: this.formData.sex,
          id_card: this.formData.id_card,
          birthday: this.formData.birthday,
          jiguan_code: this.formData.jiguan_code,
          nation: this.formData.nation,
          start_school_date: this.formData.start_school_date,
          political_status: this.formData.political_status,
          phone: this.formData.phone,
          email: this.formData.email,
          schoolprovince: this.formData.schoolprovince,
          schoolcity: this.formData.schoolcity,
          school: this.formData.school,
          school_contacts: this.formData.school_contacts,
          school_phone: this.formData.school_phone,
        }).then((res) => {
          console.log(res, "setAccount");
          if (res.data.code != 200) {
            return this.$message.error(res.data.message);
          }
          this.$message.success("提交审核成功");

          // 跳转到报名
          this.$router.push("/signUp/check");
        });
      });
    },
  },
};
</script>

<style scoped lang="scss">
.referInfo {
  padding: 0 50px 110px 50px;
  .checkForm {
    flex: 1;
    .cont_title {
      height: 48px;
      line-height: 48px;
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #12141c;
    }

    ::v-deep .el-form-item {
      margin-bottom: 20px;

      .el-form-item__label {
        height: 32px;
        line-height: 32px;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #12141c;
      }

      .el-form-item__content {
        height: 40px;
        line-height: 40px;

        .el-input {
          height: 40px;

          .el-input__inner {
            height: 40px;
            border-radius: 4px;
            border: 1px solid #e1e3e6;
            background-color: #ffffff;

            &:hover {
              border-color: #60194a;
            }

            &:focus {
              border-color: #60194a;
            }
          }
        }
        // 圆
        .el-radio-group {
          .el-radio {
            .el-radio__label {
              color: #656872;
            }

            .el-radio__input {
              .el-radio__inner {
                width: 20px;
                height: 20px;
                line-height: 20px;
                border-radius: 50%;
                &:hover {
                  border-color: #60194a;
                }
              }

              &.is-checked {
                .el-radio__inner {
                  background: #ffffff !important;
                  border-color: #60194a;

                  &::after {
                    width: 7.5px;
                    height: 7.5px;
                    background: #60194a !important;
                  }
                }
              }
            }
          }
        }
      }

      &.btn {
        .el-form-item__content {
          text-align: center;
        }
      }

      &.bgPic {
        height: 260px;
        .el-form-item__label {
          font-size: 14px;
        }
        .bgInfo {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #a7a2a6;
          line-height: 24px;
        }
        img {
          width: 160px;
          height: 160px;
          border-radius: 4px;
          border: 2px dashed #bcc2ca;
          margin: 0 10px 10px 0;
        }
      }
      .el-select {
        width: 100%;
      }
      .image_add {
        position: relative;
        margin-top: 24px;
        .image_in {
          position: absolute;
          top: 23%;
          left: 7%;
        }
        i {
          font-size: 52px;
          color: #60194a;
        }
        .text {
          font-size: 14px;
          color: #a7a2a6;
          text-align: center;
        }
      }
      .btn {
        text-align: center;
        padding-bottom: 224px;
      }
      .el-button {
        width: 200px;
        height: 50px;
        background: #60194a;
        border-radius: 4px;
        opacity: 0.8;
        line-height: 50px;
        text-align: center;
        color: #fff;
        font-size: 16px;
        padding: 0;
        margin: 30px 0 0 0;
      }
    }
  }
}
</style>
