<template>
  <div class="add-manager-wrap">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond"></bread-crumb>
    <div class="add-content screenSet" id="screenSet">
      <el-row class="step-content">
        <el-col :span="14">
          <el-steps :active="active" simple class>
            <span class="step-num" v-bind:class="{ 'on-step': stepData[0] }">1</span>
            <el-step title="基础信息"></el-step>
            <span class="step-num" v-bind:class="{ 'on-step': stepData[1] }">2</span>
            <el-step title="选择范围">2</el-step>
            <span class="step-num" v-bind:class="{ 'on-step': stepData[2] }">3</span>
            <el-step title="选择项目组件">3</el-step>
          </el-steps>
        </el-col>
        <el-col :span="5" :offset="5">
          <el-button v-if="showStorage" size="small" @click="storage">暂存</el-button>
          <el-button v-if="active<2" size="small" type="primary" @click="nextStep">下一步</el-button>
          <el-button v-if="active>=2" size="small" type="primary" @click="complete">完成</el-button>
        </el-col>
      </el-row>
      <div class="first-step" v-if="active === 0">
        <el-form
          ref="formData"
          :model="formData"
          :rules="rules"
          label-width="150px"
          class="basic-form"
        >
          <el-form-item label="项目名称：" prop="projectName">
            <el-col :span="13">
              <el-input
                size="small"
                v-model="formData.projectName"
                placeholder="请输入项目名称"
                style="width:70%;"
                :disabled="peopleLevel == 'L3'"
              ></el-input>
              <span class="word-num">{{(formData.projectName).replace(/\s+/g,"").length}}/24</span>
            </el-col>
          </el-form-item>
          <el-form-item label="发起机构名称：">
          <!-- <el-form-item label="发起机构名称：" prop="organizationNameList"> -->
            <el-col :span="13" v-for="(item, index) in formData.organizationNameList" :key="index">
              <el-input
                size="small"
                v-model="formData.organizationNameList[index]"
                placeholder="请输入发起机构名称"
                style="width:70%;"
                maxlength=16
                :disabled="peopleLevel == 'L3'"
                @input="changeOrganizationName"
                @blur = "blurName"
                @focus = "focusName(index)"
              ></el-input>
              <span class="word-num">{{(formData.organizationNameList[index]).replace(/\s+/g,"").length}}/16</span>
              <img @click="plusOrg(index)" class="edit-img" src="../../assets/image/plus.png" />
              <img @click="deleteOrg(index)" v-if="index >= 1" class="edit-img" src="../../assets/image/trash.png" />
            </el-col>
            <el-popover
              class="popover-content" :style="{'top': orgListIndex * 41 + 'px'}"
              placement="bottom"
              :content="organizationContent"
              v-model="visibleName"
              @click="checkDefault">
              <p @click="checkDefault"> 我的机构： {{ organizationContent }} </p>
            </el-popover>
          </el-form-item>
          <el-form-item label="项目时间：" required>
            <el-col :span="5">
              <el-form-item prop="projectBegintime">
                <el-date-picker
                  v-model="formData.projectBegintime"
                  size="small"
                  type="datetime"
                  placeholder="请选择开始时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :picker-options="pickerOptions0"
                  style="width: 100%;"
                  :disabled="peopleLevel == 'L3'"
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" :span="1">~</el-col>
            <el-col :span="5">
              <el-form-item label prop="projectEndtime">
                <el-date-picker
                  v-model="formData.projectEndtime"
                  size="small"
                  type="datetime"
                  placeholder="请选择结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  :picker-options="pickerOptions1"
                  default-time="23:59:59"
                  style="width: 100%;"
                  :disabled="peopleLevel == 'L3'"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>
          <el-form-item label="项目简介：" prop="projectIntro">
            <el-col :span="13">
              <el-input
                size="small"
                type="textarea"
                :autosize="{ minRows: 5}"
                placeholder="请输入项目简介"
                v-model="formData.projectIntro"
                style="width:83%;"
                :disabled="peopleLevel == 'L3'"
              ></el-input>
              <span class="word-num">{{(formData.projectIntro).replace(/\s+/g,"").length}}/200</span>
            </el-col>
          </el-form-item>
          <div class="basic-item-icon">
            <span class="require">*</span>
            <el-form-item label="列表图片：">
              <el-upload
                v-model="formData.attachmentUrl1"
                class="bg-uploader"
                action="#"
                :show-file-list="false"
                :before-upload="beforeUploadListPic"
                :disabled="peopleLevel == 'L3'"
              >
                <img v-if="formData.attachmentUrl1" @mouseover.stop="imgMouseOver=true && peopleLevel != 'L3'" :src="formData.attachmentUrl1" class="bg-img">
                <img
                  v-if="!formData.attachmentUrl1"
                  class="bg-img"
                  src="../../assets/image/small.png"
                >
                <div class="img-delete" v-show="imgMouseOver" @click.stop="deleteImg(1)" @mouseout.stop="imgMouseOver=false"><i class="el-icon-delete"></i></div>
                <div class="limit-text">
                  <p>尺寸:230*172</p>
                  <p>限制大小: 500Kb</p>
                  <p>支持.jpg,.png格式</p>
                </div>
              </el-upload>
            </el-form-item>
            <p class="upload-message" v-if="uploadImgMessage">请选择列表图片</p>
          </div>
          <el-form-item label="封面类型：">
            <el-radio-group
              size="small"
              v-model="formData.type"
              @change="changeCover"
              :disabled="peopleLevel == 'L3'"
            >
              <el-radio :label="1">图片</el-radio>
              <el-radio :label="2">视频</el-radio>
            </el-radio-group>
          </el-form-item>
          <div class="basic-item-icon">
            <span class="require">*</span>
            <el-form-item label="封面文件：">
              <el-upload
                v-model="formData.attachmentUrl2"
                class="bg-uploader"
                action="#"
                :show-file-list="false"
                :before-upload="beforeUploadCoverPic"
                :disabled="peopleLevel == 'L3'"
              >
                <img
                  v-if="formData.type == 1 && formData.attachmentUrl2"
                  :src="formData.attachmentUrl2"
                  @mouseover.stop="imgMouseOver2=true  && peopleLevel != 'L3'"
                  class="bg-img"
                >
                <video
                  v-if="formData.type == 2 && formData.attachmentUrl2"
                  width="100"
                  controls
                  class="bg-video"
                  @mouseover.stop="imgMouseOver2=true  && peopleLevel != 'L3'"
                >
                  <source :src="formData.attachmentUrl2" type="video/mp4">浏览器不支持mp4
                </video>
                <img
                  v-if="!formData.attachmentUrl2"
                  class="bg-img"
                  src="../../assets/image/small.png"
                >
                <div class="img-delete" v-show="imgMouseOver2" @click.stop="deleteImg(2)" @mouseout.stop="imgMouseOver2=false"><i class="el-icon-delete"></i></div>
                <div v-show="formData.type == 1" class="limit-text">
                  <p>尺寸:750*420</p>
                  <p>限制大小: 2.0 Mb</p>
                  <p>支持.jpg,.png格式</p>
                </div>
                <div v-show="formData.type == 2" class="limit-text">
                  <p></p>
                  <p>限制大小: 500 Mb</p>
                  <p>支持.mp4</p>
                </div>
              </el-upload>
            </el-form-item>
            <p class="upload-message" v-if="uploadImgMessage2">请选择封面</p>
          </div>
          <el-form-item label="项目结束后：">
            <el-radio-group
              size="small"
              v-model="formData.allowLearn"
              :disabled="showAllowType()"
            >
              <el-radio :label="1">允许继续学习(停止发证)</el-radio>
              <el-radio :label="2">不允许继续学习</el-radio>
            </el-radio-group>
          </el-form-item>
          <p class="p_label">项目范围来源：（一经选择无法更改）</p>
          <el-form-item label="">
            <el-radio-group
              size="small"
              v-model="formData.scopeType"
              :disabled="showScopeType()"
            >
              <el-radio :label="0">使用地区范围</el-radio>
              <el-radio :label="1">使用小生态范围</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="人员权限设定">
            <el-radio-group
              size="small"
              v-model="formData.authorityType"
              :disabled="showNoticeType()"
            >
              <el-radio :label="1">自定义</el-radio>
              <el-radio :label="2">使用平台默认权限</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="项目范围外可见">
            <el-radio-group
              size="small"
              v-model="formData.visibleFlag"
              :disabled="showNoticeType()"
            >
              <el-radio :label="1">允许项目范围外人员可见</el-radio>
              <el-radio :label="2">不允许项目范围外人员可见</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="formData.visibleFlag != 2" label="项目范围外可学">
            <el-radio-group
              size="small"
              v-model="formData.learnableFlag"
              :disabled="showNoticeType()"
            >
              <el-radio :label="1">允许项目范围外人员可学(不发证)</el-radio>
              <el-radio :label="2">不允许项目范围外人员可学</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="项目上线通知">
            <el-radio-group
              size="small"
              v-model="formData.sendOption"
              :disabled="showNoticeType()"
            >
              <el-radio :label="1">通知</el-radio>
              <el-radio :label="2">不通知</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="formData.sendOption != 2" label="通知范围">
            <el-radio-group
              size="small"
              v-model="formData.receiveOption"
              :disabled="showNoticeType()"
            >
              <el-radio :label="1">次级负责人</el-radio>
              <el-radio :label="2">所有人</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="添加下载文件：">
            <el-col :span="10">
              <el-upload
                v-model="formData.attachmentUrl3"
                class="upload-pdf"
                action="#"
                :on-preview="handlePreview"
                :on-remove="handleRemove"
                :before-upload="beforeUploadPDF"
                :on-change="handleChange"
                :before-remove="beforeRemove"
                multiple
                :on-exceed="handleExceed"
                :file-list="fileList"
                :disabled="peopleLevel == 'L3'"
              >
                <el-button class="choose-button" plain icon="el-icon-document">选择文件</el-button>
                <div slot="tip" class="el-upload__tip">支持文件类型：pdf</div>
              </el-upload>
            </el-col>
          </el-form-item>
        </el-form>
      </div>
      <div class="second-step" v-else-if="active === 1">
        <div v-if='formData.scopeType != 1'>
          <el-tabs v-model="activeName" @tab-click="handleClickTabs">
            <el-tab-pane v-if="idType != 2" label="设定行政范围" name="first">
              <el-row :gutter="20">
                <el-col class="rim" :span="12">
                  <!--
                    :load="loadNode"
                    lazy
                    default-expand-all
                    @check-change="checkUpdate"
                  -->
                  <el-tree
                    default-expand-all
                    :data="treeData"
                    show-checkbox
                    node-key="id"
                    ref="tree"
                    highlight-current
                    :props="defaultProps"
                    @check="onChecked"
                  >
                    <span class="custom-tree-node" slot-scope="{ node, data }">
                      <span>{{ node.label }}</span>
                      <span>
                        <el-button
                          v-if="node.level < 5"
                          type="text"
                          icon="el-icon-caret-bottom"
                          size="small"
                          @click="() => append(data,node)"
                        ></el-button>
                      </span>
                    </span>
                  </el-tree>
                </el-col>
                <el-col :span="11">
                  <p class="area-p">
                    项目范围包含下列区域所有机构和人员({{ tagsRegion.length }})
                  </p>
                  <el-tag
                    v-for="tag in tagsRegion"
                    :key="tag.name"
                    closable
                    :type="tag.type"
                    @close="handleCloseTree(tag)"
                  >{{tag.name}}</el-tag>
                </el-col>
              </el-row>
            </el-tab-pane>
            <el-tab-pane label="设定机构" name="second">
              <el-form :inline="true" :model="formOrganization" class="demo-form-inline">
                <el-form-item label>
                  <!-- <el-cascader
                    v-if="idType != 2"
                    size="small"
                    expand-trigger="hover"
                    :options="organizationRegion"
                    v-model="formOrganization.administrativeIdList"
                  ></el-cascader> -->
                  <el-cascader
                    size="small"
                    ref="cascaderRegion"
                    :options="optionsRegion"
                    :props="props"
                    v-model="formOrganization.administrativeIdList"
                    @change="handleChangeRegion"
                    filterable
                    change-on-select
                    placeholder="请选择地区"
                  ></el-cascader>
                </el-form-item>
                <el-form-item>
                  <el-select size="small" v-model="formOrganization.level" placeholder="全部医院级别">
                    <el-option
                      v-for="(item, index) in organizationRank"
                      :key="index"
                      :label="item.label"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label>
                  <el-input style="width:140px;" size="small" v-model="formOrganization.name" placeholder="请输入机构名称"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button size="small" type="primary" @click="searchOrganization()">搜索</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button size="small" type="primary" @click="resetOrgOrPerson('org')">重置</el-button>
                </el-form-item>
                <el-form-item style="float:right;">
                  <el-upload
                    v-if="idType == 1 && status4Flag != 1"
                    class="upload-excel"
                    action="#"
                    accept=".xlsx"
                    multiple
                    :limit="1"
                    :before-upload="uploadOrganization"
                  >
                    <el-button size="small">导入机构名单</el-button>
                    <el-button class="down-button" slot="tip" size="small" @click="download('organization')">下载导入模板</el-button>
                  </el-upload>
                  <div v-if="idType == 1 && status4Flag == 1">
                    <el-button size="small" @click="dialogUpload = true">导入机构名单</el-button>
                    <el-button class="down-button" slot="tip" size="small" @click="download('organization')">下载导入模板</el-button>
                  </div>
                </el-form-item>
              </el-form>
              <!--
                 :row-key="getRowKeys"
                 :reserve-selection="true"
                  @selection-change="selectionChangeOrganization"
              -->
              <el-table
                class="rim"
                ref="multipleOrganization"
                :data="tableOrganization"
                tooltip-effect="dark"
                style="width: 100%"
                @select-all="selectAllOrganization"
                @select="selectOrganization"
              >
                <el-table-column
                  type="selection"
                  width="55"
                  :selectable="selectableTableList"
                ></el-table-column>
                <el-table-column prop="name" label="医院名称" min-width="100" align="center"></el-table-column>
                <el-table-column prop="hospitalLevelName" label="医院级别" align="center"></el-table-column>
                <el-table-column prop="provinceName" label="所属省份" align="center"></el-table-column>
                <el-table-column prop="cityName" label="所属城市" align="center"></el-table-column>
                <el-table-column prop="countyName" label="所属区县" align="center"></el-table-column>
                <el-table-column prop="townName" label="所属街道" align="center"></el-table-column>
                <div slot="empty">
                  <div class="table-empty">
                    <img src="../../assets/image/no-content1.png">
                    <p>没有机构信息</p>
                  </div>
                </div>
              </el-table>
              <div class="pagination">
                <el-pagination
                  background
                  @size-change="handleSizeOrganization"
                  @current-change="handleCurrentOrganization"
                  :current-page="formOrganization.pageNum"
                  :page-sizes="[10, 20, 40]"
                  :page-size="formOrganization.pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="totalOrganization"
                ></el-pagination>
              </div>
            </el-tab-pane>
            <el-tab-pane v-if="peopleLevel != 'L3' || idType != 2" label="设定科室" name="third">
              <el-col :span="8">
                <el-table
                  class="department"
                  ref="multipleDepartment"
                  :data="tableDepartment.filter(data => !searchName || data.name.toLowerCase().includes(searchName.toLowerCase()))"
                  tooltip-effect="dark"
                  style="width: 100%"
                  @selection-change="selectionChangeDepartment"
                  :row-key="getRowKeysDepartment"
                >
                  <el-table-column
                    type="selection"
                    width="55"
                    :reserve-selection="true"
                    :selectable="selectableTableList2"
                  ></el-table-column>
                  <el-table-column prop="name" label="科室名称" align="center">
                    <template slot="header" slot-scope="scope">
                      <el-input
                        v-model="searchName"
                        size="mini"
                        placeholder="输入科室名称"/>
                    </template>
                  </el-table-column>
                  <div slot="empty">
                    <div class="table-empty">
                      <img src="../../assets/image/no-content1.png">
                      <p>没有科室信息</p>
                    </div>
                  </div>
                </el-table>
              </el-col>
            </el-tab-pane>
            <el-tab-pane label="设定人员" name="fourth">
              <el-form :inline="true" :model="formPerson" class="demo-form-inline">
                <!-- <el-form-item>
                  <el-select size="small" v-model="formPerson.departmentId" placeholder="全部科室">
                    <el-option
                      v-for="item in departmentList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    ></el-option>
                  </el-select>
                </el-form-item> -->
                <el-form-item label>
                  <el-input size="small" v-model="formPerson.hospitalName" placeholder="请输入机构名称"></el-input>
                </el-form-item>
                <el-form-item label>
                  <el-input size="small" v-model="formPerson.doctorName" placeholder="请输入人员名称"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button size="small" type="primary" @click="searchPeople">搜索</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button size="small" type="primary" @click="resetOrgOrPerson('person')">重置</el-button>
                </el-form-item>
                <el-form-item style="float:right;">
                  <el-upload
                    v-if="idType == 1 && status4Flag != 1"
                    class="upload-excel"
                    action="#"
                    accept=".xlsx"
                    multiple
                    :limit="1"
                    :before-upload="uploadPerson"
                  >
                    <el-button size="small">导入人员名单</el-button>
                    <el-button class="down-button" slot="tip" size="small" @click="download('person')">下载导入模板</el-button>
                  </el-upload>
                  <div v-if="idType == 1 && status4Flag == 1">
                    <el-button size="small" @click="dialogUpload = true">导入人员名单</el-button>
                    <el-button class="down-button" slot="tip" size="small" @click="download('person')">下载导入模板</el-button>
                  </div>
                </el-form-item>
              </el-form>
              <!--
                 :row-key="getRowKeys"
                 :reserve-selection="true"
                  @selection-change="selectionChangePerson"
              -->
              <el-table
                class="rim"
                ref="multiplePerson"
                :data="tablePerson"
                tooltip-effect="dark"
                style="width: 100%"
                @select-all="selectAllPerson"
                @select="selectPerson"
              >
                <el-table-column
                  type="selection"
                  width="55"
                  :selectable="selectableTableList"
                ></el-table-column>
                <el-table-column prop="name" label="人员名称" align="center"></el-table-column>
                <el-table-column prop="hospitalName" label="所属医院" align="center"></el-table-column>
                <el-table-column prop="departmentName" label="所属科室" align="center"></el-table-column>
                <el-table-column prop="provinceName" label="所属省份" align="center"></el-table-column>
                <el-table-column prop="cityName" label="所属城市" align="center"></el-table-column>
                <el-table-column prop="countyName" label="所属区县" align="center"></el-table-column>
                <div slot="empty">
                  <div class="table-empty">
                    <img src="../../assets/image/no-content1.png">
                    <p>没有人员信息</p>
                  </div>
                </div>
              </el-table>
              <div class="pagination">
                <el-pagination
                  background
                  @size-change="handleSizePerson"
                  @current-change="handleCurrentPerson"
                  :current-page="formPerson.pageNum"
                  :page-sizes="[10, 20, 40]"
                  :page-size="formPerson.pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="totalPerson"
                ></el-pagination>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
        <div v-else>
          <el-form :inline="true" :model="formOrganization" class="demo-form-inline">
              <el-form-item label>
                <el-select
                  size="small"
                  v-model="formEcology.ecology"
                  placeholder="选择小生态"
                  @change="selectChangeEcology"
                  :disabled="status4Flag == 1"
                >
                  <el-option
                    v-for="item in ecologySelect"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <span class="span_ecology">{{ checkedEcology }}</span>
            </el-form>
          <el-table
            class="rim"
            ref="multipleEcology"
            :data="tableEcology"
            tooltip-effect="dark"
            style="width: 100%"
          >
            <el-table-column
              type="selection"
              width="55"
              :selectable="selectableTableEcology"
              :reserve-selection="true"
            ></el-table-column>
            <el-table-column prop="name" label="医院名称" min-width="100" align="center"></el-table-column>
            <el-table-column prop="hospitalLevelName" label="医院级别" align="center"></el-table-column>
            <el-table-column prop="provinceName" label="所属省份" align="center"></el-table-column>
            <el-table-column prop="cityName" label="所属城市" align="center"></el-table-column>
            <el-table-column prop="countyName" label="所属区县" align="center"></el-table-column>
            <el-table-column prop="townName" label="所属街道" align="center"></el-table-column>
            <div slot="empty">
              <div class="table-empty">
                <img src="../../assets/image/no-content1.png">
                <p>没有机构信息！</p>
              </div>
            </div>
          </el-table>
          <div class="pagination">
            <el-pagination
              background
              @size-change="handleSizeEcology"
              @current-change="handleCurrentEcology"
              :current-page="formEcology.pageNum"
              :page-sizes="[10, 20, 40]"
              :page-size="formEcology.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalEcology"
            ></el-pagination>
          </div>
        </div>
        <el-dialog title :visible.sync="dialogShow" width="40%" center>
          <p class="dialog-p">设定范围数据已经被其他管理员修改，是否强制提交进行覆盖</p>

          <span slot="footer" class="dialog-footer">
            <el-button type="default" size="small" @click="dialogShow = false">取消</el-button>
            <el-button type="primary" size="small" @click="coverData()">确定</el-button>
          </span>
        </el-dialog>
        <el-dialog title="提醒" :visible.sync="dialogWarn" width="30%" center :show-close="false" :close-on-click-modal="false">
          <p v-if="warnType == 0">该项目为上架状态，确定要增加“行政范围”吗？</p>
          <span slot="footer" class="dialog-footer">
            <el-button @click="closeCheck()">取消</el-button>
            <el-button type="primary" @click="dialogWarn = false">确定增加</el-button>
          </span>
        </el-dialog>
        <el-dialog title="提醒" :visible.sync="dialogUpload" width="30%" center >
          <p v-if="activeName == 'second'" style="text-align:center">该项目为上架状态，确定要导入机构名单吗？</p>
          <p v-if="activeName == 'fourth'" style="text-align:center">该项目为上架状态，确定要导入人员名单吗？</p>
          <span slot="footer" class="dialog-footer">
            <el-upload
              v-if="activeName == 'second'"
              class="upload-excel"
              action="#"
              accept=".xlsx"
              :limit="1"
              :before-upload="uploadOrganization"
            >
              <el-button class="down-button-close" slot="tip" size="small" @click="dialogUpload = false">取消</el-button>
              <el-button @click="closeUpload()" type="primary" size="small">继续导入</el-button>
            </el-upload>
            <el-upload
              v-if="activeName == 'fourth'"
              class="upload-excel"
              action="#"
              accept=".xlsx"
              :limit="1"
              :before-upload="uploadPerson"
            >
              <el-button class="down-button-close" slot="tip" size="small" @click="dialogUpload = false">取消</el-button>
              <el-button @click="closeUpload()" type="primary" size="small">继续导入</el-button>
            </el-upload>
          </span>
        </el-dialog>
        <el-dialog
          title="导入成功"
          :visible.sync="dialogSuccess"
          width="30%"
          class="dialog-success"
          center
        >
          <p>
            本次成功导入
            <span class="upload-text">{{ updateNum }}条</span> 数据
          </p>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" size="small" @click="dialogSuccess = false">关闭</el-button>
          </span>
        </el-dialog>
        <el-dialog title="导入失败" :visible.sync="dialogFail" width="30%" class="dialog-fail" center>
          <div class="fail-type" v-if="failType == 1">
            <p>导入数据量已超限额，请修正后再次导入</p>
            <p class="fail-notice">仅支持一次导入5000条数据</p>
          </div>
          <div class="fail-type" v-if="failType == 2">
            <p>
              有
              <span class="fail-num">{{ failNum }}条</span> 数据不符合格式要求，请修正后再次导入
            </p>
            <p class="fail-notice">仅支持xlsx格式的文件</p>
            <p class="fail-link" @click="download('fail')">下载错误数据></p>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-upload
              v-if="uploadType == 'org'"
              class="upload-button"
              action="#"
              accept=".xlsx"
              multiple
              :limit="1"
              :before-upload="uploadOrganization"
            >
              <el-button slot="tip" class="down-button-close" size="small" @click="dialogFail = false">取消</el-button>
              <el-button
                stype="position: absolute;top: -14px;"
                type="primary"
                size="small"
                @click="closeFail()"
              >重新导入</el-button>
            </el-upload>
            <el-upload
              v-if="uploadType == 'person'"
              class="upload-button"
              action="#"
              accept=".xlsx"
              multiple
              :limit="1"
              :before-upload="uploadPerson"
            >
              <el-button slot="tip" class="down-button-close" size="small" @click="dialogFail = false">取消</el-button>
              <el-button
                stype="position: absolute;top: -14px;"
                type="primary"
                size="small"
                @click="closeFail()"
              >重新导入</el-button>
            </el-upload>
          </span>
        </el-dialog>
      </div>
      <div class="third-step" v-else-if="active === 2">
        <el-form
          ref="formComponent"
          class="form-component"
          label-width="150px"
          :model="formComponent"
          :rules="rulesComponent"
        >
          <el-form-item label="选择组件：" prop="component">
            <el-col :span="10">
              <!-- :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" -->
              <el-select
                v-model="formComponent.component"
                multiple
                collapse-tags
                filterable
                style="width: 350px"
                placeholder="请选择组件"
                @change="changeValue"
              >
                <el-option
                  v-for="item in optionsComponent"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="已选择：" class="check-component">
            <el-col :span="20" class="tags-list">
              <el-tag
                class = "tags-component"
                v-for="tag in tagsComponent"
                v-bind:class="{'tags-component-online': tag.disabled === true }"
                :key="tag.value"
                closable
                :type="tag.type"
                style="margin-left: 10px;"
                @close="handleCloseComponent(tag)"
              >{{tag.name}}</el-tag>
            </el-col>
          </el-form-item>
          <el-form-item required label="学习时长：" class="time-contrl">
            <el-col :span="10">
              <el-radio-group class="el-time-ctr" v-model="formComponent.courseRequire" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6">
                <el-radio :label="1">是（必须达到课程配置的观看时长要求才算通过）</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-col>
          </el-form-item>

        </el-form>
        <el-form
          ref="formExam"
          label-width="150px"
          :model="formExam"
          class="achievement"

        >
          <el-form-item required label="项目通过标准" :class="customError.standard.className">
            <el-select
                v-model="formExam.passType"
                placeholder="请选择"
                style="width: 350px"
                @change="updateCertificateType"
                :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"
              >
                <el-option
                  v-for="item in certificateTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
              <div class="el-form-item__error" v-if="customError.standard.error != ''">{{customError.standard.error}}</div>
          </el-form-item>

          <el-form-item required label="累计学习时长大于等于:" v-show="formExam.passType == 3" :class="customError.passTotalLearnTime.className">
            <el-input placeholder="请输入" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" v-model="formComponent.passTotalLearnTime" style="width:200px" @input="focusFun($event,'passTotalLearnTime')">
              <template slot="append">分钟</template>
            </el-input>
            <div class="el-form-item__error" v-if="customError.passTotalLearnTime.error != ''">{{customError.passTotalLearnTime.error}}</div>
          </el-form-item>

          <!--add 选择平均分展示-->
          <div v-show="formExam.passType == 2" >

              <div class="mleft60" v-show="formExam.passType == 2">

                <div class="mini-source" style="overflow: hidden;">
                  <el-form-item  label="项目中最高" label-width="80px" style="float: left;" :class="customError.passExamCount.className" class="min-label">
                    <div class="source-item">

                      <el-input placeholder="请输入数字" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" size="mini" v-model="formComponent.passExamCount" style="width:150px"  @input="focusFun($event,'passExamCount')">
                        <template slot="append">门</template>
                      </el-input>

                    </div>
                    <div class="el-form-item__error" v-if="customError.passExamCount.error != ''">{{customError.passExamCount.error}}</div>
                  </el-form-item>
                  <div style="float: left;padding:0 5px;line-height: 26px;font-size: 12px;color:#606266">考试成绩的平均分大于等于</div>
                  <el-form-item  label="" label-width="0px" style="float: left;" :class="customError.passAverageScore.className"  class="min-label">
                    <div class="source-item">

                       <el-input placeholder="请输入数字" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" size="mini" v-model="formComponent.passAverageScore" style="width:150px" @input="focusFun($event,'passAverageScore')">
                         <template slot="append">分</template>
                       </el-input>

                    </div>
                    <div class="el-form-item__error" v-if="customError.passAverageScore.error != ''">{{customError.passAverageScore.error}}</div>
                  </el-form-item>
                   <div style="float: left;padding:0 5px;line-height: 26px;font-size: 12px;color:#606266">则项目通过</div>

                </div>

              </div>

          </div>



          <el-form-item required label="配置证书：">
            <el-col :span="10">
            <el-radio-group class="el-configure" v-model="formComponent.configure" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
            </el-radio-group>
            </el-col>
          </el-form-item>

          <!--edit 选择配置证书展示-->

          <div v-show="formComponent.configure == 1 && formExam.passType == 2" v-for="(item , index) in formExam.exam" :key="index">
            <div class="mleft60">
              <div class="soure-configure">

                  <div class="configure-item">
                      <el-form-item label="平均分:" label-width="65px" style="float: left;" :class="item.minClass" class="min-label">
                        <el-col :span="5">
                          <el-input :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" placeholder="请输入数字" size="mini" v-model="item.rangeMin" style="width:215px"  @input="focusFun($event,'rangeMin',index)">
                           <template slot="append">分</template>
                          </el-input>
                        </el-col>
                        <div class="el-form-item__error" v-if="item.minError">{{item.minError}}</div>
                      </el-form-item>
                      <div style="float: left;padding:0 5px;line-height: 26px;">~</div>
                      <el-form-item  label-width="0" style="float: left;margin-left:0px;" :class="item.maxClass" class="min-label">
                         <el-col :span="5">
                           <el-input :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6" placeholder="请输入数字" size="mini" v-model="item.rangeMax" style="width:215px"  @input="focusFun($event,'rangeMax',index)">
                            <template slot="append">分</template>
                           </el-input>
                         </el-col>
                         <div class="el-form-item__error" v-if="item.maxError">{{item.maxError}}</div>
                      </el-form-item>
                  </div>
                 <div class="configure-item">
                   <el-form-item label="发放证书:" style="margin-left: -85px;" :class="item.certClass">
                     <el-select
                       v-model="item.certificateId"
                       placeholder="请选择证书"
                       size="mini"
                       style="width: 450px;"
                       @change="updateCertificate(index)"
                       :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"
                     >
                       <el-option
                         v-for="item in optionsCertificate"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value"
                       ></el-option>
                     </el-select>
                     <div class="el-form-item__error" v-if="item.certError">{{item.certError}}</div>
                   </el-form-item>


                 </div>

                 <!-- <el-form-item label="发放证书" style="width:100px;">

                   <el-col :span="3">
                     <el-button @click="addCertificate" icon="el-icon-plus" circle></el-button>
                     <el-button @click="reduceCertificate(index)" icon="el-icon-minus" circle></el-button>
                   </el-col>
                 </el-form-item> -->
                 <div class="configure-option">
                   <el-button size="mini" @click="addCertificate" icon="el-icon-plus" circle :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"></el-button>
                   <el-button size="mini" @click="reduceCertificate(index)" icon="el-icon-minus" circle :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"></el-button>
                 </div>
              </div>

            </div>

            <!-- <el-form-item label="项目中最高">
              <el-col :span="3">
                <el-input v-model="item.examCount" @change="updateCount(index)" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"></el-input>
              </el-col>
              <el-col class="line" :span="3.5" > &nbsp 门考试平均分：</el-col>
              <el-col :span="3">
                <el-input  v-model="item.rangeMin" @change="updateMin(index)" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"></el-input>
              </el-col>
              <el-col class="line" :span="1.5"> &nbsp 分~ &nbsp</el-col>
              <el-col :span="3">
                <el-input v-model="item.rangeMax" @change="updateMax(index)" :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"></el-input>
              </el-col>
            </el-form-item> -->

          </div>
          <el-form-item required v-show="formComponent.configure == 1 && (formExam.passType == 1 || formExam.passType == 3)" label="发放证书" :class="customError.certificate.className">
            <el-select
              v-model="formComponent.certificate"
              placeholder="请选择证书"
              style="width: 350px"
              :disabled="projectStatus == 3 || projectStatus == 4 || projectStatus == 5  || projectStatus == 6"
            >
              <el-option
                v-for="item in optionsCertificate"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
            <div class="el-form-item__error" v-if="customError.certificate.error != ''">{{customError.certificate.error}}</div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import { doUpload, getFilePath } from "../../utils/qiniu-util";
import { mapGetters } from "vuex";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
import * as operationData from "../../utils/operation";
import { getExeclUrl } from "@/utils/index";
import {
  uploadOrgExcel,
  uploadPersonExcel
} from "@/utils/education/educationApi";
import Sortable from "sortablejs";

let vm = null;
export default {
  components: {
    BreadCrumb
  },
  data() {
    let checkProjectStr = (rule, value, callback) => {
      if (value.indexOf("\\") != -1) {
        //存在
        callback(new Error("请勿输入字符“ \\ ”"));
      } else if (value.indexOf(".") != -1) {
        callback(new Error("请勿输入字符“ . ”"));
      } else {
        callback();
      }
    };
    let checkNormalInt = (rule, value, callback) => {
      const val = parseFloat(value);
      const isInteger = Number.isInteger(val);
      // if((isInteger && val > 0) || checkNeedRule(val)){
      if (!value || (isInteger && val >= 0 && val <= 100)) {
        callback();
      } else {
        callback(new Error(`请输入0~100正整数`));
      }
    };

    let checkOrgListName = (rule, value, callback) => {
      console.log(rule, value, callback);
      // const val = parseFloat(value);
      // const isInteger = Number.isInteger(val);
      // // if((isInteger && val > 0) || checkNeedRule(val)){
      // if (!value || (isInteger && val >= 0 && val <= 100)) {
      //   callback();
      // } else {
      //   callback(new Error(`请输入0~100正整数`));
      // }
    };
    
    return {
      idTypeValue: 1,
      idTypeProject: "",
      customError: {
        standard: {
          className: "",
          error: ""
        },
        certificate: {
          className: "",
          error: ""
        },
        passTotalLearnTime: {
          className: "",
          error: ""
        },
        passExamCount: {
          className: "",
          error: ""
        },
        passAverageScore: {
          className: "",
          error: ""
        }
      },
      projectId: null,
      peopleLevel: null,
      //面包屑
      curmbFirst: "教培项目",
      curmbSecond: "新建项目",
      //页面展示位置
      stepData: [true, false, false],
      active: 0,
      activeName: "first",
      //基层信息 数据
      uploadImgMessage: false,
      uploadImgMessage2: false,
      imgMouseOver: false,
      imgMouseOver2: false,
      imageUrl: "",
      formData: {
        projectName: "",
        projectBegintime: "",
        projectEndtime: "",
        projectIntro: "",
        type: 1,
        attachmentUrl1: "",
        attachmentUrl2: "",
        attachmentUrl3: "",
        attachmentMore1: {},
        attachmentMore2: {},
        scopeType: 0,
        organizationName: "",
        organizationNameList: [''],
        sendOption: 1,
        receiveOption: 1,
        visibleFlag: 1,
        learnableFlag: 2,
        authorityType: 1,
        allowLearn: 2
      },
      orgListIndex: 0,
      pickerOptions0: {
        disabledDate: time => {
          if (
            this.formData.projectEndtime != "" &&
            this.formData.projectEndtime != null
          ) {
            return (
              time.getTime() > new Date(this.formData.projectEndtime).getTime()
            );
          }
        }
      },
      pickerOptions1: {
        disabledDate: time => {
          return (
            time.getTime() < new Date(this.formData.projectBegintime).getTime()
          ); //减去一天的时间代表可以选择同一天;
        }
      },
      fileList: [],
      //设定行政范围 数据
      scopeReq: {},
      allSelectedKeys: [],
      updatedTree: false,
      defaultProps: {
        children: "children",
        label: "label",
        isLeaf: "isLeaf"
      },
      treeData: [],
      tagsRegion: [],
      //设定机构 数据
      getRowKeys(row) {
        return row.id;
      },
      checkTableState: {
        multipleOrganization: "",
        multipleDepartment: "",
        multiplePerson: ""
      },
      updatedOrganization: false,
      formOrganization: {
        name: "",
        administrativeId: "0",
        administrativeIdList: ["0"],
        level: "-1",
        chechAll: true,
        pageNum: 1,
        pageSize: 10
      },
      organizationRegion: [],
      organizationRank: [],
      hasOrganizationInit: false,
      tableOrganization: new Array(),
      multipleSelectionOrganization: [],
      currentOrganization: 1,
      totalOrganization: 10,
      pageSizeOrganization: 2,
      lookedOrganization: [],
      changedOrganization: [],
      changedOrganization2: [],
      //设定科室 数据
      firstDepartment: true,
      formDepartment: {
        grade: ""
      },
      tableDepartment: [],
      multipleSelectionDepartment: [],
      updatedDepartment: false,
      changedDepartment: {},
      //设定人员 数据
      getRowKeysPerson(row) {
        return row.id;
      },
      formPerson: {
        hospitalId: 0,
        departmentId: -1,
        doctorName: "",
        hospitalName: "",
        pageNum: 1,
        pageSize: 10
      },
      hospitalList: [],
      departmentList: [],
      tablePerson: new Array(),
      multipleSelectionPerson: [],
      currentPerson: 1,
      pageSizePerson: 2,
      totalPerson: 10,
      updatedPerson: false,
      lookedPerson: [],
      changedPerson: [],
      changedPerson2: [],
      //dialog
      dialogShow: false,
      flagCover: 0,
      //记录上次
      scopeOfOrganizationLast: [],
      scopeOfPeopleLast: [],
      setKindOfOrganizationLast: "",
      setKindOfPeopleLast: "",
      //搜索类型
      searchOrganizationType: "",
      searchPeopleType: "",
      //小生态
      checkedEcology: "",
      ecologySelect: [],
      formEcology: {
        ecology: "",
        pageNum: 1,
        pageSize: 10
      },
      totalEcology: 0,
      tableEcology: [],
      checkTableEcology: "",
      getRowKeysEcology(row) {
        return row.id;
      },
      lookedEcology: [],
      changedEcology: [],
      changedEcology2: [],
      //选择项目组件 数据
      optionsComponent: [],
      optionsCertificate: [],
      formComponent: {
        component: [],
        configure: 2,
        certificate: "",
        courseRequire: 0, //0：不控制 1：按课程时长配置要求
        passExamCount: "",
        passAverageScore: "",
        passTotalLearnTime: ""
      },
      tagsComponent: [],
      projectStatus: "",
      status4Flag: "",
      showStorage: false,
      //考试数据
      formExam: {
        certificateType: 1,
        passType: 1,
        exam: [
          {
            examCount: 1,
            rangeMin: "",
            rangeMax: "",
            certificateId: "",
            certificateName: ""
          }
        ]
      },
      certificateTypeList: [
        {
          label: "所有组件通过",
          value: 1
        },
        {
          label: "根据平均分设定",
          value: 2
        },
        {
          label: "根据项目内学习时长设定",
          value: 3
        }
      ],
      visibleName: false,
      organizationContent: "",
      //v2.2.0更新
      dialogWarn: false,
      warnType: 0,
      nowCheck: {},
      administrativeValue: "",
      optionsRegion: [],
      dialogUpload: false,
      searchName: "",
      getRowKeysDepartment(row) {
        return row.id;
      },
      updateNum: 0,
      dialogSuccess: false,
      failType: 2,
      failNum: 0,
      failExcelUrl: "",
      dialogFail: false,
      uploadType: "",
      props: {
        lazy: true,
        lazyLoad(node, resolve) {
          const { level } = node;
          console.log("node", node);
          if (node.level == 1) {
            let req = {
              provinceId: node.data.value
            };
            vm.GET("basic-data/position/cities", req).then(res => {
              let newData = vm.setMoreOption(res.data.cityList, "cities");
              resolve(newData);
            });
          } else if (node.level == 2) {
            let req = {
              cityId: node.data.value
            };
            vm.GET("basic-data/position/counties", req).then(res => {
              let newData = vm.setMoreOption(res.data.countyList, "counties");
              resolve(newData);
            });
          } else if (node.level == 3) {
            let req = {
              countyId: node.data.value
            };
            vm.GET("basic-data/position/towns", req).then(res => {
              let newData = vm.setMoreOption(res.data.townList, "towns");
              resolve(newData);
            });
          }
        }
      },
      //校验工具 数据
      rulesComponent: {
        component: [
          { required: true, message: "请选择组件", trigger: "change" }
        ],
        certificate: [
          { required: true, message: "请选择证书", trigger: "change" }
        ],
        visitTime: [
          { required: false, trigger: "change", validator: checkNormalInt }
        ],
        showRules1: [{ required: true, message: "请输入门数", trigger: "blur" }]
      },

      rules: {
        projectName: [
          { required: true, message: "请输入项目名称", trigger: "blur" },
          {
            min: 2,
            max: 24,
            message: "输入长度为2-24的内容，可包含中英文、数字及特殊符号",
            trigger: "blur"
          },
          { validator: checkProjectStr, trigger: "blur" }
        ],
        // organizationName: [
        //   { required: true, message: "请填写发起机构名称", trigger: "blur" },
        //   {
        //     min: 1,
        //     max: 16,
        //     message: "超过12个最大字数限制，请精简字数或使用简称",
        //     trigger: "blur"
        //   }
        // ],
        // organizationNameList: [
        //   { validator: checkOrgListName, trigger: "blur" }
        // ],
        duringTime: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        projectBegintime: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        projectEndtime: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ],
        type: [
          {
            type: "array",
            required: true,
            message: "请至少选择一个活动性质",
            trigger: "change"
          }
        ],
        resource: [
          { required: true, message: "请选择活动资源", trigger: "change" }
        ],
        projectIntro: [
          { required: true, message: "请填写项目简介", trigger: "blur" },
          { min: 1, max: 200, message: "超出可输入的最大长度", trigger: "blur" }
        ],
        attachmentUrl1: [
          { required: true, message: "请选择列表图片", trigger: "blur" }
        ],
        attachmentUrl2: [
          { required: true, message: "请选择封面", trigger: "blur" }
        ]
      }
    };
  },
  computed: {
    ...mapGetters(["_token"])
  },
  created() {
    vm = this;
    (this.projectId = vm.getUrlSearch(window.location.href, "projectId")),
      (this.peopleLevel = vm.getUrlSearch(window.location.href, "level"));

    this.changeOnStep(this.active);
    this.getComponentInfo();
    //this.editManager();
    vm.idType = localStorage.getItem("storageIdType");
    console.log("this.idType:" + vm.idType);
    if (vm.idType == 2) {
      this.activeName = "second";
    }
  },
  // 挂载到Dom完成时
  mounted: function() {
    commonUtil.resizeHeight();
  },
  methods: {
    plusOrg(index) {
      vm.formData.organizationNameList.splice(index + 1, 0, '');
    },
    deleteOrg(index) {
      vm.formData.organizationNameList.splice(index, 1);
    },
    focusFun(ev, parm, index) {
      if (index != undefined) {
        if (parseInt(ev) < 0 || !this.checkIntFun(ev)) {
          console.log(typeof index);
          this.formExam.exam[index][parm] = "";
        }
        if (parm == "rangeMax" && parseInt(ev) > 100) {
          this.formExam.exam[index][parm] = "100";
        }
        if (ev != "") {
          if (parm == "rangeMax") {
            this.formExam.exam[index].maxClass = "";
            this.formExam.exam[index].maxError = "";
          }
          if (parm == "rangeMin") {
            this.formExam.exam[index].minClass = "";
            this.formExam.exam[index].minError = "";
          }
        }
      } else {
        if (parseInt(ev) < 0 || !this.checkIntFun(ev)) {
          this.formComponent[parm] = "";
        }
        if (parm == "passAverageScore" && parseInt(ev) > 100) {
          this.formComponent[parm] = "100";
        }
        if (ev != "") {
          this.customError[parm] = {
            className: "",
            error: ""
          };
        }
      }
    },

    checkOrgNameList() {
      let nameList = this.formData.organizationNameList;
      for(let i = 0; i < nameList.length; i ++) {
        if(!nameList[i]) {
          this.$message.error('发起机构名称不可以为空');
          return false;
        }
      }
      for(let i = 0; i < nameList.length - 1; i ++) {
        for(let j = i + 1; j < nameList.length; j ++) {
          if(nameList[i] == nameList[j]) {
            this.$message.error('发起机构名称不能重复');
            return false;
          }
        }        
      }
      return true;
    },
    
    //表单校验
    submitForm(formName) {
      let flag = null;
      this.$refs[formName].validate(valid => {
        if (valid) {
          flag = true;
        } else {
          console.log("error submit!!");
          flag = false;
        }
      });
      return flag;
    },
    //重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //  删除图片
    deleteImg(type) {
      if (type == 1) {
        vm.formData.attachmentUrl1 = "";
        vm.imgMouseOver = false;
      } else {
        vm.formData.attachmentUrl2 = "";
        vm.imgMouseOver2 = false;
      }
    },
    //改变封面类型
    changeCover(radio) {
      this.formData.attachmentUrl2 = "";
    },
    //设置编辑数据
    setEditData(editData) {
      //console.log(editData);
      //设置基础信息页
      this.formData = {
        id: vm.getUrlSearch(window.location.href, "projectId"),
        projectName: editData.projectData.projectName,
        projectBegintime: editData.projectData.projectBegintime,
        projectEndtime: editData.projectData.projectEndtime,
        projectIntro: editData.projectData.projectIntro,
        type: editData.attachmentData[1].attachmentType,
        attachmentUrl1: editData.attachmentData[0].attachmentUrl,
        attachmentUrl2: editData.attachmentData[1].attachmentUrl,
        attachmentUrl3: "",
        attachmentMore1: {
          attachmentName: editData.attachmentData[0].attachmentName,
          attachmentExt: editData.attachmentData[0].attachmentExt,
          attachmentSize: editData.attachmentData[0].attachmentSize
        },
        attachmentMore2: {
          attachmentName: editData.attachmentData[1].attachmentName,
          attachmentExt: editData.attachmentData[1].attachmentExt,
          attachmentSize: editData.attachmentData[1].attachmentSize
        },
        scopeType: editData.projectData.scopeType,
        organizationName: editData.projectData.organizationName,
        organizationNameList: editData.projectData.organizationNameList,
        notifyId: editData.notifyData.notifyId,
        sendOption: editData.notifyData.sendOption,
        receiveOption: editData.notifyData.receiveOption,
        visibleFlag: editData.projectData.visibleFlag,
        learnableFlag: editData.projectData.learnableFlag,
        authorityType: editData.projectData.authorityType,
        allowLearn: editData.projectData.allowLearn || 2
      };
      this.organizationContent = editData.projectData.creatorOrganizationName;
      if (editData.attachmentData.length > 2) {
        for (let i = 2; i < editData.attachmentData.length; i++) {
          let pdfItem = {
            name: editData.attachmentData[i].attachmentName,
            url: editData.attachmentData[i].attachmentUrl,
            attachmentExt: editData.attachmentData[i].attachmentExt,
            attachmentSize: editData.attachmentData[i].attachmentSize
          };
          vm.fileList.push(pdfItem);
        }
      }
      //设置选择项目组件页
      let componentEdit = [];
      let certificateEdit = 0;
      for (let i = 0; i < editData.componentData.length; i++) {
        componentEdit.push(editData.componentData[i].relevanceId);
      }
      this.formComponent.component = componentEdit;
      this.initTags(componentEdit);
      if (editData.certificateData.length > 0) {
        this.formComponent.configure = 1;
        this.formComponent.certificate =
          editData.certificateData[0].relevanceId;
      }
      if (editData.certificateRule.length > 0) {
        this.formComponent.configure = 1;
      }
      //初始化考试平均分配置数据
      this.formExam.certificateType = editData.projectData.certificateType;
      this.formExam.passType = editData.projectData.passType;
      this.formExam.exam = editData.certificateRule;
      if (this.formExam.exam.length > 0) {
        for (let k = 0; k < this.formExam.exam.length; k++) {
          this.formExam.exam[k].certClass = "";
          this.formExam.exam[k].certError = "";
          this.formExam.exam[k].minClass = "";
          this.formExam.exam[k].minError = "";
          this.formExam.exam[k].maxClass = "";
          this.formExam.exam[k].maxError = "";
        }
      }
      console.log(this.formExam.exam);
      this.formComponent.passAverageScore =
        editData.projectData.passAverageScore > 0
          ? editData.projectData.passAverageScore
          : "";
      this.formComponent.passExamCount =
        editData.projectData.passExamCount > 0
          ? editData.projectData.passExamCount
          : "";
      this.formComponent.passTotalLearnTime =
        editData.projectData.passTotalLearnTime;
      if (this.formExam.exam.length == 0) {
        this.formExam.exam = [
          {
            examCount: 1,
            rangeMin: "",
            rangeMax: "",
            certificateId: "",
            certificateName: "",
            minClass: "",
            minError: "",
            maxClass: "",
            maxError: "",
            certClass: "",
            certError: ""
          }
        ];
      }
    },
    //编辑管理
    editManager(data) {
      let req = {};
      let projectId = vm.getUrlSearch(window.location.href, "projectId");
      if (projectId != null && projectId != "") {
        openLoading(vm);
        vm
          .GET("portal/portalInfo/getProjectInfo/" + projectId, req)
          .then(res => {
            closeLoading(vm);
            if (res.code == "000000" && res.data.projectData != null) {
              let editData = res.data;
              console.log(editData);
              this.status4Flag = res.data.projectData.status4Flag;
              this.setEditData(editData);
              this.idTypeProject = res.data.projectData.idType;
              this.projectStatus = res.data.projectData.projectStatus;
              this.formComponent.courseRequire =
                res.data.projectData.courseRequire || 0;
              // this.status4Flag = res.data.projectData.status4Flag;
              if (this.projectStatus == 1) {
                this.showStorage = true;
              }
              //console.log('projectStatus:',this.projectStatus);
            } else {
              console.log(res);
            }
          });
      } else {
        this.showStorage = true;
      }
    },
    //编辑/更新 基础信息
    insertOrUpdate(option) {
      //console.log(this.formData);
      let projectModel = {
        projectName: this.formData.projectName,
        projectBegintime: this.formData.projectBegintime,
        projectEndtime: this.formData.projectEndtime,
        projectIntro: this.formData.projectIntro,
        scopeType: this.formData.scopeType,
        // organizationName: this.formData.organizationName,
        organizationNameList: this.formData.organizationNameList,
        visibleFlag: this.formData.visibleFlag,
        learnableFlag: this.formData.learnableFlag,
        authorityType: this.formData.authorityType,
        allowLearn: this.formData.allowLearn
      };
      let attachmentModel = [
        {
          attachmentType: 1,
          attachmentUrl: this.formData.attachmentUrl1,
          attachmentName: this.formData.attachmentMore1.attachmentName,
          attachmentExt: this.formData.attachmentMore1.attachmentExt,
          attachmentSize: this.formData.attachmentMore1.attachmentSize,
          kind: 1,
          seqNo: 1
        },
        {
          attachmentType: this.formData.type,
          attachmentUrl: this.formData.attachmentUrl2,
          attachmentName: this.formData.attachmentMore2.attachmentName,
          attachmentExt: this.formData.attachmentMore2.attachmentExt,
          attachmentSize: this.formData.attachmentMore2.attachmentSize,
          kind: 2,
          seqNo: 1
        }
      ];
      let attachmentPDFModel = [];
      // if (option == "add") {
      for (let i = 0; i < vm.fileList.length; i++) {
        let PDFModel = {
          attachmentType: 3,
          attachmentName: vm.fileList[i].name,
          attachmentUrl: vm.fileList[i].url,
          attachmentExt: vm.fileList[i].attachmentExt,
          attachmentSize: vm.fileList[i].attachmentSize,
          kind: 3
        };
        attachmentPDFModel.push(PDFModel);
      }
      //}
      if (option == "edit" || option == "storageEdit") {
        //编辑
        projectModel.id = this.formData.id;
        projectModel.projectStatus = this.projectStatus;
        projectModel.courseRequire = this.formComponent.courseRequire; //课程完成度控制
        for (let i = 0; i < attachmentModel.length; i++) {
          attachmentModel[i].portalProjectId = this.formData.id;
        }
        for (let i = 0; i < attachmentPDFModel.length; i++) {
          attachmentPDFModel[i].portalProjectId = this.formData.id;
        }
        //idTypeProject
      }
      //教培项目v2.1.0新增通知优化
      let notifyData = {
        notifyId: 0,
        receiveOption: this.formData.receiveOption,
        sendOption: this.formData.sendOption
      };
      if (option == "edit" || option == "storageEdit") {
        notifyData.notifyId = this.formData.notifyId;
      }
      let postData = {
        projectModel: JSON.stringify(projectModel),
        attachmentModel: JSON.stringify(attachmentModel),
        attachmentPDFModel: JSON.stringify(attachmentPDFModel),
        notifyData: JSON.stringify(notifyData)
      };
      //console.log(postData);
      openLoading(vm);
      vm.POST("portal/portalInfo/insertOrUpdate", postData).then(res => {
        closeLoading(vm);
        if (option == "storage" || option == "storageEdit") {
          vm.$message.info(res.message);
        }
        if (res.code == "000000") {
          //console.log(res);
          this.projectId = res.data.id;
          this.projectStatus = res.data.projectStatus;
          this.idTypeProject = res.data.idType;

          this.operationLast();
          if (option != "storage" && option != "storageEdit") {
            this.active++;
            this.stepData = [false, true, false];
            if (this.formData.scopeType == 1) {
              this.getEcologySelect();
              //this.getEcology();
              return;
            }
            // this.projectId = res.data.id;
            this.initRange();
            this.getDepartment();
          }
        } else {
          vm.$message.info(res.message);
        }
      });
    },
    //查询上次设定范围
    operationLast() {
      let req = {};
      vm
        .GET("portal/scope/v1/" + this.projectId + "/operation/last", req)
        .then(res => {
          if (res.code == "000000") {
            this.scopeReq = res.data.scopeReq;
            //console.log(this.scopeReq);
            //operationData.getDivision(res.data.scopeReq.scopeOfAdministrative);
            this.setKindOfOrganizationLast = this.scopeReq.setKindOfOrganization;
            this.setKindOfPeopleLast = this.scopeReq.setKindOfPeople;
            this.scopeOfOrganizationLast = operationData.getDivision(
              this.scopeReq.scopeOfOrganization
            );
            this.scopeOfPeopleLast = operationData.getDivision(
              this.scopeReq.scopeOfPeople
            );
            //this.changedOrganization = list;
          }
        });
    },
    //查询组件证书信息
    getComponentInfo() {
      let param = {};
      let projectIdValue = vm.projectId;
      if (projectIdValue == null) {
        projectIdValue = 0;
      }
      vm
        .GET("portal/portalInfo/getComponentInfo/" + projectIdValue, param)
        .then(res => {
          if (res.code == "000000") {
            //console.log(res);
            let componentList = res.data.componentList;
            let certificateList = res.data.certificateList;
            let optionsComponent = [],
              optionsCertificate = [];
            for (let index = 0; index < componentList.length; index++) {
              optionsComponent[index] = {};
              optionsComponent[index].value = componentList[index].id;
              optionsComponent[index].label = componentList[index].name;
              optionsComponent[index].name = componentList[index].name;
            }
            for (let index = 0; index < certificateList.length; index++) {
              optionsCertificate[index] = {};
              optionsCertificate[index].value = certificateList[index].id;
              optionsCertificate[index].label = certificateList[index].name;
              optionsCertificate[index].name = certificateList[index].name;
            }
            this.optionsComponent = optionsComponent;
            this.optionsCertificate = optionsCertificate;
            this.organizationContent = res.data.creatorOrganizationName;
          }
          this.editManager();
        });
    },
    //项目组件信息 暂存/完成
    componentDraft(type) {
      let param = {
        // componentIds: this.formComponent.component,
        componentIds: operationData.getComponent(vm.tagsComponent),
        // certificateId: this.formComponent.certificate,
        certificateId: [],
        projectId: this.projectId,
        type: type,
        status: this.projectStatus,
        certificateType: this.formExam.passType == 2 ? 2 : 1,
        getCertificateRule: [],
        courseRequire: this.formComponent.courseRequire,
        passType: this.formExam.passType
      };
      if (this.formExam.passType == 2) {
        param.passAverageScore = this.formComponent.passAverageScore;
        param.passExamCount = this.formComponent.passExamCount;
      }
      if (this.formExam.passType == 3) {
        param.passTotalLearnTime = this.formComponent.passTotalLearnTime;
      }
      // console.log('排序后',vm.tagsComponent,'param',param);
      if (this.formComponent.configure == 1) {
        //  2.多证书有规
        if (this.formExam.passType == 2) {
          let ruleData = vm.formExam.exam;
          for (let o = 0; o < ruleData.length; o++) {
            if (
              ruleData[o].certificateId != "" &&
              ruleData[o].certificateId != null
            ) {
              param.certificateId[o] = ruleData[o].certificateId;
            }
            param.getCertificateRule[o] = {
              certificateId: ruleData[o].certificateId,
              certificateName: ruleData[o].certificateName,
              examCount: ruleData[o].examCount,
              portalProjectId: this.projectId,
              rangeMax: ruleData[o].rangeMax,
              rangeMin: ruleData[o].rangeMin
            };
          }
        } else {
          // 1.单证书无规则
          if (
            this.formComponent.certificate != "" &&
            this.formComponent.certificate != null
          ) {
            param.certificateId[0] = this.formComponent.certificate;
          }
        }
      }
      vm.POST("portal/portalInfo/componentDraft", param).then(res => {
        console.log(res);
        vm.$message({
          message: res.message,
          type: "info"
        });
        if (res.code == "000000") {
          //notify
          if (type == 2) {
            let query = {};
            if (this.$route.query.pageNum) {
              query = { pageNum: this.$route.query.pageNum };
            }
            this.$router.push({ path: "item-manager", query: query });
            // this.$router.push("item-manager?pageNum="+this.$route.query.pageNum);
          }
        }
      });
    },
    //步骤style
    changeOnStep(active) {
      if (active == 0) {
        this.stepData = [true, false, false];
      } else if (active == 1) {
        this.stepData = [false, true, false];
        this.operationLast();
        this.initRange();
        this.getDepartment();
      } else if (active == 2) {
        this.stepData = [false, false, true];
        setTimeout(function() {
          vm.tagDrop();
        }, 800);
      }
    },
    //点击暂存
    storage() {
      console.log("暂存步骤" + (this.active + 1));
      if (this.active == 0) {
        if (this.formData.projectName != "") {
          if (
            this.formData.projectName.length < 2 ||
            this.formData.projectName.length > 20
          ) {
            this.$message.error("输入长度为2-20的内容");
            return;
          }
          let urlProjectId = vm.getUrlSearch(window.location.href, "projectId");

          if (urlProjectId == null) {
            let param = {
              projectName: this.formData.projectName
            };
            vm.GET("portal/portalInfo/checkProjectName", param).then(res => {
              //console.log(res);
              if (res.code == "000000") {
                //移动到第二页 选择范围
                this.insertOrUpdate("storage");
              } else {
                this.$message.info(res.message);
              }
            });
          } else {
            //console.log('urlProjectId'+urlProjectId);
            this.insertOrUpdate("storageEdit");
          }
        } else {
          this.$message.error("请输入项目名称");
        }
      } else if (this.active == 1) {
        //暂存步骤2
        if (this.formData.scopeType == 1) {
          //小生态暂存
          if (this.formEcology.ecology == "") {
            vm.$message.info("完成");
          } else {
            let req = {};
            req.ecology = [];
            req.ecology[0] = this.formEcology.ecology;
            vm
              .POST("portal/scope/v1/" + this.projectId + "/organization", req)
              .then(res => {
                //console.log('设定小生态范围',res);
                vm.$message.info(res.message);
              });
          }
          return;
        }
        if (this.tagsRegion.length == 0) {
          vm.$message({
            type: "info",
            message: "成功"
          });
          return;
        }
        let req = {
          projectId: this.projectId,
          // setKindOfAdministrative: this.getKind("administrativeScope"),
          // setKindOfOrganization: this.getKind("organization"),
          // setKindOfDepartment: this.getKind("department"),
          // setKindOfPeople: this.getKind("person"),
          // flag: this.flagCover,
          scopeOfAdministrative: this.getScope("administrativeUpdate"),
          scopeOfDepartment: this.getScopeDepartment(),
          flag: 1 //0：下一步 1：暂存
        };
        // if (req.setKindOfAdministrative == 3) {
        //   req.scopeOfAdministrative = this.getScope("administrativeUpdate");
        // }
        // if (req.setKindOfOrganization == 2 || req.setKindOfOrganization == 3) {
        //   req.scopeOfOrganization = this.getScopeOrganization(
        //     req.setKindOfOrganization
        //   );
        // }
        // if (req.setKindOfDepartment == 3) {
        //   req.scopeOfDepartment = this.getScopeDepartment();
        // }
        // if (req.setKindOfPeople == 2 || req.setKindOfPeople == 3) {
        //   req.scopeOfPeople = this.getScopePeople(req.setKindOfPeople);
        // }
        openLoading(vm);
        // vm.POST("portal/scope", req).then(res => {
        vm.POST("portal/new/scope", req).then(res => {
          //暂存范围
          closeLoading(vm);
          console.log(res);
          vm.$message({
            type: "info",
            message: res.message
          });
        });
      } else if (this.active == 2) {
        //暂存步骤3
        this.componentDraft(1);
      }
    },
    //点击完成
    complete() {
      //type 1:暂存 2：完成
      // if (this.status4Flag == 1) {
      //   vm.$message.info("完成");
      //   vm.$router.push({ path: "item-manager" });
      //   return;
      // }
      console.log("this.peopleLevel", this.peopleLevel);
      if (this.peopleLevel == "L3") {
        vm.$message.info("完成");
        vm.$router.push({ path: "item-manager" });
        return;
      }
      let formName = "formComponent";
      let completeState = this.submitForm(formName);
      let certificateState = this.checkCertificate();
      if (completeState === true && certificateState === true) {
        this.componentDraft(2);
      }
    },
    //覆盖数据
    coverData() {
      this.dialogShow = false;
      this.flagCover = 1;
      this.nextStep();
    },
    //点击下一步
    nextStep() {
      if (this.active == 0) {
        let formName = "formData";
        if(!this.checkOrgNameList()) return;
        let removeState = this.submitForm(formName);
        if (!vm.formData.attachmentUrl1) {
          vm.uploadImgMessage = true;
        } else {
          vm.uploadImgMessage = false;
        }
        if (!vm.formData.attachmentUrl2) {
          vm.uploadImgMessage2 = true;
        } else {
          vm.uploadImgMessage2 = false;
        }
        //console.log("判断移动" + removeState);
        if (
          removeState === true &&
          vm.formData.attachmentUrl1 != "" &&
          vm.formData.attachmentUrl2 != ""
        ) {
          //校验名字
          let projectId = vm.getUrlSearch(window.location.href, "projectId");
          if (projectId == null) {
            //新建
            let param = {
              projectName: this.formData.projectName
            };
            vm.GET("portal/portalInfo/checkProjectName", param).then(res => {
              if (res.code == "000000") {
                //移动到第二页 选择范围
                // this.operationLast();
                this.insertOrUpdate("add");
                // this.active++;
                // this.stepData = [false, true, false];
                //this.initRange();
              } else {
                this.$message.info(res.message);
              }
            });
          } else {
            //编辑
            // this.operationLast();
            this.insertOrUpdate("edit");
          }
        }
      } else if (this.active == 1) {
        //进入第三步
        if (this.formData.scopeType == 1) {
          //设定小生态范围
          if (this.formEcology.ecology == "") {
            vm.$message({
              type: "info",
              message: "请选择小生态范围"
            });
            return;
          }
          let req = {};
          req.ecology = [];
          req.ecology[0] = this.formEcology.ecology;
          vm
            .POST("portal/scope/v1/" + this.projectId + "/organization", req)
            .then(res => {
              console.log("设定小生态范围", res);
              if (res.code == "000000") {
                this.active++;
                this.stepData = [false, false, true];
                this.tagDrop();
              }
            });
          return;
        }
        if (this.idType == 1) {
          //内部管理员
          // if (this.tagsRegion.length > 0 || this.idTypeProject == 2) {
          //选择了范围
          let req = {
            projectId: this.projectId,
            // setKindOfAdministrative: this.getKind("administrativeScope"),
            // setKindOfOrganization: this.getKind("organization"),
            // setKindOfDepartment: this.getKind("department"),
            // setKindOfPeople: this.getKind("person"),
            // flag: this.flagCover,
            scopeOfAdministrative: this.getScope("administrativeUpdate"),
            scopeOfDepartment: this.getScopeDepartment(),
            flag: 0 //0：下一步 1：暂存
          };
          // if (req.setKindOfAdministrative == 3) {
          //   req.scopeOfAdministrative = this.getScope("administrativeUpdate");
          // }
          // if (
          //   req.setKindOfOrganization == 2 ||
          //   req.setKindOfOrganization == 3
          // ) {
          //   req.scopeOfOrganization = this.getScopeOrganization(
          //     req.setKindOfOrganization
          //   );
          // }
          // if (req.setKindOfDepartment == 3) {
          //   req.scopeOfDepartment = this.getScopeDepartment();
          // }
          // if (req.setKindOfPeople == 2 || req.setKindOfPeople == 3) {
          //   req.scopeOfPeople = this.getScopePeople(req.setKindOfPeople);
          // }
          openLoading(vm);
          // vm.POST("portal/scope", req).then(res => {
          vm.POST("portal/new/scope", req).then(res => {
            closeLoading(vm);
            if (res.code == "000000") {
              //移动到选择项目组件
              //console.log(res);
              let statusMove = this.scopeStatus(res.data.status);
              if (statusMove === 0) {
                this.active++;
                this.stepData = [false, false, true];
                this.tagDrop();
              } else {
                console.log("不能改变范围status：" + res.data.status);
              }
            } else {
              vm.$message({
                type: "info",
                message: res.message
              });
            }
          });
          // }
          // else {
          //   //没有选择范围
          //   vm.$message({
          //     showClose: true,
          //     message: "项目范围不能为空",
          //     type: "error"
          //   });
          // }
        } else {
          //外部人员
          let req = {
            projectId: this.projectId,
            // setKindOfAdministrative: 0,
            // setKindOfOrganization: this.getKind("organization"),
            // setKindOfDepartment: this.getKind("department"),
            // setKindOfPeople: this.getKind("person"),
            // flag: this.flagCover,
            scopeOfAdministrative: null,
            scopeOfDepartment: this.getScopeDepartment(),
            flag: 0 //0：下一步 1：暂存
          };
          // if (
          //   req.setKindOfOrganization == 2 ||
          //   req.setKindOfOrganization == 3
          // ) {
          //   req.scopeOfOrganization = this.getScopeOrganization(
          //     req.setKindOfOrganization
          //   );
          // }
          // if (req.setKindOfDepartment == 3) {
          //   req.scopeOfDepartment = this.getScopeDepartment();
          // }
          // if (req.setKindOfPeople == 2 || req.setKindOfPeople == 3) {
          //   req.scopeOfPeople = this.getScopePeople(req.setKindOfPeople);
          // }
          // vm.POST("portal/scope", req).then(res => {
          openLoading(vm);
          vm.POST("portal/new/scope", req).then(res => {
            closeLoading(vm);
            if (res.code == "000000") {
              //移动到选择项目组件
              let statusMove = this.scopeStatus(res.data.status);
              if (statusMove === 0) {
                this.active++;
                this.stepData = [false, false, true];
                this.tagDrop();
              } else {
                console.log("不能改变范围status：" + res.data.status);
              }
            } else {
              vm.$message({
                type: "info",
                message: res.message
              });
            }
          });
        }
      }
    },
    //图片上传
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    //上传列表图片
    beforeUploadListPic(file) {
      let fileLimit = {
        // width: 230,
        // height: 172,
        size: 0.5,
        sizeText: "500K",
        key: "attachmentUrl1",
        more: "attachmentMore1",
        show: "uploadImgMessage"
      };
      this.beforeAvatarUpload(file, fileLimit);
    },
    //上传封面图片
    beforeUploadCoverPic(file) {
      let fileLimit = {
        // width: 750,
        // height: 420,
        size: 2,
        sizeText: "2.0M",
        key: "attachmentUrl2",
        more: "attachmentMore2",
        show: "uploadImgMessage2"
      };
      if (this.formData.type == 1) {
        this.beforeAvatarUpload(file, fileLimit);
      } else {
        this.beforeUploadMp4(file);
      }
    },
    //上传PDF
    beforeUploadPDF(file) {
      // console.log(file);
      // console.log(this.fileList);
      const isPDF = file.type === "application/pdf";
      if (!isPDF) {
        this.$message.error("请上传PDF格式文件!");
      } else {
        openLoading(vm);
        doUpload(
          vm,
          file,
          getFilePath(file, null),
          "preview4",
          "progress1",
          1
        ).then(function(path) {
          closeLoading(vm);
          console.log(path);
          let fileItem = {
            name: path.name,
            url: path.fullPath,
            attachmentExt: path.ext,
            attachmentSize: path.size
          };
          vm.fileList.push(fileItem);
          vm.$message.success("上传成功");
        });
      }
    },
    handleChange(file, fileList) {
      //this.fileList3 = fileList.slice(-3);
    },
    //上传mp4
    beforeUploadMp4(file) {
      console.log(file);
      const isMP4 = file.type === "video/mp4";
      const isLt = file.size / 1024 / 1024 < 500;
      if (!isLt) {
        this.$message.error("视频不符合规范，请根据规范上传视频");
        return;
      }
      if (!isMP4) {
        this.$message.error("视频不符合规范，请根据规范上传视频");
      } else {
        openLoading(vm);
        doUpload(
          vm,
          file,
          getFilePath(file, null),
          "preview4",
          "progress1",
          ""
        ).then(function(path) {
          closeLoading(vm);
          console.log(path);
          vm.uploadImgMessage2 = false;
          vm.formData.attachmentUrl2 = path.fullPath;
          vm.$message.success("上传成功");
        });
      }
    },
    //上传图片校验
    beforeAvatarUpload(file, fileLimit) {
      const isJPG = file.type === "image/jpeg";
      const isPNG = file.type === "image/png";
      const isLt2M = file.size / 1024 / 1024 < fileLimit.size;
      if (!isJPG && !isPNG) {
        this.$message.error("图片不符合规范，请根据规范上传图片");
        // return;
      }
      if (!isLt2M) {
        this.$message.error("图片不符合规范，请根据规范上传图片 ");
        // return;
      }
      let _img = new FileReader();
      _img.readAsDataURL(file);
      _img.onload = function(theFile) {
        let image = new Image();
        image.src = theFile.target.result;
        image.onload = function() {
          let _this = this;
          if ( false
            // _this.width != fileLimit.width ||
            // _this.height != fileLimit.height
          ) {
            vm.$message.error("图片不符合规范，请根据规范上传图片");
          } else {
            openLoading(vm);
            doUpload(
              vm,
              file,
              getFilePath(file, null),
              "preview4",
              "progress1",
              1
            ).then(function(path) {
              closeLoading(vm);
              console.log(path);
              if (fileLimit.show == "uploadImgMessage") {
                vm.uploadImgMessage = false;
              } else if (fileLimit.show == "uploadImgMessage2") {
                vm.uploadImgMessage2 = false;
              }
              vm.formData[fileLimit.key] = path.fullPath;
              vm.formData[fileLimit.more] = {
                attachmentName: path.name,
                attachmentExt: path.ext,
                attachmentSize: path.size
              };
              vm.$message.success("上传成功");
            });
          }
        };
      };
      return isJPG && isLt2M;
    },
    handleRemove(file, fileList) {
      for (let i = 0; i < vm.fileList.length; i++) {
        if (vm.fileList[i].name == file.name) {
          vm.fileList.splice(i, 1);
          console.log("删除" + i);
        }
      }
    },
    handlePreview(file) {},
    handleExceed(files, fileList) {},
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    //第二步 选择范围 初始化
    initRange() {
      let projectId = this.projectId;
      if (projectId == null) {
        //新建
      } else {
        //编辑
        this.listLevels();
        if (this.idType != 2) {
          this.getAdministrative();
        } else {
          this.activeName = "second";
          this.getOrganization();
          this.getCheckedTree();
          this.getRegionOption();
        }
      }
    },
    //切换tabs
    handleClickTabs(tab, event) {
      let tabName = tab.name;
      if (tabName == "second") {
        //设定机构
        this.formOrganization.pageNum = 1;
        this.formOrganization.name = "";
        this.formOrganization.administrativeIdList = ["0"];
        this.formOrganization.level = "-1";
        this.getCheckedTree();
        this.getOrganization();
        // this.listLevels();
        this.getRegionOption();
      } else if (tabName == "third") {
        //设定科室
        // if (this.checkTableState.multipleDepartment && this.firstDepartment) {
        //   this.$refs.multipleDepartment.toggleAllSelection();
        //   this.firstDepartment = false;
        // }
      } else if (tabName == "fourth") {
        //设定人员
        this.formPerson.pageNum = 1;
        this.formPerson.doctorName = "";
        this.formPerson.hospitalName = "";
        // this.getHospital();
        this.departmentList = this.getDepartmentList();
        //console.log('departmentList',this.departmentList);
        this.getPeople();
      }
    },
    //获取勾选树
    getCheckedTree() {
      if (this.idType != 2) {
        let allTree = JSON.parse(JSON.stringify(this.treeData[0].children));
        let changedTags = JSON.parse(JSON.stringify(this.tagsRegion));
        let organizationArea = operationData.treeHandler(allTree, changedTags);
        console.log("多级树：", organizationArea);
        this.organizationRegion = organizationArea;
        //改
        // this.organizationRegion = operationData.getOrganizationList(
        //   this.tagsRegion
        // );
        //console.log(this.organizationRegion);
      }
    },
    //初始化范围树
    setTreeData(administrative) {
      let treeIdList = [];
      let checkList = [];
      for (let i = 0; i < administrative.length; i++) {
        treeIdList.push(administrative[i].id);
        checkList[i] = {};
        checkList[i].name = administrative[i].label;
        checkList[i].key = administrative[i].id;
      }
      //console.log(treeIdList);
      this.$refs.tree.setCheckedKeys(treeIdList);
      this.tagsRegion = checkList;
    },
    //查询行政范围（树）
    getAdministrative() {
      let req = {
        projectId: this.projectId
      };
      openLoading(vm);
      vm.GET("portal/scope/v1/administrative", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          //console.log(res.data);
          let administrativeAll = res.data.administrativeAll;
          let administrative = res.data.administrative;
          this.treeData = [];
          this.treeData[0] = administrativeAll;
          this.setTreeData(administrative);
          this.getCheckedTree();
          //console.log("treeData", this.treeData);
        }
      });
    },
    //列举选中地区
    initCheckList(allSelectedKeys) {
      this.tagsRegion = [];
      // console.log(allSelectedKeys);
      // console.log(this.$refs.tree.getCheckedNodes());
      let nodeData = this.$refs.tree.getCheckedNodes();
      for (let i = 0; i < nodeData.length; i++) {
        for (let j = 0; j < allSelectedKeys.length; j++) {
          if (
            allSelectedKeys[j].type == 1 &&
            nodeData[i].id == allSelectedKeys[j].key
          ) {
            let tagObj = {};
            tagObj.name = nodeData[i].label;
            tagObj.key = nodeData[i].id;
            this.tagsRegion.push(tagObj);
          }
        }
      }
    },
    //子节点选中
    appendCheck(administrative, checked) {
      //console.log(checked,administrative)
      let checkList = [];
      checkList = this.$refs.tree.getCheckedKeys();
      if (checked) {
        for (let i = 0; i < administrative.length; i++) {
          checkList.push(administrative[i].id);
          // console.log(checkList);
        }
      }
      this.$nextTick(function() {
        this.$refs.tree.setCheckedKeys(checkList);
      });
    },
    //添加子节点
    append(data, node) {
      console.log("data:", data);
      console.log("node:", node);
      if (data.children.length == 0) {
        //let id = data.id + "add";
        let statusValue = 0;
        if (node.checked == true) {
          statusValue = 1;
        }
        let req = {
          id: data.id,
          status: statusValue,
          disabled: data.disabled
        };
        vm.GET("portal/scope/v1/administrative/children", req).then(res => {
          if (res.code == "000000") {
            let administrative = res.data.administrative;
            //console.log(administrative);
            data.children = administrative;
            this.appendCheck(administrative, node.checked);
          }
        });
      }
    },
    getCheckedKeys() {
      console.log(this.$refs.tree.getCheckedKeys());
    },
    onChecked(node, data) {
      vm.checkUpdate(node, data);
      //重构归并树
      let checkedTree = operationData.getSimpleCheckedNodes(
        this.$refs.tree.store
      );
      let halfCheckedTree = this.$refs.tree.getHalfCheckedKeys();
      let allSelectedKeys = operationData.setSelectedKeys(
        checkedTree,
        halfCheckedTree
      );
      //重构内容

      this.allSelectedKeys = allSelectedKeys;
      this.initCheckList(allSelectedKeys);
      //console.log("allSelectedKeys", allSelectedKeys);
      //改变行政范围后，更新设定机构和设定人员
      this.updateOrganizationAndPerson(allSelectedKeys);
      this.updatedTree = true;
    },
    getTreeCheck() {
      //重构归并树
      let checkedTree = operationData.getSimpleCheckedNodes(
        this.$refs.tree.store
      );
      let halfCheckedTree = this.$refs.tree.getHalfCheckedKeys();
      let allSelectedKeys = operationData.setSelectedKeys(
        checkedTree,
        halfCheckedTree
      );
      vm.allSelectedKeys = allSelectedKeys;
      //重构内容
      return allSelectedKeys;
    },
    //通过key设置tree
    setCheckedKeys(tagsRegion) {
      console.log(tagsRegion);
      let treeKeyList = [];
      for (let index = 0; index < tagsRegion.length; index++) {
        treeKeyList[index] = tagsRegion[index].key;
      }
      console.log(treeKeyList);
      this.$refs.tree.setCheckedKeys(treeKeyList);
    },

    //删除label节点 同步树结构
    handleCloseTree(tag) {
      if (this.status4Flag != 1) {
        this.tagsRegion.splice(this.tagsRegion.indexOf(tag), 1);
        this.setCheckedKeys(this.tagsRegion);
      }
    },
    //获取医院等级
    listLevels() {
      let req = {};
      vm.GET("contents/courseDoctor/listLevels?sysCode=10", req).then(res => {
        if (res.code == "000000") {
          // console.log(res);
          this.organizationRank = operationData.getLevelList(res.data.list);
        } else {
          this.organizationRank = [
            {
              id: "0",
              label: "全部医院等级"
            }
          ];
        }
      });
    },
    selectableTableList(row, index) {
      // if (this.status4Flag == 1) {
      if (row.modifyFlag == 1) {
        return false;
      }
      return true;
      // }
      // return true;
    },
    selectableTableList2(row, index) {
      if (this.status4Flag == 1) {
        if (row.status == 1) {
          return false;
        }
        return true;
      }
      return true;
    },
    selectableTableEcology(row, index) {
      return false;
    },
    //改变 设定机构选项
    selectionChangeOrganization(rows) {
      this.changedOrganization = [];
      this.changedOrganization2 = [];
      if (rows) {
        rows.forEach(row => {
          if (row) {
            this.changedOrganization.push(row.id);
          }
        });
      }
      this.changedOrganization2 = operationData.getDifference(
        this.lookedOrganization,
        this.changedOrganization
      );
      console.log(
        "选",
        this.changedOrganization,
        "没",
        this.changedOrganization2
      );
      this.updatePerson();
      this.$refs.multiplePerson.clearSelection();
    },
    //改变机构 table 的check状态
    selectionChangeDepartment(val) {
      this.multipleSelectionDepartment = val;
    },
    //改变人员 table的check状态
    selectionChangePerson(rows) {
      this.changedPerson = [];
      this.changedPerson2 = [];
      if (rows) {
        rows.forEach(row => {
          if (row) {
            this.changedPerson.push(row.id);
          }
        });
      }
      this.changedPerson2 = operationData.getDifference(
        this.lookedPerson,
        this.changedPerson
      );
      console.log("选", this.changedPerson, "没", this.changedPerson2);
    },

    //改变小生态 table check
    selectionChangeEcology(rows) {
      this.changedEcology = [];
      this.changedEcology2 = [];
      if (rows) {
        rows.forEach(row => {
          if (row) {
            this.changedEcology.push(row.id);
          }
        });
      }
      this.changedEcology2 = operationData.getDifference(
        this.lookedEcology,
        this.changedEcology
      );
      console.log("选", this.changedEcology, "没", this.changedEcology2);
    },
    resetPeople() {
      this.checkTableState.multiplePerson = "";
      this.lookedPerson = [];
      this.changedPerson = [];
      this.changedPerson2 = [];
    },
    //获取用户类型
    getKind(type) {
      let kind = 3;
      if (type == "administrative") {
        kind = 3;
        if (this.updatedTree == true) {
          kind = 3;
        }
        //console.log('this.idTypeProject',this.idTypeProject);
        if (this.idTypeProject == 2 && this.tagsRegion.length == 0) {
          kind = 0;
        }
        if (this.idType == 2) {
          kind = 0;
        }
      } else if (type == "administrativeScope") {
        kind = 3;
        if (this.tagsRegion.length > 0) {
          kind = 3;
        }
        if (this.idTypeProject == 2 && this.tagsRegion.length == 0) {
          kind = 0;
        }
        if (this.idType == 2) {
          kind = 0;
        }
      } else if (type == "organization") {
        //设置机构类别0：无 1：全选 2：去掉 3：选中
        if (this.checkTableState.multipleOrganization === false) {
          //全部不选
          kind = 0;
          if (this.changedOrganization.length > 0) {
            kind = 3;
          }
        } else if (this.checkTableState.multipleOrganization === true) {
          //设置机构类别0：无 1：全选 2：去掉 3：选中
          kind = 1;
          if (this.changedOrganization2.length > 0) {
            kind = 2;
          }
        } else if (this.checkTableState.multipleOrganization === "") {
          kind = this.setKindOfOrganizationLast;
          if (this.setKindOfOrganizationLast === -1) {
            kind = 1;
          }
          //初始化0或1
          if (kind == 0 && this.changedOrganization.length > 0) {
            kind = 3;
          }
          if (kind == 1 && this.changedOrganization2.length > 0) {
            kind = 2;
          }
        }
      } else if (type == "department") {
        kind = 3;
        if (this.multipleSelectionDepartment.length > 0) {
          kind = 3;
        }
      } else if (type == "person") {
        //设置人员类别0：无 1：全选 2：去掉 3：选中
        if (this.checkTableState.multiplePerson === false) {
          //全部不选
          kind = 0;
          if (this.changedPerson.length > 0) {
            kind = 3;
          }
        } else if (this.checkTableState.multiplePerson === true) {
          kind = 1;
          if (this.changedPerson2.length > 0) {
            kind = 2;
          }
        } else if (this.checkTableState.multiplePerson === "") {
          kind = this.setKindOfPeopleLast;
          if (this.setKindOfPeopleLast === -1) {
            kind = 1;
          }
          //初始化0或1
          if (kind == 0 && this.changedPerson.length > 0) {
            kind = 3;
          }
          if (kind == 1 && this.changedPerson2.length > 0) {
            kind = 2;
          }
        }
      }
      return kind;
    },
    //设定的行政范围内容
    getScope(type) {
      if (vm.idType == 2) {
        return null;
      }
      let scope = "";
      let noChangeTree = this.getTreeCheck();
      if (type == "administrative") {
        for (let i = 0; i < this.tagsRegion.length; i++) {
          scope += this.tagsRegion[i].key;
          if (i < this.tagsRegion.length - 1) {
            scope += "|";
          }
        }
      } else if (type == "administrativeUpdate") {
        console.log("this.allSelectedKeys", this.allSelectedKeys);
        if (this.allSelectedKeys.length > 0) {
          for (let i = 0; i < this.allSelectedKeys.length; i++) {
            scope +=
              this.allSelectedKeys[i].key + ":" + this.allSelectedKeys[i].type;
            if (i < this.allSelectedKeys.length - 1) {
              scope += "|";
            }
          }
        } else {
          // let noChangeTree = this.getTreeCheck();
          console.log("noChangeTree值", noChangeTree);
          if (noChangeTree.length > 0) {
            for (let i = 0; i < noChangeTree.length; i++) {
              scope += noChangeTree[i].key + ":" + noChangeTree[i].type;
              if (i < noChangeTree.length - 1) {
                scope += "|";
              }
            }
          } else {
            //选全国项目
            if (this.tagsRegion.length > 0 && this.tagsRegion[0].key == "000") {
              scope = "000:1";
              console.log(this.tagsRegion, "scope", scope);
            }
          }
        }
      }
      //console.log(scope);
      if (scope == "") {
        return null;
      }
      return scope;
    },
    initOrganizationStatus() {
      let tableStatus = this.tableOrganization;
      tableStatus.forEach(row => {
        if (row.status == 1) {
          this.$nextTick(function() {
            this.$refs.multipleOrganization.toggleRowSelection(row);
          });
        }
      });
    },
    //选择搜索机构方式
    searchOrganization() {
      this.formOrganization.pageNum = 1;
      let searchForm = this.formOrganization;
      if (
        searchForm.administrativeId == "0" &&
        searchForm.administrativeIdList[
          searchForm.administrativeIdList.length - 1
        ] == "0" &&
        searchForm.level == "-1" &&
        searchForm.name == ""
      ) {
        this.searchOrganizationType = "";
        this.getOrganization();
      } else {
        this.searchOrganizationType = "choose";
        this.getOrganizationChoose();
      }
    },
    //初始化搜索机构状态
    initOrganizationChoose() {
      let tableStatus = this.tableOrganization;
      if (typeof tableStatus === "undefined") {
        return;
      }
      tableStatus.forEach(row => {
        let idList = [];
        idList[0] = row.id;
        //console.log('this.changedOrganization2',this.changedOrganization2);
        let intersect = operationData.getIntersect(
          idList,
          this.changedOrganization
        );
        let intersect2 = operationData.getIntersect(
          idList,
          this.changedOrganization2
        );
        if (intersect.length > 0) {
          //选中
          //this.$refs.multipleOrganization.toggleRowSelection(row);
        } else if (intersect2.length > 0) {
          //不选
        } else {
          if (row.status == 1) {
            this.$nextTick(function() {
              this.$refs.multipleOrganization.toggleRowSelection(row);
            });
          }
        }
      });
    },
    //机构搜索
    getOrganizationChoose() {
      // console.log('formOrganization',this.formOrganization);
      let administrativeIdItem = operationData.setAdministrativeId(
        this.formOrganization.administrativeIdList
      );
      let req = {
        projectId: this.projectId,
        administrativeId: administrativeIdItem,
        hospitalLevel: this.formOrganization.level,
        hospitalName: this.formOrganization.name,
        pageNum: this.formOrganization.pageNum,
        pageSize: this.formOrganization.pageSize,
        scope: this.getScope("administrative")
      };
      openLoading(vm);
      // vm.POST("portal/scope/v1/organization/choose", req).then(res => {
      vm.POST("portal/new/scope/org/v1/organization/search", req).then(res => {
        closeLoading(vm);
        console.log(res);
        if (res.code == "000000") {
          this.tableOrganization = res.data.organizationList;
          this.totalOrganization = res.data.total;

          vm.initOrganizationStatus();
        } else {
          vm.$message(res.message);
        }
      });
    },
    //查询机构列表
    getOrganization() {
      let req = {
        projectId: this.projectId,
        administrativeId: "",
        hospitalLevel: "",
        hospitalLevel: "",
        scope: this.getScope("administrative"),
        pageNum: this.formOrganization.pageNum,
        pageSize: this.formOrganization.pageSize
      };
      openLoading(vm);
      // vm.POST("portal/scope/v1/organization", req).then(res => {
      vm.POST("portal/new/scope/org/v1/organization", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          this.tableOrganization = res.data.organizationList;
          this.totalOrganization = res.data.total;

          vm.initOrganizationStatus();
        } else {
          vm.$message(res.message);
        }
      });
    },
    //获取科室信息
    getDepartment() {
      let req = {
        projectId: this.projectId
      };
      vm.GET("portal/scope/v1/department", req).then(res => {
        if (res.code == "000000") {
          this.tableDepartment = res.data.department;
          if (vm.peopleLevel != "L3" || vm.idType != 2) {
            let rowCheck = this.tableDepartment;
            rowCheck.forEach(row => {
              if (row.status == 1) {
                this.$nextTick(function() {
                  this.$refs.multipleDepartment.toggleRowSelection(row);
                });
              }
            });
          }
        }
      });
    },
    //获取机构id列表
    getScopeOrganization(type) {
      let scope = "";
      //2：去掉 3：选中
      if (type == 2) {
        // console.log(this.scopeOfOrganizationLast,this.changedOrganization);
        let differenceScope = operationData.getDifference(
          this.scopeOfOrganizationLast,
          this.changedOrganization
        );
        //console.log('differenceScope',differenceScope);
        let unionScope = operationData.getUnion(
          this.changedOrganization2,
          differenceScope
        );
        //console.log('unionScope',unionScope);
        for (let i = 0; i < unionScope.length; i++) {
          scope += unionScope[i] + "|";
        }
      } else if (type == 3) {
        console.log(this.scopeOfOrganizationLast, this.changedOrganization2);
        let differenceScope = operationData.getDifference(
          this.scopeOfOrganizationLast,
          this.changedOrganization2
        );
        let unionScope = operationData.getUnion(
          this.changedOrganization,
          differenceScope
        );
        for (let i = 0; i < unionScope.length; i++) {
          scope += unionScope[i] + "|";
        }
      }
      scope = scope.substring(0, scope.length - 1);
      console.log("scope", scope);
      return scope;
    },
    //获取人员id列表
    getScopePeople(type) {
      let scope = "";
      //2：去掉 3：选中
      if (type == 2) {
        let differenceScope = operationData.getDifference(
          this.scopeOfPeopleLast,
          this.changedPerson
        );
        //console.log('differenceScope',differenceScope);
        let unionScope = operationData.getUnion(
          this.changedPerson2,
          differenceScope
        );
        for (let i = 0; i < unionScope.length; i++) {
          scope += unionScope[i] + "|";
        }
      } else if (type == 3) {
        //console.log(this.changedPerson2,this.scopeOfPeople);
        let differenceScope = operationData.getDifference(
          this.scopeOfPeopleLast,
          this.changedPerson2
        );
        let unionScope = operationData.getUnion(
          this.changedPerson,
          differenceScope
        );
        for (let i = 0; i < unionScope.length; i++) {
          scope += unionScope[i] + "|";
        }
      }

      scope = scope.substring(0, scope.length - 1);
      console.log("scope people", scope);
      return scope;
    },
    //获取科室列表
    getScopeDepartment() {
      let scope = "";
      if (
        this.multipleSelectionDepartment.length == this.tableDepartment.length
      ) {
        return 99999999;
      }
      if (this.multipleSelectionDepartment.length == 0) {
        return null;
      }
      for (let i = 0; i < this.multipleSelectionDepartment.length; i++) {
        scope += this.multipleSelectionDepartment[i].id + "|";
      }
      scope = scope.substring(0, scope.length - 1);
      return scope;
    },
    //获取医院
    getHospital() {
      let req = {
        projectId: this.projectId,
        setKindOfAdministrative: this.getKind("administrative"),
        setKindOfOrganization: this.getKind("organization"),
        pageNum: this.formPerson.pageNum,
        pageSize: this.formPerson.pageSize
      };
      if (req.setKindOfAdministrative == 3) {
        req.scopeOfAdministrative = this.getScope("administrative");
      }
      if (req.setKindOfOrganization == 2 || req.setKindOfOrganization == 3) {
        req.scopeOfOrganization = this.getScopeOrganization(
          req.setKindOfOrganization
        );
      }
    },
    //选择搜索机构方式
    searchPeople() {
      this.formPerson.pageNum = 1;
      let searchForm = this.formPerson;
      if (searchForm.hospitalName === "" && searchForm.doctorName === "") {
        this.searchPeopleType = "";
        this.getPeople();
      } else {
        this.searchPeopleType = "choose";
        this.getPeopleChoose();
      }
    },
    //初始化搜索人员状态
    initPeopleChoose() {
      let tableStatus = this.tablePerson;
      if (typeof tableStatus === "undefined") {
        return;
      }
      tableStatus.forEach(row => {
        let idList = [];
        idList[0] = row.id;
        let intersect = operationData.getIntersect(idList, this.changedPerson);
        let intersect2 = operationData.getIntersect(
          idList,
          this.changedPerson2
        );
        if (intersect.length > 0) {
          //选中
          //this.$refs.multiplePerson.toggleRowSelection(row);
        } else if (intersect2.length > 0) {
          //不选
        } else {
          if (row.status == 1) {
            this.$nextTick(function() {
              this.$refs.multiplePerson.toggleRowSelection(row);
            });
          }
        }
      });
    },
    //人员搜索
    getPeopleChoose() {
      // console.log('formOrganization',this.formOrganization);
      let req = {
        projectId: this.projectId,
        pageNum: this.formPerson.pageNum,
        pageSize: this.formPerson.pageSize,
        doctorName: this.formPerson.doctorName,
        hospitalName: this.formPerson.hospitalName,
        scopeOfAdministrative: this.getScope("administrative"),
        scopeOfDepartment: this.getScopeDepartment()
      };
      openLoading(vm);
      // vm.POST("portal/scope/v1/people/choose", req).then(res => {
      vm.POST("portal/new/scope/doctor/v1/doctor/search", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          this.tablePerson = res.data.people;
          this.totalPerson = res.data.total;
          vm.initPeopleStatus();
        } else {
          vm.$message(res.message);
        }
      });
    },
    initPeopleStatus() {
      let tableStatus = this.tablePerson;
      tableStatus.forEach(row => {
        if (row.status == 1) {
          this.$nextTick(function() {
            this.$refs.multiplePerson.toggleRowSelection(row);
          });
        }
      });
    },
    //查询人员列表
    getPeople() {
      let req = {
        projectId: this.projectId,
        doctorName: "",
        hospitalName: "",
        scopeOfAdministrative: this.getScope("administrative"),
        scopeOfDepartment: this.getScopeDepartment(),
        pageNum: this.formPerson.pageNum,
        pageSize: this.formPerson.pageSize
      };
      openLoading(vm);
      // vm.POST("portal/scope/v1/people", req).then(res => {
      vm.POST("portal/new/scope/doctor/v1/doctor", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          console.log(res);
          this.tablePerson = res.data.people;
          this.totalPerson = res.data.total;
          vm.initPeopleStatus();
        } else {
          vm.$message(res.message);
        }
      });
    },
    //设定人员中科室列表
    getDepartmentList() {
      let list = [];
      list[0] = {
        value: -1,
        label: "全部科室"
      };
      for (let i = 0; i < this.tableDepartment.length; i++) {
        if (this.tableDepartment[i].status == 1) {
          let obj = {
            value: this.tableDepartment[i].id,
            label: this.tableDepartment[i].name
          };
          list.push(obj);
        }
      }
      return list;
    },
    //判断项目范围选择
    showScopeType() {
      if (this.projectStatus == "" || this.projectStatus == 1) {
        if (this.peopleLevel != "L3") {
          return false;
        }
      }
      return true;
    },
    //判断通知展示问题
    showNoticeType() {
      if (
        this.projectStatus == "" ||
        this.projectStatus == 1 ||
        this.projectStatus == 2
      ) {
        if (this.peopleLevel != "L3") {
          return false;
        }
      }
      return true;
    },
    //判断通知展示问题
    showAllowType() {
      if (this.peopleLevel == "L3" || this.peopleLevel == "L0") {
        return true;
      }
      return false;
    },
    //选择小生态
    selectChangeEcology(value) {
      this.formEcology.pageNum = 1;
      //console.log('select',value);
      for (let i = 0; i < this.ecologySelect.length; i++) {
        if (this.ecologySelect[i].value == value) {
          this.checkedEcology = this.ecologySelect[i].label;
        }
      }
      this.formEcology.ecology = value;
      this.getEcology();
    },
    getEcologySelect() {
      let req = {};
      vm
        .GET("portal/scope/v1/" + this.projectId + "/ecology", req)
        .then(res => {
          console.log("查询小生态列表", res);
          this.ecologySelect = operationData.getEcologySelect(res.data.list);
          if (res.data.chooseIdList.length > 0) {
            this.formEcology.ecology = res.data.chooseIdList[0];
            this.getEcology();
          }
        });
    },
    initEcology() {
      let tableStatus = this.tableEcology;
      if (typeof tableStatus === "undefined") {
        return;
      }
      tableStatus.forEach(row => {
        let idList = [];
        idList[0] = row.id;
        let intersect = operationData.getIntersect(idList, this.changedEcology);
        let intersect2 = operationData.getIntersect(
          idList,
          this.changedEcology2
        );
        if (intersect.length > 0) {
          //选中
        } else if (intersect2.length > 0) {
          //不选
        } else {
          if (row.status == 1) {
            this.$nextTick(function() {
              this.$refs.multipleEcology.toggleRowSelection(row);
            });
          }
        }
      });
    },
    //获取小生态数据
    getEcology() {
      let req = {};
      req = this.formEcology;
      openLoading(vm);
      vm
        .GET("portal/scope/v1/" + this.projectId + "/organization", req)
        .then(res => {
          closeLoading(vm);
          console.log("根基小生态查询机构列表信息", res);
          this.tableEcology = res.data.organizationList;
          this.totalEcology = res.data.total;

          let tableStatus = this.tableEcology;
          tableStatus.forEach(row => {
            this.$refs.multipleEcology.toggleRowSelection(row);
          });
        });
    },
    //
    //机构table修改
    handleSizeOrganization(val) {
      console.log(`每页 ${val} 条`);
      this.formOrganization.pageSize = val;
      this.searchOrganization();
    },
    handleCurrentOrganization(val) {
      //console.log(`当前页: ${val}`);
      this.formOrganization.pageNum = val;
      if (this.searchOrganizationType == "choose") {
        this.getOrganizationChoose();
      } else {
        this.getOrganization();
      }
    },
    //角色table修改
    handleSizePerson(val) {
      console.log(`每页 ${val} 条`);
      this.formPerson.pageSize = val;
      this.searchPeople();
    },
    handleCurrentPerson(val) {
      console.log(`当前页: ${val}`);
      this.formPerson.pageNum = val;
      if (this.searchPeopleType == "choose") {
        this.getPeopleChoose();
      } else {
        this.getPeople();
      }
    },
    handleSizeEcology(val) {
      console.log(`每页 ${val} 条`);
      this.formEcology.pageSize = val;
      this.getEcology();
    },
    handleCurrentEcology(val) {
      console.log(`当前页: ${val}`);
      this.formEcology.pageNum = val;
      this.getEcology();
    },
    //行政范围改变更新设定机构和设定人员
    updateOrganizationAndPerson(allSelectedKeys) {
      this.tableOrganization = [];
      this.tablePerson = [];
      this.$refs.multipleOrganization.clearSelection();
      this.lookedOrganization = [];
      this.changedOrganization = [];
      this.changedOrganization2 = [];
    },
    //设定机构改变更新设定人员
    updatePerson() {
      this.lookedPerson = [];
      this.changedPerson = [];
      this.changedPerson2 = [];
    },
    //scope的不同status操作
    scopeStatus(data) {
      //console.log('范围提交status:'+data);
      let status = data;
      //console.log('范围提交status:'+status);
      if (status === 0) {
        this.flagCover = 0;
      } else if (status === 1) {
        vm.$message({
          type: "info",
          message: "您已被上级管理员移除项目，暂无权限操作"
        });
        this.$router.push("item-manager");
      } else if (status === 2) {
        console.log("弹框");
        this.flagCover = 1;
        this.dialogShow = true;
      } else if (status === 3) {
        //3：项目范围没有可参与的人员
        vm.$message({
          type: "info",
          message: "没有选择任何人员"
        });
      }
      return status;
    },
    //选择项目组件
    //改变组件选择情况
    changeValue(value) {
      //console.log('value',value,'optionsComponent',this.optionsComponent);
      this.tagsComponent = [];
      let len = 0;
      for (let i = 0; i < value.length; i++) {
        for (let j = 0; j < this.optionsComponent.length; j++) {
          if (value[i] == this.optionsComponent[j].value) {
            this.tagsComponent[len] = {};
            this.tagsComponent[len] = this.optionsComponent[j];
            this.tagsComponent[len].value = this.optionsComponent[j].value;
            this.tagsComponent[len].name = this.optionsComponent[j].label;
            len++;
          }
        }
      }
      //console.log('this.tagsComponent',this.tagsComponent);
      vm.tagDrop();
    },
    initTags(value) {
      //console.log('value',value,'optionsComponent',this.optionsComponent);
      this.tagsComponent = [];
      let len = 0;
      for (let i = 0; i < value.length; i++) {
        for (let j = 0; j < this.optionsComponent.length; j++) {
          if (value[i] == this.optionsComponent[j].value) {
            this.tagsComponent[len] = {};
            this.tagsComponent[len].value = this.optionsComponent[j].value;
            this.tagsComponent[len].name = this.optionsComponent[j].label;
            if (vm.status4Flag == 1) {
              this.optionsComponent[j].disabled = true;
              this.tagsComponent[len].disabled = true;
            }
            len++;
          }
        }
      }
      console.log("this.optionsComponent值：", this.optionsComponent);
    },
    //选择组件数据绑定
    handleCloseComponent(tag) {
      if (tag.disabled == true) {
        return;
      }
      // if (this.projectStatus == 1 || this.projectStatus == 2) {
      this.tagsComponent.splice(this.tagsComponent.indexOf(tag), 1);
      this.formComponent.component = [];
      for (let j = 0; j < this.tagsComponent.length; j++) {
        this.formComponent.component[j] = this.tagsComponent[j].value;
      }
      // }
    },
    addCertificate() {
      if (vm.formExam.exam.length == 5) {
        return vm.$message("最多配置5个证书");
      }
      let obj = {
        examCount: 1,
        rangeMin: "",
        rangeMax: "",
        certificateId: "",
        certificateName: "",
        minClass: "",
        minError: "",
        maxClass: "",
        maxError: "",
        certClass: "",
        certError: ""
      };
      vm.formExam.exam.push(obj);
    },
    reduceCertificate(index) {
      // console.log(index);
      if (vm.formExam.exam.length > 1) {
        vm.formExam.exam.splice(index, 1);
      } else {
        vm.$message("至少配置1个证书");
      }
    },
    //考试门数更新校验
    updateCount(index) {
      if (vm.formExam.exam[index].examCount) {
        vm.formExam.exam[index].examCount = parseInt(
          vm.formExam.exam[index].examCount
        );
        if (!Number.isInteger(vm.formExam.exam[index].examCount)) {
          vm.formExam.exam[index].examCount = "";
        }
        if (vm.formExam.exam[index].examCount <= 0) {
          vm.formExam.exam[index].examCount = "";
        }
        if (vm.formExam.exam[index].examCount != "") {
          for (let i = 0; i < vm.formExam.exam.length; i++) {
            vm.formExam.exam[i].examCount = vm.formExam.exam[index].examCount;
          }
        }
      }
    },
    //区间控制在0~100
    baseCheck(index) {
      if (vm.formExam.exam[index].rangeMin != "") {
        vm.formExam.exam[index].rangeMin = parseInt(
          vm.formExam.exam[index].rangeMin
        );
        if (vm.formExam.exam[index].rangeMin > 100) {
          vm.formExam.exam[index].rangeMin = 100;
        }
        if (vm.formExam.exam[index].rangeMin < 0) {
          vm.formExam.exam[index].rangeMin = 0;
        }
      }
      if (vm.formExam.exam[index].rangeMax != "") {
        vm.formExam.exam[index].rangeMax = parseInt(
          vm.formExam.exam[index].rangeMax
        );
        if (vm.formExam.exam[index].rangeMax > 100) {
          vm.formExam.exam[index].rangeMax = 100;
        }
        if (vm.formExam.exam[index].rangeMax < 0) {
          vm.formExam.exam[index].rangeMax = 0;
        }
      }
    },
    //区间不能有交集
    withoutUnion(index, type) {
      let examList = vm.formExam.exam;
      let nowMin = vm.formExam.exam[index].rangeMin;
      let nowMax = vm.formExam.exam[index].rangeMax;
      console.log("nowMin", nowMin, "nowMax", nowMax);
      if (nowMin !== "" && nowMax !== "") {
        for (let i = 0; i < examList.length; i++) {
          if (
            index !== i &&
            examList[i].rangeMin !== "" &&
            examList[i].rangeMax !== ""
          ) {
            let overlapStatus = operationData.isOverlap(
              examList[i].rangeMin,
              examList[i].rangeMax,
              nowMin,
              nowMax
            );
            if (overlapStatus === true) {
              //区间有交集
              vm.$message("设置分数区间不能重合");
              vm.formExam.exam[index].rangeMin = "";
              vm.formExam.exam[index].rangeMax = "";
              // console.log('重合制空',vm.formExam.exam[index])
            }
          }
        }
      }
    },
    updateMin(index) {
      vm.baseCheck(index);
      if (!Number.isInteger(vm.formExam.exam[index].rangeMin)) {
        vm.formExam.exam[index].rangeMin = "";
        return;
      }
      // console.log('更新 nowMin',vm.formExam.exam[index].rangeMin,'nowMax',vm.formExam.exam[index].rangeMax);
      if (
        vm.formExam.exam[index].rangeMin == "" ||
        vm.formExam.exam[index].rangeMax == ""
      ) {
        return;
      }
      if (vm.formExam.exam[index].rangeMin > vm.formExam.exam[index].rangeMax) {
        vm.formExam.exam[index].rangeMin = vm.formExam.exam[index].rangeMax;
      }
      vm.withoutUnion(index, "min");
    },
    updateMax(index) {
      vm.baseCheck(index);
      if (!Number.isInteger(vm.formExam.exam[index].rangeMax)) {
        // console.log('只能整数');
        vm.formExam.exam[index].rangeMax = "";
        return;
      }
      if (
        vm.formExam.exam[index].rangeMin == "" ||
        vm.formExam.exam[index].rangeMax == ""
      ) {
        return;
      }
      if (vm.formExam.exam[index].rangeMin > vm.formExam.exam[index].rangeMax) {
        vm.formExam.exam[index].rangeMax = vm.formExam.exam[index].rangeMin;
      }
      vm.withoutUnion(index, "max");
    },
    updateCertificate(index) {
      // console.log('optionsCertificate',vm.optionsCertificate,'index',index,'item',vm.formExam.exam[index])
      for (let i = 0; i < vm.optionsCertificate.length; i++) {
        if (
          vm.optionsCertificate[i].value ==
          vm.formExam.exam[index].certificateId
        ) {
          vm.formExam.exam[index].certificateName =
            vm.optionsCertificate[i].label;
          break;
        }
      }
      vm.formExam.exam[index].certClass = "";
      vm.formExam.exam[index].certError = "";
    },
    // add 校验输入是否为整数
    checkIntFun(str) {
      let r = /^\+?[0-9]*$/;
      return r.test(str);
    },
    //更新项目成绩评定条件
    updateCertificateType() {
      console.log("更新certificateType", vm.formExam.certificateType);
      if (vm.formExam.passType == 2) {
        vm.formExam.exam = [
          {
            examCount: 1,
            rangeMin: "",
            rangeMax: "",
            certificateId: "",
            certificateName: "",
            minClass: "",
            minError: "",
            maxClass: "",
            maxError: "",
            certClass: "",
            certError: ""
          }
        ];
      } else if (vm.formExam.passType == 1) {
        vm.formComponent.certificate = "";
      }
    },
    //校验分数是否存在交叉
    checkCrossFun(d) {
      let isRepart = false,
        index = null,
        parm = null;
      //alert(d.length)
      if (d.length > 0) {
        for (let i = 1; i < d.length; i++) {
          console.log(d[i - 1].rangeMin, d[i - 1].rangeMax);
          if (parseInt(d[i - 1].rangeMax) < parseInt(d[i - 1].rangeMin)) {
            isRepart = true;
            index = i - 1;
            parm = "1";
            break;
          }
          if (
            (d[i].rangeMin <= d[i - 1].rangeMax &&
              d[i].rangeMin >= d[i - 1].rangeMin) ||
            (d[i - 1].rangeMax >= d[i].rangeMin &&
              d[i - 1].rangeMax <= d[i].rangeMax) ||
            (d[i].rangeMax >= d[i - 1].rangeMin &&
              d[i].rangeMax <= d[i - 1].rangeMax)
          ) {
            isRepart = true;
            index = i;
            parm = "2";
            //alert(isRepart)
            break;
          }
          if (parseInt(d[i].rangeMin) > parseInt(d[i].rangeMax)) {
            isRepart = true;
            index = i;
            parm = "3";
            break;
          }
        }
      }
      console.log(parm);
      return { isRepart: isRepart, index: index, parm: parm };
    },

    hideErrorInfo(str) {
      if (str) {
        this.customError[str] = {
          className: "",
          error: ""
        };
      } else {
        this.customError = {};
      }
    },

    dioErrorPop(str) {
      return this.$message({
        message: str,
        type: "warning"
      });
    },

    //校验考试通过平均分配置
    checkCertificate() {
      // if(vm.formComponent.configure == 2) {
      //   return true;
      // }
      console.log(vm.formExam.exam);
      if (vm.formExam.passType == 2) {
        if (vm.formComponent.passExamCount == "") {
          this.customError.passExamCount = {
            className: "is-error",
            error: "请输入门数"
          };
          return;
        }

        if (vm.formComponent.passAverageScore == "") {
          this.customError.passAverageScore = {
            className: "is-error",
            error: "请输入分数"
          };
          return;
        }

        if (!vm.checkIntFun(vm.formComponent.passAverageScore)) {
          return vm.dioErrorPop("项目通过分数只能是数字");
        }
      } else if (vm.formExam.passType == 3) {
        if (
          vm.formComponent.passTotalLearnTime === "" ||
          vm.formComponent.passTotalLearnTime == null
        ) {
          vm.customError.passTotalLearnTime = {
            className: "is-error",
            error: "请输入学习时长"
          };
          return;
        }
      }
      console.log(vm.formExam.exam);
      //空判断
      if (vm.formComponent.configure == 1) {
        if (vm.formExam.passType == 2) {
          let checkIdList = [];
          var compare = function(obj1, obj2) {
            var val1 = obj1.rangeMin;
            var val2 = obj2.rangeMin;
            if (val1 < val2) {
              return -1;
            } else if (val1 > val2) {
              return 1;
            } else {
              return 0;
            }
          };
          vm.formExam.exam.sort(compare);

          let isCross = vm.checkCrossFun(vm.formExam.exam).isRepart;
          if (isCross) {
            let l = vm.checkCrossFun(vm.formExam.exam).index;
            if (parm == "1" || parm == "3") {
              vm.formExam.exam[l].minClass = "is-error";
              vm.formExam.exam[l].minError = "分数最小值不能大于最大值";
              //return;
            } else if (parm == "2") {
              vm.formExam.exam[l].minClass = "is-error";
              vm.formExam.exam[l].minError = "请重新输入，不能出现重合分数";
            }
            this.$set(vm.formExam.exam, l, vm.formExam.exam[l]);
            return;
          }
          for (let i = 0; i < vm.formExam.exam.length; i++) {
            if (vm.formExam.exam[i].rangeMin === "") {
              vm.formExam.exam[i].minClass = "is-error";
              vm.formExam.exam[i].minError = "请输入平均分";
              this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
              return;
            }
            vm.formExam.exam[i].minClass = "";
            vm.formExam.exam[i].minError = "";

            if (vm.formExam.exam[i].rangeMax === "") {
              vm.formExam.exam[i].maxClass = "is-error";
              vm.formExam.exam[i].maxError = "请输入平均分";
              this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
              return;
            }
            vm.formExam.exam[i].maxClass = "";
            vm.formExam.exam[i].maxError = "";

            if (
              parseInt(vm.formExam.exam[i].rangeMin) >
              parseInt(vm.formExam.exam[i].rangeMax)
            ) {
              vm.formExam.exam[i].minClass = "is-error";
              vm.formExam.exam[i].minError = "分数最小值不能大于最大值";
              this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
              return;
            }
            if (vm.formExam.exam[i].certificateId == "") {
              vm.formExam.exam[i].certClass = "is-error";
              vm.formExam.exam[i].certError = "请选择证书";
              this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
              return;
            }
            vm.formExam.exam[i].certClass = "";
            vm.formExam.exam[i].certError = "";

            if (
              parseInt(vm.formComponent.passAverageScore) >
              parseInt(vm.formExam.exam[i].rangeMin)
            ) {
              vm.formExam.exam[i].minClass = "is-error";
              vm.formExam.exam[i].minError = "平均分不能低于考试通过分数";
              vm.customError.passAverageScore = {
                className: "is-error",
                error: "平均分不能低于考试通过分数"
              };
              return;
            }
            if (checkIdList.indexOf(vm.formExam.exam[i].certificateId) == -1) {
              checkIdList.push(vm.formExam.exam[i].certificateId);
            } else {
              vm.formExam.exam[i].certClass = "is-error";
              vm.formExam.exam[i].certError = "请重新选择，不能出现重复证书";
              this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
              return;
            }
            this.customError.passAverageScore = {
              className: "",
              error: ""
            };
            //checkIdList[i] = vm.formExam.exam[i].certificateId;
            this.$set(vm.formExam.exam, i, vm.formExam.exam[i]);
          }
          // 判断证书不能重复
          // checkIdList = checkIdList.sort();
          // for(let j=0;j<checkIdList.length-1;j++) {
          //   if (checkIdList[j] == checkIdList[j+1]) {
          //     //vm.$message('证书不能重复选择');
          //     this.$message({
          //       message: '请重新选择，不能出现重复证书',
          //       type: 'warning'
          //     });
          //     return false;
          //   }
          // }
          // 考试门数必须相同
          // for(let i=0;i<vm.formExam.exam.length-1;i++) {
          //   if (vm.formExam.exam[i].examCount != vm.formExam.exam[i+1].examCount) {
          //    // vm.$message('考试门数必须相同');
          //     this.$message({
          //       message: '考试门数必须相同',
          //       type: 'warning'
          //     });
          //     return false;
          //   }
          // }
        } else {
          if (this.formComponent.certificate == "") {
            vm.customError.certificate = {
              className: "is-error",
              error: "请选择证书"
            };
            return;
          }
        }
      } else if (vm.formExam.certificateType == 1) {
        //组件通过即发放 证书必填
        // if(vm.formComponent.configure == 1 && vm.formExam.certificateType == 1) {
        //   if(vm.formComponent.certificate == '') {
        //     vm.$message('证书不能为空!');
        //     return false;
        //   }
        // }
      }
      return true;
    },
    blurName() {
      vm.visibleName = false;
      setTimeout(function() {
        // console.log('失去焦点');
        vm.submitForm("formData");
      }, 200);
    },
    focusName(index) {
      let textLength = vm.formData.organizationNameList[index].length;
      if (textLength == 0) {
        this.orgListIndex = index;
        vm.visibleName = true;
      } else {
        vm.visibleName = false;
      }
    },
    changeOrganizationName() {
      let textLength = vm.formData.organizationName.length;
      console.log("文字长度", textLength);
      if (textLength == 0) {
        vm.visibleName = true;
      } else {
        vm.visibleName = false;
      }
    },
    checkDefault() {
      // vm.formData.organizationNameList[0] = vm.organizationContent;
      vm.formData.organizationNameList.splice(this.orgListIndex, 1, vm.organizationContent);
      // vm.formData.organizationNameList.push(vm.organizationContent);
      // vm.formData.organizationName = vm.organizationContent;
      vm.visibleName = false;
    },
    tagDrop() {
      this.$nextTick(function() {
        if (vm.tagsComponent.length > 0) {
          const ele = document.querySelector(".check-component .el-col-20");
          // console.log('ele',ele);
          // Sortable.create(ele,{});
          Sortable.create(ele, {
            onEnd({ newIndex, oldIndex }) {
              const currRow = vm.tagsComponent.splice(oldIndex, 1)[0];
              vm.tagsComponent.splice(newIndex, 0, currRow);
            }
          });
        }
      });
    },
    //v2.2教培更新
    checkUpdate(node, data) {
      let flag = -1;
      flag = data.checkedKeys.indexOf(node.id);
      if (vm.status4Flag == 1 && flag >= 0) {
        console.log(node, data, flag, vm.status4Flag);
        vm.nowCheck = node;
        vm.warnType = 0;
        vm.dialogWarn = true;
        // this.$refs.tree.setChecked(data,false)
      }
    },
    closeCheck() {
      vm.dialogWarn = false;
      this.$refs.tree.setChecked(vm.nowCheck, false, true);
      vm.initCheckList(vm.getTreeCheck());
      // for(let i=0;i<vm.tagsRegion.length;i++) {
      //   if(vm.tagsRegion[i].key == vm.nowCheck.id) {
      //     vm.tagsRegion.splice(i,1);
      //   }
      // }
    },
    closeFail() {
      vm.dialogFail = false;
    },
    closeUpload() {
      vm.dialogUpload = false;
    },
    setDialog(res) {
      if (res.code == "000000") {
        if (res.data.success == true) {
          //导入成功
          vm.dialogSuccess = true;
          vm.updateNum = res.data.total;
          if (vm.uploadType == "org") {
            vm.searchOrganization();
          } else {
            vm.searchPeople();
          }
        } else {
          if (res.data.outCount == true) {
            //导入数据超5000
            vm.failType = 1;
            vm.dialogFail = true;
            vm.failNum = res.data.total;
            vm.failExcelUrl = res.data.url;
          } else {
            //导入失败
            // setTimeout(function() {
            vm.failType = 2;
            vm.dialogFail = true;
            vm.failNum = res.data.total;
            vm.failExcelUrl = res.data.url;
            // }, 800);
          }
        }
      } else {
        //接口失败
        vm.$message.error(res.message);
      }
    },
    uploadOrganization(file) {
      vm.dialogFail = false;
      vm.uploadType = "org";
      console.log(file);
      let arr = file.type.split("/");
      let ext = "." + arr[1];
      let name = file.name;
      let reader = new FileReader();
      reader.onload = function(e) {
        let fileJson = {
          fileName: file.name,
          file: e.target.result.substr(e.target.result.indexOf("base64,") + 7),
          ext: ext
        };
        let fileArray = [
          {
            type: "",
            base64: fileJson
          }
        ];
        let req = {
          fileArray: fileArray,
          scopeOfAdministrative: vm.getScope("administrative")
        };
        let projectId = vm.projectId;
        console.log("req", req);
        let reqStr = JSON.stringify(req);
        openLoading(vm);
        uploadOrgExcel(reqStr, projectId).then(res => {
          closeLoading(vm);
          vm.setDialog(res);
        });
      };
      reader.readAsDataURL(file);
    },
    uploadPerson(file) {
      vm.dialogFail = false;
      vm.uploadType = "person";
      let arr = file.type.split("/");
      let ext = "." + arr[1];
      let name = file.name;
      let reader = new FileReader();
      reader.onload = function(e) {
        let fileJson = {
          fileName: file.name,
          file: e.target.result.substr(e.target.result.indexOf("base64,") + 7),
          ext: ext
        };
        let fileArray = [
          {
            type: "",
            base64: fileJson
          }
        ];
        let req = {
          fileArray: fileArray,
          scopeOfAdministrative: vm.getScope("administrative"),
          scopeOfDepartment: vm.getScopeDepartment()
        };
        let projectId = vm.projectId;
        console.log("req", req);
        let reqStr = JSON.stringify(req);
        openLoading(vm);
        uploadPersonExcel(reqStr, projectId).then(res => {
          closeLoading(vm);
          vm.setDialog(res);
        });
      };
      reader.readAsDataURL(file);
    },
    download(type) {
      let downloadUrl = "";
      if (type == "organization") {
        downloadUrl = getExeclUrl(
          "%E6%95%99%E5%9F%B9%E9%A1%B9%E7%9B%AE%E8%AE%BE%E7%BD%AE%E6%9C%BA%E6%9E%84%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx"
        );
      } else if (type == "person") {
        downloadUrl = getExeclUrl(
          "%E6%95%99%E5%9F%B9%E9%A1%B9%E7%9B%AE%E8%AE%BE%E7%BD%AE%E4%BA%BA%E5%91%98%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx"
        );
      } else if (type == "fail") {
        downloadUrl = vm.failExcelUrl;
      }
      setTimeout(() => {
        window.open(downloadUrl);
      }, 500);
    },
    handleChangeRegion(value) {
      let areaId = "000";
      for (let i = 0; i < value.length; i++) {
        areaId += "_" + value[i];
      }
      vm.administrativeValue = areaId;
      console.log(value, vm.administrativeValue);
    },
    setMoreOption(data, type) {
      let option = [];
      for (let i = 0; i < data.length; i++) {
        let obj = data[i];
        if (type == "cities") {
          obj.label = data[i].cityName;
          obj.value = data[i].cityId;
        } else if (type == "counties") {
          obj.label = data[i].countyName;
          obj.value = data[i].countyId;
          // obj.leaf = true;
        } else if (type == "towns") {
          obj.label = data[i].townName;
          obj.value = data[i].townId;
          obj.leaf = true;
        }
        option.push(obj);
      }
      return option;
    },
    //获取地区
    getRegionOption() {
      let req = {};
      openLoading(vm);
      vm.GET("basic-data/position/provinces", req).then(res => {
        closeLoading(vm);
        if (res.code == "000000") {
          vm.optionsRegion = operationData.setRegionOption2(
            res.data.provinceList
          );
        }
      });
    },
    //机构table中勾选一排
    selectAllOrganization(selection) {
      let setList = [];
      let selectList = [];
      for (let i = 0; i < vm.tableOrganization.length; i++) {
        if (vm.tableOrganization[i].modifyFlag == 0) {
          setList.push(vm.tableOrganization[i].id);
        }
      }
      for (let j = 0; j < selection.length; j++) {
        selectList.push(selection[j].id);
      }
      let intersect = operationData.getIntersect(setList, selectList);
      let typeStatus = 0;
      if (intersect.length > 0) {
        typeStatus = 1;
      }
      // let  = this.$refs.multipleTable.selection
      console.log(selection, setList, selectList);
      if (setList.length > 0) {
        let req = {
          ids: setList,
          projectId: this.projectId,
          type: typeStatus
        };
        openLoading(vm);
        vm.PUT("portal/new/scope/org/v1/organization/option", req).then(res => {
          closeLoading(vm);
        });
      }
    },
    //机构table中勾选一个
    selectOrganization(selection, row) {
      console.log("select", selection, row);
      let flag = false;
      for (let i = 0; i < selection.length; i++) {
        if (selection[i].id == row.id) {
          flag = true;
        }
      }
      let req = {
        ids: [row.id],
        projectId: this.projectId,
        type: flag === false ? 0 : 1
      };
      openLoading(vm);
      vm.PUT("portal/new/scope/org/v1/organization/option", req).then(res => {
        closeLoading(vm);
      });
    },
    //
    //人员table中勾选一排
    selectAllPerson(selection) {
      let setList = [];
      let selectList = [];
      for (let i = 0; i < vm.tablePerson.length; i++) {
        if (vm.tablePerson[i].modifyFlag == 0) {
          setList.push(vm.tablePerson[i].id);
        }
      }
      for (let j = 0; j < selection.length; j++) {
        selectList.push(selection[j].id);
      }
      let intersect = operationData.getIntersect(setList, selectList);
      let typeStatus = 0;
      if (intersect.length > 0) {
        typeStatus = 1;
      }
      console.log(selection, setList, selectList);
      if (setList.length > 0) {
        let req = {
          ids: setList,
          projectId: this.projectId,
          type: typeStatus
        };
        openLoading(vm);
        vm.PUT("portal/new/scope/doctor/v1/doctor/option", req).then(res => {
          closeLoading(vm);
        });
      }
    },
    //人员table中勾选一个
    selectPerson(selection, row) {
      console.log("select", selection, row);
      let flag = false;
      for (let i = 0; i < selection.length; i++) {
        if (selection[i].id == row.id) {
          flag = true;
        }
      }
      let req = {
        ids: [row.id],
        projectId: this.projectId,
        type: flag === false ? 0 : 1
      };
      openLoading(vm);
      vm.PUT("portal/new/scope/doctor/v1/doctor/option", req).then(res => {
        closeLoading(vm);
      });
    },
    //重置机构、人员查询
    resetOrgOrPerson(type) {
      if (type == "org") {
        vm.formOrganization.name = "";
        vm.formOrganization.administrativeId = "0";
        vm.formOrganization.administrativeIdList = ["0"];
        vm.formOrganization.level = "-1";
        vm.formOrganization.pageNum = 1;
        vm.searchOrganization();
      } else if (type == "person") {
        vm.formPerson.hospitalName = "";
        vm.formPerson.doctorName = "";
        vm.formPerson.pageNum = 1;
        vm.searchPeople();
      }
    }
  }
};
</script>
<style lang="scss">
.min-label {
  .el-form-item__label {
    line-height: 26px;
  }
  .el-form-item__content {
    line-height: 26px;
  }
}
.add-manager-wrap {
  .add-content {
    background: #fff;
  }
  .rim {
    border: 1px solid #dddddd;
  }
  .mleft60 {
    margin-left: 60px;
  }
  .soure-configure {
    background: #f9f9f9;
    padding: 15px;
    width: 550px;
    font-size: 12px;
    color: #606266;
    position: relative;
    margin-bottom: 20px;
    .configure-option {
      position: absolute;
      right: -95px;
      top: 50%;
      margin-top: -15px;
    }
    .mb15 {
      margin-bottom: 15px;
    }
    .configure-item {
      overflow: hidden;
      .configure-item-l {
        display: inline-block;
        width: 60px;
        text-align: right;
      }
    }
  }
  .mini-source {
    background: #f9f9f9;
    width: 650px;
    padding: 15px;
    margin-bottom: 20px;
    .source-item {
      padding-top: 0px;
      font-size: 12px;
      line-height: 28px;
      color: #606266;
    }
  }
  .step-content {
    overflow: hidden;
    height: 60px;
    // margin-top: 66px;
    padding: 15px 0 50px 0;
    border-bottom: 1px solid #efefef;
    .is-text {
      display: none;
    }
    .el-steps--simple {
      background: #fff;
    }
    .button-green {
      color: #ffffff;
      background: #449284;
      border-color: #bfdad5;
      border-radius: 2px;
    }
    .button-white {
      color: #606266;
      background: #ffffff;
      border-color: #ecedf1;
      border-radius: 2px;
    }
    .step-num {
      display: block;
      margin-top: 1.5px;
      font-size: 12px;
      border: 1px solid #999 !important;
      border-radius: 50%;
      width: 25px;
      height: 18px;
      line-height: 15px;
      text-align: center;
      color: #999;
    }
    .el-step__title.is-wait {
      color: #999;
    }
    .el-step__title.is-process {
      color: #449284;
    }
    .is-finish {
      color: #999 !important;
    }
    .on-step {
      color: #449284;
      border: 1px solid #449284 !important;
    }
  }
  .first-step {
    margin-top: 20px;
    .p_label {
      margin-left: 56px;
      font-size: 12px;
      color: #606266;
    }
    .basic-item-icon {
      position: relative;
      .require {
        position: absolute;
        left: 67px;
        top: 11px;
        color: #f56c6c;
      }
      .upload-message {
        position: absolute;
        left: 160px;
        top: 105px;
        font-size: 12px;
        color: #f56c6c;
      }
      .img-delete {
        position: absolute;
        left: 0px;
        top: 0px;
        width: 84px;
        height: 100px;
        background: #000;
        opacity: 0.7;
        z-index: 999;
        i {
          color: #fff;
          margin-top: 39px;
          margin-left: 0px;
        }
      }
    }
    .word-num {
      font-size: 12px;
      color: #999;
      padding-top: 5px;
    }
    .line {
      margin-left: 10px;
      width: 20px;
    }
    .bg-uploader {
      img {
        float: left;
      }
      .bg-img {
        width: 84px;
        height: 100px;
      }
      .bg-video {
        float: left;
        width: 84px;
        height: 100px;
      }
      .limit-text {
        float: left;
        margin-left: 10px;
        margin-top: -10px;
        p {
          font-size: 12px;
          color: #999;
        }
      }
    }
    .el-upload__tip {
      position: absolute;
      top: -6px;
      left: 130px;
    }
    .choose-button {
      background: #fff;
      color: #409eff;
      border: 1px solid #409eff;
    }
    .el-popover--plain {
      padding: 18px 20px;
      top: 40px;
    }
  }
  .second-step {
    margin: 10px 0 0 20px;
    .area-p {
      margin-bottom: 15px;
      font-size: 14px;
    }
    .span_ecology {
      line-height: 45px;
      margin-left: 8px;
    }
    .dialog-p {
      text-align: center;
      span {
        color: #449284;
      }
    }
    //隐藏树展开
    .table-empty {
      img {
        width: 100px;
      }
      p {
        margin-top: -50px;
      }
    }
    .el-tree-node__expand-icon {
      display: none;
    }
    .department {
      margin-top: 20px;
      border: 1px solid #dddddd;
    }
    .el-tabs__nav-wrap::after {
      display: none;
    }
    .el-tabs__active-bar {
      display: none;
    }
    #tab-first,
    #tab-second,
    #tab-third {
      padding-right: 0px;
    }
    #tab-first::after,
    #tab-second::after,
    #tab-third::after {
      color: #c7cbd2;
      margin-left: 20px;
      content: "•";
    }
    .el-tabs__item.is-active {
      color: #fff;
    }
    .el-tag {
      margin: 0 10px 10px 0;
      border: 1.3px solid #48a8fe;
      color: #1e92fe;
      background-color: #e7f6fe;
      .el-icon-close {
        width: 13px;
        height: 13px;
        line-height: 13px;
        font-size: 12px;
        background-color: #0486fe;
        border-radius: 50%;
        color: #d4edfe;
      }
    }
    .down-button {
      margin-left: 10px;
    }
    .down-button-close {
      margin-left: 100px;
      float: left;
    }
    .dialog-success {
      p {
        text-align: center;
        .upload-text {
          color: #449284;
        }
      }
    }
    .dialog-fail {
      .fail-type {
        p {
          margin-top: 10px;
        }
        .fail-num {
          color: #db3f52;
        }
        .fail-notice {
          color: #e3e3e3;
          font-size: 13px;
        }
        .fail-link {
          text-align: center;
          color: #449284;
          cursor: pointer;
        }
      }
    }
  }
  .third-step {
    margin: 30px 0 0px 30px;
    padding-bottom: 30px;
    ::-webkit-scrollbar {
      width: 4px;
      height: 20px;
      background-color: #d8d8d8;
    }
    ::-webkit-scrollbar-thumb {
      background-color: #d8d8d8;
    }
    .el-tag {
      margin-top: 5px;
      display: table;
      background-color: #e6f1fc;
      color: #389efe;
    }
    .el-select {
      .el-tag {
        i {
          display: none;
        }
      }
    }
    .tags-list {
      border: 1px #e8e8e8 solid;
      height: 350px;
      min-width: 280px;
      overflow-y: scroll;
    }
    .tags-component-online {
      color: #9aceff;
      background-color: #f3f8fe;
      border-color: #d5eafe;
    }
    .achievement {
      margin-top: 60px;
    }
    .form-component {
      position: relative;
    }
    .check-component {
      top: 0px;
      right: 5%;
      position: absolute;
      z-index: 999;
    }
    .el-time-ctr {
      .el-radio {
        display: block;
        padding: 10px 0;
      }
    }
    .el-configure {
      width: 200px;
    }
    .time-contrl {
      .el-input__inner {
        padding-right: 0;
      }
      .el-input-group__append {
        padding: 0 8px;
      }
    }
  }
}
.edit-img {
  width: 20px;
}
.popover-content {
  position: relative;
  top: 0;
  left: 0;
}
</style>
