<template>
  <div class="app-container">
    <h1 style="font-size: 30px;text-align: center;">个人信息填写</h1>
    <div class="stylecard">
      <el-card class="box-card1">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="学号" prop="stId" :rules="rules.reason1">
            <el-input v-model="form.stId" placeholder="请输入学号" @blur="changeGet" />
          </el-form-item>
          <el-form-item label="姓名" prop="stName" :rules="rules.reason2">
            <el-input v-model="form.stName" placeholder="请输入姓名" />
          </el-form-item>
          <el-form-item label="辅导员名字" prop="fdName" :rules="rules.reason3">
            <el-input v-model="form.fdName" placeholder="请输入辅导员名字" />
          </el-form-item>
          <el-form-item label="性别" prop="sex" :rules="rules.reason4">
            <el-select v-model="form.sex" placeholder="请选择性别">
              <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="民族" prop="nations" :rules="rules.reason5">
            <!-- <el-input v-model="form.nations" placeholder="请输入民族" /> -->
            <el-select v-model="form.nations" placeholder="请选择民族">
              <el-option v-for="dict in dict.type.rt_nation" :key="dict.value" :label="dict.label"
                :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="班级" prop="stClass" :rules="rules.reason6">
            <el-input v-model="form.stClass" placeholder="请输入班级" />
          </el-form-item>
          <el-form-item label="专业" prop="majors" :rules="rules.reason7">
            <el-input v-model="form.majors" placeholder="请输入专业" />
          </el-form-item>
          <el-form-item label="年级" prop="grade" :rules="rules.reason8">
            <el-input v-model="form.grade" placeholder="请输入年级" />
          </el-form-item>
          <el-form-item label="学院" prop="college" :rules="rules.reason9">
            <!-- <el-input v-model="form.college" placeholder="请输入学院" /> -->
            <el-select v-model="form.college" placeholder="请选择学院" :rules="rules.reason10">
              <el-option v-for="dict in dict.type.rt_filling_college" :key="dict.value" :label="dict.label"
                :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="原因" prop="reasons" :rules="rules.reason10">
            <el-input v-model="form.reasons" placeholder="请输入原因" type="textarea" />
          </el-form-item>
          <el-form-item label="时间" prop="times" :rules="rules.reason11">
            <!-- <el-input v-model="form.times" placeholder="请输入时间" /> -->
            <el-date-picker v-model="form.times" clearable type="date" value-format="yyyy-MM-dd"
              placeholder="请选择填报时间" />
          </el-form-item>

          <!-- 入伍时间 -->
          <el-form-item label="入伍时间" prop="rwTime" :rules="rules.reason11">
            <el-date-picker v-model="form.rwTime" clearable type="date" value-format="yyyy-MM-dd"
              placeholder="请选择填报时间" />
          </el-form-item>

            <!-- 退伍时间 -->
           <el-form-item label="退伍时间" prop="dataa" :rules="rules.reason11">
            <!-- <el-input v-model="form.dataa" placeholder="请输入" /> -->
              <el-date-picker v-model="form.dataa" clearable type="date" value-format="yyyy-MM-dd"
              placeholder="请选择填报时间" />
          </el-form-item>

          <!-- 手机号 -->
          <el-form-item label="手机号" prop="datab" :rules="rules.reason13">
            <el-input v-model="form.datab" placeholder="请输入手机号" />
          </el-form-item>

        
         

          <el-form-item label="专业转换" prop="conversion" :rules="rules.reason12">
            <el-select v-model="form.conversion" placeholder="请选择专业转换">
              <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
                :value="dict.value"></el-option>
            </el-select>

          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-card>

    </div>

    <div slot="footer" class="stylecard">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>


  </div>
</template>

<script>
import { listBasic, getBasic, delBasic, addBasic, updateBasic } from "@/api/routine/basic";
import { listMate, getMate, delMate, addMate, updateMate } from "@/api/routine/mate";
import { getStudentInfoByStuId } from '@/api/routine/stuIdReissue'

export default {
  name: "Basic",
  dicts: ['sys_yes_no', 'sys_user_sex', 'rt_filling_college', 'sys_commit_status', 'sys_teacher_kpi_filling_year', 'rt_nation', 'rt_classes'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退伍复学申请表格数据
      basicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
       queryParams: {
        pageNum: 1,
        pageSize: 10,
        fxId: null,
        fxTime: null,
        stId: null,
        stName: null,
        fdName: null,
        sex: null,
        nations: null,
        fdQm: null,
        xwQm: null,
        erQm: null,
        xjQm: null,
        jwQm: null,
        stClass: null,
        majors: null,
        grade: null,
        college: null,
        reasons: null,
        fdIdea: null,
        twoIdea: null,
        xwIdea: null,
        xjIdea: null,
        jwIdea: null,
        zsIdea: null,
        zsStatus: null,
        times: null,
        fdStatus: null,
        xwStatus: null,
        twoStatus: null,
        xjglStatus: null,
        jwStatus: null,
        rwTime: null,
        zsTime: null,
        fdTime: null,
        xwTime: null,
        twoTime: null,
        xjTime: null,
        jwTime: null,
        datab: null,
        dataa: null,
        conversion: null,
        processId: null,
        deployId: null
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        reason1: [
          { required: true, message: '学号不能为空', trigger: 'blur' },
        ],
        reason2: [
          { required: true, message: '姓名不能为空', trigger: 'blur' },
        ],
        reason3: [
          { required: true, message: '辅导员不能为空', trigger: 'blur' },
        ],
        reason4: [
          { required: true, message: '请选择性别', trigger: 'blur' },
        ],
        reason5: [
          { required: true, message: '请选择民族', trigger: 'blur' },
        ],
        reason6: [
          { required: true, message: '请输入班级', trigger: 'blur' },
        ],
        reason7: [
          { required: true, message: '请输入专业', trigger: 'blur' },
        ],
        reason8: [
          { required: true, message: '请输入年级', trigger: 'blur' },
        ],
        reason9: [
          { required: true, message: '请选择学院', trigger: 'blur' },
        ],
        reason10: [
          { required: true, message: '请填写原因', trigger: 'blur' },
        ],
        reason11: [
          { required: true, message: '请选择时间', trigger: 'blur' },
        ],
        reason12: [
          { required: true, message: '请选择是否专业转换', trigger: 'blur' },
        ],
         reason13: [
          { required: true, message: '请输入手机号', trigger: 'blur' },
        ],
      }

    };
  },
  created() {
    this.getList();
  },
  methods: {

    // 填写学号时自动获取其他信息
    changeGet() {
      this.form.stuId = this.form.stId ? this.form.stId : this.$route.query.stId
      getStudentInfoByStuId(this.form.stuId).then(response => {
        if (response.data == null) {
          this.$message.error('学号不存在')
          return
        }
        this.form = response.data
        console.log(this.form)
        this.form.stId = response.data.stuNo
        this.form.stName = response.data.studentName
        this.form.college = response.data.departmentName
        this.majors = response.data.className
        this.form.sex = response.data.gender
        this.form.grade = response.data.gradeName

      })
    },

    /** 查询退伍复学申请列表 */
    getList() {
      this.loading = true;
      listBasic(this.queryParams).then(response => {
        this.basicList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(this.basicList)
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        stId: null,
        stName: null,
        fdName: null,
        sex: null,
        nations: null,
        stClass: null,
        majors: null,
        grade: null,
        college: null,
        reasons: null,
        times: null,
        fdStatus: null,
        xwStatus: null,
        twoStatus: null,
        xjglStatus: null,
        datab: null,
        dataa: null,
        conversion: null,
        jwcStatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加退伍复学申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getBasic(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改退伍复学申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBasic(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
              // this.form.stId
              this.dataform = {
                id: null,
                stId: this.form.stId,
                stName: this.form.stName,
                times: null,
                college: this.form.college,
                oldgrade: this.form.grade,
                oldmajor: this.form.majors,
                newgrade: null,
                newmajor: null,
                proof: null,
                idcard: null,
                material: null,
                data1: null,
                data2: null
              };
              addMate(this.dataform).then(response => {

                this.open = false;
                this.getList();
              });
            });
          } else {
            addBasic(this.form).then(response => {
              if (response.code === 200) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
                console.log(this.form.stId)
                this.dataform = {
                id: null,
                stId: this.form.stId,
                stName: this.form.stName,
                times: null,
                college: this.form.college,
                oldgrade: this.form.grade,
                oldmajor: this.form.majors,
                newgrade: null,
                newmajor: null,
                proof: null,
                idcard: null,
                material: null,
                data1: null,
                data2: null
              };
              addMate(this.dataform).then(response => {

                this.open = false;
                this.getList();

              });
              if (this.form.conversion == "N") {
                this.$router.push({
                  path: '/routine/dis/appli',
                })
              } else {
                this.$router.push({
                  path: '/routine/dis/disma',
                })
              }
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除退伍复学申请编号为"' + ids + '"的数据项？').then(function () {
        return delBasic(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('routine/basic/export', {
        ...this.queryParams
      }, `basic_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style>
.box-card1 {
  width: 600px;
  max-width: 100%;
  /* 新增：适配小屏幕，避免溢出 */
  text-align: center;
  margin: 0 auto;
  /* 替代原margin-left，实现水平居中更优雅 */
  padding: 20px;
  /* 新增：内边距，提升内容呼吸感 */
  background-color: #fff;
  /* 新增：卡片背景色 */
  border-radius: 8px;
  /* 新增：圆角，增强视觉友好度 */
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  /* 新增：阴影，突出卡片层次 */
  box-sizing: border-box;
  /* 新增：保证width包含padding和border */
  white-space: nowrap
}

.stylecard {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>