comment.js
15.2 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
// 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) {
console.log(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
});
// var filePath = res.tempFilePaths[0];
// 交给七牛上传
qiniuUploader.upload(filePath, (res) => {
// 每个文件上传成功后,处理相关的事情
// 其中 info 是文件上传成功后,服务端返回的json,形式如
// {
// "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
// "key": "gogopher.jpg"
// }
// 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html
var img_urls = that.data.imgUrls;
let aa = 'http://qiniu.himrhi.com/' + res.key
img_urls.push(aa);
let imgStr = img_urls.join(',')
console.log(imgStr)
that.setData({
'imageURL': res.imageURL,
key: imgStr,
imgBox: img_arr,
imgUrls: img_urls
});
}, (error) => {
console.log('error: ' + error);
}, {
region: 'ECN',
domain: 'qiniu.himrhi.com', // // bucket 域名,下载资源时用到。如果设置,会在 success callback 的 res 参数加上可以直接使用的 ImageURL 字段。否则需要自己拼接
// key: 'customFileName.jpg', // [非必须]自定义文件 key。如果不设置,默认为使用微信小程序 API 的临时文件名
// 以下方法三选一即可,优先级为:uptoken > uptokenURL > uptokenFunc
// uptoken: 'JMgHPK8vEdZfUfxZIW8qIsyucRCZeTZ4aqHLWsjI:9VjchzcKJTa9uqK_0MWELzc4_zg=:eyJzY29wZSI6ImhpLWZyZXNoIiwiZGVhZGxpbmUiOjE1NjA3MzU3ODF9', // 由其他程序生成七牛 uptoken
uptokenURL: 'http://www.himrhi.com/api/wxapp/public/getQiniuToken', // 从指定 url 通过 HTTP GET 获取 uptoken,返回的格式必须是 json 且包含 uptoken 字段,例如: {"uptoken": "[yourTokenString]"}
uptokenFunc: function () {
return 'JMgHPK8vEdZfUfxZIW8qIsyucRCZeTZ4aqHLWsjI:9VjchzcKJTa9uqK_0MWELzc4_zg=:eyJzY29wZSI6ImhpLWZyZXNoIiwiZGVhZGxpbmUiOjE1NjA3MzU3ODF9';
}
}, (res) => {
console.log('上传进度', res.progress)
console.log('已经上传的数据长度', res.totalBytesSent)
console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
}, () => {
// 取消上传
}, () => {
// `before` 上传前执行的操作
}, (err) => {
// `complete` 上传接受后执行的操作(无论成功还是失败都执行)
});
}
})
},
//点击删除图片
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() {
let url = '/wxapp/order/setComment'
let goods = this.data.goods
let gid = this.data.gid.toFixed(0)
let list = this.data.orderList
console.log(gid);
list.forEach(function (ele, index) {
let i = ele.id
if (ele.flag1) {
goods[i] = 0
}
if (ele.flag2) {
goods[i] = 1
}
})
console.log(goods)
goods = JSON.stringify(goods);
console.log(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;
}
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;
// } ,
})