<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="5" :offset="5">
            <el-button  size="small" type="primary" @click="nextStep">提交</el-button>
          </el-col>
        </el-row>
        <div class="second-step" >
          <div >
                <el-form :inline="true" :model="formOrganization" class="demo-form-inline">
                  <el-form-item label>
                    <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>
                <!--
                   :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-tabs>
          </div>
          <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>
    </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 {

        idTypeProject: "",
        customError: {
          standard: {
            className: "",
            error: ""
          },
          certificate: {
            className: "",
            error: ""
          },
          passTotalLearnTime: {
            className: "",
            error: ""
          },
          passExamCount: {
            className: "",
            error: ""
          },
          passAverageScore: {
            className: "",
            error: ""
          }
        },
        projectId: null,
        peopleLevel: null,
     
        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: [],
     
        //设定机构 数据
        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: [],
        //搜索类型
        searchOrganizationType: "",
        searchPeopleType: "",
        //v2.2.0更新
        warnType: 0,
        nowCheck: {},
        administrativeValue: "",
        optionsRegion: [],
        dialogUpload: false,
        searchName: "",
        getRowKeysDepartment(row) {
          return row.id;
        },
        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);
              });
            }
          }
        },
      };
    },
    computed: {
      ...mapGetters(["_token"])
    },
    created() {
      vm = this;
      (this.projectId = 775),
        (this.peopleLevel = vm.getUrlSearch(window.location.href, "level"));
      this.initRange();
      //this.editManager();
      vm.idType = localStorage.getItem("storageIdType");
      console.log("this.idType:" + vm.idType);
    },
    // 挂载到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: ""
            };
          }
        }
      },
      //第二步 选择范围 初始化
      initRange() {
        let projectId = this.projectId;
          this.getRegionOption();
          this.listLevels();
          this.getOrganization();
            this.activeName = "second";
            this.formOrganization.pageNum = 1;
          this.formOrganization.name = "";
          this.formOrganization.administrativeIdList = ["0"];
          this.formOrganization.level = "-1"; 
      },
 
      //初始化范围树
      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;
      },
      //列举选中地区
      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() {
      debugger
        //重构归并树
        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;
      },
      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 = [];
      },
     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 == ""
        ) {
          console.log("wei")
          this.searchOrganizationType = "";
          this.getOrganization();
        } else {
          console.log("choose")
          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);
              });
            }
          }
        });
      },
       //设定的行政范围内容
    getScope(type) {
      console.log(type)
      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;
    },
      //机构搜索
      getOrganizationChoose() {
        console.log('formOrganization',this.formOrganization);
        let administrativeIdItem = operationData.setAdministrativeId(
          this.formOrganization.administrativeIdList
        );
        console.log('administrativeIdItem',administrativeIdItem);
        let req = {
          projectId: 775,
          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: 775,
          administrativeId: "",
          hospitalLevel: "",
          hospitalLevel: "",
          scope: "000_110",
          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);
          }
        });
      },
      //获取机构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;
      },
  
      //选择搜索机构方式
      searchPeople() {
        this.formPerson.pageNum = 1;
        let searchForm = this.formPerson;
        if (searchForm.hospitalName === "" && searchForm.doctorName === "") {
          this.searchPeopleType = "";
          this.getPeople();
        } else {
          this.searchPeopleType = "choose";
          this.getPeopleChoose();
        }
      },
 
      //判断项目范围选择
      showScopeType() {
        if (this.projectStatus == "" || this.projectStatus == 1) {
          if (this.peopleLevel != "L3") {
            return false;
          }
        }
        return true;
      },
      //机构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 = [];
      },
 
      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);
      },
 
      // add 校验输入是否为整数
      checkIntFun(str) {
        let r = /^\+?[0-9]*$/;
        return r.test(str);
      },
 
      hideErrorInfo(str) {
        if (str) {
          this.customError[str] = {
            className: "",
            error: ""
          };
        } else {
          this.customError = {};
        }
      },
  
      dioErrorPop(str) {
        return this.$message({
          message: str,
          type: "warning"
        });
      },
  
   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;
      },

      //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)
        }
      },
      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;
      }
    }
    .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;
          }
        }
      }
    }

  }
  .edit-img {
    width: 20px;
  }
  .popover-content {
    position: relative;
    top: 0;
    left: 0;
  }
  </style>
  