<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-07-03 15:47:15
 -->
<template>
  <div class="my-customer-wrap common-set-wrap">
    <!-- <nav-crumb :navpath="navpath"> </nav-crumb> -->
    <div class="right-content">
      <div class="right-box" style="min-height: calc(100vh - 104px);">
        <div class="apps-content flex" style="min-height: calc(100vh - 104px);">
          <div class="apps-content-right">
            <div class="flex flex-space-between">
              <div class="flex flex-start">
                <div class="font-16 color-303133 w-140 line-h-32">好办使用详情</div>
                <div role="alert" class="el-alert el-alert-tip el-alert--info flex flex-align-start">
                  <i class="el-alert__icon el-icon-info font-12 color-2f54eb"></i>
                  <div class="el-alert__content">
                    <span class="el-alert__title color-606266 font-14">数据更新截至于昨日。今日数据需要隔天上午8点后进行查看。</span>
                  </div>
                </div>
              </div>
              <div class="my-customer-brand">
                <span class="font-14 color-606266 ">切换商户</span
                ><el-select class="p-l-10" v-model="activeBrand" placeholder="请选择" @change="changeSelect">
                  <el-option v-for="item in brandListData" :key="item.enterpriseId" :label="item.enterpriseName" :value="item.enterpriseId"> </el-option>
                </el-select>
              </div>
            </div>
            <div class="data-total-view m-t-20">
              <total-preview :activeBrand="activeBrand" :loginData="loginData"></total-preview>
            </div>
            <div class="chart-body m-t-20">
              <div class="chart-wrap flex flex-space-between">
                <div class="chart-left flex-1">
                  <div class="chart-top flex flex-space-between">
                    <div class="flex">
                      <div :class="['font-14  cursor-pointer', tabActive == 1 ? 'color-303133' : 'color-909399']" @click="changeTab('1')">日访问趋势</div>
                      <div :class="['font-14 day-tend cursor-pointer', tabActive == 2 ? 'color-303133' : 'color-909399']" @click="changeTab('2')">日时段访问趋势</div>
                    </div>
                    <div @click="changeRoute('/loginDetail?brandId=' + activeBrand)" class="cursor-pointer"><span class="font-14 color-909399">查看登录人员明细</span><i class="el-icon-arrow-right el-icon--right font-14 color-909399"></i></div>
                  </div>
                  <div v-if="tabActive == 2" class="date-div m-t-20">
                    <el-date-picker v-model="selectTendDay" :value-format="'yyyy-MM-dd'" type="date" placeholder="选择日期" :picker-options="pickerOptions"> </el-date-picker>
                  </div>
                  <div class="chart-content m-t-20">
                    <day-login-chart :charData="charData" id="day-login-chart"></day-login-chart>
                  </div>
                </div>
                <div class="chart-right flex-1 m-l-10">
                  <div class="chart-top flex flex-space-between">
                    <div class="font-14 color-303133">昨日区域登录统计</div>
                    <div @click="changeRoute('/areaLoginDetail?brandId=' + activeBrand)" class="cursor-pointer"><span class="font-14 color-909399">区域登录明细</span><i class="el-icon-arrow-right el-icon--right font-14 color-909399"></i></div>
                  </div>
                  <div class="chart-content">
                    <area-progress :charData="processData" id="a-chart"></area-progress>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
  </div>
</template>
<script>
import navCrumb from '@/components/nav/nav.vue';
import totalPreview from '@/components/login-data/total-preview.vue';
import dayLoginChart from '@/components/login-data/day-login-chart.vue';
import areaProgress from '@/components/login-data/area-progress.vue';
import { getRequest, postRequest } from '@/api/api';
import errMsg from '@/common/js/error';
// import { _debounce } from '@/common/js/public';
// import showMsg from '@/common/js/showmsg';
export default {
  name: 'activeDetail',
  data() {
    return {
      // 面包屑参数
      navpath: [
        {
          name: '好办使用详情',
          path: '/enterpriseUseData'
        },
        {
          name: '激活人员明细',
          path: ''
        }
      ],
      selectTendDay: '',
      pickerOptions: {
        disabledDate(time) {
          const one = 8 * 24 * 3600 * 1000;
          const seven = Date.now() - one;
          return time.getTime() >= Date.now() - 8.64e7 || time.getTime() < seven;
        }
      },
      brandListData: [],
      activeBrand: '',
      loginData: {},
      tabActive: '1',
      charData: [{ time: '10:10', call: 4, waiting: 2, people: 2 }, { time: '10:15', call: 2, waiting: 6, people: 3 }, { time: '10:20', call: 13, waiting: 2, people: 5 }, { time: '10:25', call: 9, waiting: 9, people: 1 }, { time: '10:30', call: 5, waiting: 2, people: 3 }, { time: '10:35', call: 8, waiting: 2, people: 1 }, { time: '10:40', call: 13, waiting: 1, people: 2 }],
      processData: [
        {
          storeGroupName: '100',
          totalClerkCnt: 100,
          loginClerkCnt: 69,
          loginRate: '69%'
        }
      ]
    };
  },
  computed: {},
  methods: {
    /**
     * 切换tab
     */
    changeTab(val) {
      const that = this;
      that.tabActive = val;
      // 重新获取数据
    },
    /**
     * 选择品牌
     */
    changeSelect(val) {
      const that = this;
      that.brandListData.forEach(ele => {
        if (ele.enterpriseId == val) {
          that.activeBrand = ele.enterpriseId;
        }
      });
    },
    /**
     * 获取品牌
     */
    getBrandData() {
      const that = this;
      postRequest('/haoban-manage3-web/wx-enterprise-list', {})
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result && !!resData.result.length) {
              that.brandListData = resData.result;
              that.activeBrand = that.brandListData[0].enterpriseId;
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 路由跳转
     */
    changeRoute(path) {
      this.$router.push(path);
    },

    /**
     * 分页---页码变化
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },
    /**
     * 获取列表数据
     */
    getTableList(val) {
      const that = this;
      let para = {};
      getRequest('/haoban-manage3-web/wx-enterprise-list', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.tableData = resData.result || [];
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    activeBrand: function(newData, oldData) {
      const that = this;
      that.activeBrand = newData;
    },
    activeGroup: function(newData, oldData) {
      const that = this;
      that.activeGroup = newData;
    }
  },
  mounted() {
    const that = this;
    that.getBrandData();
    that.getTableList();
    document.documentElement.style.backgroundColor = '#f0f2f5';
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {
    navCrumb,
    totalPreview,
    dayLoginChart,
    areaProgress
  }
};
</script>
<style type="text/less" lang="less" scoped>
.span-dot {
  display: inline-block;
  vertical-align: middle;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 3px;
  &.bg-52c41a {
    background: #52c41a;
  }
  &.bg-f5222d {
    background: #f5222d;
  }
}
.bg-82C5FF {
  background: #82c5ff;
}
.color-508CEE {
  color: #508cee;
}
.color-FF585C {
  color: #ff585c;
}
.line-h-18 {
  line-height: 18px;
}
.line-h-32 {
  line-height: 32px;
}
.tooltip-text {
  width: 100%;
  white-space: pre-wrap;
  word-break: break-all;
}
.w-140 {
  width: 140px;
}
.w-293 {
  width: 293px;
}
.w-191 {
  width: 191px;
}
.el-alert--info {
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
  -webkit-box-align: flex-start;
  -webkit-align-items: flex-start;
  -ms-flex-align: flex-start;
  align-items: flex-start;
  .el-alert__icon {
    font-size: 12px;
    padding-top: 3px;
  }
}
.my-customer-wrap {
  height: 100%;
}
.right-content {
  /*width: 100%;*/
  padding: 20px;
  min-height: calc(100% - 160px);
  .right-box {
    background: #fff;
    min-height: 500px;
    padding: 0px;
    .apps-content {
      .apps-content-right {
        width: 100%;
        padding: 20px;
        background: #fff;
        .overstore-body {
          background: #fff;
        }
        .daily-set-wrap {
          height: 100%;
          background: #fff;
        }
        .app-detail-wrap {
          height: 100%;
          background: #fff;
        }
        .common-set-wrap {
          height: 100%;
          background: #fff;
        }
      }
    }
  }
}
.chart-body {
  .chart-wrap {
    .flex-1 {
      width: 655px;
      height: 662px;
      padding: 20px;
      background: rgba(245, 247, 250, 0.71);
      border-radius: 10px;
    }
    .chart-left {
      .day-tend {
        margin-left: 12px;
        padding-left: 12px;
        position: relative;
        &::before {
          content: '';
          position: absolute;
          left: 0;
          top: 2px;
          height: 13px;
          width: 1px;
          background: #dcdfe6;
        }
      }
    }
  }
}
</style>
