index.vue 4.76 KB
<template>
  <div class="layout-wrap">
    <div class="head-bg"></div>
    <time-search ref="timeSearch" class="timeSearch"></time-search>
    <div class="content">
      <statistics></statistics>
      <ranking ref="ranking"></ranking>
      <!-- 门店周报客户和产值单独提取出来 -->
      <template v-if="reportType == 0 && userInfo.accountLevel == 4">
        <stores-ranking></stores-ranking>
      </template>
      <template v-else>
        <canvas-tab ref="canvasTab" @change="canvasChange">
          <tab-container ref="tabContainer" :tabIndex="tabIndex"></tab-container>
        </canvas-tab>
      </template>
    </div>
    <div class="bottom">
      <tab :list="['客户统计', '产值统计']" @change="change" :index="tabIndex"></tab>
    </div>
  </div>
</template>
<script>
import { mapState, mapActions, mapMutations } from 'vuex'
import { util } from '../../utils'
export default {
  name: 'report',
  data() {
    return {
      accountLevel: '', //集团 门店(4)
      fastData: [],
      detail: {},
      reportTimeStart: '2021.10.23',
      reportTimeEnd: '2021.10.23'
    }
  },
  computed: {
    ...mapState({
      reportData: state => state.report.reportData,
      tabIndex: state => state.report.tabIndex,
      reportType: state => state.report.reportType,
      tabType: state => state.report.tabType,
      userInfo: state => state.report.userInfo,
      outputData: state => state.report.outputData,
      userInfo: state => state.report.userInfo
    })
  },
  mounted() {
    this.getData()
  },
  created() {
    let reportType = this.getQuery().reportType ? this.getQuery().reportType : JSON.parse(window.localStorage.getItem('reportType')).reportType
    //   let reportType =1
    if (reportType == 0) {
      document.title = '周报'
    } else {
      document.title = '月报'
    }
    this.SET_REPORT_TYPE({
      reportType: reportType
    })
  },
  methods: {
    ...mapActions({
      getReport: 'report/getReport',
      getCumerchantReport: 'report/getCumerchantReport',
      getCugroupReport: 'report/getCugroupReport',
      navigation: 'navigation'
    }),
    ...mapMutations({
      SET_TAB_INDEX: 'report/SET_TAB_INDEX',
      SET_TABTYPE_INDEX: 'report/SET_TABTYPE_INDEX',
      INIT_DATA: 'report/INIT_DATA',
      SET_UESR_INFI: 'report/SET_UESR_INFI', //切换集团门店
      SET_REPORT_TYPE: 'report/SET_REPORT_TYPE' //获取周报月报
    }),
    canvasChange(index) {
      this.SET_TABTYPE_INDEX({ index: index })
    },
    //重新登录
    reLogin() {
      /**登录过期 重新登录 */
      util.clearSessionId()
      this.navigation()
    },
    //底部tab
    change(index) {
      this.SET_TAB_INDEX({ tabIndex: index })
      this.SET_TABTYPE_INDEX({ index: 0 })
      this.$refs.timeSearch.showDateSelect = false
      // this.$refs.timeSearch.initDate() //切换时间重置不需要
      this.toTop()
      this.getData()
    },
    getData() {
      this.INIT_DATA()
      this.showLoading()
      if (this.tabIndex == 1) {
        this.getReport({
          reportType: this.reportType,
          reportTimeStart: this.outputData.reportTimeStart,
          success: res => {
            this.hideLoading()
            this.$refs.ranking.initFastData()
          },
          fail: () => {
            this.hideLoading()
            this.reLogin()
          }
        })
      } else if (this.tabIndex == 0 && this.userInfo.accountLevel == 4) {
        /**获取当前门店周报月报客户统计 */
        this.getCumerchantReport({
          startDate: this.outputData.reportTimeStart,
          reportType: this.reportType,
          success: res => {
            this.hideLoading()
            // this.INIT_DATA()
            this.$refs.ranking.initFastData()
          },
          fail: () => {
            this.hideLoading()
            this.reLogin()
          }
        })
      } else {
        /**获取当前集团周报月报客户统计 */
        this.getCugroupReport({
          startDate: this.outputData.reportTimeStart,
          reportType: this.reportType,
          success: res => {
            this.hideLoading()
            this.$refs.ranking.initFastData()
          },
          fail: () => {
            this.reLogin()
            this.hideLoading()
          }
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.layout-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  color: #333333;
  font-size: 14px;
  box-sizing: border-box;
  overflow: scroll;
  .timeSearch {
    position: absolute;
    top: 0;
    left: 15px;
    right: 15px;
    z-index: 100;
  }
  .content {
    position: absolute;
    top: 67px;
    left: 15px;
    right: 15px;
    z-index: 9;
  }
}
.bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  background: #ffffff;
  z-index: 90;
  width: 100%;
  right: 0;
}
</style>