operatingShow.js 8.59 KB
import { IMG_URL } from '../../../utils/imageBase.js'
// tabOperating/pages/operatingShow/operatingShow.js
import api from '../../api.js'
import { getYQInfo } from '~/store/index'
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    IMG_URL,
    statusBarHeight: app.globalData.statusBarHeight + 43,
    tableHeaderList: [
      {
        name: '日期',
        propName: 'dataDateStr'
      },
      {
        name: '营业额',
        propName: 'orderMoneyTotal'
      },
      {
        name: '工单量',
        // propName: 'toShopTotal'
        // propName: 'totalUpgrade'
        propName: 'upgradeTotal'
      },
      {
        name: '转化率',
        propName: 'upgradeRate'
      }
    ],
    tableList: [],
    // tableList: {
    //   totalOrderMoney: 0,

    //   totalAdd: 0,

    //   totalUpgrade: 0,

    //   totalUpgradeRate: null,
    //   list: []
    // },
    currentPage: 1,
    pageSize: 20,
    pages: 1,
    dateObj: {
      beginDateStr: ''
    },
    showPicker: false
  },
  showStorePicker() {
    let { merchantRange } = this.data
    merchantRange.length > 1 &&
      this.setData({
        showPicker: true
      })
  },
  getStoreList(e) {
    console.log(e)
    let { value } = e.detail
    getYQInfo(this.data.userInfo)
      .then(result => {
        // console.log(result)
        let { merchantRange } = result
        if (value) {
          merchantRange = merchantRange.filter(item => item.merchantName.includes(value))
        }
        this.setData({
          merchantRange
        })
      })
      .catch(err => {})
  },
  navbarReady(e) {
    let navBarHeight = e.detail.height
    this.setData({
      navBarHeight
    })
  },
  jump() {
    // console.log('back')
    // let { refresh } = this.data
    // wx.$router.back()
    wx.$router.back()
    // if (refresh) {
    //   wx.$router.reLaunch('tabOperating.index')
    // } else {
    // }
  },
  changePicker(e) {
    let { value } = e.detail

    let { merchantId } = this.data.merchantRange[value]
    // 修改对应下标显示
    app.globalData.yqdInfo.subIndex = value
    let obj = {}
    if (merchantId) obj.merchantId = merchantId
    wx.$util.showLoading('加载中...')
    api.swtichSubLoginInfo(obj).then(res => {
      // console.log(res)
      let { code, data, message } = res
      wx.hideLoading()

      if (code == 0) {
        wx.$util.setUserInfo(data)
        this.init(data)
        // this.refresh()
        this.initTime()
        this.getAccumulateList()
        this.getAccumulateCount()
      } else {
        this.showToast(message)
      }
    })
    // this.setData({
    //   refresh: true
    // })
    this.tapPicker()
  },
  // 切换园区
  tapPicker() {
    this.setData({
      moveArrow: !this.data.moveArrow
    })
  },
  // 切换日历
  tapCalendar() {
    console.log(this.data.whiteArrow)
    this.setData({
      whiteArrow: !this.data.whiteArrow
    })
  },
  init(userInfo) {
    // app.
    getYQInfo(userInfo)
      .then(result => {
        console.log(result)
        this.setData({
          ...result
        })
      })
      .catch(err => {})
    // return
    // if (!userInfo.isSuper && userInfo.merchantType && userInfo.userType == 2) {
    //   this.setData({
    //     merchantRange: [
    //       {
    //         merchantName: userInfo.merchantName
    //       }
    //     ],
    //     subIndex: 0
    //   })
    //   return
    // }
    // let all = {
    //   merchantName: '全部'
    // }
    // api.getYQList().then(res => {
    //   console.log(res)
    //   let { code, data } = res
    //   if (code == 0) {
    //     let subIndex = 0
    //     let arr = []
    //     if (data.length > 1) {
    //       if (userInfo.merchantId != userInfo.subLoginUser.merchantId) {
    //         data.map((e, index) => {
    //           if (e.merchantId == userInfo.subLoginUser.merchantId) subIndex = index + 1
    //         })
    //       }
    //       arr = [all, ...data]
    //     } else {
    //       arr = [
    //         {
    //           merchantName: userInfo.merchantName
    //         }
    //       ]
    //     }
    //     this.setData({
    //       merchantRange: arr,
    //       subIndex
    //     })
    //   }
    // })
    // this.getAccumulateList()
  },
  // 获取选中天数
  rangeSelect(e) {
    console.log(e.detail)
    // let { date } = e.detail
    // this.setTimeList(date)
    let { date, type } = e.detail
    let { dateObj } = this.data
    // let dateObj
    // let dateObj = {
    //   beginDateStr: date.start,
    //   endDateStr: date.end
    // }
    // dateObj.pointUnit = type ? 2 : 1
    // 按月份
    dateObj = Object.assign(dateObj, date)
    // return
    if (type) {
      let [year, month] = date.end.split('-')
      let day = this.getLastDay(year, month)

      dateObj.beginDateStr = date.start + '-01'
      dateObj.endDateStr = date.end + '-' + day
      dateObj.pointUnit = 2
      dateObj.type = 'month'
      // }
    } else {
      // 按日期
      dateObj.beginDateStr = date.start
      dateObj.endDateStr = date.end
      dateObj.pointUnit = 1
      dateObj.type = 'day'
    }
    this.setData({
      dateObj,
      currentPage: 1
    })
    this.getAccumulateList()
    this.getAccumulateCount()
  },
  getLastDay(year, month) {
    var new_year = year //取当前的年份
    var new_month = month++ //取下一个月的第一天,方便计算(最后一天不固定)
    if (month > 12) {
      new_month -= 12 //月份减
      new_year++ //年份增
    }
    var new_date = new Date(new_year, new_month, 1) //取当年当月中的第一天
    return new Date(new_date.getTime() - 1000 * 60 * 60 * 24).getDate() //获取当月最后一天日期
  },
  initTime() {
    let today = new Date().format('yyyy-MM-dd')
    let NewYearDay = new Date().format('yyyy')
    console.log(NewYearDay)
    this.setData({
      dateObj: {
        beginDateStr: NewYearDay + '-01-01',
        endDateStr: today,
        today: today,
        pointUnit: 1, // 1日,2月,默认日
        type: 'year',
        label: NewYearDay
      }
    })
  },
  scrollonReachBottom() {
    console.log('scrollonReachBottom')
    let { pages, currentPage } = this.data
    // 判断当前页是否是末页
    if (pages == currentPage) return wx.$util.showToast('列表已到底')

    this.setData({
      currentPage: currentPage + 1
    })
    this.getAccumulateList()
  },
  restPageNum() {
    console.log('restPageNum')
    this.setData({
      currentPage: 1
    })
    this.getAccumulateList()
  },
  getAccumulateCount() {
    let {
      dateObj: { beginDateStr, endDateStr }
    } = this.data
    let params = {
      beginDateStr,
      endDateStr
    }
    api
      .accumulateCount(params)
      .then(result => {
        console.log(result)
        let { code, data } = result
        if (code == 0) {
          this.setData({
            tableObj: data
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  getAccumulateList() {
    // console.log('getAccumulateList')
    // wx.$util.showLoading()
    wx.$util.showLoading('加载中...')
    let {
      dateObj: { beginDateStr, endDateStr, pointUnit },
      currentPage,
      pageSize,
      tableList
    } = this.data

    // let params = JSON.parse(JSON.stringify(dateObj))
    let params = {
      beginDateStr,
      endDateStr,
      pointUnit,
      currentPage,
      pageSize
    }
    api
      .accumulatePage(params)
      .then(result => {
        wx.hideLoading()
        console.log(result)
        let { code, data } = result
        if (code == '0') {
          this.setData({
            tableList: currentPage == 1 ? data.list : [...tableList, ...data.list],
            // tableObj:data,
            triggered: false,
            pages: data.pages
          })
        }
      })
      .catch(err => {
        console.log(err)
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initTime()
    this.getAccumulateList()
    this.getAccumulateCount()
    this.setData({
      flag: true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})