<template>
  <div class="resource-search">
    <!-- 类别 -->
    <div class="resource-type">
      <div
        class="resource-type-item"
        v-for="item in resourceTypes"
        :class="[
          item.value === activeType ? 'resource-type-item-active' : '',
          item.value == 5 ? 'resource-type-item-disabled' : '',
        ]"
        :key="item.value"
        @click="switchType(item.value)"
      >
        <i class="icon" :class="'icon-' + item.value"></i>
        <span class="name">{{ item.name }}</span>
      </div>
    </div>
    <!-- 筛选框 搜企业-->
    <div v-if="activeType === '1' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formCompany">
        <el-form-item label="企业类型" style="padding-top: 3px" v-if="isSecurity || isPoliceStation">
          <el-radio-group v-model="formCompany.institutional">
            <el-radio label="" style="padding-top: 8px">全部</el-radio>
            <el-radio style="padding-top: 8px" v-for="item in securityTypes" :key="item.code" :label="item.code">{{
              item.name
            }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="isSecurity || isPoliceStation || isPopulationTeam" label="辖区" style="padding-top: 6px">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer1"
            v-model="formCompany.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            @select="onSelectCompanyDeparts"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            @click="searchCompany"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜保安员 -->
    <div v-if="activeType === '2' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formEmployee">
        <el-form-item label="类型" style="padding-top: 6px" v-if="isPoliceStation">
          <el-radio-group class="multi-row-radio" v-model="formEmployee.resourceType">
            <el-radio :label="1" style="margin-right: 10px">全部</el-radio>
            <el-radio :label="2" style="margin-right: 10px">保安员</el-radio>
            <el-radio v-if="platform === '1'" :label="3" style="margin-right: 10px">社会力量</el-radio>
            <el-radio v-if="platform === '1'" :label="4" style="margin-right: 10px">社会力量（保安员）</el-radio>
            <el-radio v-if="platform === '2'" :label="5" style="margin-right: 10px">保卫管理员</el-radio>
            <el-radio :label="6" disabled style="margin-right: 10px">智能设备持有人</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="类型" style="padding-top: 6px" v-if="isPopulationTeam">
          <el-radio-group v-model="formEmployee.resourceType">
            <el-radio :label="1">全部</el-radio>
            <el-radio v-if="platform === '1'" :label="3">社会力量</el-radio>
            <el-radio v-if="platform === '1'" :label="4">社会力量（保安员）</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="关注类型"
          style="padding-top: 6px"
          v-if="isSecurity || isPoliceStation || isPopulationTeam || isCompany"
        >
          <el-radio-group v-model="formEmployee.type">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">已关注</el-radio>
            <el-radio :label="3">未关注</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="在岗状态"
          style="padding-top: 6px"
          v-if="isSecurity || isPoliceStation || isPopulationTeam || isCompany"
        >
          <el-radio-group v-model="formEmployee.status">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">在岗</el-radio>
            <el-radio :label="3">离岗</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="辖区" style="padding-top: 6px" v-if="isSecurity || isPoliceStation || isPopulationTeam">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer"
            v-model="formEmployee.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            :flat="true"
            @select="onSelectEmployeeDeparts"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click.prevent="searchEmployee(false)"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜驻勤点 -->
    <div v-if="activeType === '3' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formStation">
        <station-types-form
          v-if="formStation.resourceType === 2"
          :station-types="stationTypes"
          :is-security="isSecurity"
          :is-police-station="isPoliceStation"
          @handleCheckChange="handleCheckChange"
        ></station-types-form>
        <el-form-item label="类型" style="padding-top: 3px" v-if="isPoliceStation || isPopulationTeam">
          <el-radio-group v-model="formStation.resourceType">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">驻勤点</el-radio>
            <el-radio :label="3">社区警务</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="关注类型"
          style="padding-top: 3px"
          v-if="isSecurity || isPoliceStation || isPopulationTeam || isCompany"
        >
          <el-radio-group v-model="formStation.type">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">已关注</el-radio>
            <el-radio :label="3">未关注</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="辖区" style="padding-top: 3px" v-if="isSecurity || isPoliceStation || isPopulationTeam">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer1"
            v-model="formStation.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            @select="onSelectStationDepart"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click="searchStation"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜内保单位 -->
    <div v-if="activeType === '4' && platform === '2' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formCompany">
        <el-form-item label="内保单位类型" style="padding-top: 3px" v-if="platform === '2' && isPoliceStation">
          <el-checkbox :indeterminate="isIndeterminatePro" v-model="checkAllPro" @change="handleCheckAllChangePro"
            >全选</el-checkbox
          >
          <el-checkbox-group v-model="formCompany.institutional" @change="handleCheckedCitiesChangePro">
            <el-row>
              <el-col style="padding-top: 10px" v-for="item in proprietorTypes" :key="item.code" :span="8">
                <el-checkbox :label="item.code">
                  <span style="font-size: 12px; padding-left: 2px">{{ item.name }}</span>
                </el-checkbox>
              </el-col>
            </el-row>
          </el-checkbox-group>
        </el-form-item>

        <el-form-item label="关注类型" style="padding-top: 3px">
          <el-radio-group v-model="formCompany.type">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">已关注</el-radio>
            <el-radio :label="3">未关注</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="isPoliceStation || !isProprietor" label="辖区" style="padding-top: 3px">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer1"
            v-model="formCompany.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            @select="onSelectCompanyDeparts"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click="searchProprietor"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜智能设备 -->
    <div v-if="activeType === '5' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formDevice">
        <el-form-item label="关注类型" style="padding-top: 6px">
          <el-radio-group v-model="formDevice.focus">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">已关注</el-radio>
            <el-radio :label="3">未关注</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="设备类型" style="padding-top: 6px">
          <el-radio-group v-model="formDevice.type">
            <el-radio :label="1">全部</el-radio>
            <el-radio v-for="item in deviceTypes" :key="item.code" :label="item.code">{{ item.name }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click="searchDevice"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜电子围栏 -->
    <div v-if="activeType === '6' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formSecurityStationRail">
        <el-form-item v-if="isSupervision" label="辖区" style="padding-top: 6px">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer1"
            v-model="formSecurityStationRail.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            @select="onSelectRailDepart"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click="searchRail"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选框 搜考场 -->
    <div v-if="activeType === '7' && filterShow" class="filter-content">
      <el-form class="filter-form" :model="formExam">
        <el-form-item label="关注类型" style="padding-top: 6px">
          <el-radio-group v-model="formExam.type">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">已关注</el-radio>
            <el-radio :label="3">未关注</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="考场状态" style="padding-top: 6px">
          <el-radio-group v-model="formExam.status">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">启用</el-radio>
            <el-radio :label="3">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="考试状态" style="padding-top: 6px">
          <el-radio-group v-model="formExam.examTaking">
            <el-radio :label="1">全部</el-radio>
            <el-radio :label="2">考试中</el-radio>
            <el-radio :label="3">无考试</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="isSupervision" label="辖区" style="padding-top: 6px">
          <tree-select
            class="tree-select"
            :options="departs"
            placeholder="请选择"
            :normalizer="normalizer1"
            v-model="formEmployee.depart"
            noOptionsText="无数据"
            noResultsText="无数据"
            @select="onSelectExamDepart"
          />
        </el-form-item>
        <el-form-item class="center is-last">
          <el-button
            class="btn-full"
            type="primary"
            :disabled="loading"
            v-loading="loading"
            element-loading-spinner="el-icon-loading"
            @click.prevent="searchExamSiteRooms(false)"
          >
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 筛选/收起 按钮 -->
    <div v-if="activeType && activeType !== '1'" class="filter-bar" @click="filterShow = !filterShow">
      <span class="text">{{ filterText }}</span>
      <i class="arrow" :class="'arrow-' + (filterShow ? 'up' : 'down')"></i>
    </div>
    <!-- 查询总数统计值 -->
    <div v-if="activeType && activeType !== '5'" class="total">
      <span class="label">总数</span>
      <span class="value">{{ total }}</span>
      <span v-if="activeType === '2'" class="label label-green">在岗数</span>
      <span v-if="activeType === '2'" class="value value-on">{{ onDuty }}</span>
      <span v-if="activeType === '2'" class="label label-gray">离岗数</span>
      <span v-if="activeType === '2'" class="value value-off">{{ noDuty }}</span>
      <span v-if="activeType === '2'" class="label label-gray">未激活数</span>
      <span v-if="activeType === '2'" class="value value-off">{{ noActivation }}</span>
      <span v-if="activeType === '1' || activeType === '3'" class="label label-gray">无坐标数</span>
      <span v-if="activeType === '1' || activeType === '3'" class="value value-off">{{ noLonLat }}</span>
      <span v-if="activeType === '6'" class="label label-green">启用总数</span>
      <span v-if="activeType === '6'" class="value value-on">{{ onExam }}</span>
      <span v-if="activeType === '6'" class="label label-gray">禁用总数</span>
      <span v-if="activeType === '6'" class="value value-off">{{ noExam }}</span>
    </div>
  </div>
</template>

<script>
// import {mapGetters} from "vuex";
import treeSelect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { getEmployees } from "@/api/employee-controller";
import { getExamSiteRooms } from "@/api/exam-site-room-controller";
import { getCompanys } from "@/api/company-controller";
import { getAllStationTypes, getStations } from "@/api/security-station-controller";
import { getDeparts } from "@/api/departs-controller";
import { getDeviceType, getOrganizationType } from "@/api/resource-controller";
import { searchRail } from "@/api/security-station-rails-controller";
import _ from "lodash";
import stationTypesForm from "@/components/StationTypesForm/index.vue";

export default {
  name: "resourceSearch",
  components: { treeSelect, stationTypesForm },
  data() {
    return {
      platform: localStorage.getItem("platform") || "1",
      deskTypes: localStorage.getItem("platform") === "1" ? ["Normal"] : ["Proprietor"],
      isCompany: false,
      isIndeterminate: false,
      isIndeterminatePro: false,
      checkAll: false,
      checkAllPro: false,
      companyTypes: [],
      securityTypes: [],
      securityTypesCode: [],
      proprietorTypes: [],
      proprietorTypesCode: [],
      deviceTypes: [],
      resourceTypes: [],
      activeType: "",
      filterShow: false,
      isSecurity: false, //当前用户角色是否为治安市局/分局
      isPopulationTeam: false, //当前用户角色是否为人口总队市局/分局
      isPoliceStation: false, //当前用户角色是否为派出所
      isSupervision: false, //是否监管端 显示辖区：企业账号进来不展示【辖区】筛选项:false，只有监管账号进来才展示:true
      isProprietor: false, //是否内保单位
      stationTypes: [],
      departs: [],
      normalizer(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.code,
          label: node.name,
          children: node.children,
          isDisabled: !node.selectable,
        };
      },
      normalizer1(node) {
        if (node.children && !node.children.length) {
          delete node.children;
        }
        return {
          id: node.code,
          label: node.name,
          children: node.children,
        };
      },
      total: 0, //总数
      onDuty: 0, //在岗
      noDuty: 0, //离岗
      noActivation: 0, //未激活
      noLonLat: 0, //无坐标数
      onExam: 0, //启用总数
      noExam: 0, //禁用总数
      formCompany: {
        institutional: [],
        type: 1,
        depart: null,
        superviseDepartIds: [],
      },
      formEmployee: {
        resourceType: 1,
        type: 1,
        status: 1,
        depart: null,
        superviseDepartIds: [],
      },
      formDevice: {
        focus: null,
        type: null,
      },
      formStation: {
        resourceType: 1,
        type: 1,
        stationType: [],
        depart: null,
        superviseDepartIds: [],
      },
      formSecurityStationRail: {
        depart: null,
        superviseDepartIds: [],
      },
      formExam: {
        type: 1,
        status: 1,
        examTaking: 1,
        depart: null,
        superviseDepartIds: [],
      },
      loading: false,
    };
  },
  computed: {
    filterText() {
      return this.filterShow ? "收起" : "筛选";
    },
  },
  methods: {
    handleCheckChange(val) {
      this.formStation.stationType = val;
    },
    handleCheckAllChange(val) {
      this.formStation.stationType = val ? this.stationTypes.map((x) => x.code) : [];
      this.isIndeterminate = false;
    },
    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.stationTypes.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.stationTypes.length;
    },
    handleCheckAllChangePro(val) {
      this.formCompany.institutional = val ? this.proprietorTypes.map((x) => x.code) : [];
      this.isIndeterminatePro = false;
    },
    handleCheckedCitiesChangePro(value) {
      let checkedCount = value.length;
      this.checkAllPro = checkedCount === this.proprietorTypes.length;
      this.isIndeterminatePro = checkedCount > 0 && checkedCount < this.proprietorTypes.length;
    },
    async init() {
      this.stationTypes = await getAllStationTypes(); //获取驻勤点信息
      console.log("stationTypes", this.stationTypes);
      this.companyTypes = await getOrganizationType(); // 获取企业类型 {code,name}
      this.securityTypes = this.companyTypes.filter((item) => item.category === "Security");
      this.securityTypesCode = this.securityTypes.map((item) => {
        return item.code;
      });
      this.proprietorTypes = this.companyTypes.filter((item) => item.category === "Proprietor");
      this.proprietorTypesCode = this.proprietorTypes.map((item) => {
        return item.code;
      });
      console.log(
        "proprietorTypes",
        this.proprietorTypes.map((item) => {
          return item.code;
        })
      );
      this.deviceTypes = await getDeviceType(); // 获取设备类型 {code,name}
      console.log("deviceTypes", this.deviceTypes);
      this.departs = await getDeparts(); // 获取辖区树
      console.log("departs", this.departs);
      //判断是否显示辖区
      // let accountType = "";
      // let deviceDeskServiceScopes = [];
      const userInfo = localStorage.getItem("userInfo");
      if (userInfo) {
        this.isSupervision = JSON.parse(userInfo).superviseDesk; //判断身份 ture:监管账户；false:企业账户
        this.isCompany = JSON.parse(userInfo).role === "Company" || JSON.parse(userInfo).role === "Proprietor";
        this.isSecurity = JSON.parse(userInfo).role === "Urban" || JSON.parse(userInfo).role === "SubUrb";
        this.isPopulationTeam =
          JSON.parse(userInfo).role === "PopulationUrban" || JSON.parse(userInfo).role === "PopulationSubUrb";
        this.isPoliceStation =
          JSON.parse(userInfo).role === "PopulationPoliceStation" || JSON.parse(userInfo).role === "PoliceStation";
        this.isProprietor = JSON.parse(userInfo).role === "Proprietor"; //是否内保单位
        if (this.isPopulationTeam || this.isPoliceStation) {
          //如果用户角色是人口总队 PopulationUrban 人口市局  PopulationSubUrb 人口分局  PopulationPoliceStation 人口派出所  PoliceStation 派出所
          if (this.platform === "1") {
            this.resourceTypes = [
              {
                name: "企业",
                value: "1",
              },
              {
                name: "人员",
                value: "2",
              },
              {
                name: "执勤点",
                value: "3",
              },
              {
                name: "智能设备",
                value: "5",
              },
              {
                name: "电子围栏",
                value: "6",
              },
            ];
          } else {
            this.resourceTypes = [
              {
                name: "人员",
                value: "2",
              },
              {
                name: "驻勤点",
                value: "3",
              },
              {
                name: "内保单位",
                value: "4",
              },
              {
                name: "智能设备",
                value: "5",
              },
              {
                name: "电子围栏",
                value: "6",
              },
            ];
          }
        } else if (this.isProprietor || this.platform === "2") {
          this.resourceTypes = [
            {
              name: "人员",
              value: "2",
            },
            {
              name: "驻勤点",
              value: "3",
            },
            {
              name: "内保单位",
              value: "4",
            },
            {
              name: "智能设备",
              value: "5",
            },
            {
              name: "电子围栏",
              value: "6",
            },
          ];
        } else {
          this.resourceTypes = [
            {
              name: "企业",
              value: "1",
            },
            {
              name: "保安员",
              value: "2",
            },
            {
              name: "驻勤点",
              value: "3",
            },
            {
              name: "智能设备",
              value: "5",
            },
            {
              name: "电子围栏",
              value: "6",
            },
            // {
            //   name: "考场",
            //   value: "6",
            // },
          ];
        }
      }
    },
    // 切换搜索类型
    switchType(type) {
      this.activeType = type;
      this.filterShow = true;
      this.$emit("switchType", this.activeType);
      this.$emit("clearMap");
      this.total = 0;
      this.onDuty = 0;
      this.noDuty = 0;
      this.noActivation = 0;
      this.noLonLat = 0;
      this.onExam = 0;
      this.noExam = 0;

      if (this.isSupervision) {
        //监管调度
      } else {
        //企业调度
        if (type == 1) {
          this.filterShow = false;
          this.searchCompany();
        }
      }
    },
    // 显示筛选条件
    showFilter() {
      this.filterShow = true;
    },
    // 收起筛选条件
    hideFilter() {
      this.filterShow = false;
    },
    // 搜企业
    searchCompany() {
      var institutional = [];
      console.log("institutional", this.formCompany.institutional);
      if (this.formCompany.institutional.length === 0) {
        institutional = this.securityTypesCode;
      } else {
        institutional = [this.formCompany.institutional + ""];
      }

      this.loading = true;
      getCompanys({
        institutionals: institutional,
        superviseDepartIds: this.formCompany.superviseDepartIds,
        deskTypes: this.isCompany ? ["Normal", "Proprietor"] : this.deskTypes,
        searchModel: "SecurityResource",
      })
        .then((res) => {
          console.log(res);
          this.$emit("searchCompany", res);
        })
        .catch((err) => {
          this.$emit("searchCompany", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜保安员
    searchEmployee() {
      if (this.isSupervision && !this.formEmployee.depart) {
        this.$message({
          message: "请选择辖区",
          type: "warning",
        });
        return;
      }
      var resourceTypes = null;
      if (this.formEmployee.resourceType == "2") {
        resourceTypes = ["Security"];
      } else if (this.formEmployee.resourceType == "3") {
        resourceTypes = ["Population"];
      } else if (this.formEmployee.resourceType == "4") {
        resourceTypes = ["Population", "Security"];
      } else if (this.formEmployee.resourceType == "5") {
        resourceTypes = ["Proprietor"];
      }

      var followed = null;
      if (this.formEmployee.type == "2") {
        followed = true;
      } else if (this.formEmployee.type == "3") {
        followed = false;
      }
      var onDuty = null;
      if (this.formEmployee.status == "2") {
        onDuty = true;
      } else if (this.formEmployee.status == "3") {
        onDuty = false;
      }
      this.loading = true;
      getEmployees({
        pageIndex: 1,
        pageSize: 5000,
        followed: followed,
        onDuty: onDuty,
        resourceTypes: resourceTypes,
        superviseDepartIds: this.formEmployee.superviseDepartIds,
        searchModel: "SecurityResource",
        deskTypes: this.isCompany ? ["Normal", "Proprietor"] : this.deskTypes,
      })
        .then((res) => {
          console.log(res);
          this.$emit("searchEmployee", res);
        })
        .catch((err) => {
          this.$emit("searchEmployee", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //设置保安员人数
    setEmployeeNum(onDuty, noDuty, noActivation) {
      this.total = onDuty + noDuty + noActivation;
      this.onDuty = onDuty;
      this.noDuty = noDuty;
      this.noActivation = noActivation;
    },
    // 搜驻勤点
    searchStation() {
      //指挥调度搜索驻勤点
      let resourceType = null;
      if (this.isPopulationTeam || this.isPoliceStation) {
        //如果是人口总队
        if (this.formStation.resourceType === 2) {
          resourceType = "Security";
        } else if (this.formStation.resourceType === 3) {
          resourceType = "Population";
        }
      } else {
        resourceType = "Security";
      }
      let followed = null;
      if (this.formStation.type === 2) {
        followed = true;
      } else if (this.formStation.type === 3) {
        followed = false;
      }
      // var stationType = [];
      // if (this.formStation.stationType !== 0) {
      //   stationType.push(this.formStation.stationType + "");
      // }
      this.loading = true;
      getStations({
        pageIndex: 1,
        pageSize: 5,
        followed: followed,
        resourceType: resourceType,
        stationTypes: resourceType === "Security" ? this.formStation.stationType : [],
        superviseDepartIds: this.formStation.superviseDepartIds,
        searchModel: "SecurityResource",
        deskTypes: this.isCompany ? ["Normal", "Proprietor"] : this.deskTypes,
      })
        .then((res) => {
          res["stationTypes"] = this.stationTypes;
          console.log(res);

          this.$emit("searchStation", res);
        })
        .catch((err) => {
          this.$emit("searchStation", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜内保单位
    searchProprietor() {
      //安保调度搜索内保单位
      var institutional = this.proprietorTypesCode;
      if (this.formCompany.institutional && this.formCompany.institutional.length > 0) {
        institutional = this.formCompany.institutional;
      }
      var followed = null;
      if (this.formCompany.type == "2") {
        followed = true;
      } else if (this.formCompany.type == "3") {
        followed = false;
      }
      this.loading = true;
      getCompanys({
        pageIndex: 1,
        pageSize: 5,
        institutionals: institutional,
        followed: followed,
        superviseDepartIds: this.formCompany.superviseDepartIds,
        deskTypes: this.isCompany ? ["Normal", "Proprietor"] : this.deskTypes,
        searchModel: "SecurityResource",
      })
        .then((res) => {
          this.$emit("searchCompany", res, "Proprietor");
        })
        .catch((err) => {
          this.$emit("searchCompany", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //设置驻勤点数
    setStationNum(total, noLonLat) {
      this.total = total;
      this.noLonLat = noLonLat;
    },
    //设置企业数
    setCompanyNum(total, noLonLat) {
      this.total = total;
      this.noLonLat = noLonLat;
    },
    //设置考场数
    setExamNum(onExam, noExam) {
      this.total = onExam + noExam;
      this.onExam = onExam;
      this.noExam = noExam;
    },
    // 搜智能设备
    searchDevice() {},
    // 搜电子围栏
    searchRail() {
      this.loading = true;
      searchRail({
        pageIndex: 1,
        pageSize: 50,
        superviseDepartIds: this.formSecurityStationRail.superviseDepartIds,
        searchModel: "SecurityResource",
      })
        .then((res) => {
          console.log("searchRail", res);
          if (res) {
            console.log(res);
            this.$emit("searchRail", res);
          }
        })
        .catch((err) => {
          this.$emit("searchRail", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 搜考场
    searchExamSiteRooms() {
      var followed = null;
      if (this.formExam.type == "2") {
        followed = true;
      } else if (this.formExam.type == "3") {
        followed = false;
      }

      //考场状态
      var status = null;
      if (this.formExam.status == "2") {
        status = true;
      } else if (this.formExam.status == "3") {
        status = false;
      }

      //考试状态
      var examTaking = null;
      if (this.formExam.examTaking == "2") {
        examTaking = true;
      } else if (this.formExam.examTaking == "3") {
        examTaking = false;
      }

      this.loading = true;
      getExamSiteRooms({
        pageIndex: 1,
        pageSize: 5,
        forExport: false,
        followed: followed,
        status: status,
        examTaking: examTaking,
        superviseDepartId: this.formEmployee.depart,
        searchModel: "SecurityResource",
      })
        .then((res) => {
          console.log(res);
          this.$emit("searchExam", res);
        })
        .catch((err) => {
          this.$emit("searchExam", []);
          this.$message.error(err);
        })
        .finally(() => {
          this.loading = false;
        });
    },
    onSelectEmployeeDeparts(node) {
      console.log(node);
      if (node?.children?.length > 0) {
        const getTail = (item) => (item.children && item.children.length > 0 ? item.children.map((m) => getTail(m)) : [item]);
        const result = _.flattenDeep(node.children.map((m) => getTail(m)));
        console.log(" log result", result);
        this.formEmployee.superviseDepartIds = [node.code, ...result.map((x) => x.code)];
      } else {
        this.formEmployee.superviseDepartIds = [node.code];
      }
    },
    onSelectCompanyDeparts(node) {
      if (node?.children?.length > 0) {
        const getTail = (item) => (item.children && item.children.length > 0 ? item.children.map((m) => getTail(m)) : [item]);
        const result = _.flattenDeep(node.children.map((m) => getTail(m)));
        console.log(" log result", result);
        this.formCompany.superviseDepartIds = [node.code, ...result.map((x) => x.code)];
      } else {
        this.formCompany.superviseDepartIds = [node.code];
      }
    },
    onSelectStationDepart(node) {
      if (node?.children?.length > 0) {
        const getTail = (item) => (item.children && item.children.length > 0 ? item.children.map((m) => getTail(m)) : [item]);
        const result = _.flattenDeep(node.children.map((m) => getTail(m)));
        console.log(" log result", result);
        this.formStation.superviseDepartIds = [node.code, ...result.map((x) => x.code)];
      } else {
        this.formStation.superviseDepartIds = [node.code];
      }
    },
    onSelectRailDepart(node) {
      if (node?.children?.length > 0) {
        const getTail = (item) => (item.children && item.children.length > 0 ? item.children.map((m) => getTail(m)) : [item]);
        const result = _.flattenDeep(node.children.map((m) => getTail(m)));
        console.log(" log result", result);
        this.formSecurityStationRail.superviseDepartIds = [node.code, ...result.map((x) => x.code)];
      } else {
        this.formSecurityStationRail.superviseDepartIds = [node.code];
      }
    },
    onSelectExamDepart(node) {
      console.log(node);
      if (node?.children?.length > 0) {
        const getTail = (item) => (item.children && item.children.length > 0 ? item.children.map((m) => getTail(m)) : [item]);
        const result = _.flattenDeep(node.children.map((m) => getTail(m)));
        console.log(" log result", result);
        this.formExam.superviseDepartIds = [node.code, ...result.map((x) => x.code)];
      } else {
        this.formExam.superviseDepartIds = [node.code];
      }
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style scoped lang="scss">
.resource-search {
  position: absolute;
  top: 13px;
  left: 34px;
  width: 588px;
  //height: 140px;
  background: #ffffff;
  box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.2);
  border-radius: 4px 4px 4px 4px;
  z-index: 2;
  .resource-type {
    width: 100%;
    padding: 8px 12px 14px 12px;
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    &-item {
      width: 94px;
      height: 94px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      padding: 9px 0 11px 0;
      cursor: pointer;
      &-active {
        background: #f2f2f2;
      }
      &-disabled {
        pointer-events: none;
        opacity: 0.3;
      }
      .icon {
        display: block;
        &-1 {
          width: 38px;
          height: 39px;
          background: url("~@/assets/images/mapSearch/搜地址.png") no-repeat;
          background-size: 100% 100%;
        }
        &-2 {
          width: 42px;
          height: 43px;
          background: url("~@/assets/images/mapSearch/保安人员.png") no-repeat;
          background-size: 100% 100%;
        }
        &-3 {
          width: 42px;
          height: 42px;
          background: url("~@/assets/images/mapSearch/驻勤点备份.png") no-repeat;
          background-size: 100% 100%;
        }
        &-4 {
          width: 44px;
          height: 44px;
          background: url("~@/assets/images/mapSearch/内保单位.png") no-repeat;
          background-size: 100% 100%;
        }
        &-5 {
          width: 44px;
          height: 44px;
          background: url("~@/assets/images/mapSearch/智能对讲终端.png") no-repeat;
          background-size: 100% 100%;
        }
        &-6 {
          width: 44px;
          height: 44px;
          background: url("~@/assets/images/mapSearch/电子围栏.png") no-repeat;
          background-size: 100% 100%;
        }
        &-7 {
          width: 42px;
          height: 42px;
          background: url("~@/assets/images/mapSearch/驻勤点备份.png") no-repeat;
          background-size: 100% 100%;
        }
      }
      .name {
        font-size: 14px;
        font-weight: 400;
        color: #000000;
        line-height: 17px;
      }
    }
  }
  .filter-content {
    padding: 0 15px;
    ::v-deep .filter-form {
      .el-form-item {
        // padding-top: 10px;
        width: 100%;
        border-top: 1px solid #eeeeee;
        margin-bottom: 10px;
        &.is-last {
          border-top: 0;
        }
        &.center {
          width: 100%;
          display: flex;
          justify-content: center;
          .btn-full {
            width: 428px;
            height: 39px;
            line-height: 10px;
            background: #0e71ff;
            &:hover,
            &:active {
              background: #569bff;
            }
            .el-loading-spinner {
              margin-top: 0;
              transform: translate(-26px, -6px);
              i {
                color: #fff;
              }
            }
          }
        }
      }
      .el-form-item__label {
        border-left: 4px solid #0e71ff;
        height: 20px;
        width: 100%;
        padding-left: 12px;
        font-size: 14px;
        font-weight: 400;
        color: #000000;
        line-height: 18px;
        display: flex;
        align-items: center;
        margin-bottom: 10px;
      }
      .el-form-item__content {
        padding-left: 4px;
        line-height: 1;
      }
      .type-icon {
        width: 16px;
        height: 16px;
      }
      .tree-select {
        padding-top: 6px;
        width: 477px;
        font-size: 14px;
        line-height: 35px;
        // font-family: PingFang SC-Regular, PingFang SC;
        // font-weight: 400;
        color: #606266;
        .vue-treeselect__placeholder {
          line-height: 35px;
        }
        .vue-treeselect__control {
          height: 35px !important;
        }
        .vue-treeselect__placeholder,
        .vue-treeselect__single-value {
          line-height: 35px;
        }
      }
      .el-checkbox-group {
        .el-row {
          //height: 270px;
          overflow-y: auto;
          overflow-x: hidden;
          .el-checkbox {
            line-height: 1;
          }
        }
      }
      .multi-row-radio {
        .el-radio {
          margin-bottom: 10px;
        }
      }
    }
    .filter-item {
      padding-top: 16px;
      width: 100%;
      border-top: 1px solid #eeeeee;
    }
  }
  .filter-bar {
    width: 588px;
    height: 24px;
    background: #ffffff;
    border-radius: 0 0 4px 4px;
    opacity: 1;
    border-top: 2px solid #e1e1e1;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    .arrow {
      display: block;
      width: 24px;
      height: 24px;
      &-down {
        background: url("~@/assets/images/mapSearch/24px展开.png") no-repeat;
        background-size: 100% 100%;
      }
      &-up {
        background: url("~@/assets/images/mapSearch/24px展开-2.png") no-repeat;
        background-size: 100% 100%;
      }
    }
    .text {
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      line-height: 19px;
      margin-right: 16px;
    }
  }
  .total {
    position: absolute;
    right: -16px;
    top: 0;
    min-width: 152px;
    height: 60px;
    background: rgba(255, 255, 255, 0.8);
    transform: translate(100%, 0);
    border-radius: 4px;
    border-left: 4px solid #0e70ff;
    padding: 0 12px;
    display: flex;
    align-items: center;
    .label {
      height: 30px;
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      display: flex;
      align-items: center;
      word-wrap: normal;
      white-space: nowrap;
      &::before {
        content: "";
        display: block;
        width: 8px;
        height: 8px;
        background: #0e70ff;
        border-radius: 50%;
        margin-right: 2px;
      }
      &-green {
        &::before {
          background: #60da84;
        }
      }
      &-gray {
        &::before {
          background: #999999;
        }
      }
      &-green,
      &-gray {
        margin-left: 10px;
        padding-left: 16px;
        border-left: 2px solid #b2cce4;
      }
    }
    .value {
      font-size: 24px;
      font-weight: 500;
      color: #000000;
      margin-left: 8px;
      word-wrap: normal;
      white-space: nowrap;
    }
  }
}
</style>
