<template>
  <el-form ref="form" :model="value" :rules="rules" label-width="100px">
    <el-row>
      <el-col :span="24">
        <el-form-item label="专家头像:" prop="image">
          <ImageUpload
            v-model="value.image"
            :isShowTip="true"
            :fileSize="2"
            :limit="1"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item label="姓名:" prop="name">
          <el-input
            v-model="value.name"
            :disabled="isAdd ? false : true"
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="手机号:" prop="mobile">
          <el-input
            v-model="value.mobile"
            :disabled="isAdd ? false : true"
          ></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item label="所属单位:" prop="research_id">
          <el-select
            v-model="value.research_id"
            filterable
            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="12">
        <el-form-item label="所属实验室:">
          <el-select
            v-model="value.laboratory_id"
            filterable
            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-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="所属站点:" prop="tenant_id">
          <SiteOptions :size="''" :limitWidth="false" v-model="value" />
        </el-form-item>
      </el-col>
    </el-row>

    <CityOptions v-model="value" ref="cityForm" />

    <el-row>
      <el-col :span="24">
        <el-form-item label="详细地址:">
          <el-input v-model="value.address"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="毕业院校:" prop="school">
          <el-input v-model="value.school"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item label="最高学历:" prop="education">
          <el-select v-model="value.education" placeholder="请选择">
            <el-option
              v-for="item in educationOptions"
              :key="item.text"
              :label="item.text"
              :value="item.text"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="主修专业:" prop="major">
          <el-input v-model="value.major"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item label="职务:" prop="job">
          <el-input v-model="value.job"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="职称:" prop="title">
          <el-input v-model="value.title"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <el-form-item label="从业时间:" prop="work_at">
          <el-date-picker
            v-model="value.work_at"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期"
          >
          </el-date-picker>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="性别:" prop="gender">
          <el-radio v-model="value.gender" :label="1">男</el-radio>
          <el-radio v-model="value.gender" :label="2">女</el-radio>
        </el-form-item>
      </el-col>
    </el-row>

    <FieldOptions v-model="value" ref="fieldForm" />

    <InputBoxAdd
      v-model="value"
      title="关键词"
      placeholder="应用场景关键词+技术产品关键词"
      fieldKey="keywords"
      ref="keywordsForm"
    />
    <InputBoxAdd
      v-model="value"
      title="研究方向"
      placeholder="请输入研究方向"
      fieldKey="researchs"
      ref="researchsForm"
    />

    <el-row>
      <el-col :span="24">
        <el-form-item label="个人简介:" prop="introduce">
          <el-input
            v-model="value.introduce"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 6 }"
          />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import CityOptions from "@/views/components/CityOptions";
import FieldOptions from "@/views/components/FieldOptions";
import InputBoxAdd from "@/views/components/InputBoxAdd";
export default {
  components: {
    CityOptions,
    FieldOptions,
    InputBoxAdd,
  },
  props: {
    value: Object,
    isAdd: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      options: [
        {
          value: "选项1",
          label: "黄金糕",
        },
        {
          value: "选项2",
          label: "双皮奶",
        },
      ],
      rules: {
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
        mobile: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        research_id: [
          { required: true, message: "请选择所属单位", trigger: "change" },
        ],
        tenant_id: [
          {
            required: true,
            message: "请选择所属站点",
            trigger: ["blur", "change"],
          },
        ],
        school: [
          { required: true, message: "毕业院校不能为空", trigger: "blur" },
        ],
        education: [
          { required: true, message: "请选择所最高学历", trigger: "change" },
        ],
        major: [
          { required: true, message: "主修专业不能为空", trigger: "blur" },
        ],
        job: [{ required: true, message: "职务不能为空", trigger: "blur" }],
        title: [{ required: true, message: "职称不能为空", trigger: "blur" }],
        work_at: [
          {
            required: true,
            message: "从业时间不能为空",
            trigger: ["change", "blur"],
          },
        ],
        introduce: [
          { required: true, message: "个人简介不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      const flag = false;
      this.$refs["form"].validate((valid) => {
        const cityForm = this.$refs.cityForm.submitForm();
        const fieldForm = this.$refs.fieldForm.submitForm();
        const keywordsForm = this.$refs.keywordsForm.submitForm();
        const researchsForm = this.$refs.researchsForm.submitForm();
        if (cityForm && fieldForm && keywordsForm && researchsForm) {
          flag = !flag;
        }
      });
      return flag;
    },
  },
};
</script>
<style lang="scss" scoped>
// 上传图片框限制
// ::v-deep .el-upload--picture-card {
//   width: 120px;
//   height: 120px;
//   line-height: 120px;
// }
.el-select,
.el-date-editor {
  display: block;
  width: 100%;
}
</style>