<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-07-15 11:13:07
 -->
<template>
  <div class="my-customer-wrap common-set-wrap">
    <div class="right-content">
      <div class="right-box">
        <div class="apps-content flex">
          <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 font-w-bold ">好办使用详情</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>
            <div class="data-total-view m-t-20">
              <total-preview :activeBrand="activeBrand" :loginData="loginData"></total-preview>
            </div>
            <div class="chart-body m-t-32">
              <div class="chart-wrap flex flex-space-between">
                <div class="chart-left flex-1 border-box">
                  <div class="chart-top flex flex-space-between">
                    <div class="flex">
                      <div :class="['font-14 font-w-bold   cursor-pointer', tabActive == 1 ? 'color-303133' : 'color-909399']" @click="changeTab('1')">日访问趋势</div>
                      <div :class="['font-14 font-w-bold  day-tend cursor-pointer', tabActive == 2 ? 'color-303133' : 'color-909399']" @click="changeTab('2')">日时段访问趋势</div>
                    </div>
                    <div @click="changeRoute('/loginDetail?brandId=' + activeBrand)" class="cursor-pointer hover-link"><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="选择日期" :clearable="false" :picker-options="pickerOptions" @change="changeDate"> </el-date-picker>
                  </div>
                  <div class="chart-content m-t-20">
                    <day-login-chart v-if="charData.length" :charData="charData" id="day-login-chart"></day-login-chart>
                    <div v-if="!charData.length" class="no-data-char m-t-90">
                      <img src="../../assets/data/bar.png" alt="" />
                      <p class="font-12 color-c0c4cc m-t-20">- 暂无数据 -</p>
                    </div>
                    <div v-if="charData.length" class="m-t-20">
                      <time-login-chart :charData="charData" id="time-login-chart"></time-login-chart>
                    </div>
                    <div v-if="!charData.length" class="no-data-char m-t-150">
                      <img src="../../assets/data/bar.png" alt="" />
                      <p class="font-12 color-c0c4cc m-t-20">- 暂无数据 -</p>
                    </div>
                  </div>
                </div>
                <div class="chart-right flex-1 m-l-10 border-box">
                  <div class="chart-top flex flex-space-between">
                    <div class="font-14 color-303133 font-w-bold ">昨日区域登录统计</div>
                    <div @click="changeRoute('/areaLoginDetail?brandId=' + activeBrand)" class="cursor-pointer hover-link"><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="processData.length" class="chart-content">
                    <area-progress :charData="processData" id="a-chart"></area-progress>
                  </div>
                  <div v-if="!processData.length" class="no-data-char m-t-180">
                    <img class="w-274" src="../../assets/data/line-colomn.png" alt="" />
                    <p class="font-12 color-c0c4cc m-t-20">- 暂无数据 -</p>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <vue-gic-footer></vue-gic-footer> -->
  </div>
</template>
<script>
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 timeLoginChart from '@/components/login-data/time-login-chart.vue';
import { getRequest } from '@/api/api';
import errMsg from '@/common/js/error';
import dateFormat from '@/filters/index.js';
// import { _debounce } from '@/common/js/public';
// import showMsg from '@/common/js/showmsg';
export default {
  name: 'activeDetail',
  data() {
    return {
      selectTendDay: '',
      selectStartDay: '', // 默认当天之前一天时间
      selectEndDay: '', // 默认当天之前七天时间
      pickerOptions: {
        disabledDate(time) {
          const one = 8 * 24 * 3600 * 1000;
          const seven = Date.now() - one;
          return time.getTime() >= Date.now() - 8.64e7 || time.getTime() < seven;
        }
      },
      activeBrand: '',
      loginData: {
        totalClerkCnt: '0',
        activeClerkCnt: '0',
        loginClerkCnt: '0',
        avgLoginTimes: '0',
        avgVisitTime: '',
        toDayLoginClerkCnt: '0'
      },
      tabActive: '1',
      charData: [], //[{ bizDates: '10:10', call: 4, loginClerkCnt: 2, avgLoginTimes: 1, avgVisitTime: 2 }, { bizDates: '10:15', call: 2, loginClerkCnt: 6, avgLoginTimes: 15, avgVisitTime: 3 }, { bizDates: '10:20', call: 13, loginClerkCnt: 2, avgLoginTimes: 10, avgVisitTime: 5 }, { bizDates: '10:25', call: 9, loginClerkCnt: 9, avgLoginTimes: 6, avgVisitTime: 1 }, { bizDates: '10:30', call: 5, loginClerkCnt: 2, avgLoginTimes: 16, avgVisitTime: 3 }, { bizDates: '10:35', call: 8, loginClerkCnt: 2, avgLoginTimes: 6, avgVisitTime: 1 }, { bizDates: '10:40', call: 13, loginClerkCnt: 1, avgLoginTimes: 19, avgVisitTime: 2 }],
      processData: [
        // {
        //   storeGroupName: '100',
        //   totalClerkCnt: 100,
        //   loginClerkCnt: 69,
        //   loginRate: '69%'
        // }
      ]
    };
  },
  computed: {},
  methods: {
    /**
     * 切换日
     */
    changeDate() {
      const that = this;
      // 重新获取数据
      that.getTendData();
    },
    /**
     * 切换tab
     */
    changeTab(val) {
      const that = this;
      that.tabActive = val;
      // 重新获取数据
      that.getTendData();
    },
    /**
     * 路由跳转
     */
    changeRoute(path) {
      this.$router.push(path);
    },

    /**
     * 获取总览登录数据
     */
    getLoginData(val) {
      const that = this;
      let para = {
        enterpriseId: that.activeBrand,
        startDate: that.selectEndDay,
        endDate: that.selectEndDay
      };
      getRequest('/haoban-manage3-web/web/total-activation-data', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            resData.result.avgVisitTime = parseInt(resData.result.avgVisitTime);
            that.loginData = resData.result || {
              totalClerkCnt: '0',
              activeClerkCnt: '0',
              loginClerkCnt: '0',
              avgLoginTimes: '0',
              avgVisitTime: '',
              toDayLoginClerkCnt: '0'
            };
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取访问趋势数据
     */
    getTendData(val) {
      const that = this;
      let para = {
        enterpriseId: that.activeBrand,
        datesType: that.tabActive,
        startDate: that.tabActive == 1 ? that.selectStartDay : that.selectTendDay, // 前第七日
        endDate: that.tabActive == 1 ? that.selectEndDay : that.selectTendDay // 前一日
      };
      getRequest('/haoban-manage3-web/web/total-login-data', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (resData.result.result) {
              resData.result.result.forEach(ele => {
                ele.bizDates = that.tabActive == 1 ? ele.bizDates.split('-')[1] + '-' + ele.bizDates.split('-')[2] : ele.bizDates;
                ele.avgLoginTimes = parseInt(ele.avgLoginTimes);
                ele.avgVisitTime = parseInt(ele.avgVisitTime);
              });
            }
            that.charData = resData.result.result || [];
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取访问区域数据
     */
    getAreaLoginData(val) {
      const that = this;
      let para = {
        enterpriseId: that.activeBrand,
        startDate: that.selectEndDay, // 区域是同一
        endDate: that.selectEndDay
      };
      getRequest('/haoban-manage3-web/web/area-login-ranking', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (resData.result.result) {
              resData.result.result.forEach(ele => {
                ele.loginRate = Math.round((ele.loginClerkCnt / ele.totalClerkCnt).toFixed(3) * 100) + '%';
              });
            }
            that.processData = resData.result.result || [];
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  mounted() {
    const that = this;
    that.selectStartDay = dateFormat.timeStampToYmd(new Date().getTime() - 7 * 24 * 3600 * 1000);
    that.selectEndDay = dateFormat.timeStampToYmd(new Date().getTime() - 24 * 3600 * 1000);
    that.selectTendDay = dateFormat.timeStampToYmd(new Date().getTime() - 24 * 3600 * 1000);
    this.activeBrand = JSON.parse(sessionStorage.getItem('userInfos')).enterpriseId;
    that.getLoginData();
    that.getTendData();
    that.getAreaLoginData();
  },
  components: {
    totalPreview,
    dayLoginChart,
    areaProgress,
    timeLoginChart
  }
};
</script>
<style type="text/scss" lang="scss" scoped>
.font-w-bold {
  font-weight: bold;
}
.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;
}
.m-t-32 {
  margin-top: 32px;
}
.m-t-90 {
  margin-top: 90px;
}
.m-t-150 {
  margin-top: 150px;
}
.m-t-180 {
  margin-top: 180px;
}
.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;
      min-height: 620px;
      // min-height: calc(100vh - 304px);
      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;
        }
      }
    }
  }
}
.hover-link {
  &:hover {
    span {
      color: #606266;
    }
    i {
      color: #606266;
    }
  }
}
.no-data-char {
  .w-274 {
    width: 274px;
  }
}
</style>
