<template>
  <div>
    <div class="borderless">
      <div class="customer-head">
        <div class="customer-back">
          <el-button
            type="danger"
            style="border: none;background: none;color: red"
            icon="el-icon-arrow-left"
            @click="backToList"
            >返回列表
          </el-button>
        </div>
        <el-button
          class="el-button--small-yh add-customer-btn"
          type="primary"
          size="small"
          @click="editCustomer"
          >保存数据
        </el-button>
      </div>
      <containerTitle
        title="基础资料"
        style="margin-top: 60px"
      ></containerTitle>
      <basic-container>
        <el-row>
          <el-col :span="18">
            <avue-form
              ref="form"
              class="trading-form"
              v-model="form"
              :option="option"
            />
          </el-col>
          <el-col :span="6">
            <avue-form class="img-form" :option="option4" v-model="form" />
          </el-col>
        </el-row>
        <avue-form
          ref="form"
          class="trading-form"
          v-model="form"
          :option="option2"
        />
      </basic-container>
      <containerTitle title="详细信息"></containerTitle>
      <basic-container>
        <avue-form
          ref="form"
          class="trading-form"
          v-model="form"
          :option="option3"
        />
      </basic-container>
    </div>
  </div>
</template>

<script>
import { detail, submit } from "@/api/basicData/facultyManagement";
export default {
  name: "index",
  data() {
    return {
      form: {},
      option: {
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "姓名",
            prop: "cname",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 8
          },
          {
            label: "工号",
            prop: "code",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 8
          },
          {
            label: "曾用名",
            prop: "usedName",
            span: 8
          },
          {
            label: "性别",
            prop: "gender",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=sex",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 8
          },
          {
            label: "籍贯",
            prop: "nativePlace",
            span: 8
          },
          {
            label: "民族",
            prop: "nation",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=nationa_lity",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 8
          },
          {
            label: "身份证",
            prop: "idNumber",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 8
          },
          {
            label: "出生日期",
            prop: "birthdate",
            type: "date",
            valueFormat: "yyyy-MM-dd",
            span: 8
          },
          {
            label: "婚姻状况",
            prop: "maritalStatus",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=marital_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 8
          },
          {
            label: "政治面貌",
            prop: "politicsStatus",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=politics_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 8
          },
          {
            label: "加入日期",
            prop: "joiningDate",
            type: "date",
            valueFormat: "yyyy-MM-dd",
            span: 8
          },
          {
            label: "健康状况",
            prop: "healthCondition",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=health_condition",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 8
          }
        ]
      },
      option2: {
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "血型",
            prop: "bloodType",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=blood_type",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "家庭住址",
            prop: "familyAddress",
            span: 6
          },
          {
            label: "邮政编码",
            prop: "postalCode",
            span: 6
          },
          {
            label: "户口性质",
            prop: "category",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=category",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "户口所在地",
            prop: "residentCity",
            span: 6
          },
          {
            label: "联系电话",
            prop: "phone",
            span: 6
          },
          {
            label: "电子邮箱",
            prop: "emailAddress",
            span: 6
          },
          {
            label: "宗教信仰",
            prop: "faith",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=faith",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "紧急联系人",
            prop: "contacts",
            span: 6
          },
          {
            label: "紧急联系人电话",
            prop: "contactNumber",
            span: 6
          },
          {
            label: "国别",
            prop: "nationnality",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=nationnality",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "港澳台侨",
            prop: "indentation",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=TF_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          }
        ]
      },
      option3: {
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "编制类别",
            prop: "compileCategory",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=compile_category",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "身份类别",
            prop: "identityCategory",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=identity_category",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "教师类别",
            prop: "teacherCategory",
            type: "select",
            dataType: "string",
            multiple: true,
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=teacher_category",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "工作状态",
            prop: "workingCondition",
            type: "select",
            dicUrl:
              "/api/blade-system/dict-biz/dictionary?code=working_condition",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "现工作单位",
            prop: "currentEmployer",
            span: 12
          },
          {
            label: "所在校区",
            prop: "inCampus",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=in_campus",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "所在部门",
            prop: "inSection",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=in_section",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "所在院系",
            prop: "department",
            type: "select",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=department",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "所在教研室",
            prop: "inStaffRoom",
            type: "select",
            dataType: "string",
            multiple: true,
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=in_staff_room",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6,
            row: true
          },
          {
            label: "双师",
            prop: "doubleTeachers",
            type: "radio",
            dataType: "string",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=TF_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "专业带头人",
            prop: "professionalLeader",
            type: "radio",
            dataType: "string",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=TF_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6
          },
          {
            label: "骨干教师",
            prop: "coreTeacher",
            type: "radio",
            dataType: "string",
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=TF_status",
            props: {
              label: "dictValue",
              value: "dictValue"
            },
            span: 6,
            row: true
          },
          {
            label: "专业特长",
            prop: "professionalExpertise",
            type: "textarea",
            span: 24
          }
        ]
      },
      option4: {
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "个人头像",
            prop: "headPortrait",
            type: "upload",
            listType: "picture-img",
            dataType: "string",
            action: "/api/blade-resource/oss/endpoint/put-file",
            propsHttp: {
              res: "data",
              url: "link"
            }
          }
        ]
      }
    };
  },
  props: {
    detailData: {
      type: Object
    }
  },
  created() {
    if (this.detailData.id) {
      this.getDetail(this.detailData.id);
    }
  },
  methods: {
    getDetail(id) {
      detail(id)
        .then(res => {
          this.form = res.data.data;
        })
        .finally(() => {
          // this.loading = false;
          // this.showBut = true;
          // this.pageLoading = false;
        });
    },
    //修改提交触发
    editCustomer() {
      this.$refs["form"].validate((valid, done) => {
        done();
        if (valid) {
          submit({ ...this.form })
            .then(res => {
              this.$message.success("保存成功");
              this.form = res.data.data;
            })
            .finally(() => {});
        } else {
          return false;
        }
      });
    },
    //返回列表
    backToList() {
      this.$emit("goBack");
    }
  }
};
</script>

<style lang="scss" scoped>
.trading-form ::v-deep .el-form-item {
  margin-bottom: 8px !important;
}
::v-deep .el-form-item__error {
  display: none !important;
}
.img-form ::v-deep .el-form-item {
  height: 150px;
  line-height: 150px;
  margin-bottom: 8px !important;
}
.img-form ::v-deep .avue-upload__icon {
  font-size: 20px;
  width: 150px;
  height: 150px;
  line-height: 150px;
}
</style>
