r_detail.js
9.88 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
var bookOrder=require('../../utils/bookCommon.js')
Page({
data:{
contactlist:[
{
type:'custom',
title:'顾客构成',
isactive:true
},
{
type:'order',
title:'订单构成',
isactive:false
},
{
type:'price',
title:'收入构成',
isactive:false
},
{
type:'discount',
title:'优惠构成',
isactive:false
}
],
detaildim:'day',
type:'custom',
isloading:false
},
onLoad:function(opt){
console.log(opt)
var time;
if(opt.selectdim=='days'){
time=opt.dateall.split('-')[0]+opt.dateall.split('-')[1]+opt.dateall.split('-')[2]
}else{
if(opt.selectdim=='week'){
var arr=opt.date.split('-');
var begin=arr[0].split('.');
var end=arr[1].split('.');
time=''
for(var i=0;i<begin.length;i++){
time+=begin[i]
}
time+='-';
for(var i=0;i<end.length;i++){
time+=end[i]
}
}else{
console.log(opt)
arr=opt.dateall.split('.');
time=''+arr[0]+arr[1]
}
console.log(time)
}
this.setData({
opt:opt,
time:time,
sellerid:util.cache('sellerid'),
selectdim:opt.selectdim,
detaildim:opt.selectdim=='days' ? 'day' : opt.selectdim
})
console.log(opt)
if(this.data.detaildim=='day'){
util.setBarTitle('日报表')
}else{
if(this.data.detaildim=='week'){
util.setBarTitle('周报表')
}else{
util.setBarTitle('月报表')
}
}
},
onShow:function(){
if(util.cache('date')){
if(this.data.detaildim=='day'){
var thisyear=util.cache('date').split('-')[0];
var thismonth=util.cache('date').split('-')[1][0]=='0' ? util.cache('date').split('-')[1][1] : util.cache('date').split('-')[1];
var thisday=util.cache('date').split('-')[2][0]=='0' ? util.cache('date').split('-')[2][1] : util.cache('date').split('-')[2]
this.setData({
time:thisyear+(thismonth.length==1 ? '0'+thismonth : thismonth)+(thisday.length==1 ? '0'+thisday : thisday),
})
}else{
// if(this.data.detaildim=='week'){
// this.data.opt.date=util.cache('date')
// this.setData({
// time:util.cache('time'),
// opt:this.data.opt
// })
// }
this.data.opt.date=util.cache('date')
this.setData({
time:util.cache('time'),
opt:this.data.opt
})
}
}
this.setData({
isloading:false,
})
this.getreportdetail();
var that=this;
util.postSuccessFun=function(json,uri_code) {
switch (uri_code) {
case uri.CGI_USER_GETOPERDATEBYDAY__CODE:
console.log(json)
if(json.ret==200){
var list=json.data;
var reportlist=[];
var contactinfo='';
for(var key in list){
console.log(key)
var date,dd
if(that.data.selectdim=='days'){
date=bookOrder.getdate_num(key.split('-')[1]+'-'+key.split('-')[2]);
var thisdate=key+' 12:00:00';
var timestamp=bookOrder.gettimestamp(thisdate);
dd=bookOrder.changedate(timestamp*1000);
}
if(that.data.selectdim=='week'){
date=key;
}
if(that.data.selectdim=='month'){
var arr=key.split('.');
date=arr[0]+'年'+arr[1]+'月';
}
if(list[key]!=''){
var obj={
date:date,
dateall:key,
totaldate:that.data.selectdim=='days' ? dd.year+'年'+date : that.data.opt.date,
total_order:list[key].total_order,
unit_price:Number(list[key].unit_price).toFixed(2),
total_pnum:list[key].total_pnum ? list[key].total_pnum : null,
total_price:list[key].total_price,
}
console.log(key)
contactinfo=list[key].contactinfo
//x:新顾客 l:老顾客 w:外卖就餐 t:堂食就餐 tp:堂食总收入 wp:外卖总收入 mdp:免单 gzp:挂账 zdzkp:整单折扣 hyp:会员 zdyp:自定义
reportlist.push(obj)
}else{
reportlist.push({
date:date,
dateall:key,
totaldate:dd.year+'年'+date
})
}
}
console.log(reportlist[0])
that.setData({
opt:reportlist[0],
isloading:true,
contactinfo:contactinfo
})
that.getformlist();
}
break;
}
}
},
selecttime:function(){
console.log(this.data.opt)
wx.navigateTo({
url:'r_time?date='+this.data.opt.dateall+'&selectdim='+this.data.selectdim
})
},
getreportdetail:function () {
util.post(uri.CGI_USER_GETOPERDATEBYDAY,{sid:this.data.sellerid,dim:this.data.detaildim,time:this.data.time},uri.CGI_USER_GETOPERDATEBYDAY__CODE)
},
selectform:function(e){
var type=e.currentTarget.dataset.type;
var contactlist=this.data.contactlist;
contactlist.forEach(function(v,i){
v.isactive=false
if(v.type==type){
v.isactive=true
}
})
this.setData({
contactlist:contactlist,
type:type
})
this.getformlist();
},
getformlist:function () {
var that=this;
var type=this.data.type;
var reportinfo=this.data.opt;
var sum=0;
var contactinfo=this.data.contactinfo;
console.log(contactinfo)
var ifcondition=typeof contactinfo==='object' && !isNaN(contactinfo.length)
if(ifcondition==false && contactinfo!=''){
for(var key in contactinfo){
if(type+'form'==key){
var list=contactinfo[key];
if(reportinfo!='' && list){
list.forEach(function(v,i){
if(!v.count){
v.count=0
}
if(type=='custom'){
if(v.count && v.count!=0){
v.per=bookOrder.isInteger(v.count/Number(that.data.opt.total_pnum)*100)==true ? (v.count/Number(that.data.opt.total_pnum)*100) : (v.count/Number(that.data.opt.total_pnum)*100).toFixed(1)
}
}
if(type=='order'){
if(v.count && v.count!=0){
v.per=bookOrder.isInteger(v.count/Number(that.data.opt.total_order)*100)==true ? (v.count/Number(that.data.opt.total_order)*100) : (v.count/Number(that.data.opt.total_order)*100).toFixed(1)
}
}
if(type=='price'){
if(v.count && v.count!=0){
v.per=bookOrder.isInteger(v.count/Number(that.data.opt.total_price)*100)==true ? (v.count/Number(that.data.opt.total_price)*100) : (v.count/Number(that.data.opt.total_price)*100).toFixed(1)
}
}
})
list.sort(function(a,b){
var max=Number(a.count);
var min=Number(b.count);
if(max>=min) return 1;
if(max<min) return -1;
})
}
}
}
if(type=='discount'){
contactinfo[type+'form'].forEach(function (v,i) {
console.log(typeof v.count)
sum+=Number(v.count);
})
contactinfo[type+'form'].forEach(function (v,i) {
v.per=bookOrder.isInteger(v.count/sum*100)==true ? (v.count/sum*100) : (v.count/sum*100).toFixed(1)
})
}
this.setData({
infolist:contactinfo[type+'form'] ? contactinfo[type+'form'].reverse() : []
})
}else{
this.setData({
infolist:[]
})
}
},
netchange:function(){
this.onShow();
}
})