import * as echarts from '../../ec-canvas/echarts'; const util = require('../../utils/util.js') const app = getApp(); var barec1 = null var barec2 = null Page({ /** * 页面的初始数据 */ data: { ec1: { onInit: function (canvas, width, height,dpr) { barec1 = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); canvas.setChart(barec1); return barec1; } }, ec2: { onInit: function (canvas, width, height,dpr) { barec2 = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr }); canvas.setChart(barec2); return barec2; } }, dateList: [{ id: 1, name: "七天" }, { id: 2, name: "本月" }, { id: 3, name: "今年" }], searchParams: { dateType: '', dateTypeName: '' }, saleXdata:[], saleYdata:[], saleOdata:[], userInfo:{}, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ userInfo: app.globalData.userInfo }) this.getStatis(); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ current: 1 // 根据tab的索引值设置 }) } }, bindDatePickerChange: function (e) { var item = this.data.dateList[e.detail.value] this.setData({ ['searchParams.dateType']: e.detail.value, ['searchParams.dateTypeName']: item.name }) }, bindData() { var option = { color: ["#37A2DA"], grid: { left: '5%', right: '5%', top: '5%', bottom: '5%', containLabel: true }, tooltip: { show: true, trigger: 'axis' }, xAxis: { type: 'category', boundaryGap: false, data: this.data.saleXdata, }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } } }, series: [{ name: '销售总额', type: 'line', smooth: true, data: this.data.saleYdata }] }; var option2 = { color: ["#37A2DA"], grid: { left: '5%', right: '5%', top: '5%', bottom: '5%', containLabel: true }, tooltip: { show: true, trigger: 'axis' }, xAxis: { type: 'category', boundaryGap: false, data: this.data.saleXdata, }, yAxis: { x: 'center', type: 'value', splitLine: { lineStyle: { type: 'dashed' } } }, series: [{ name: '订单数量', type: 'line', smooth: true, data: this.data.saleOdata }] }; console.log(option) console.log(option2) barec1.setOption(option); barec2.setOption(option2); }, toList(){ wx.navigateTo({ url: 'salesTotalList', }) }, getStatis(){ if(!app.globalData.isLogin){ return } let that = this; if(this.data.userInfo.mgvmRole==1){ return; } util.request(util.api.salesOrderApp, null, "GET", false, true,app.globalData.token).then((res)=>{ if (res.code == 200) { let dataList = res.result; let saleXdata = []; let saleYdata = []; let saleOdata = []; dataList.forEach(d => { // d.orderNumber if(this.data.userInfo.mgvmRole==3){ saleYdata.push(d.agentMoney==null?0:d.agentMoney) }else if(this.data.userInfo.mgvmRole==2){ saleYdata.push(d.storeCommission==null?0:d.storeCommission) }else if(this.data.userInfo.mgvmRole==0){ console.log(d.productSellPrice) saleYdata.push(d.productSellPrice==null?0:d.productSellPrice) }else if(this.data.userInfo.mgvmRole==4){ saleYdata.push(d.areaAgentMoney==null?0:d.areaAgentMoney) } let createTime = util.formatDate(d.createTime,'MM')+"-"+util.formatDate(d.createTime,'dd') saleXdata.push( createTime) saleOdata.push(d.orderNumber==null?0:d.orderNumber) }); that.setData({ saleYdata:saleYdata, saleXdata:saleXdata, saleOdata:saleOdata }) setTimeout(this.bindData, 1000); }else{ util.toast(res.message); } }).catch((res) => {}) } })