<template>
  <div class="index-home">
    <div v-loading.fullscreen.lock="loadingFull" />

    <div v-if="roles == 'Super admin' || roles == 'Admin'">
      <div class="index_search">
        <el-form ref="searchParams" :model="searchParams" label-width="80px">
          <el-select
            v-model="searchParams.organization_id"
            filterable
            clearable
            remote
            reserve-keyword
            placeholder="请选择支部"
          >
            <el-option
              v-for="item in treeList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="searchParams.classes"
            clearable
            filterable
            allow-create
            @keydown.native.enter.prevent="keyDownEvent"
            placeholder="请输入班级"
            @change="changeSelect"
            :multiple="true"
            :collapse-tags="true"
          >
            <el-option
              v-for="item in classList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-date-picker
            v-model="searchParams.grade"
            type="year"
            value-format="yyyy"
            placeholder="选择年级"
          >
          </el-date-picker>
          <el-button
            type="primary"
            @click="screenClick"
            style="margin-left:20px;"
            icon="el-icon-search"
            >筛选</el-button
          >
        </el-form>
      </div>
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
            <div class="card-panel-icon-wrapper icon-people">
              <img
                src="@/assets/image/user.png"
                alt=""
                srcset=""
                class="card-img"
              />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                总用户数
              </div>
              <count-to
                :start-val="0"
                :end-val="indexDate.user_nums"
                class="card-panel-num"
              />
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('messages')">
            <div class="card-panel-icon-wrapper icon-message">
              <img
                src="@/assets/image/zhibu.png"
                alt=""
                srcset=""
                class="card-img"
              />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                支部数
              </div>
              <count-to
                :start-val="0"
                :end-val="indexDate.organization_nums"
                :duration="3000"
                class="card-panel-num"
              />
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('purchases')">
            <div class="card-panel-icon-wrapper icon-money">
              <img
                src="@/assets/image/dangyuan.png"
                alt=""
                srcset=""
                class="card-img"
              />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                正式党员数
              </div>
              <count-to
                :start-val="0"
                :end-val="indexDate.dy_nums"
                class="card-panel-num"
              />
            </div>
          </div>
        </el-col>
        <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
          <div class="card-panel" @click="handleSetLineChartData('purchases')">
            <div class="card-panel-icon-wrapper icon-money">
              <img
                src="@/assets/image/guidang.png"
                alt=""
                srcset=""
                class="card-img"
              />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">
                已归档人员数
              </div>
              <count-to
                :start-val="0"
                :end-val="indexDate.graduate_nums"
                class="card-panel-num"
              />
            </div>
          </div>
        </el-col>
      </el-row>
      <el-row :gutter="32">
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <pie-chart :chartDate="indexDate" />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <sex-chart :chartDate="indexDate" />
          </div>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="8">
          <div class="chart-wrapper">
            <huan-chart :chartDate="indexDate" />
          </div>
        </el-col>
      </el-row>
    </div>
    <div v-else>
      <div class="liucheng">
        <div class="liucheng-img">
          <div class="stu-title">中国共产党发展党员流程图</div>
          <img src="@/assets/image/index.jpg" alt="" />
        </div>
        <div class="ad">
          <div class="top-title">通知公告</div>

          <div class="ad-list">
            <el-collapse v-model="activeName" accordion @change="changeAd">
              <el-collapse-item
                v-for="(item, index) in noticeList"
                :key="index"
                :title="item.title"
                :name="index"
              >
                <div>{{ item.start_send_time }}</div>
                <div>{{ item.body }}</div>
              </el-collapse-item>
            </el-collapse>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CountTo from "vue-count-to";
import { statistics } from "@/api/index/index";
import PieChart from "./admin/components/PieChart";
import HuanChart from "./admin/components/HuanChart";
import SexChart from "./admin/components/SexChart";
import RaddarChart from "./admin/components/RaddarChart";
import SwitchRoles from "@/views/permission/components/SwitchRoles";
import store from "@/store";
import { fatherLists, classLists } from "@/api/organizationList/index";
import { processFlow } from "@/api/process/index";
import { messagesList } from "@/api/reminder/index";
export default {
  components: {
    CountTo,
    PieChart,
    RaddarChart,
    HuanChart,
    SexChart
  },
  data() {
    return {
      roles: store.getters.roles[0],
      indexDate: "",
      girlPercent: 0,
      boyPercent: 0,
      loadingFull: false,
      noticeList: [],
      searchParams: {
        classes: [],
        organization_id: "",
        grade: "",
        with_graduate: 1
      },
      selected: [],
      classList: "",
      treeList: [
        {
          pid: 0,
          id: 0,
          name: "未选择"
        }
      ] //支部列表
    };
  },
  created() {
    this.messagesList();
    this.statistics();
    //获取班级列表
    classLists().then(res => {
      this.classList = res;
    });
    fatherLists().then(res => {
      console.log(res, "llllll");
      this.treeList = res.data;
    });
  },
  methods: {
    changeZb(e) {},
    //筛选
    screenClick() {
      this.statistics();
    },
    async statistics() {
      this.loadingFull = true;
      console.log(this.select, "__________________");

      await statistics(this.searchParams).then(res => {
        this.indexDate = res.data;
        console.log(this.boyPercent);
        this.loadingFull = false;
      });
    },
    changeSelect(select) {
      console.log(select, "xuanzhongdezhi ");
      let arr = [];
      select.map(item => {
        arr.push(item);
      });
      console.log(arr, "++++++++++++++");
      this.searchParams.classes = arr;
    },
    async messagesList() {
      this.loadingFull = true;
      await messagesList().then(res => {
        this.noticeList = res.data.data;
        this.loadingFull = false;
      });
    },
    changeAd(e) {
      console.log(e, "ceshi----------");
    },
    handleSetLineChartData(type) {
      this.$emit("handleSetLineChartData", type);
    }
  }
};
</script>

<style lang="scss" scoped>
.index-home {
  .stu-title {
    height: 100px;
    line-height: 100px;
    text-align: center;
    font-size: 40px;
    font-weight: bold;
    color: #bc1d16;
  }
  .index_search {
    margin-top: 30px;
    .el-select {
      margin-right: 20px;
      min-width: 300px;
    }
  }
  .panel-group {
    margin-top: 18px;

    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
      border-color: rgba(0, 0, 0, 0.05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #ffffff;
        }
      }
      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }
      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }

  @media (max-width: 550px) {
    .card-panel-description {
      display: none;
    }

    .card-panel-icon-wrapper {
      float: none !important;
      width: 100%;
      height: 100%;
      margin: 0 !important;

      .svg-icon {
        display: block;
        margin: 14px auto !important;
        float: none !important;
      }
    }
  }
  .dashboard-editor-container {
    padding: 32px;
    background-color: rgb(240, 242, 245);
    position: relative;

    .github-corner {
      position: absolute;
      top: 0px;
      border: 0;
      right: 0;
    }
  }
  .chart-wrapper {
    background: #ffffff;
    padding-top: 20px;
    padding: 20px;
    margin-bottom: 32px;
    box-shadow: 4px 4px 40px rgb(0 0 0 / 5%);
    .list {
      display: flex;
    }

    .left {
      flex: 1;
      width: 10%;
      position: relative;
      background-color: olive;
      .icon {
        height: 100px;
        margin: 48px;
      }
      .sex-nums {
        flex: 1;
        text-align: center;
        line-height: 210px;
        color: #fff;
        font-weight: bold;
        font-size: 18px;
      }
    }

    .right {
      flex: 1;
      margin-top: 90px;
      margin-right: 30px;
    }

    .el-progress-circle {
      height: 90px;
      width: 90px;
    }
  }
  .wrapper {
    display: flex;
  }
  .el-progress-bar__outer {
    height: 32px !important;
  }
  .card-img {
    height: 50px;
  }
  .ellipsis {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    word-wrap: break-word;
  }

  .child {
    line-height: 40px;
    height: 40px;
  }

  .liucheng {
    display: flex;
    .liucheng-img {
      flex: 0 0 80%;
      margin-right: 20px;
      text-align: center;
      .stu-title {
        height: 100px;
        line-height: 100px;
        text-align: center;
        font-size: 40px;
        font-weight: bold;
        color: #bc1d16;
      }
      img {
        margin: 0 auto;
        width: 50%;
        height: auto;
      }
    }
    .ad {
      margin-top: 20px;
      margin-right: 20px;
      font-size: 16px;
      padding: 20px;
      box-shadow: 4px 4px 40px rgb(0 0 0 / 15%);
      line-height: 30px;
      border-radius: 10px;
      flex: 1;
      .top-title {
        border-left: solid 5px #bc1d16;
        height: 30px;
        line-height: 30px;
        padding-left: 10px;
      }
      .el-collapse-item {
        padding-left: 15px;
      }
      .el-collapse-item__header {
        font-size: 14px !important;
      }
      .ad-list {
        margin-top: 10px;

        .ad-title {
          flex: 30%;
        }
        .ad-time {
          flex: 1;
          text-align: right;
          margin-top: 10px;
          font-size: 14px;
          color: #666;
        }
      }
    }
  }
}
</style>
