| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- // pages/index/index.js
- import * as echarts from '../../ec-canvas/echarts';
- const app = getApp()
- import http from "../../utils/http"
- import util from "../../utils/util"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- chartType: 0,
- menuH: '32px',
- safeTop: `40px`,
- ec: '',
- date: '',
- show: false,
- chartShow: true,
- starttime: '',
- endtime: '',
- info: '',
- xAxis: '',
- price: '',
- count: '',
- series: '',
- start: '',
- end: '',
- minDate: new Date(2023, 0, 1).getTime(),
- maxDate: new Date().getTime(),
- token: wx.getStorageSync('token'),
- config: ''
- },
- order(){
- if (!wx.getStorageSync('token')) {
- util.skip('/service/login/login')
- retturn
- }
- wx.requestSubscribeMessage({
- tmplIds: [app.globalData.templateconfig.shop_order_template,app.globalData.templateconfig.shop_finish_template,app.globalData.templateconfig.shop_sales_template],
- success :(res) =>{
- console.log(res)
- },
- fail :(e) =>{
- console.log(e)
- },
- complete :(res) =>{
- wx.switchTab({
- url: '/pages/order/order'
- })
- }
- })
-
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.setData({
- safeTop: `${app.globalData.safeTop}px`,
- menuH: `${app.globalData.menuH}px`,
- })
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.setData({
- token: wx.getStorageSync('token')
- })
- this.getInfo()
- },
- onLoadConfig(option){
- this.setData({
- config: app.globalData.config
- })
- },
- timeShow() {
- this.setData({
- show: true,
- chartShow: false
- })
- },
- onDisplay() {
- this.setData({
- show: true,
- chartShow: false
- });
- },
- onClose() {
- this.setData({
- show: false,
- chartShow: true
- });
- },
- formatDate(date) {
- date = new Date(date);
- return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
- },
- onConfirm(event) {
- const [start, end] = event.detail;
- let starttime = new Date(start.toLocaleDateString()).getTime();
- let endtime = new Date(end.toLocaleDateString()).getTime();
- this.setData({
- show: false,
-
- starttime: starttime / 1000,
- endtime: endtime / 1000,
- date: `${util.formatTime(starttime,'yyyy/mm/dd')} - ${util.formatTime(endtime,'yyyy/mm/dd')}`,
- });
- this.getInfo()
- },
- //核销
- tosweep() {
- util.authSkip('/service/sweep/sweep')
- },
- // 平台公告
- toNotice() {
- wx.navigateTo({
- url: '/service/notice/notice'
- })
- },
- cutChart(e) {
- this.setData({
- chartType: e.currentTarget.dataset.type,
- chartShow: false,
- })
- if (this.data.chartType == 1) {
- this.setData({
- series: this.data.count,
- chartShow: true,
- ec: {
- onInit: this.initChart
- }
- })
- } else {
- this.setData({
- series: this.data.price,
- chartShow: true,
- ec: {
- onInit: this.initChart
- }
- })
- }
- },
- initChart(canvas, width, height) {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height
- });
- canvas.setChart(chart);
- var option = {
- xAxis: {
- type: 'category',
- data: this.data.xAxis
- },
- tooltip: {
- show: true,
- trigger: 'axis'
- },
- yAxis: {
- type: 'value',
- axisLabel: {
- interval: 0
- }
- },
- grid:{
- left:0,
- right:0,
- top:10,
- bottom:32,
- containLabel:true
- },
- series: [{
- data: this.data.series,
- type: 'line',
- itemStyle: {
- normal: {
- color: '#671CF7',
- lineStyle: {
- color: '#671CF7'
- }
- }
- },
- }]
- };
- chart.setOption(option);
- return chart;
- },
- getInfo() {
-
- if (!wx.getStorageSync('token')) return
- this.setData({
- chartShow: false
- })
- let data = {};
- if (this.data.starttime) {
- data['starttime'] = this.data.starttime
- data['endtime'] = this.data.endtime
- }
- http.post('shop/shophome', data, !this.data.info).then(res => {
- let xAxis = res.data.form.map(value => {
- return value.date
- })
- let price = res.data.form.map(value => {
- return value.price
- })
- let count = res.data.form.map(value => {
- return value.count
- })
- this.setData({
- info: res.data,
- xAxis: xAxis,
- price: price,
- count: count,
- date: `${this.formatDate(res.data.form[0].date)} - ${this.formatDate(res.data.form[res.data.form.length-1].date)}`,
- })
- if (this.data.chartType == 1) {
- this.setData({
- series: this.data.count,
- chartShow: true,
- ec: {
- onInit: this.initChart
- }
- })
- } else {
- this.setData({
- series: this.data.price,
- chartShow: true,
- ec: {
- onInit: this.initChart
- }
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- return {}
- }
- })
|