<template>
  <el-form
    ref="form"
    :model="value"
    :rules="rules"
    :label-width="labelWidth + 'px'"
  >
    <div class="form_title" v-if="showTitle">基本信息</div>
    <el-row>
      <el-col :span="24">
        <el-form-item label="机构logo" prop="image">
          <ImageUpload v-model="value.image" :fileSize="2" :limit="1" />
        </el-form-item>
      </el-col>
    </el-row>

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

    <el-row>
      <el-col :span="24">
        <el-form-item label="组织机构代码:" prop="code">
          <el-row type="flex" justify="space-between">
            <el-col :span="20">
              <el-input v-model="value.code" :disabled="!isAdd"></el-input>
            </el-col>
            <el-col :span="3">
              <el-button type="primary" @click="" :disabled="!isAdd"
                >查找</el-button
              >
            </el-col>
          </el-row>
        </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" :labelWidth="labelWidth" 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>

    <FieldSingle
      v-model="value"
      :isAdd="isAdd"
      :labelWidth="labelWidth"
      ref="fieldForm"
    />

    <InputBoxAdd
      :labelWidth="labelWidth"
      v-model="value"
      title="研究方向"
      placeholder="请输入研究方向"
      fieldKey="researchs"
      ref="directionsForm"
    />

    <el-row>
      <el-col :span="24">
        <el-form-item label="营业执照:" prop="license">
          <ImageUpload v-model="value.license" :isShowTip="false" :limit="1" />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="机构简介" prop="introduce">
          <Editor
            v-model="value.introduce"
            :minHeight="150"
            ref="introduceRef"
            @click.native="handleEditAble"
          />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import CityOptions from "@/views/components/CityOptions";
import FieldSingle from "@/views/components/FieldSingle";
import InputBoxAdd from "@/views/components/InputBoxAdd";
import { researchSelect } from "@/api/dataList/research";
import { laboratorySelect } from "@/api/dataList/laboratory";
export default {
  components: {
    CityOptions,
    FieldSingle,
    InputBoxAdd,
  },
  props: {
    value: Object,
    isAdd: {
      type: Boolean,
      default: true,
    },
    showTitle: {
      type: Boolean,
      default: false,
    },
    labelWidth: {
      type: Number,
      default: 120,
    },
  },
  data() {
    return {
      researchOptions: [],
      options: [
        // { value: "", label: "" }
      ],
      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",
          },
        ],
        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"],
          },
        ],
        license: [
          {
            required: true,
            message: "请上传",
            trigger: ["blur", "change"],
          },
        ],
        introduce: [{ required: true, message: "请输入", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.introduceRef.Quill.enable(false);
    });
  },
  methods: {
    // 富文本聚焦
    handleEditAble() {
      this.$refs.introduceRef.Quill.enable(true);
      this.$refs.introduceRef.Quill.focus();
    },
    setLaboratory(e) {
      laboratorySelect({ research_id: e }).then((res) => {
        console.log(res);
      });
    },
    submitForm() {
      let flag = false;
      this.$refs["form"].validate((valid) => {
        const cityForm = this.$refs.cityForm.submitForm();
        const fieldForm = this.$refs.fieldForm.submitForm();
        if (valid && cityForm && fieldForm) {
          flag = !flag;
        }
      });
      return flag;
    },
  },
};
</script>
<style lang="scss" scoped>
.form_title {
  font-weight: 700;
  margin-bottom: 30px;
}
// 上传图片框限制
// ::v-deep .el-upload--picture-card {
//   width: 120px;
//   height: 120px;
//   line-height: 120px;
// }
.el-select,
.el-date-editor {
  display: block;
  width: 100%;
}
</style>