<template>
  <div
    style="width: 100%; background: #fff; min-height: 700px"
    class="userCenterAuthenticationPersonal"
  >
    <div
      v-show="$i18n.locale == 'zh'"
      style="
        height: 80px;
        line-height: 80px;
        margin-top: 20px;
        margin: 0 20px;
        color: #666;
        font-size: 15px;
        border-bottom: 1px solid #bcbcbc;
      "
    >
      添加项目
      <!-- <span style="float: right;margin-top: 27px;"> <i class="el-icon-edit"></i> 修改</span> -->
    </div>
    <div v-show="$i18n.locale == 'zh'" style="width: 900px">
      <el-form
        ref="form"
        :model="baseProjectView"
        label-width="160px"
        class="demo-ruleForm"
        style="margin-left: 100px; margin-top: 20px; width: 900px"
        :rules="chineseFormRules"
      >
        <el-form-item label="项目名称(原语言):" prop="name">
          <el-input
            v-model="baseProjectView.originalLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目名称(中文):" prop="chineseLanguageProjectName">
          <el-input
            v-model="baseProjectView.chineseLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目名称(英文):" prop="englishLanguageProjectName">
          <el-input
            v-model="baseProjectView.englishLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目业主:" prop="projectOwner">
          <el-input
            v-model="baseProjectView.projectOwner"
            :disabled="false"
            style="width: 70%"
            maxlength="50"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目已有合作方:" prop="projectPartner">
          <el-input
            v-model="baseProjectView.projectPartner"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item :required="true" label="大洲:" prop="continentCountry">
          <el-select
            v-model="baseProjectView.continentCountry"
            placeholder="请选择或输入大洲"
            filterable
            multiple
            :disabled="false"
            style="width: 70%"
          >
            <el-option
              v-for="item in continentCountryDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :required="true" label="国家:" prop="unitCountry">
          <el-select
            v-model="baseProjectView.unitCountry"
            placeholder="请选择或输入国家"
            filterable
            multiple
            style="width: 70%"
          >
            <el-option
              v-for="item in unitCountryDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="城市:" prop='name'>
                    <el-select v-model="baseProjectView.reserveOne" placeholder="请选择城市" style="width: 70%;">
                        <el-option
                            v-for="item in reserveOnes"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            :disabled="false">
                        </el-option>
                      </el-select>
                  </el-form-item> -->
        <el-form-item
          :required="true"
          label="项目门类:"
          prop="technicalCategories"
        >
          <el-select
            v-model="baseProjectView.technicalCategories"
            placeholder="请选择门类"
            style="width: 70%"
          >
            <el-option
              v-for="item in technicalCategoriesDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :required="true" label="技术范围:" prop="technicalScope">
          <el-select
            v-model="baseProjectView.technicalScope"
            placeholder="请选择范围"
            style="width: 70%"
          >
            <el-option
              v-for="item in technicalScopeDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :required="true" label="当前阶段:" prop="phaseType">
          <el-select
            v-model="baseProjectView.phaseType"
            placeholder="请选择当前阶段"
            style="width: 70%"
          >
            <el-option
              v-for="item in phaseTypeDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目标签:" prop="name">
          <!-- <el-input v-model="baseProjectView.projectLabel" :disabled="false" style="width: 70%;"></el-input> -->
          <div>
            <el-tag
              :key="index"
              style="margin-right: 5px"
              v-for="(tag, index) in systemLabel"
              :disable-transitions="false"
              :type="tag.type"
              effect="plain"
            >
              {{ tag.label }}
            </el-tag>
          </div>

          <el-button type="success" @click="dialogVisibles()"
            >选择标签</el-button
          >
        </el-form-item>
        <el-form-item label="项目描述:" prop="name">
          <el-input
            type="textarea"
            :rows="10"
            v-model="baseProjectView.projectDescription"
            :placeholder="this.textareaMessaage"
            :disabled="false"
            style="width: 70%; min-height: 100px"
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目评估:" prop="name">
          <el-input
            type="textarea"
            v-model="baseProjectView.projectRequirements"
            :disabled="false"
            style="width: 70%"
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="项目附件:">
          <el-upload
            class="upload-demo"
            drag
            action="/api/file/upload/attachment?module=BaseProjectInfoForm&attachmentBusinessType=base_project_info"
            :on-change="handleChange"
            :on-success="handleAvatarSuccessAnnex"
            :on-preview="handlePreview"
            :headers="myHeaders"
            :on-remove="handleRemove"
            :before-upload="beforeUpload"
            :file-list="fileList"
            multiple
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              提示：请上传ZIP,PDF,DOC,DOCX,XLS,XLSX格式的附件，文件不能超过50MB
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="封面图片:" style="position: relative">
          <el-upload
            class="avatar-uploader"
            action="/api/file/upload/attachment?module=BaseProjectInfoForm&attachmentBusinessType=base_project_info_banner"
            :show-file-list="false"
            :headers="myHeaders"
            :on-success="photoSuccess"
          >
            <img
              v-if="path != ''"
              :src="'/api/file/pub/' + path"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            <div
              slot="tip"
              class="el-upload__tip"
              style="display: inline-block; margin-left: 5px"
            >
              {{ $t("common.resourceHint")
              }}{{ $t("common.resourceUploadJPGPNG") }}，{{
                $t("common.resourceFilesCannotExceed10Mb")
              }}，{{ $t("common.resourceUploadOne") }}
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="信息是否公开:">
          <el-radio-group v-model="baseProjectView.messageOpenType">
            <el-radio
              :label="item.value"
              :key="item.value"
              v-for="(item, index) in isCreateNewUser"
              >{{ item.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>

    <div v-show="$i18n.locale == 'zh'" style="height: 200px">
      <div style="margin-top: 100px">
        <el-button type="warning" style="margin-left: 300px" @click="save"
          >保存</el-button
        >
        <el-button type="primary" style="margin-left: 30px" @click="close"
          >关闭</el-button
        >
      </div>
    </div>
    <div v-if="dialogVisible && $i18n.locale == 'zh'">
      <userCenterAddTag
        v-bind:systemLabel="systemLabel"
        :mergeSelectedLabels="mergeSelectedLabels"
        @closeMain="closeMain"
      ></userCenterAddTag>
      <!-- :mergeSelectedLabels="mergeSelectedLabels"  -->
    </div>

    <div
      v-show="$i18n.locale == 'en'"
      style="
        height: 80px;
        line-height: 80px;
        margin-top: 20px;
        margin: 0 20px;
        color: #666;
        font-size: 15px;
        border-bottom: 1px solid #bcbcbc;
      "
    >
      Add Project
    </div>
    <div v-show="$i18n.locale == 'en'" style="width: 900px">
      <el-form
        ref="form"
        :model="baseProjectView"
        label-width="160px"
        class="demo-ruleForm"
        style="margin-left: 100px; margin-top: 20px; width: 900px"
        :rules="englishFormRules"
      >
        <el-form-item label="Project name (original language):" prop="name">
          <el-input
            v-model="baseProjectView.originalLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item
          label="Project name (Chinese):"
          prop="chineseLanguageProjectName"
        >
          <el-input
            v-model="baseProjectView.chineseLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item
          label="Project name (English):"
          prop="englishLanguageProjectName"
        >
          <el-input
            v-model="baseProjectView.englishLanguageProjectName"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="Project owner:" prop="projectOwner">
          <el-input
            v-model="baseProjectView.projectOwner"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="Project partners:" prop="projectPartner">
          <el-input
            v-model="baseProjectView.projectPartner"
            :disabled="false"
            style="width: 70%"
            maxlength="100"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item
          :required="true"
          label="Continent:"
          prop="continentCountry"
        >
          <el-select
            v-model="baseProjectView.continentCountry"
            multiple
            :placeholder="placehoders"
            :disabled="false"
            style="width: 70%"
          >
            <el-option
              v-for="item in continentCountryDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :required="true" label="Country:" prop="unitCountry">
          <el-select
            v-model="baseProjectView.unitCountry"
            multiple
            :placeholder="placehoders"
            style="width: 70%"
          >
            <el-option
              v-for="item in unitCountryDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="city:" prop='name'>
                    <el-select v-model="baseProjectView.reserveOne" placeholder="Please select a city" style="width: 70%;">
                        <el-option
                            v-for="item in reserveOnes"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            :disabled="false">
                        </el-option>
                      </el-select>
                  </el-form-item> -->
        <el-form-item
          :required="true"
          label="Project category:"
          prop="technicalCategories"
        >
          <el-select
            v-model="baseProjectView.technicalCategories"
            placeholder="Please select the category"
            style="width: 70%"
          >
            <el-option
              v-for="item in technicalCategoriesDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          :required="true"
          label="Technology:"
          prop="technicalScope"
        >
          <el-select
            v-model="baseProjectView.technicalScope"
            placeholder="Please select a range"
            style="width: 70%"
          >
            <el-option
              v-for="item in technicalScopeDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item :required="true" label="Current stage:" prop="phaseType">
          <el-select
            v-model="baseProjectView.phaseType"
            placeholder="Please select current stage"
            style="width: 70%"
          >
            <el-option
              v-for="item in phaseTypeDicts"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              :disabled="false"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="Tag:" prop="name">
          <div>
            <el-tag
              :key="index"
              style="margin-right: 5px"
              v-for="(tag, index) in systemLabel"
              :disable-transitions="false"
              :type="tag.type"
              effect="plain"
            >
              {{ tag.label }}
            </el-tag>
          </div>
          <el-button type="success" @click="dialogVisibles()"
            >Add tag</el-button
          >
        </el-form-item>
        <el-form-item label="Project description:" prop="name">
          <el-input
            :rows="10"
            type="textarea"
            v-model="baseProjectView.projectDescription"
            :placeholder="this.textareaMessaageEn"
            :disabled="false"
            resize="800"
            style="width: 70%"
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="Project Evaluation:" prop="name">
          <el-input
            type="textarea"
            v-model="baseProjectView.projectRequirements"
            :disabled="false"
            style="width: 70%"
            maxlength="500"
            show-word-limit
          ></el-input>
        </el-form-item>

        <el-form-item label="Project attachment:">
          <el-upload
            class="upload-demo"
            drag
            action="/api/file/upload/attachment?module=BaseProjectInfoForm&attachmentBusinessType=base_project_info"
            :on-change="handleChange"
            :on-success="handleAvatarSuccessAnnex"
            :on-preview="handlePreview"
            :headers="myHeaders"
            :on-remove="handleRemove"
            :before-upload="beforeUpload"
            :file-list="fileList"
            multiple
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              Drag the file here, or<em>Click upload</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              Hint: Please upload the attachment of ZIP,PDF,DOC,DOCX,XLS and
              XLSX, The file cannot exceed 50MB
            </div>
          </el-upload>
        </el-form-item>
        
        <el-form-item label="Cover image:" style="position: relative">
          <el-upload
            class="avatar-uploader"
            action="/api/file/upload/attachment?module=BaseProjectInfoForm&attachmentBusinessType=base_project_info_banner"
            :show-file-list="false"
            :headers="myHeaders"
            :on-success="photoSuccess"
          >
            <!-- <img v-if="path != ''" :src="'/api/file/pub/'+path" class="avatar"> -->
            <img
              v-if="path != ''"
              :src="'/api/file/pub/' + path"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            <div
              slot="tip"
              class="el-upload__tip"
              style="display: inline-block; margin-left: 5px"
            >
              {{ $t("common.resourceHint")
              }}{{ $t("common.resourceUploadJPGPNG") }}，{{
                $t("common.resourceFilesCannotExceed10Mb")
              }}，{{ $t("common.resourceUploadOne") }}
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item label="Disclose project to public:">
          <el-radio-group v-model="baseProjectView.messageOpenType">
            <el-radio
              :label="item.value"
              :key="item.value"
              v-for="(item, index) in isCreateNewUserEn"
              >{{ item.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
      </el-form>
    </div>

    <div v-show="$i18n.locale == 'en'" style="height: 200px">
      <div style="margin-top: 100px">
        <el-button type="warning" style="margin-left: 300px" @click="save"
          >Save</el-button
        >
        <el-button type="primary" style="margin-left: 30px" @click="close"
          >Close</el-button
        >
      </div>
    </div>
    <div v-if="dialogVisible && $i18n.locale == 'en'">
      <userCenterAddTag
        v-bind:systemLabel="systemLabel"
        :mergeSelectedLabels="mergeSelectedLabels"
        @closeMain="closeMain"
      ></userCenterAddTag>
    </div>
  </div>
</template>
<script>
import { regionDataPlus } from "element-china-area-data";
import ue from "@/components/ue";
import userCenterAddTag from "./userCenterAddTag";
import Base from "@/views/base/Base";
import { getDicts } from "@/api/dict";
import {
  getTreeByLanguagePortal,
  getAllCountryAndCity,
} from "@/api/operation/baseCityInformationDict";
import {
  saveOrUpdate,
  getBaseProjectBizViewById,
} from "@/api/project/baseProjectInfo";
import { getToken, resetToken } from "@/utils/auth";
import { searchFiles } from "@/api/file";
import { addIntegral, addGrowth } from "@/utils/toCompleteTask";
export default {
  name: "userCenteraddMaintenanceJournalInformations",
  extends: Base,
  components: {
    ue,
    userCenterAddTag,
  },
  data() {
    return {
      placehoders: "Please select",
      textareaMessaage:
        "项目描述可包含但不限于以下方面：\n" +
        "（一）项目意义\n" +
        "（二）项目方案\n" +
        "（三）项目进展\n" +
        "（四）当前需求\n" +
        "  ...",
      textareaMessaageEn:
        "Please add project description that may include but not limited to the subjects such as:\n" +
        "1.Project significance\n" +
        "2.Project plan\n" +
        "3.Project progress\n" +
        "4.Project Demand\n" +
        "  ...",
      fileList: [],
      myHeaders: { Authorization: "Bearer " + getToken() },
      isCreateNewUser: [
        { label: "是", value: "Y" },
        { label: "否（只对合作组织公开）", value: "N" },
      ],
      isCreateNewUserEn: [
        { label: "Yes", value: "Y" },
        { label: "No (Visible only to GEIDCO)", value: "N" },
      ],
      informationsClass: "1",
      dialogVisible: false,
      ifDiaslog: "",
      title: "",
      options: regionDataPlus,
      selectedOptions: [],
      systemLabel: [],
      mergeSelectedLabels: [],
      baseProjectView: {
        originalLanguageProjectName: "",
        englishLanguageProjectName: "",
        chineseLanguageProjectName: "",
        projectOwner: "",
        projectPartner: "",
        projectLabel: "",
        projectDescription: "",
        projectRequirements: "",
        region: "普通用户",
        date1: "2018-05-19",
        date3: "2018-05-19",
        date2: "2020-05-25  11：20：23",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
        startData: "",
        id: this.$route.params.key,
        projectNum: "",
        projectName: "",
        projectConsultantId: "",
        setUpDate: new Date(),
        setDownDate: "",
        technicalCategories: "",
        technicalScope: "",
        phaseType: "",
        releaseStatus: "0",
        approveStatus: "",
        publishingChannels: "1",
        continentCountry: "",
        unitCountry: "",
        unitInfo: "",
        recommendFlag: "n",
        messageOpenType: "Y",
        status: "",
        childCount: "",
        entityZh: "",
        entityEn: "",
        entityFr: "",
        entityDe: "",
        entityEs: "",
        entityJa: "",
        entityAr: "",
        entityRu: "",
        createBy: "",
        createDate: new Date(),
        updateBy: "",
        updateDate: "",
        reserveOne: "",
        reserveTwo: "",
        reserveThree: "",
        reserveFour: "",
        reserveFive: "",
      },
      continentCountryDicts: [],
      unitCountryDicts: [],
      reserveOnes: [],
      technicalCategoriesDicts: [],
      technicalScopeDicts: [],
      phaseTypeDicts: [],
      languageDicts: [],
      imageUrl: "",
      form: {},
      files: [],
      imgList: [],
      path: "",
      user: {
        umsUser: {},
      },
    };
  },
  watch: {
    // "baseProjectView.continentCountry"() {
    //     this.continentCountryDicts.forEach((i) => {
    //         if (this.baseProjectView.continentCountry == i.value) {
    //         this.unitCountryDicts = i.data;
    //         }
    //     });
    // },
    // "baseProjectView.unitCountry"() {
    //     this.unitCountryDicts.forEach((i) => {
    //         if (this.baseProjectView.unitCountry == i.value) {
    //             this.reserveOnes= i.data;
    //         }
    //     })
    // },
    "$i18n.locale"() {
      this.initData();
      // this.getBaseProject();
    },
  },
  mounted() {
    this.initData();
  },
  computed: {
    englishFormRules() {
      return {
        // resultTheResourceType: [
        //     { required: true, message: this.$i18n.locale=='zh'?'请选择资源类型':'Select the resource type', trigger: 'change' },
        // ],
        chineseLanguageProjectName: [
          {
            required: true,
            message: "please input chineseLanguageProjectName",
            trigger: "change",
          },
        ],
        projectOwner: [
          {
            required: true,
            message: "please input projectOwner",
            trigger: "change",
          },
        ],
        projectPartner: [
          {
            required: true,
            message: "please input projectPartner",
            trigger: "change",
          },
        ],
        continentCountry: [
          {
            required: true,
            message: "please select continentCountry",
            trigger: "change",
          },
        ],
        unitCountry: [
          {
            required: true,
            message: "please select unitCountry",
            trigger: "change",
          },
        ],
        technicalCategories: [
          {
            required: true,
            message: "please select technicalCategories",
            trigger: "change",
          },
        ],
        technicalScope: [
          {
            required: true,
            message: "please select technicalScope",
            trigger: "change",
          },
        ],
        phaseType: [
          {
            required: true,
            message: "please select phaseType",
            trigger: "change",
          },
        ],
        englishLanguageProjectName: [
          {
            required: true,
            message: "please input englishLanguageProjectName",
            trigger: "change",
          },
        ],
      };
    },
    chineseFormRules() {
      return {
        // resultTheResourceType: [
        //     { required: true, message: this.$i18n.locale=='zh'?'请选择资源类型':'Select the resource type', trigger: 'change' },
        // ],
        chineseLanguageProjectName: [
          {
            required: true,
            message: "请输入项目名称(中文)",
            trigger: "change",
          },
        ],
        projectOwner: [
          { required: true, message: "请输入项目业主", trigger: "change" },
        ],
        projectPartner: [
          { required: true, message: "请输入项目合作方", trigger: "change" },
        ],
        continentCountry: [
          { required: true, message: "请选择大洲", trigger: "change" },
        ],
        unitCountry: [
          { required: true, message: "请选择国家", trigger: "change" },
        ],
        technicalCategories: [
          { required: true, message: "请选择项目门类", trigger: "change" },
        ],
        technicalScope: [
          { required: true, message: "请选择技术范围", trigger: "change" },
        ],
        phaseType: [
          { required: true, message: "请选择当前阶段", trigger: "change" },
        ],
        englishLanguageProjectName: [
          {
            required: true,
            message: "请输入项目名称(英文)",
            trigger: "change",
          },
        ],
      };
    },
  },
  methods: {
    initData() {
      this.user = JSON.parse(window.localStorage.getItem("user"));
    },
    searchFiles() {
      var _that = this;
      var file1 = {
        attachmentBusinessId: _that.baseProjectView.reserveFive,
        attachmentBusinessType: "base_project_info",
      };
      var file2 = {
        attachmentBusinessId: _that.baseProjectView.reserveFive,
        attachmentBusinessType: "base_project_info_banner",
      };
      _that.path = "";
      searchFiles(file2).then((result) => {
        _that.path = result.data.attachmentInfos[0].attachmentSavePath;
      });
      _that.fileList = [];
      searchFiles(file1).then((result) => {
        result.data.attachmentInfos.forEach((i) => {
          var fileTo = {
            name: i.attachmentName,
            url: i.attachmentSavePath,
            uid: i.id,
          };
          _that.fileList.push(fileTo);
          _that.files.push(i.id);
          console.log(_that.files + "_that.files");
        });
      });
    },
    initData() {
      var _that = this;
      var language = _that.$i18n.locale.toUpperCase();
      if (_that.baseProjectView.id != null) {
        getBaseProjectBizViewById(_that.baseProjectView.id, language).then(
          (result) => {
            _that.baseProjectView = result.data
              ? result.data.baseProjectBizView
              : {};
            _that.baseProjectView.continentCountry =
              _that.baseProjectView.continentCountry.split(",");
            _that.baseProjectView.unitCountry =
              _that.baseProjectView.unitCountry.split(",");
            _that.searchFiles();
          }
        );
      }
      _that.continentCountryDicts = [];
      _that.unitCountryDicts = [];
      var language = _that.$i18n.locale.toUpperCase();
      getAllCountryAndCity().then((result) => {
        var allCountry = result.data.allCountry;
        var unitCountryDictsValue = [];
        if (_that.$i18n.locale == "zh") {
          allCountry.forEach((i) => {
            var j = {};
            j.data = [];
            j.value = i.country_iso_code;
            j.label = i.country_name;
            unitCountryDictsValue.push(j);
          });
          _that.unitCountryDicts = unitCountryDictsValue;
        }
        if (_that.$i18n.locale == "en") {
          allCountry.forEach((i) => {
            var j = {};
            j.data = [];
            j.value = i.country_iso_code;
            j.label = i.country_name_en;
            unitCountryDictsValue.push(j);
          });
          _that.unitCountryDicts = unitCountryDictsValue;
        }
      }),
        getTreeByLanguagePortal(language).then((result) => {
          var keys = Object.keys(result.data);
          for (var i = 0; i < keys.length; i++) {
            _that.continentCountryDicts.push(result.data[keys[i]]);
          }
        });
      // getTreeByLanguagePortal(language).then(result => {
      //     var keys = Object.keys(result.data);
      //     _that.continentCountryDicts = [];
      //     for(var i = 0;i < keys.length;i++){
      //     _that.continentCountryDicts.push(result.data[keys[i]]);
      //     }
      //     if (_that.baseProjectView.continentCountry != null) {
      //     _that.continentCountryDicts.forEach((i) => {
      //         if (_that.baseProjectView.continentCountry == i.value) {

      //         _that.unitCountryDicts = i.data;
      //         }
      //     });
      //     }
      //     if (_that.baseProjectView.unitCountry != null) {
      //     _that.unitCountryDicts.forEach((i) => {
      //         if (_that.baseProjectView.unitCountry == i.value) {
      //         _that.reserveOnes= i.data;
      //         }
      //     })
      //     }
      // })
      if (_that.$i18n.locale.toUpperCase() == "ZH") {
        getDicts(
          "PROJECT_CATEGORIES_DICT,TECHNICAL_SCOPE_DICT,PHASE_TYPE_DICT,LANGUAGE_DICT"
        ).then((result) => {
          var data = result.data;
          if (data) {
            _that.technicalCategoriesDicts = result.data[0] || [];
            _that.technicalScopeDicts = result.data[1] || [];
            _that.phaseTypeDicts = result.data[2] || [];
            _that.languageDicts = result.data[3] || [];
          }
        });
      }
      if (_that.$i18n.locale.toUpperCase() == "EN") {
        getDicts(
          "PROJECT_CATEGORIES_DICT_EN,TECHNICAL_SCOPE_DICT_EN,PHASE_TYPE_DICT_EN,LANGUAGE_DICT"
        ).then((result) => {
          var data = result.data;
          if (data) {
            _that.technicalCategoriesDicts = result.data[0] || [];
            _that.technicalScopeDicts = result.data[1] || [];
            _that.phaseTypeDicts = result.data[2] || [];
            _that.languageDicts = result.data[3] || [];
          }
        });
      }
    },
    // 下载文件方法file参数为已上传文件的信息，其实就是取得fileList里的值
    handlePreview(file, fileList) {
      document.location.href = "http://localhost:8080/api/file/pub/" + file.url;
    },
    handleRemove(file, fileList) {
      this.files.forEach((i) => {
        if (i == file.uid) {
          var index = this.files.indexOf(i);
          this.files.splice(index, 1);
        }
      });
    },
    handleAvatarSuccessAnnex(res, file) {
      this.files.push(res.data.attachmentId);
    },
    beforeUpload(file) {
      var FileExt = file.name.replace(/.+\./, "");
      if (
        ["zip", "pdf", "doc", "docx", "excel", "xls", "xlsx"].indexOf(
          FileExt.toLowerCase()
        ) === -1
      ) {
        if (this.$i18n.locale.toUpperCase() == "ZH") {
          this.$message({
            type: "warning",
            message: "请上传zip,pdf,word,excel的附件！",
          });
        } else {
          this.$message({
            type: "warning",
            message:
              "Please upload the attachment of zip, PDF, word and excel!",
          });
        }
        this.fileList.splice(this.fileList.indexOf(file), 1);
        return false;
      }
      this.isLt2k = file.size / 1024 / 1024 < 2 ? "1" : "0";
      if (this.isLt2k === "0") {
        if (this.$i18n.locale.toUpperCase() == "ZH") {
          this.$message({
            message: "上传文件大小不能超过2M!",
            type: "error",
          });
        } else {
          this.$message({
            message: "Upload file size cannot exceed 2m!",
            type: "error",
          });
        }
        this.fileList.splice(this.fileList.indexOf(file), 1);
        return false;
      }
    },

    save: function () {
      this.baseProjectView.reserveFour = this.$i18n.locale.toUpperCase();
      this.baseProjectView.id = this.$route.params.key;
      this.baseProjectView.updateDate = new Date();
      if (this.baseProjectView.continentCountry) {
        var continentCountry = "";
        console.log("this.baseProjectView.continentCountry",this.baseProjectView.continentCountry)
        this.baseProjectView.continentCountry.forEach((item) => {
          continentCountry = continentCountry + item + ",";
        });
        this.baseProjectView.continentCountry = continentCountry;
      }
      if (this.baseProjectView.unitCountry) {
        var unitCountry = "";
        this.baseProjectView.unitCountry.forEach((item) => {
          unitCountry = unitCountry + item + ",";
        });
        this.baseProjectView.unitCountry = unitCountry;
      }
      this.baseProjectView.continentCountry =
        this.baseProjectView.continentCountry.substring(
          this.baseProjectView.continentCountry.length - 1
        ) == ","
          ? this.baseProjectView.continentCountry.substring(
              0,
              this.baseProjectView.continentCountry.length - 1
            )
          : this.baseProjectView.continentCountry;
      this.baseProjectView.unitCountry =
        this.baseProjectView.unitCountry.substring(
          this.baseProjectView.unitCountry.length - 1
        ) == ","
          ? this.baseProjectView.unitCountry.substring(
              0,
              this.baseProjectView.unitCountry.length - 1
            )
          : this.baseProjectView.unitCountry;
      let token = getToken();
      this.submitHandler((token) => {
        saveOrUpdate(
          JSON.stringify(this.baseProjectView),
          JSON.stringify(Array.from(this.files)),
          JSON.stringify(Array.from(this.imgList)),
          token
        )
          .then((result) => {
            if (this.user.umsUser.userUsertypeDict !== "2") {
              addIntegral("point_task_upload_resources_project", "50");
              addGrowth("point_task_upload_resources_project");
            }
            if (this.$i18n.locale.toUpperCase() == "ZH") {
              alert("项目保存成功");
            } else {
              alert("Project saved successfully");
            }

            this.baseProjectView = {};
            this.$router.go(-1); //返回上一层
          })
          .catch((error) => {
            // 此处你的业务代码
            this.resetToken();
          });
      });
    },
    close() {
      this.$router.go(-1);
    },
    closeMain(val) {
      this.mergeSelectedLabels = [];
      val.forEach((element, index) => {
        this.mergeSelectedLabels.push(element.label);
      });
      this.systemLabel = val;
      this.baseProjectView.projectLabel = JSON.stringify(
        this.mergeSelectedLabels
      )
        .replace(/\[|]/g, "")
        .replace(/\"/g, "");
      this.dialogVisible = false;
    },
    goAithentication(num) {
      this.$router.go(-1); //返回上一层
    },
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-3);
    },
    photoSuccess(res, file) {
      this.imgList = [];
      this.path = res.data.path;
      this.imgList.push(res.data.attachmentId);
    },
    dialogVisibles() {
      this.dialogVisible = true;
    },
    // beforeAvatarUpload(file) {
    //     const isJPG = file.type === 'image/jpeg';
    //     const isLt2M = file.size / 1024 / 1024 < 2;

    //     if (!isJPG) {
    //     this.$message.error('上传头像图片只能是 JPG 格式!');
    //     }
    //     if (!isLt2M) {
    //     this.$message.error('上传头像图片大小不能超过 2MB!');
    //     }
    //     return isJPG && isLt2M;
    // },
  },
};
</script>
<style scoped>
.el-button {
  width: 200px;
  height: 45px;
}
.authenticationBox1 {
  margin-left: 35px;
  margin-right: 150px;
  height: 100px;
  border: 1px solid rgba(153, 153, 153, 1);
  border-radius: 10px;
  margin-top: 50px;
  position: relative;
}
.authenticationBox2 {
  margin: 50px 150px 0 35px;
  height: 100px;
  border: 1px solid rgba(153, 153, 153, 1);
  border-radius: 10px;
  position: relative;
}
.authenticationBox1:hover,
.authenticationBox2:hover {
  border: 1px solid #ff8400;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.userCenterAuthenticationPersonal >>> .el-upload {
  border: 1px solid rgba(204, 204, 204, 1);
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
/deep/.el-textarea__inner {
  display: block;
  resize: vertical;
  padding: 5px 15px;
  line-height: 3;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  width: 100%;
  font-size: inherit;
  color: #606266;
  background-color: #fff;
  background-image: none;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  -webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}
/*.el-textarea/deep/::-webkit-input-placeholder {*/
/*    color: red;*/
/*}*/
/*.el-textarea/deep/::-moz-input-placeholder {*/
/*    color: red;*/
/*}*/
/*.el-textarea/deep/::-ms-input-placeholder {*/
/*    color: red;*/
/*}*/
</style>