<template>
  <div class="main-data data-official">
    <div class="left">
      <div class="left-cont" v-if="leftShow">
        <div
          class="left-top"
          @click="showDialog(1)"
          @mouseover="showDialog(1)"
        >
          <div class="cont-title-area">
            <img
              class="cont-title-bg"
              src="@/assets/images/main/cont_title_bg.png"
              alt=""
            />
            <div class="cont-title">各单位终端数据</div>
          </div>
          <div class="components-item bg2">
            <terminal-data :key="appOrg"></terminal-data>
          </div>
        </div>
        <div class="left-bottom">
          <div class="cont-title-area">
            <img
              class="cont-title-bg"
              src="@/assets/images/main/cont_title_bg.png"
              alt=""
            />
            <div class="cont-title">公务用车资源情况</div>
          </div>
          <div class="components-item">
            <car-stock :key="appOrg"></car-stock>
          </div>
        </div>
      </div>
    </div>
    <div class="middle">
      <province v-if="showMap" ref="province" @mapClick="onMapClick"></province>
      <img
        v-if="showLocal"
        class="build"
        src="@/assets/images/build.png"
        alt=""
      />
      <!-- 返回按钮 -->
      <div class="bottom-area flex-row align-items-center space-between">
        <div class="bottom-left flex-row align-items-center">
          <div class="left-item">
            <el-cascader
              v-model="curCompany"
              :options="company"
              @change="handleCompanyChange"
              placeholder="单位"
              :show-all-levels="false"
            >
              <template slot-scope="{ node, data }">
                <div style="display: flex; align-items: center">
                  <img
                    v-if="data.label == '山西省公司(本部)'"
                    src="../../../assets/images/main/tiaozhuanlouyu.png"
                    style="width: 15px; margin-right: 10px"
                  />
                  <span
                    v-else-if="data.value == '1A001' || data.value == '1A002' || data.value == '1A004' || data.value == '1A005'"
                    style="
                      display: inline-block;
                      width: 10px;
                      height: 10px;
                      border-radius: 50%;
                      margin-right: 10px;
                      background: rgb(255, 180, 74);
                    "
                  ></span>
                  <span
                    v-else-if="data.value.length == 5 && data.value != '10001'"
                    style="
                      display: inline-block;
                      width: 10px;
                      height: 10px;
                      border-radius: 50%;
                      margin-right: 10px;
                      background: rgb(74, 194, 29);
                    "
                  ></span>
                  <span
                    v-else-if="data.value.length == 7"
                    style="
                      display: inline-block;
                      width: 10px;
                      height: 10px;
                      border-radius: 50%;
                      margin-right: 10px;
                      background: rgb(99, 235, 255);
                    "
                  ></span>
                  <span>{{ data.label }}</span>
                </div>
                <!-- <div
                    v-if="data.level == 2"
                    style="width: 1.5vh;height: 1.5vh;background-color: red;border-radius: 60%;margin-top:10px;margin-left:10px;float:right"
                  ></div> -->
              </template>
            </el-cascader>
          </div>
          <div class="office" disabled>办公区</div>
        </div>
        <div class="bottom-right">
          <img
            v-if="showBack"
            @click="onBack"
            src="@/assets/images/main/back.png"
            class="back"
          />
        </div>
      </div>
    </div>
    <div class="right">
      <div class="right-cont" v-if="rightShow">
        <div
          class="right-top"
        >
          <div class="cont-title-area">
            <img
              class="cont-title-bg"
              src="@/assets/images/main/cont_title_bg.png"
              alt=""
            />
            <div class="cont-title">监控管理</div>
          </div>
          <div class="components-item">
            <car-warning :key="appOrg"></car-warning>
          </div>
        </div>
        <div class="right-bottom" @mouseover="showDialog(4)">
          <div class="cont-title-area">
            <img
              class="cont-title-bg"
              src="@/assets/images/main/cont_title_bg.png"
              alt=""
            />
            <div class="cont-title">成本管理</div>
          </div>
          <div class="components-item bg2">
            <car-terminal :key="appOrg"></car-terminal>
          </div>
        </div>
      </div>
    </div>
    <!--弹出层-->
    <div
      :class="dialogType < 3 ? 'dialog' : 'dialog-r'"
      v-if="dialogShow"
      @click="closeDialog"
    >
      <terminal-data-dialog
        v-if="dialogType === 1"
        @closeDialog="closeDialog"
      ></terminal-data-dialog>
      <car-warning-dialog
        v-if="dialogType === 4"
        @choose="chooseCost"
        @closeDialog="closeDialog"
      ></car-warning-dialog>
    </div>

    <div v-if="showC" class="dialog-2">
      <div class="dialog-center">
        <resource-list
          v-if="showRes === 1"
          @close="onCloseRes"
          @choose="onChooseRes"
        ></resource-list>
        <car-cost
          v-if="showCost === 1"
          @close="onCloseCost"
        ></car-cost>
      </div>
    </div>
  </div>
</template>

<script>
import ResourceList from '@/views/screen/official/resourceList.vue'
import Province from "../map/province.vue";
import TerminalData from "./terminalData.vue";
import TerminalDataDialog from "./terminalDataDialog.vue";
import TerminalOnline from "./terminalOnline.vue";
import CarWarning from "./carWarning.vue";
import CarWarningDialog from "./carWarningDialog.vue";
import CarStock from "../logistics/car/carStock.vue";
import CarTerminal from "../logistics/car/carTerminal.vue";
import company from "@/views/screen/data/company.json";
import CarCost from '@/views/screen/official/carCost.vue'

export default {
  name: "OfficialMain",
  components: {
    CarCost,
    ResourceList,
    Province,
    TerminalData,
    TerminalOnline,
    CarWarning,
    CarStock,
    CarTerminal,
    TerminalDataDialog,
    CarWarningDialog,
  },
  // props: {
  //   appOrg: {
  //     type: String,
  //     default: "0000",
  //   },
  // },
  watch:{
    appOrg(newValue,oldValue){
      this.resetData();
    },
  },
  data() {
    return {
      showC:false,
      showRes:0,
      showCost:0,
      leftShow: true,
      rightShow: true,
      dialogShow: false,
      dialogType: 1,
      curDeep: 1,
      showBack: false,
      showMap: true,
      showLocal: false,
      appOrg: "0000",
      curCompany: [],
      company: company,
    };
  },
  created() {},
  destroyed() {},
  beforeDestroy() {},
  mounted() {},
  methods: {
    chooseCost(){
      this.closeDialog()
      this.showC = true
      this.showCost = 1
    },
    onCloseCost(){
      this.showC = false
      this.showCost = 0
    },

    showDialog(type) {
      if (type < 4) {
        this.leftShow = false;
        this.rightShow = true;
      } else {
        this.rightShow = false;
        this.leftShow = true;
      }
      this.dialogShow = true;
      this.dialogType = type;
    },
    closeDialog() {
      this.leftShow = true;
      this.rightShow = true;
      this.dialogShow = false;
    },
    //点击地图事件
    onMapClick(e) {
      this.curDeep = e.deep;
      if (e.deep > 1) {
        this.showBack = true;
      } else {
        this.showBack = false;
      }
      //点击山西省本部
      if (e.name == "山西省公司(本部)") {
        this.showMap = false;
        this.showLocal = true;
        this.curCompany = ["10001", "10001"];
        this.appOrg = "10001";
      } else {
        this.showMap = true;
        this.showLocal = false;
        this.curCompany = e.curCompany;
      }
      //判断是否点击了子单位
      if (e.curCompany && e.curCompany.length > 0) {
        let appOrg = e.curCompany[e.curCompany.length - 1];
        this.appOrg = appOrg;
      }
    },

    //返回操作
    onBack() {
      this.curDeep = 1;
      if (this.curDeep <= 1) {
        this.showBack = false;
        this.showMap = true;
        this.showLocal = false;
        this.curCompany = [];
      }
      this.appOrg = "0000";
      this.$refs.province.reloadMap(this.curDeep);
    },

    //选择公司
    handleCompanyChange(e) {
      console.log(e);
      if (e && e.length > 0) {
        if (e[1] == "10001") {
          this.showMap = false;
          this.showLocal = true;
          this.showBack = true;
        } else {
          this.showMap = true;
          this.showLocal = false;
        }
        let appOrg = e[e.length - 1];
        this.appOrg = appOrg;
      }
      if(e[1] == "1A001" || e[1] == "1A002" || e[1] == "1A004" || e[1] == "1A005"){
        this.showMap = true;
        this.showLocal = false;
        this.showBack = true;
        // return;
      }
      this.$refs.province.chooseUnit(e);
    },
  },
};
</script>

<style lang="scss">
.data-official {
  width: 100%;
  height: 100%;
  margin: 0 auto;
  // background-image: url("../../../assets/images/official_car/bg.jpg");
  // background-size: cover;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  .left {
    margin: 125px 0 0 40px;
    width: 580px;
    .left-cont {
      width: 100%;
      height: 920px;
      padding-top: 19px;
      background: url("../../../assets/images/main/main_bg.png") no-repeat;
      background-size: cover;
    }
    .components-item {
      width: 550px;
      height: 389px;
      background: url("../../../assets/images/main/components_mid_bg.png")
        no-repeat;
      background-size: cover;
      margin-bottom: 28px;
      margin-left: 15px;
      overflow: hidden;
    }
    .components-item.bg2 {
      background: url("../../../assets/images/main/components_mid_bg2.png")
        no-repeat;
      background-size: cover;
    }
    .left-top {
      // width: 550px;
      // height: 444px;
      // background: url("../../../assets/images/service_new/left_top_2.png")
      //   no-repeat;
      // background-size: cover;
      // margin-bottom: 21px;
    }
    .left-bottom {
      // width: 550px;
      // height: 444px;
      // background: url("../../../assets/images/service_new/left_top_2.png")
      //   no-repeat;
      // background-size: cover;
    }
  }
  .middle {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    padding: 125px 0 0 0px;
    position: relative;
    .bottom-area {
      position: absolute;
      right: 50px;
      left: 50px;
      bottom: 50px;

      .bottom-left {
        .left-item {
          width: 180px;
          height: 30px;
          background: url("../../../assets/images/main/choose_bg_long.png")
            no-repeat;
          background-size: cover;
          input {
            background: rgba(255, 255, 255, 0);
            border: none;
            color: #00ffff;
          }
          .el-input__icon {
            color: #00ffff;
          }
        }
        .office {
          margin-left: 10px;
          width: 180px;
          height: 30px;
          line-height: 30px;
          padding-left: 15px;
          color: #898989;
          background: url("../../../assets/images/main/choose_bg_long.png")
            no-repeat;
          background-size: cover;
          font-size: 14px;
        }
      }

      .bottom-right {
        .back {
          width: 34px;
          height: 30px;
          cursor: pointer;
        }
      }
    }
  }
  .right {
    margin: 125px 40px 0 0px;
    width: 580px;
    .right-cont {
      width: 100%;
      height: 920px;
      padding-top: 19px;
      background: url("../../../assets/images/main/main_bg.png") no-repeat;
      background-size: cover;
    }
    .components-item {
      width: 550px;
      height: 389px;
      background: url("../../../assets/images/main/components_mid_bg.png")
        no-repeat;
      background-size: cover;
      margin-bottom: 28px;
      margin-left: 15px;
      overflow: hidden;
    }
    .components-item.bg2 {
      background: url("../../../assets/images/main/components_mid_bg2.png")
        no-repeat;
      background-size: cover;
    }
    .right-top {
      // width: 550px;
      // height: 444px;
      // background: url("../../../assets/images/service_new/left_top_2.png")
      //   no-repeat;
      // background-size: cover;
      // margin-bottom: 21px;
    }
    .right-bottom {
      // width: 550px;
      // height: 444px;
      // background: url("../../../assets/images/service_new/left_top_2.png")
      //   no-repeat;
      // background-size: cover;
    }
  }

  .cont-title-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 10px;
    img {
      width: 284px;
      height: 32px;
    }
    .cont-title {
      font-size: 20px;
      font-weight: 900;
      font-family: "PingFangSC";
      width: 100%;
      position: absolute;
      display: flex;
      align-items: center;
      justify-content: center;
      top: -5px;
      color: #fff;
    }
  }

  .dialog {
    position: fixed;
    top: 125px;
    left: 40px;
    z-index: 10;
    width: 100%;
  }
  .dialog-r {
    position: fixed;
    top: 125px;
    right: 40px;
    z-index: 10;
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }

  .build {
    margin: 0 auto;
    width: 90%;
    height: auto;
    object-fit: contain;
  }

  ::-webkit-scrollbar {
    width: 3px;
    height: 3px;
  }

  ::-webkit-scrollbar-thumb {
    //滑块部分
    // border-radius: 5px;
    background-color: #58cbbb;
  }

  ::-webkit-scrollbar-track {
    //轨道部分
    // box-shadow: inset 0 0 5px #ddd;
    background: #ddd;
    // border-radius: 5px;
  }
}
</style>

