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

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

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

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

    <InputBoxAdd
      :labelWidth="labelWidth"
      v-model="modelValue"
      title="擅长领域"
      placeholder="请输入擅长领域"
      fieldKey="researchs"
      ref="researchsForm"
    />

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

    <el-row>
      <el-col :span="24">
        <el-form-item label="身份证:" required>
          <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item prop="id_image.front">
                <ImageUpload
                  v-model="modelValue.id_image.front"
                  :isShowTip="false"
                  :limit="1"
                />
              </el-form-item>
              <div style="text-align: center">身份证人像面</div>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="id_image.behind">
                <ImageUpload
                  v-model="modelValue.id_image.behind"
                  :isShowTip="false"
                  :limit="1"
                />
              </el-form-item>
              <div style="text-align: center">身份证国徽面</div>
            </el-col>
            <el-col :span="8">
              <el-form-item prop="id_image.hold">
                <ImageUpload
                  v-model="modelValue.id_image.hold"
                  :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">
            <el-col :span="8">
              <ImageUpload
                v-model="modelValue.credential_image"
                :isShowTip="false"
                :limit="1"
              />
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import CityOptions from "../CityOptions";
import FieldSingle from "../FieldSingle";
import FieldOptions from "../FieldOptions";
import InputBoxAdd from "../InputBoxAdd";
import { researchSelect } from "@/api/identity/index";
export default {
  components: {
    CityOptions,
    FieldSingle,
    FieldOptions,
    InputBoxAdd,
  },
  props: {
    modelValue: Object,
    isAdd: {
      type: Boolean,
      default: true,
    },
    showTitle: {
      type: Boolean,
      default: false,
    },
    labelWidth: {
      type: Number,
      default: 120,
    },
  },
  data() {
    return {
      researchOptions: [],
      rules: {
        product: [{ required: true, message: "请输入", trigger: "blur" }],
        name: [{ required: true, message: "请输入", trigger: "blur" }],
        kind: [{ required: true, message: "请选择", trigger: "change" }],
        code: [{ 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",
          },
        ],
        id_card: [{ required: true, message: "请输入", trigger: "blur" }],
        work_place: [{ required: true, message: "请输入", trigger: "blur" }],
        work_experience: [
          { required: true, message: "请输入", trigger: "blur" },
        ],
        "id_image.front": [
          {
            required: true,
            message: "请上传",
            trigger: ["blur", "change"],
          },
        ],
        "id_image.behind": [
          {
            required: true,
            message: "请上传",
            trigger: ["blur", "change"],
          },
        ],
        "id_image.hold": [
          {
            required: true,
            message: "请上传",
            trigger: ["blur", "change"],
          },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      let flag = false;
      this.$refs["formRef"].validate((valid) => {
        const researchsForm = this.$refs.researchsForm.submitForm();
        const keywordsForm = this.$refs.keywordsForm.submitForm();
        if (valid && researchsForm && keywordsForm) {
          flag = !flag;
        }
      });
      return flag;
    },
  },
  created() {
    researchSelect().then(({ data }) => {
      this.researchOptions = data;
    });
  },
};
</script>
<style lang="scss" scoped>
.form_title {
  font-weight: 700;
  margin-bottom: 30px;
}
::v-deep .el-upload--picture-card {
  width: 100%;
}
::v-deep .hide {
  height: 148px;
}
::v-deep .el-upload-list--picture-card .el-upload-list__item {
  width: 100%;
}
// 上传图片框限制
// ::v-deep .el-upload--picture-card {
//   width: 120px;
//   height: 120px;
//   line-height: 120px;
// }
.el-select,
.el-date-editor {
  display: block;
  width: 100%;
}
</style>