comment.js
10.8 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// pages/my/comment/comment.js
const app = getApp();
const qiniuUploader = require("../../../utils/qiniuUploader");
Page({
/**
* 页面的初始数据
*/
data: {
flagId: 9,
id: 0,
gid: 1122,
imgUrl: app.globalData.imgUrl,
photoPath: '',
arr: [{
id: 0
}, {
id: 1
}, {
id: 2
}, {
id: 3
}, {
id: 4
}],
arr1: [{
id: 0
}, {
id: 1
}, {
id: 2
}, {
id: 3
}, {
id: 4
}],
test: '',
length: 0,
imgBox: [],
imgUrls: [],
logistics_stars: 0,
text: "",
index: 0,
orderList: [],
imgURL: [],
token: '',
imageURL: '',
key: '',
goods: {}
},
//返回
get_back() {
wx.navigateBack({})
},
//点亮星星
changeStarId(e) {
let flag = e.currentTarget.dataset.flag
let index = e.currentTarget.dataset.index * 1
// let indexs=index*1+1
let new_arr = this.data.arr
for (let i = 0; i < new_arr.length; i++) {
new_arr[i].flag = false;
}
for (let i = 0; i < index; i++) {
new_arr[i].flag = true;
}
this.setData({
arr: new_arr,
index: index
});
},
changeStarIds(e) {
let flag = e.currentTarget.dataset.flag
let index = e.currentTarget.dataset.index
let new_arr = this.data.arr1
for (let i = 0; i < new_arr.length; i++) {
new_arr[i].flag = false;
}
for (let i = 0; i < index; i++) {
new_arr[i].flag = true;
}
console.log(index)
this.setData({
arr1: new_arr,
logistics_stars: index * 1
});
},
//点赞
changeSupport(e) {
let gid = e.currentTarget.dataset.gid
let list = this.data.orderList
list.forEach(function(ele, index) {
if (gid == ele.id) {
ele.flag1 = true
ele.flag2 = false
}
})
this.setData({
gid: gid,
orderList: list
});
},
//踩
changeSupport2(e) {
let gid = e.currentTarget.dataset.gid
let list = this.data.orderList
list.forEach(function(ele, index) {
if (gid == ele.id) {
ele.flag2 = true
ele.flag1 = false
}
})
this.setData({
gid: gid,
orderList: list
});
},
//限制字数
limit(e) {
let value = e.detail.value;
var length = parseInt(value.length);
this.setData({
length: length,
text: value
});
},
//点击增加图片
changePhoto: function() {
var that = this;
var img_arr = []
// 选择图片
wx.chooseImage({
count: 9,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function(res) {
const filePath = res.tempFilePaths;
// var filePath = res.tempFilePaths[0];
img_arr = filePath
let arr = [];
img_arr = that.data.imgBox.concat(img_arr)
that.setData({
imgBox: img_arr
});
// tempFilePath可以作为img标签的src属性显示图片
// console.log(res);
let successUp = 0; //成功个数
let failUp = 0; //失败个数
let i = 0; //第几个
// let tempFilePaths = res.tempFilePaths //总文件
let length = res.tempFilePaths.length //总共个数
that.uploadAllfile(filePath, successUp, failUp, i, length);
}
})
},
// 上传图片至七牛云
uploadAllfile(filePaths, successUp, failUp, i, length) {
let that = this;
qiniuUploader.upload(filePaths[i], (res) => {
var img_urls = that.data.imgUrls;
console.log(res)
let aa = 'http://qiniu.himrhi.com/' + res.key
img_urls.push(aa);
let imgStr = img_urls.join(',')
that.setData({
imageURL: res.imageURL,
key: imgStr,
imgUrls: img_urls
});
}, (error) => {
console.log('error: ' + error);
}, {
region: 'ECN',
domain: 'qiniu.himrhi.com',
uptokenURL: 'http://www.himrhi.com/api/wxapp/public/getQiniuToken',
uptokenFunc: function () {
return 'JMgHPK8vEdZfUfxZIW8qIsyucRCZeTZ4aqHLWsjI:9VjchzcKJTa9uqK_0MWELzc4_zg=:eyJzY29wZSI6ImhpLWZyZXNoIiwiZGVhZGxpbmUiOjE1NjA3MzU3ODF9';
}
}, (res) => {
console.log('上传进度', res.progress)
console.log('已经上传的数据长度', res.totalBytesSent)
console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
}, () => {
// 取消上传
}, () => {
// `before` 上传前执行的操作
}, (err) => {
// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
i++;
// let img = that.data.img
if (i == length) {
// console.log('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');
} else { //递归调用uploadDIY函数
that.uploadAllfile(filePaths, successUp, failUp, i, length);
}
});
},
//点击删除图片
deleteImg(e) {
let val = e.currentTarget.dataset.index
let imgUrls = this.data.imgUrls
let imgBox = this.data.imgBox
let indexs = imgBox.indexOf(val)
imgUrls.splice(indexs, 1)
imgBox.splice(indexs, 1)
this.setData({
imgUrls: imgUrls,
imgBox: imgBox
})
},
//点击提交评论
submitComment() {
console.log('-------')
console.log(this.data.key)
console.log('-------')
let url = '/wxapp/order/setComment'
let goods = this.data.goods
let gid = this.data.gid.toFixed(0)
let list = this.data.orderList
list.forEach(function (ele, index) {
let i = ele.id
if (ele.flag1) {
goods[i] = 1
}
if (ele.flag2) {
goods[i] = 0
}
})
goods = JSON.stringify(goods);
if (this.data.index == 0) {
wx.showToast({
title: '请对商品做评价',
icon: 'none'
})
return;
}
if (this.data.logistics_stars == 0) {
wx.showToast({
title: '请对物流做评价',
icon: 'none'
})
return;
}
for (var v in goods) {
if (goods[v] == '') {
wx.showToast({
title: '请对菜品做评价',
icon: 'none'
})
return;
}
}
if (this.data.id == 0) {
wx.showToast({
title: '订单错误',
icon: 'none'
})
return;
}
if (this.data.text == '') {
wx.showToast({
title: '评价内容不能为空',
icon: 'none'
})
return;
}
if (this.data.key == '') {
wx.showToast({
title: '请上传图片',
icon: 'none'
})
return;
}
console.log("评价图片:3张", this.data.key)
let params = {
object_id: this.data.id,
goods_stars: this.data.index,
logistics_stars: this.data.logistics_stars,
goods: goods,
content: this.data.text,
images: this.data.key
}
app.post(url, params).then(r => {
console.log('上传')
console.log(r)
if (r.code == 1) {
wx.showToast({
title: '评价成功',
duration: 1000
})
wx.navigateTo({
url: '../myOrder/myOrder?status=' + 5,
})
this.fetchOrderDetail();
}
});
},
//渲染订单详情
fetchOrderDetail() {
let url = '/wxapp/order/detail'
let goods = {}
let params = {
id: this.data.id
}
app.post(url, params).then(r => {
console.log(r)
r.data.detail.forEach(function(ele, index) {
let i = ele.id
goods[i] = ''
ele.flag1 = true
ele.flag2 = false
})
this.setData({
orderList: r.data.detail,
goods: goods
})
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({
id: options.id
});
this.fetchOrderDetail();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
// uploadURLFromRegionCode(code) {
// var uploadURL = null;
// switch(code) {
// case 'ECN': uploadURL = 'https://up.qiniup.com'; break;
// case 'NCN': uploadURL = 'https://up-z1.qiniup.com'; break;
// case 'SCN': uploadURL = 'https://up-z2.qiniup.com'; break;
// case 'NA': uploadURL = 'https://up-na0.qiniup.com'; break;
// case 'ASG': uploadURL = 'https://up-as0.qiniup.com'; break;
// default: console.error('please make the region is with one of [ECN, SCN, NCN, NA, ASG]');
// }
// return uploadURL;
// } ,
})