<template>
  <div class="app-container">
    <el-card shadow="always" style="width: 55%; margin: 0 auto">
      <el-form ref="formRef" :label-width="labelWidth + 'px'" :model="formData">
        <p>
          <b> {{ t("admin.form.basicInfo") }}</b>
        </p>

        <el-row>
          <el-col :span="24">
            <el-form-item
              :label="t('admin.form.name', { type: t('admin.common.demand') })"
              prop="title"
            >
              <el-input v-model="formData.title"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item
              :label="
                t('admin.form.category', { type: t('admin.common.demand') })
              "
            >
              <el-checkbox-group v-model="formData.kinds">
                <el-checkbox
                  v-for="item in formData.kinds"
                  :key="item"
                  :label="item"
                  >{{ item }}
                </el-checkbox>
              </el-checkbox-group>
              <!--              <el-row :gutter="20">-->
              <!--                <el-col :span="20">-->
              <!--                  <el-input-->
              <!--                      v-model="checkInput"-->
              <!--                      placeholder="请输入需求类别"-->
              <!--                  ></el-input>-->
              <!--                </el-col>-->
              <!--                <el-col :span="4">-->
              <!--                  <el-button type="primary" @click="addCheck">添加</el-button>-->
              <!--                </el-col>-->
              <!--              </el-row>-->
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item :label="t('webSearch.demandDescription')" prop="add">
              <!--              <editor v-model="formData.add" :minHeight="150" />-->
              <el-input
                type="textarea"
                v-model="formData.add"
                :autosize="{ minRows: 6, maxRows: 8 }"
                :placeholder="
                  t('admin.form.placeholder', {
                    type: t('webSearch.demandDescription'),
                  })
                "
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!--COMPLETED-->
        <el-form-item :label="t('admin.form.country')" prop="country">
          <el-select
            v-model="formData.country"
            :placeholder="
              t('admin.form.pleaseSelect', { type: t('admin.form.country') })
            "
          >
            <el-option
              v-for="option in countryOptions"
              :label="option[locale]"
              :value="option.key"
            />
          </el-select>
        </el-form-item>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="t('admin.form.demandContact')" prop="name">
              <el-input
                v-model="formData.name"
                :placeholder="
                  t('admin.form.placeholder', {
                    type: t('admin.form.demandContact'),
                  })
                "
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="t('admin.form.contactPhone')" prop="mobile">
              <el-input
                v-model="formData.mobile"
                :placeholder="
                  t('admin.form.placeholder', {
                    type: t('admin.form.mobile'),
                  })
                "
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="需求提交人:" prop="username">-->
        <!--              <el-input-->
        <!--                  v-model="formData.username"-->
        <!--                  placeholder="自动获取"-->
        <!--              ></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item :label="t('admin.form.mobile')" prop="userPhone">-->
        <!--              <el-input-->
        <!--                  v-model="formData.userPhone"-->
        <!--                  placeholder="自动获取"-->
        <!--              ></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
      </el-form>
      <el-row justify="center">
        <el-col :span="1.5">
          <el-button type="primary" @click="cancel"
            >{{ t("admin.identity.entrance.back") }}
          </el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script setup>
import CityOptions from "@/views/components/CityOptions/index.vue";
import { computed, reactive, ref, toRefs } from "vue";
import { ElMessage } from "element-plus";
import { useRoute } from "vue-router";
import tab from "@/plugins/tab";
import { serviceDemandInfo } from "@/api/admin/research/service-demand";
import { useI18n } from "vue-i18n";
import { countryOptions } from "@/utils/parameter";

const { t, locale } = useI18n();
const data = reactive({
  formData: {
    check: [],
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    postCode: undefined,
  },
  rules: {
    name: [
      {
        required: true,
        /*"需求名称不能为空"*/
        message: computed(() =>
          t("admin.validation.required", {
            type: t("admin.form.name", { type: t("admin.common.demand") }),
          })
        ),
        trigger: "blur",
      },
    ],
    add: [
      {
        required: true,
        /* "需求描述不能为空"*/
        message: computed(() =>
          t("admin.validation.required", {
            type: t("webSearch.demandDescription"),
          })
        ),
        trigger: "blur",
      },
    ],
    bankAccount: [
      {
        required: true,
        /*"需求联系人不能为空"*/
        message: computed(() =>
          t("admin.validation.required", {
            type: t("admin.form.demandContact"),
          })
        ),
        trigger: "blur",
      },
    ],
    bankPhone: [
      {
        required: true,
        /*"联系人手机号不能为空"*/
        message: computed(() =>
          t("admin.validation.required", {
            type: t("admin.form.mobile"),
          })
        ),
        trigger: "blur",
      },
    ],
    username: [
      {
        required: true,
        message: computed(() => t("webContact.demandSubmit")),
        trigger: "blur",
      },
    ],
    userPhone: [
      {
        required: true,
        /*"手机号不能为空"*/
        message: computed(() =>
          t("admin.validation.required", { type: t("admin.form.mobile") })
        ),
        trigger: "blur",
      },
    ],
  },
});

const { queryParams, formData, rules } = toRefs(data);
const route = useRoute();
const labelWidth = 140;
// const checkList = reactive([
//   {
//     id: 1,
//     name: "成果推广",
//     i18n: computed(() => t("dict.achievementPromotion")),
//   },
//   {
//     id: 2,
//     name: "关键成果解决",
//     i18n: computed(() => t("dict.keyAchievementSolution")),
//   },
//   {
//     id: 3,
//     name: "对接专家院士",
//     i18n: computed(() => t("dict.expertDocking")),
//   },
//   {
//     id: 4,
//     name: "上市辅导",
//     i18n: computed(() => t("dict.listingGuidance")),
//   },
// ]);
// const checkInput = ref("");

// function addCheck() {
//   if (!checkInput.value.trim().length) return ElMessage.error("请输入");
//   const flag = checkList.some((item) => {
//     return item.name.trim() === checkInput.value.trim();
//   });
//   if (!flag) {
//     checkList.push({
//       id: checkList.length + 1,
//       name: checkInput.value,
//     });
//     checkInput.value = "";
//   }
// }

const cancel = () => {
  tab.closeOpenPage({
    path: "/admin/research/service-demand",
  });
};

if (route.params.id) {
  serviceDemandInfo(route.params.id).then((resp) => {
    formData.value = resp.data;
    // form.value.keywords = form.value.keyword?.split(',') ?? []
    // form.value.researchs = form.value.researchDirection?.split(',') ?? []
  });
} else {
  cancel();
}
</script>
