<template>
  <el-form
    ref="formRef"
    :model="modelValue"
    :rules="rules"
    :label-width="labelWidth + 'px'"
  >
    <el-row class="mb20">
      <el-radio-group v-model="modelValue.mode">
        <el-radio-button :label="1">免费成果发布</el-radio-button>
        <el-radio-button :label="2">付费成果发布</el-radio-button>
      </el-radio-group>
    </el-row>

    <div class="form_title" v-if="showTitle">基本信息</div>

    <el-alert
      v-if="modelValue.mode == 2"
      style="margin-bottom: 20px"
      title="1创新币=1元"
      type="warning"
      show-icon
      :closable="false"
    ></el-alert>

    <el-row v-if="modelValue.mode == 2">
      <el-col :span="12">
        <el-form-item label="视频定价:">
          <el-input v-model="modelValue.title" placeholder="请输入创新币个数">
            <template #append>创新币</template>
          </el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="免费观看时长:">
          <el-input v-model="modelValue.title" placeholder="默认视频的1/3时长">
            <template #append>min</template>
          </el-input>
        </el-form-item>
      </el-col>
    </el-row>

    <el-row v-if="modelValue.mode == 2">
      <el-col :span="24">
        <el-form-item label="视频文件:">
          <FileUpload
            v-model="modelValue.image"
            :limit="1"
            :fileType="['mp4']"
          />
        </el-form-item>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="24">
        <el-form-item label="成果名称:" prop="title">
          <el-input
            v-model="modelValue.title"
            placeholder="请输入成果名称"
          ></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <!-- <CityOptions v-model="modelValue" :labelWidth="labelWidth" ref="cityForm" />
    <el-row>
      <el-col :span="24">
        <el-form-item label="详细地址:">
          <el-input v-model="modelValue.address"></el-input>
        </el-form-item>
      </el-col>
    </el-row> -->

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

    <InputBoxAdd
      :labelWidth="labelWidth"
      v-model="modelValue"
      title="应用客户"
      placeholder="请输入应用客户"
      fieldKey="customer"
      ref="directionsForm"
    />

    <el-row>
      <el-col :span="24">
        <el-form-item label="成果成熟度:" prop="maturity">
          <el-select
            v-model="modelValue.maturity"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in maturityOptions"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="成果领先性:" prop="lead_standard">
          <el-select
            v-model="modelValue.lead_standard"
            clearable
            placeholder="请选择"
          >
            <el-option
              v-for="item in leadOptions"
              :key="item.key"
              :label="item.value"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="合作模式:" prop="lead_standard">
          <el-select
            v-model="modelValue.province"
            clearable
            placeholder="请选择"
          >
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>

    <InputBoxAdd
      v-if="modelValue.mode == 2"
      :labelWidth="labelWidth"
      v-model="modelValue"
      title="应用场景"
      placeholder="请输入应用场景"
      fieldKey="kws"
      ref="directionsForm"
    />

    <InputBoxAdd
      :labelWidth="labelWidth"
      v-model="modelValue"
      title="关键词"
      placeholder="请输入关键词"
      fieldKey="keywords"
      ref="directionsForm"
    />

    <el-row>
      <el-col :span="24">
        <el-form-item label="成果简介:" prop="introduce">
          <Editor
            v-model="modelValue.introduce"
            :minHeight="150"
            ref="introduceRef"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-if="modelValue.mode == 1">
      <el-col :span="24">
        <el-form-item label="成果来源:" prop="introduce">
          <Editor
            v-model="modelValue.introduce"
            :minHeight="150"
            ref="introduceRef"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <el-row v-if="modelValue.mode == 1">
      <el-col :span="24">
        <el-form-item label="成果图片:" prop="image">
          <ImageUpload
            v-model="modelValue.image"
            :isShowTip="false"
            :limit="1"
          />
        </el-form-item>
      </el-col>
    </el-row>
    <p>
      <b>图片材料上传</b>
    </p>
    <el-row>
      <el-col :span="24">
        <el-form-item label="成熟度证明材料:" prop="file">
          <FileUpload
            v-model="modelValue.file"
            :limit="1"
            :fileType="['doc', 'xls', 'ppt', 'txt', 'pdf', 'jpg']"
          />
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import CityOptions from "@/views/identity/components/CityOptions";
import FieldOptions from "@/views/identity/components/FieldOptions";
import InputBoxAdd from "@/views/identity/components/InputBoxAdd";
// import { researchSelect, laboratorySelect } from "@/api/identity/index";
export default {
  components: {
    CityOptions,
    FieldOptions,
    InputBoxAdd,
  },
  props: {
    modelValue: Object,
    isAdd: {
      type: Boolean,
      default: true,
    },
    showTitle: {
      type: Boolean,
      default: false,
    },
    labelWidth: {
      type: Number,
      default: 120,
    },
  },
  data() {
    return {
      rules: {
        product: [{ required: true, message: "请输入", trigger: "blur" }],
        title: [{ 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"],
          },
        ],
        lead_standard: [
          {
            required: true,
            message: "请上传",
            trigger: ["blur", "change"],
          },
        ],
        introduce: [
          {
            required: true,
            message: "请输入",
            trigger: ["change", "blur"],
          },
        ],
      },
    };
  },
  methods: {
    submitForm() {
      let flag = false;
      this.$refs["formRef"].validate((valid) => {
        const cityForm = this.$refs.cityForm.submitForm(); // 城市
        const fieldForm = this.$refs.fieldForm.submitForm();
        const directionsForm = this.$refs.directionsForm.submitForm();
        if (valid && cityForm && fieldForm && directionsForm) {
          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>