<template>
  <el-form
      ref="formRef"
      :label-width="labelWidth + 'px'"
      :model="modelValue"
      :rules="rules"
  >
    <div v-if="showTitle" class="form_title">基本信息</div>

    <el-row>
      <el-col :span="24">
        <el-form-item label="姓名:" prop="name">
          <el-input v-model="modelValue.name" :disabled="!isAdd"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row v-if="!isAdd">
      <el-col :span="24">
        <el-form-item label="手机号:" prop="mobile">
          <el-input v-model="modelValue.mobile" :disabled="!isAdd"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <!--    ADDEMAIL-->
    <!--    邮箱-->
    <el-row>
      <el-col :span="24">
        <el-form-item label="邮箱" prop="email">
          <el-input placeholder="请输入邮箱" v-model="modelValue.email"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <!--    其他联系方式-->
    <el-row>
      <el-col :span="24">
        <el-form-item label="其他联系方式" prop="otherContact">
          <el-input v-model="modelValue.otherContact"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="身份证号:" prop="idCard">
          <el-input v-model="modelValue.idCard" :disabled="!isAdd"></el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="工作所在地:" prop="wordAddress">
          <el-input v-model="modelValue.wordAddress"/>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="工作经历:" prop="experience">
          <el-input
              v-model="modelValue.experience"
              :autosize="{ minRows: 2, maxRows: 6 }"
              type="textarea"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <!--    <el-row>-->
    <!--      <el-col :span="24">-->
    <!--        <el-form-item label="所属站点:" prop="tenantId">-->
    <!--          <site-options-->
    <!--            v-model="modelValue.tenantId"-->
    <!--            :limitWidth="false"-->
    <!--            :site-list="siteList"-->
    <!--            :size="''"-->
    <!--          />-->
    <!--        </el-form-item>-->
    <!--      </el-col>-->
    <!--    </el-row>-->

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

    <field-options
        ref="researchsFormRef"
        v-model="modelValue"
        :labelWidth="labelWidth"
        placeholder="请选择擅长领域"
    />

    <InputBoxAdd
        ref="keywordsFormRef"
        v-model="modelValue"
        :labelWidth="labelWidth"
        fieldKey="keywords"
        placeholder="应用场景关键词+技术产品关键词"
        title="关键词"
    />

    <el-row>
      <el-col :span="24">
        <el-form-item label="身份证:" >
          <el-row :gutter="20" justify="space-between" type="flex">
            <el-col :span="8">
              <el-form-item prop="idImage.0">
                <ImageUpload
                    v-model="modelValue.idImage[0]"
                    :isShowTip="false"
                    :limit="1"
                />
              </el-form-item>
              <div style="text-align: center">身份证人像面</div>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="idImage.1">
                <ImageUpload
                    v-model="modelValue.idImage[1]"
                    :isShowTip="false"
                    :limit="1"
                />
              </el-form-item>
              <div style="text-align: center">身份证国徽面</div>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="idImage.2">
                <ImageUpload
                    v-model="modelValue.idImage[2]"
                    :isShowTip="false"
                    :limit="1"
                />
              </el-form-item>
              <div style="text-align: center">手持身份证人像面</div>
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="成果经纪资格证书:" prop="credential_image">
          <el-row :gutter="20" justify="space-between" type="flex">
            <el-col :span="8">
              <image-upload
                  v-model="modelValue.certificatePics"
                  :isShowTip="false"
              />
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script setup>
import InputBoxAdd from "@/views/components/InputBoxAdd";
import FieldOptions from "@/views/components/FieldOptions";
import {reactive, ref, toRefs} from "vue";
import {tenantSelect} from "@/api/subPlatform/tenant";
import ImageUpload from "@/components/ImageUpload/index.vue";

// import { researchSelect } from "@/api/dataList/research";
// import { laboratorySelect } from "@/api/dataList/laboratory";
const props = defineProps({
  modelValue: Object,
  isAdd: {
    type: Boolean,
    default: true,
  },
  showTitle: {
    type: Boolean,
    default: false,
  },
  formType: {
    type: Number,
    default: 1,
  },
  labelWidth: {
    type: Number,
    default: 120,
  },
});
const data = reactive({
  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",
      // },
    ],
    idCard: [/*{required: true, message: "请输入", trigger: "blur"}*/],
    workAddress: [{required: true, message: "请输入", trigger: "blur"}],
    experience: [{required: true, message: "请输入", trigger: "blur"}],
    // tenantId: [
    //   {
    //     required: true,
    //     message: "请选择",
    //     trigger: ["blur", "change"],
    //   },
    // ],
    "idImage.0": [
      /*{
        required: true,
        message: "请上传",
        trigger: ["blur", "change"],
      },*/
    ],
    "idImage.1": [
      /*{
        required: true,
        message: "请上传",
        trigger: ["blur", "change"],
      },*/
    ],
    "idImage.2": [
      /*{
        required: true,
        message: "请上传",
        trigger: ["blur", "change"],
      },*/
    ],
  },
});
const {rules} = toRefs(data);

const researchOptions = ref([]);
const formRef = ref();
const keywordsFormRef = ref();
const researchsFormRef = ref();
const siteList = ref([]);

// 获取站点列表
const getSiteList = async () => {
  const resp = await tenantSelect();
  siteList.value = resp.rows;
};
getSiteList();
const validateForm = async function () {
  let formValid;
  try {
    formValid = await formRef.value.validate();
  } catch (error) {
    formValid = false;
  }
  const keywordsFormValid = await keywordsFormRef.value.validateForm(); // 关键词
  const researchsFormValid = await researchsFormRef.value.validateForm(); // 研究方向
  return formValid && keywordsFormValid && researchsFormValid;
};
defineExpose({
  validateForm,
});
</script>
<style lang="scss" scoped>
.form_title {
  font-weight: 700;
  margin-bottom: 30px;
}

//:deep(.el-upload--picture-card) {
//  width: 100%;
//}

//:deep(.hide) {
//  height: 148px;
//}

//:deep(.el-upload-list--picture-card .el-upload-list__item) {
//  width: 100%;
//}

.el-select,
.el-date-editor {
  display: block;
  width: 100%;
}
</style>
