index.vue 4.9 KB
<template>
  <div class="layout">
    <div class="top flex">
      <div class="report-name text-hide">
        {{ outputData.reportName || '' }}
      </div>
      <template v-if="outputData.reportTimeStart">
        <div
          class="time"
          @click="showDateSelect = true"
        >
          {{ new Date(outputData.reportTimeStart).format('yyyy.MM.dd') }}- {{ new Date(outputData.reportTimeEnd).format('yyyy.MM.dd') }}
          <van-icon name="arrow-down" />
        </div>
      </template>
    </div>
    <template v-if="tabIndex == 0">
      <customer-statistics
        :data="customerData"
        :reportType="reportType"
      />
    </template>
    <template v-else>
      <output-statistics
        :data="outputData"
        :reportType="reportType"
      />
    </template>
    <div class="bottom">
      <tab
        :list="['客户统计', '产值统计']"
        @change="change"
        :index="tabIndex"
      ></tab>
    </div>
    <van-popup
      v-model="showDateSelect"
      position="bottom"
    >
      <van-picker
        show-toolbar
        :title="reportType == 0 ? '选择周报' : '选择月报'"
        :columns="dateColumns"
        :default-index="dateColumns.length"
        @confirm="confirmDate"
        @cancel="showDateSelect = false"
      />
    </van-popup>
  </div>
</template>

<script>
import { reportApi } from '@/api'
export default {
  name: '',
  data() {
    return {
      tabIndex: 1,
      reportType:0, //0 周 1 月
      customerData: {},
      outputData: {},
      detail: {},
      showDateSelect: false,
      dateColumns: []
    }
  },

  mounted() {
    this.initDate()
    this.getOutputReport()
  },
  methods: {
    initDate() {
      let { reportType } = this
      let now = new Date()
      let dateColumns = []
      if (reportType == 0) {
        let dateTime = now.getTime()
        let day = now.getDay() || 7
        let oneDayTime = 24 * 60 * 60 * 1000
        for (let i = 24; i > 0; i--) {
          let monday = new Date(dateTime - (day - 1 + i * 7) * oneDayTime).format('yyyy-MM-dd') // 获取周一
          let sunday = new Date(dateTime + (7 - day - i * 7) * oneDayTime).format('yyyy-MM-dd') // 获取周日
          dateColumns.push(`${monday}~${sunday}`)
        }
        this.dateColumns = dateColumns
      } else {
        let nowMonth = now.getMonth()
        for (let i = nowMonth - 12; i <= nowMonth - 1; i++) {
          dateColumns.push(new Date(new Date().setMonth(i)).format('yyyy-MM'))
        }
        this.dateColumns = dateColumns
      }
    },
    change(e) {
      this.tabIndex = e
    },
    getOutputReport(reportTimeStart = '') {
      let userInfo = this.getLocalStorage('dj_scrm_userInfo')
      let { reportType } = this
      reportApi
        .getReport({
          reportType,
          reportTimeStart
        })
        .then(({ code, data, message }) => {
          this.hideLoading()
          if (code == 0) {
            if (data) {
              if (data.newProductionValueSequential) data.newProductionValueSequential = Number(data.newProductionValueSequential.replace('%', ''))
              if (data.newEquityBillLadingSequential) data.newEquityBillLadingSequential = Number(data.newEquityBillLadingSequential.replace('%', ''))
              if (data.merchantProductionValueReportList) {
                data.merchantProductionValueReportList.map(e => Number((e.newProductionValue = this.centsToyuan(e.newProductionValue))))
              }
              if (data.productionValueReportList) {
                data.productionValueReportList.map(e => Number((e.newProductionValue = this.centsToyuan(e.newProductionValue))))
              }
              if (data.trendList) {
                data.trendList.map(e => Number((e.orderMoneyTotalSum = this.centsToyuan(e.orderMoneyTotalSum))))
              }
              data.userInfo = userInfo
              this.outputData = data
            }
          } else {
            this.refreshPage(`产值统计:${message}`).then(() => {
              this.getOutputReport(reportTimeStart)
            })
          }
        })
    },
    confirmDate(e) {
      let { reportType } = this
      this.showLoading('加载中...')
      if (reportType == 1) {
        this.getOutputReport(`${e}-01`)
        this.showDateSelect = false
      } else {
        let [start] = e.split('~')
        this.getOutputReport(start)
        this.showDateSelect = false
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.layout {
  color: #333333;
  font-size: 14px;
  padding-bottom: 65px;

  .top {
    position: sticky;
    height: 44px;
    padding: 0 16px;
    background: #ffffff;
    box-shadow: 0px 2px 5px 0px rgba(0, 0, 0, 0.05);
    z-index: 9;
    top: 0;
    .report-name{
      width: 50%;
    }
    .time {
      margin-left: auto;
      font-weight: 500;
      font-size: 12px;
    }
  }

  .bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    background: #ffffff;
    z-index: 2;
    width: 100%;
  }
}
</style>