Files
2023-01-28 11:44:29 +08:00

633 lines
15 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import _ from '../../commons/js/commons'
import * as echarts from '../../ecCanvas/components/ec-canvas/echarts';
const app = getApp()
let barChartData;
let pieChartData;
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 pieChart(canvas, width, height, dpr) {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
let option = pieChartData
chart.setOption(option);
return chart;
}
Page({
data: {
isShowMain:false,//显示页面内容
imgUrl:_.config.imgUrl,
userCal:'',
deallist:'',
hoursTip:'',
showBarChart:false,//是否显示Bar图表
ecBar:{},
showPieChart:false,//是否显示Pie图表
ecPie:{},
isShowNotice:false,//是否显示通知
stopNotice:false,//是否不再显示通知
isShowReport:false,//是否显示调拨盘点弹框
isShowProfile:true,//是否显示授权用户信息按钮
isShowGoods:false,//是否显示库存预警
banneractive: 0,
banneractive2: 0,
banneractive3: 0,
remindTab:[],//调拨盘点入口
remindMsg:[],//调拨盘点弹框
levelStIndex:0,
levelSt:[],//客户等级
isResetbiz:false,//是否重置过BIZID
isShowVersionInfo:false,//是否显示版本更新
versionInfo:{
number:'V3.0.51',
list:[
// '',
// '',
// '',
// '',
// '',
// '',
// '修改【订单详情】页面样式及交互;',
// '修改【保单上传】的相应内容,上传后需补充相应保单信息。',
],
},
},
onLoad(options) {
for (let key in options) {
this.setData({
[key]: options[key]
})
}
if(this.data.biz_id){
let that = this
setTimeout(function () {
that.putAppUserResetbiz()
}, 500)
}else{
this.setData({
isResetbiz:true,
});
this.getUserInfo()
}
//this.getAppStatisticsHorder()
//消息通讯 是否显示授权用户信息按钮
_.eventBus.on("isShowProfile", this, function(res){
this.setData({
isShowProfile:res,
})
})
//判断是否显示版本更新内容
if(this.data.versionInfo.list.length>0&&app.getStorageByKey("appversion")!=this.data.versionInfo.number){
this.setData({
isShowVersionInfo:true,
})
}
},
onShow: function () {
this.getHoursTip()
//确保bizID重置完成再执行
if(this.data.isResetbiz){
this.setData({
remindTab:[],
remindMsg:[],
isShowReport:false,//是否显示调拨盘点弹框
isShowGoods:false,
});
this.getAppUserCal()
this.getAppTransferRemind()
this.getAppInventoryRemind()
this.getAppGoodsRemind()
this.getAppStatisticsHcust()
}
},
//生命周期函数--监听页面卸载
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
})
},
//更新用户店铺id
putAppUserResetbiz(){
let params = {};
params['biz_id'] = this.data.biz_id;
_.apiQuery.putAppUserResetbiz(params).then(res => {
this.setData({
isResetbiz:true,
});
this.getUserInfo()
this.getAppUserCal()
this.getAppTransferRemind()
this.getAppInventoryRemind()
this.getAppGoodsRemind()
this.getAppStatisticsHcust()
});
},
//调拨提醒
getAppTransferRemind(){
_.apiQuery.getAppTransferRemind().then(res => {
this.setData({
diaoboNum:res.data.total,
})
if(res.data.total>0){
let remindTab = this.data.remindTab
remindTab.push({
title:'车辆调拨',
content:'您有新的车辆调拨,需要您进行确认操作。',
img:'https://qs.haodian.cn/wechat_app/lichebao/allot/car.gif?v=220224',
url:'/pages/allot/list/index',
allotNum:res.data.total,
})
let remindMsg = this.data.remindMsg
remindMsg.push({
title:'调拨提醒',
content:'您有新的车辆调拨,需要您进行确认操作。',
img:'https://qs.haodian.cn/wechat_app/lichebao/allot/car.gif?v=220224',
btn:{
title:'前往操作',
url:'/pages/allot/list/index',
},
})
this.setData({
remindTab,
remindMsg,
isShowReport:true,
isShowNotice:false,
isShowGoods:false,
})
}
});
},
//盘点提醒
getAppInventoryRemind(){
_.apiQuery.getAppInventoryRemind().then(res => {
this.setData({
pandianNum:res.data.total,
})
if(res.data.total>0){
let remindTab = this.data.remindTab
remindTab.push({
title:'车辆盘点',
content:'您有新的车辆调拨,需要您进行确认操作。',
img:'https://qs.haodian.cn/wechat_app/lichebao/inventory/icon.png',
url:'/pages/inventory/list/index',
allotNum:res.data.total,
})
let remindMsg = this.data.remindMsg
remindMsg.push({
title:'盘点提醒',
content:'您有新的车辆盘点,需要您进行确认操作。',
img:'https://qs.haodian.cn/wechat_app/lichebao/inventory/animation.gif',
btn:{
title:'前往操作',
url:'/pages/inventory/list/index',
},
})
this.setData({
remindTab,
remindMsg,
isShowReport:true,
isShowNotice:false,
isShowGoods:false,
})
}
});
},
//库存提醒/预警
getAppGoodsRemind(){
_.apiQuery.getAppGoodsRemind().then(res => {
this.setData({
inventory:res.data.inventory,
warning:res.data.warning,
})
if(res.data.warning.list&&res.data.warning.list.length>0){
if(!app.getStorageByKey("showGoods")||app.getStorageByKey("showGoods").data!=new Date().getDate()){
//清除
wx.removeStorageSync('showGoods')
this.setData({
isShowGoods:true,
})
let showGoods = {}
if(this.data.biz_id){
showGoods.data = new Date().getDate()
showGoods.list =[{
biz_id:this.data.biz_id,
num:1,
}]
}else{
showGoods.data = new Date().getDate()
showGoods.list =[{
biz_id:'b1',
num:1,
}]
}
app.setStorage('showGoods',showGoods)
}else{
let showGoods = app.getStorageByKey("showGoods")
let index = -1
if(this.data.biz_id){
showGoods.list.forEach((item,i) => {
if(item.biz_id == this.data.biz_id){
index = i
item.num = item.num + 1
}
})
}else{
showGoods.list.forEach((item,i) => {
if(item.biz_id == 'b1'){
index = i
item.num = item.num + 1
}
})
}
if(index > -1){
if(showGoods.list[index].num<4){
this.setData({
isShowGoods:true,
})
app.setStorage('showGoods',showGoods)
}
}else{
this.setData({
isShowGoods:true,
})
if(this.data.biz_id){
showGoods.list.push({
biz_id:this.data.biz_id,
num:1,
})
}else{
showGoods.list.push({
biz_id:'b1',
num:1,
})
}
app.setStorage('showGoods',showGoods)
}
}
}
});
},
//获取用户信息
getUserInfo(){
_.apiQuery.getUserInfo().then(res => {
this.setData({
userInfo: res
})
});
},
//获取用户统计
getAppUserCal(){
let params = {};
if(this.data.biz_id){
params['biz_id'] = this.data.biz_id;
}
_.apiQuery.getAppUserCal(params).then(res => {
this.setData({
isShowMain:true,
userCal:res.data,
levelSt:res.data.levelSt,
})
if(res.data.deallist.length>0){
let deallist = res.data.deallist
if(res.data.deallist.length%2==1){
deallist.push({})
}
this.setData({
deallist:deallist,
})
}
wx.stopPullDownRefresh()
});
},
//数据分析-客户数据
getAppStatisticsHcust(){
this.setData({
showPieChart:false,
})
let params = {};
if(this.data.biz_id){
params['biz_id'] = this.data.biz_id;
}
_.apiQuery.getAppStatisticsHcust(params).then(res => {
pieChartData = res.data.stat_data
pieChartData.series.label = {
formatter: '\n{b|{b}}\n{c|{c}}\n{per|{d}%} ',
rich: {
b: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
c: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
per: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
}
}
this.setData({
cust_total:res.data.total,
cust_cont_total:res.data.cont_total,
cust_top_total:res.data.top_total,
showPieChart:true,
['ecPie.onInit']:pieChart,
})
wx.stopPullDownRefresh()
});
},
//数据分析-订单数据
getAppStatisticsHorder(){
this.setData({
showBarChart:false,
})
let params = {};
if(this.data.biz_id){
params['biz_id'] = this.data.biz_id;
}
_.apiQuery.getAppStatisticsHorder(params).then(res => {
barChartData = res.data.stat_data
this.setData({
order_total:res.data.total,
showBarChart:true,
['ecBar.onInit']:barChart,
})
wx.stopPullDownRefresh()
});
},
//推送链接
pushLink(e) {
if(e.currentTarget.dataset.url){
_.$router.openUrlScheme(e.currentTarget.dataset.url)
}
},
//客服电话
call(e) {
wx.makePhoneCall({
phoneNumber: '18965133055',
})
},
//不再提示
checkNotice(e){
this.setData({
stopNotice:!this.data.stopNotice,
})
},
//关闭通知
closeNotice(){
if(this.data.stopNotice){
app.setStorage('stopNotice', 'true')
}
this.setData({
isShowNotice:false,
})
},
//公众号关注组件
officialaccount(e){
if(e.detail.status == 0&&!app.getStorageByKey("stopNotice")&&!this.data.isShowReport){
// this.setData({
// isShowNotice:true,
// })
}
},
//显示隐藏调拨盘点弹窗
optShowReport(e){
this.setData({
isShowReport:!this.data.isShowReport,
})
},
//显示隐藏库存预警弹窗
optShowGoods(e){
this.setData({
isShowGoods:!this.data.isShowGoods,
})
},
//开发中
development(){
wx.showToast({
title: '暂无数据',
icon: 'none',
duration: 2000
})
},
//调拨盘点轮播点
bannerChange: function (e) {
this.setData({
banneractive:e.detail.current,
});
},
//banner轮播点
bannerChange2: function (e) {
this.setData({
banneractive2:e.detail.current,
});
},
//库存预警轮播点
bannerChange3: function (e) {
this.setData({
banneractive3:e.detail.current,
});
},
//关闭版本提示
closeVersionInfo(){
this.setData({
isShowVersionInfo:false,
})
app.setStorage('appversion',this.data.versionInfo.number)
},
//切换tab
changeTab(e){
this.setData({
levelStIndex:e.currentTarget.dataset.index,
})
},
//页面相关事件处理函数--监听用户下拉动作
onPullDownRefresh: function () {
this.setData({
remindTab:[],
remindMsg:[],
isShowReport:false,//是否显示调拨盘点弹框
isShowGoods:false,
});
this.getAppUserCal()
this.getAppStatisticsHcust()
//this.getAppStatisticsHorder()
this.getAppTransferRemind()
this.getAppInventoryRemind()
this.getAppGoodsRemind()
},
})
function getPieOption() {
return {
tooltip: {
trigger: 'axis',
},
legend: {
top: 'bottom',
orient: 'horizontal',
textStyle:{
fontSize:9,
}
},
series: [
{
type: 'pie',
top: '0',
radius: ['30%', '48%'],
data: [
{value: 1048, name: '未见潜客'},
{value: 735, name: '到店潜客'},
{value: 580, name: '订单客户'},
{value: 484, name: '战败客户'},
],
label: {
formatter: '\n{b|{b}}\n{c|{c}}\n{per|{d}%} ',
rich: {
b: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
c: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
per: {
color: '#4C5058',
fontSize: 10,
lineHeight:15,
align:'left',
},
}
},
}
]
};
}
function getBarOption() {
return {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
top: '8%',
left: '2%',
right: '5%',
bottom: '2%',
containLabel: true
},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01]
},
yAxis: {
type: 'category',
data: ['恭喜提车', '保险上牌', '已开发票','车辆确认','配车准备','申请退款','办理按揭','已交定金','已签合同',],
},
series: [
{
type: 'bar',
itemStyle: {
color:'#2e3246',
borderRadius: [0, 20, 20, 0],
},
barWidth:'15',
data: [33, 23, 29,18, 23, 29,18, 23, 29,],
label: {
show: true,
position: 'right',
formatter: '{@[n]}',
valueAnimation: true
}
},
]
};
}