import _ from '../../commons/js/commons' import * as echarts from '../../ecCanvas/components/ec-canvas/echarts'; const app = getApp() let barChartData; let lineChartData; function barChart(canvas, width, height, dpr) { const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr // new }); canvas.setChart(chart); let option = barChartData chart.setOption(option); return chart; } function lineChart(canvas, width, height, dpr) { const chart = echarts.init(canvas, null, { width: width, height: height, devicePixelRatio: dpr // new }); canvas.setChart(chart); let option = lineChartData chart.setOption(option); return chart; } Page({ data: { imgUrl:_.config.imgUrl, shoplist:[],//管理门店 showBarChart:false,//是否显示Bar图表 ecBar:{}, showLineChart:false,//是否显示Line图表 ecLine:{}, deallist:'', hoursTip:'', isShowProfile:true,//是否显示授权用户信息按钮 }, onLoad(options) { for (let key in options) { this.setData({ [key]: options[key] }) } this.getUserInfo() this.getAppCity() this.getAppArea() //20240526新增 //消息通讯 是否显示授权用户信息按钮 _.eventBus.on("isShowProfile", this, function(res){ this.setData({ isShowProfile:res, }) }) }, onShow: function () { this.getHoursTip() this.getAppTransferRemind() }, //生命周期函数--监听页面卸载 onUnload: function () { //卸载消息通讯 是否显示授权用户信息 _.eventBus.remove('isShowProfile',this); }, //候取时间 getHoursTip(){ let hoursTip = ''; let date=new Date();   if(date.getHours()>=0&&date.getHours()<12){   hoursTip="上午好!"   }else if(date.getHours()>=12&&date.getHours()<18){   hoursTip="下午好!"   }else{   hoursTip="晚上好!"   } this.setData({ hoursTip:hoursTip }) }, //获取用户信息 getUserInfo(){ _.apiQuery.getUserInfo().then(res => { this.setData({ userInfo: res }) }); }, //调拨提醒 getAppTransferRemind(){ _.apiQuery.getAppTransferRemind().then(res => { this.setData({ allotNum: res.data.total, }) if(res.data.total>0){ this.setData({ isShowReport:true, }) }else{ this.setData({ isShowReport:false, }) } }); }, //获取系统配置城市 getAppCity(){ _.apiQuery.getAppCity().then(res => { let cityArray = [] res.data.list.forEach((item,index) => { cityArray.push(item.name) if(item.city_id==res.data.default){ this.setData({ cityIndex:index, }) } }) this.setData({ city_id:res.data.default, cityArray:cityArray, cityList:res.data.list, }) this.getAppUserBizs() }); }, //20240526 获取系统配置城市省市 getAppArea(){ let area_list = [{ "name": "福建省", "id": 1, "propvince_id": "35", "children": [{ "id":"19","city_id":"350900","name":"宁德市"}, {"id":"18","city_id":"350700","name":"南平市"}] },{ "name": "湖南省", "id": 1, "propvince_id": "36", "children": [{ "city_id": "120900", "id": "20", "name": "长沙市", },{ "city_id": "120000", "id": "21", "name": "湘潭市", }] }] let area_id = [35,350900] let areaArr = [] // let cur_index = [] area_list.forEach((item,index) => { if(item.propvince_id==area_id[0]){ item.children.forEach((it,idx)=>{ if(it.city_id==area_id[1]){ // cur_index = [item.propvince_id,it.city_id] this.setData({ areaIndex: [index,idx] }) areaArr = [area_list,area_list[index].children] return; } }) } }); this.setData({ area_id: area_id, area_list: area_list, areaArr: areaArr // cityList: res.data.list, }) }, //获取管理门店 getAppUserBizs(){ let params = {}; params['city_id'] = this.data.city_id; _.apiQuery.getAppUserBizs(params).then(res => { this.setData({ shoplist: res.data.list, }) }); }, //选择城市 changeCity(e) { this.setData({ city_id:this.data.cityList[e.detail.value].city_id, cityIndex: e.detail.value }) this.getAppUserBizs() // this.getAppStatisticsCust() // this.getAppStatisticsOrders() }, //20240526选择地区 changeArea(e){ this.setData({ areaIndex: e.detail.value, }) }, //20240526地区联动 columnChangeArea(e){ let multiData = this.data.area_list; let multiIndex = this.data.areaIndex; let columnIndex = e.detail.column; let columnValue = e.detail.value; multiIndex[columnIndex] = columnValue; console.log(e) console.log(multiIndex) console.log(multiData) this.setData({ areaArr: [ multiData, multiData[multiIndex[0]].children ], }) }, //客户选择季度 changeCust(e) { this.setData({ custSeasonKey: e.detail.value }) this.getAppStatisticsCust() }, //订单选择季度 changeOrder(e) { this.setData({ orderSeasonKey: e.detail.value }) this.getAppStatisticsOrders() }, //获取渠道客户统计 getAppStatisticsCust(){ this.setData({ showBarChart:false, }) let params = {}; params['city_id'] = this.data.city_id; if(this.data.custSeasonKey){ params['season'] = this.data.custSeasonKey; } _.apiQuery.getAppStatisticsCust(params).then(res => { //barChartData = getBarOption() barChartData = res.data.stat_data let custLine = Math.ceil(barChartData.series.length/3) // barChartData.series.forEach(item => { // item.barMaxWidth = 30 // }) barChartData.tooltip.position=['10', '10'] barChartData.grid.top = '5' barChartData.grid.bottom = 23*(custLine+1) this.setData({ barheight:100 + 150*(custLine+1), custLine:custLine, custSeasonKey:this.data.custSeasonKey?this.data.custSeasonKey:res.data.season, custSeason:this.data.custSeason?this.data.custSeason:res.data.season_data, showBarChart:true, ['ecBar.onInit']:barChart, }) wx.stopPullDownRefresh() }) }, //获取渠道订单统计 getAppStatisticsOrders(){ this.setData({ showLineChart:false, }) let params = {}; params['city_id'] = this.data.city_id; if(this.data.orderSeasonKey){ params['season'] = this.data.orderSeasonKey; } _.apiQuery.getAppStatisticsOrders(params).then(res => { //lineChartData = getLineOption() lineChartData = res.data.stat_data let orderLine = Math.ceil(lineChartData.series.length/3) lineChartData.grid.top = '5' lineChartData.grid.bottom = 23*(orderLine+1) lineChartData.tooltip.position=['10', '10'] this.setData({ lineheight:100 + 150*(orderLine+1), orderLine:orderLine, orderSeasonKey:this.data.orderSeasonKey?this.data.orderSeasonKey:res.data.season, orderSeason:this.data.orderSeason?this.data.orderSeason:res.data.season_data, showLineChart:true, ['ecLine.onInit']:lineChart, }) wx.stopPullDownRefresh() }) }, //显示短信弹框 optShowReport(e){ this.setData({ isShowReport:!this.data.isShowReport, }) }, //推送链接 pushLink(e) { if(e.currentTarget.dataset.url){ _.$router.openUrlScheme(e.currentTarget.dataset.url) } }, //客服电话 call(e) { wx.makePhoneCall({ phoneNumber: '18965133055', }) }, //页面相关事件处理函数--监听用户下拉动作 onPullDownRefresh: function () { this.getAppUserBizs() // this.getAppStatisticsCust() // this.getAppStatisticsOrders() this.getAppTransferRemind() }, }) function getBarOption() { return { tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' }, position: ['10', '10'] }, legend: { top: 'bottom', data: [ '丰泽店1', '鲤城区2', '南安店3','丰泽店4', '鲤城区5', '南安店6','丰泽店7', '鲤城区8', '丰泽店9', '鲤城区10', '丰泽店11', '鲤城区12', '南安店13','丰泽店14', '鲤城区15', '南安店16','丰泽店17', '鲤城区18', '丰泽店19', '鲤城区20', '丰泽店21', '鲤城区22', '南安店23','丰泽店24', '鲤城区25', '南安店26','丰泽店27', '鲤城区28', '丰泽店29', '鲤城区30', '丰泽店31', '鲤城区32', '南安店33','丰泽店34', '鲤城区35', '南安店36','丰泽店37', '鲤城区38', '丰泽店39', '鲤城区40', '丰泽店41', '鲤城区42', '南安店43','丰泽店44', '鲤城区45', '南安店46','丰泽店47', '鲤城区48', '丰泽店49', '鲤城区50', ] }, grid: { top: '8%', left: '2%', right: '5%', bottom: '12%', containLabel: true }, xAxis: { type: 'value', boundaryGap: [0, 0.01] }, yAxis: { type: 'category', data: ['1月', ] }, series: [ { name: '丰泽店1', type: 'bar', data: [18, ], }, { name: '鲤城区2', type: 'bar', data: [19, ], }, { name: '南安店3', type: 'bar', data: [19, ], }, { name: '丰泽店4', type: 'bar', data: [18, ], }, { name: '鲤城区5', type: 'bar', data: [19, ], }, { name: '南安店6', type: 'bar', data: [19, ], }, { name: '丰泽店7', type: 'bar', data: [18, ], }, { name: '鲤城区8', type: 'bar', data: [19, ], }, { name: '丰泽店9', type: 'bar', data: [18, ], }, { name: '鲤城区10', type: 'bar', data: [19, ], }, { name: '丰泽店11', type: 'bar', data: [18, ], }, { name: '鲤城区12', type: 'bar', data: [19, ], }, { name: '南安店13', type: 'bar', data: [19, ], }, { name: '丰泽店14', type: 'bar', data: [18, ], }, { name: '鲤城区15', type: 'bar', data: [19, ], }, { name: '南安店16', type: 'bar', data: [19, ], }, { name: '丰泽店17', type: 'bar', data: [18, ], }, { name: '鲤城区18', type: 'bar', data: [19, ], }, { name: '丰泽店19', type: 'bar', data: [18, ], }, { name: '鲤城区20', type: 'bar', data: [19, ], }, { name: '丰泽店21', type: 'bar', data: [18, ], }, { name: '鲤城区22', type: 'bar', data: [19, ], }, { name: '南安店23', type: 'bar', data: [19, ], }, { name: '丰泽店24', type: 'bar', data: [18, ], }, { name: '鲤城区25', type: 'bar', data: [19, ], }, { name: '南安店26', type: 'bar', data: [19, ], }, { name: '丰泽店27', type: 'bar', data: [18, ], }, { name: '鲤城区28', type: 'bar', data: [19, ], }, { name: '丰泽店29', type: 'bar', data: [18, ], }, { name: '鲤城区30', type: 'bar', data: [19, ], }, { name: '丰泽店31', type: 'bar', data: [18, ], }, { name: '鲤城区32', type: 'bar', data: [19, ], }, { name: '南安店33', type: 'bar', data: [19, ], }, { name: '丰泽店34', type: 'bar', data: [18, ], }, { name: '鲤城区35', type: 'bar', data: [19, ], }, { name: '南安店36', type: 'bar', data: [19, ], }, { name: '丰泽店37', type: 'bar', data: [18, ], }, { name: '鲤城区38', type: 'bar', data: [19, ], }, { name: '丰泽店39', type: 'bar', data: [18, ], }, { name: '鲤城区40', type: 'bar', data: [19, ], }, { name: '丰泽店41', type: 'bar', data: [18, ], }, { name: '鲤城区42', type: 'bar', data: [19, ], }, { name: '南安店43', type: 'bar', data: [19, ], }, { name: '丰泽店44', type: 'bar', data: [18, ], }, { name: '鲤城区45', type: 'bar', data: [19, ], }, { name: '南安店46', type: 'bar', data: [19, ], }, { name: '丰泽店47', type: 'bar', data: [18, ], }, { name: '鲤城区48', type: 'bar', data: [19, ], }, { name: '丰泽店49', type: 'bar', data: [18, ], }, { name: '鲤城区50', type: 'bar', data: [19, ], }, ] }; } function getLineOption() { return{ tooltip: { trigger: 'axis' }, legend: { top: 'bottom', data: ['丰1', '鲤城区2', '南安店3','丰4', '鲤城区5', '南安店6','丰7', '鲤城区8', '南安店9','丰10', '鲤城区11', '南安店12','丰13', '鲤城区14', '南安店15','丰16', '鲤城区17', '南安店18','丰19', '鲤城区20', '南安店21','丰22', '鲤城区23', '南安店24', '丰25', '鲤城区26', '南安店27','丰28', '鲤城区29', '南安店30','丰31', '鲤城区32', '南安店33','丰34', '鲤城区35', '南安店36','丰37', '鲤城区38', '南安店39','丰40', '鲤城区41', '南安店42','丰43', '鲤城区44', '南安店45','丰46', '鲤城区47', '南安店48', ] }, grid: { top: '10%', left: '2%', right: '5%', bottom: '12%', containLabel: true }, xAxis: { type: 'category', boundaryGap: false, data: ['1月', '2月', '3月',] }, yAxis: { type: 'value' }, series: [ { name: '丰1', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区2', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店3', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰4', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区5', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店6', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰7', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区8', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店9', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰10', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区11', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店12', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰13', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区14', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店15', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰16', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区17', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店18', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰19', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区20', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店21', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰22', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区23', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, //--------------------------------------- { name: '南安店24', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰25', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区26', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店27', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰28', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区29', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店30', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰31', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区32', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店33', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰34', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区35', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店36', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰37', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区38', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店39', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰40', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区41', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店42', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰43', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区44', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店45', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, { name: '丰46', type: 'line', stack: '总量', data: [120, 132, 101,], smooth: true, }, { name: '鲤城区47', type: 'line', stack: '总量', data: [220, 182, 191, ], smooth: true, }, { name: '南安店48', type: 'line', stack: '总量', data: [820, 932, 901, ], smooth: true, }, ] }; }