boutiqueComment.js
7.63 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// packagePersonal/pages/boutique/boutique.js
const filter = require('../../../utils/filter.js');
import api from '../../restapi'
import util from '../../../utils/util.js'
const app = getApp();
Page(filter.identityFilter({
/**
* 页面的初始数据
*/
data: {
initFlag: true,
showFlag: false,
orderCode: '',
batchCode: '',
commentOrNot: false, // 是否评价过
score: 0,
commentResult: '',
orderItem: [],
getTotalPrice: '',
label: [
{
text: '服务态度好'
// active: false
},
{
text: '性价比高'
// active: false
},
{
text: '价格便宜'
// active: false
}
],
commentVal: '',
errMsg: ''
},
/**
* 生命周期函数--监听页面显示
*/
onLoad: function (options) {
this.initData(options);
console.log('boutiqueComment onload', options);
},
onShow() {
// 解决二次扫码数据缓存问题
if(this.data.initFlag) {
let pages = getCurrentPages(),
currentPage = pages[pages.length-1],
options = currentPage.options,
appSceneData = app.globalData.sceneData,
hasScene = options.scene ? options.scene : null;
if(appSceneData){
options.mainOrderCode = appSceneData.query.mainOrderCode;
options.batchCode = appSceneData.query.batchCode;
}
if(hasScene && options.mainOrderCode) {
options.fromMenu = false;
this.initData(options);
console.log('boutiqueComment onshow', options);
}
}
},
initData(options) {
/** 三种情况:
* 1、orderCode从正式版本扫码过来的scene获取,且还需验证手机号是否一致
* 2、orderCode从体验版的query获取
* 3、点击菜单栏status为1时直接过来*/
if(this.data.initFlag) {
this.setData({
initFlag: false
})
const needRefresh = wx.getStorageSync('needRefresh');
let orderCode = '',
batchCode = '',
scene = '',
query = '',
fromMenu = options.fromMenu;
wx.showLoading({title: '加载中'});
if(!needRefresh) {
// 若用户未登录要缓存场景值, 解决跳转登录页面场景值丢失的问题
orderCode = options.mainOrderCode;
batchCode = options.batchCode;
scene = options.scene;
query = options.query;
options.sceneUrl = getCurrentPages()[0].route;
wx.setStorageSync('needRefresh', options);
} else {
// 登录后回来直接拿缓存的值(此时options为空),但排除登录以外的情况因此要优先拿options的值
const getOptionsType = options.mainOrderCode ? options : needRefresh;
orderCode = getOptionsType.mainOrderCode;
batchCode = getOptionsType.batchCode;
scene = getOptionsType.scene;
query = getOptionsType.query;
wx.removeStorageSync('needRefresh');
}
if(scene) {
this.setData({
orderCode,
batchCode
})
} else if(query) {
orderCode = query.mainOrderCode;
batchCode = query.batchCode;
fromMenu = query.fromMenu;
this.setData({
orderCode,
batchCode
})
}
if(fromMenu) {
let data = wx.getStorageSync('fromMenuData');
this.render(data, true);
} else {
this.getAllOrderList();
}
this.getLabel();
}
},
getAllOrderList() {
// 二次扫码获取订单详情
let { orderCode, batchCode } = this.data;
// 测试数据:{orderCode: '2007071702209842', batchCode : '08320070910592739'};
if(orderCode && batchCode) {
api.getBoutiqueSecondScanData({ orderCode, batchCode }, res => {
this.render(res, false);
}, error => {
util.showToast('网络连接错误');
console.log(error, 'secondScan request error');
})
} else {
wx.hideLoading();
this.setData({
errMsg: '暂无精品交付单~'
})
}
},
render(res, fromMenu) {
let resData = fromMenu ? res.data.order : res.data,
{ returnCode } = res,
getTotalPrice = 0;
if(resData && returnCode == '0' ) {
let { subOrderList: orderItem, status } = resData,
commentOrNot = status == 1 ? false : true; // status:1未评价,其余评价过
wx.hideLoading();
if(orderItem && orderItem.length > 0) {
orderItem.forEach(item => getTotalPrice += item.totalPrice);
}
let setDataRes = {
showFlag: true,
orderItem,
getTotalPrice: getTotalPrice.toFixed(2),
commentOrNot
}
if(commentOrNot) {
// 评价过
let { customerComment: commentResult, customerScore: score} = resData;
setDataRes['commentResult'] = commentResult;
setDataRes['score'] = score;
}
this.setData( setDataRes );
} else {
let { message } = res;
console.log('error message', message);
wx.redirectTo({
url: `/packagePersonal/pages/error/error?msg=${message}`
})
}
},
getLabel() {
// 获取标签数据
api.getBoutiqueCommentLabel({}, res => {
let { returnCode } = res,
resData = res.data;
if(resData && returnCode == '0') {
let label = [];
resData.forEach(item => label.push({text: item.confName}));
this.setData({ label });
}
}, error => {
console.log(error, 'getCommentLabelList request error');
})
},
commentInput(e) {
// 同步textarea内容数据
let { value } = e.detail;
this.setData({
commentVal: value
})
},
syncScore(e) {
let { score } = e.detail;
this.setData({
score
})
},
tapLabel(e) {
// 点击标签添加内容到输入框
let index = e.target.dataset.index,
{ label, commentVal } = this.data;
// labelItem = `label[${index}].active`,
// result = label[index]['active'] ? false : true;
commentVal += label[index].text + ', ';
this.setData({
commentVal
// [labelItem]: result
})
},
haveEmoji(val) {
// 过滤表情包
const emojiReg = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac])/g;
return emojiReg.test(val);
},
confirm() {
// 点击确认提交
let { batchCode, commentVal: customerComment, score: customerScore } = this.data;
let data = {
batchCode,
customerComment,
customerScore
};
if(customerScore === 0) {
// 未评星级弹出提示框
util.showToast('请对本次服务进行打分');
return false;
}
if (this.haveEmoji(customerComment)) {
data.customerComment = util.replaceEmoji(customerComment);
}
api.sendBoutiqueCommentResult(data, res => {
let { returnCode } = res;
if(returnCode == '0') {
let { commentVal } = this.data;
util.showToast('提交成功');
this.setData({
score: customerScore,
commentOrNot: true,
commentResult: commentVal
})
// 提交成功后精细化小程序还需要进行消息推送
} else {
console.log(res.message);
util.showToast('提交错误');
}
}, error => {
console.log(error, 'confirmUpgrade request error');
})
},
onLogin() {
}
}))