add_comment.js
5.86 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
var t = getApp(), oo = t.globalData, a = t.globalData.setting, os = a, e = t.request, s = require("../../../utils/util.js"),
i = require("../../../utils/selectFiles.js");
var regeneratorRuntime = require('../../../utils/runtime.js');
Page({
data: {
url: a.url,
resourceUrl: a.resourceUrl,
iurl: a.imghost,
defaultPhoto: a.resourceUrl + "/static/images/camera.png",
uploadPath: [], //上传后文件路径
maxWord: 0,
is_anonymous: !1,
goods_rank: 0,
service_rank: 0,
deliver_rank: 0,
content: "",
options: null,
isLongPress: !1,
userinfo: null,
imgs: [], //本地文件再上传时的路径
lenMore:0
},
onLoad: async function (a) {
var th = this;
await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + a.goods_id, { 1: 1 }).then(res => {
a.img = th.data.iurl + res.data.data.original_img
})
this.setData({ options: a });
t.getUserInfo(function (e) {
console.log(e);
th.setData({
userinfo: e
})
})
},
keyUpChangeNum: function (t) {
this.setData({
maxWord: t.detail.value.length
}), this.data.content = t.detail.value;
},
checkAnonymous: function () {
this.setData({
is_anonymous: !this.data.is_anonymous
});
},
checkGoodsRank: function (t) {
this.setData({
goods_rank: parseInt(t.currentTarget.dataset.i) + 1
});
},
checkServiceRank: function (t) {
this.setData({
service_rank: parseInt(t.currentTarget.dataset.i) + 1
});
},
checkDeliverRank: function (t) {
this.setData({
deliver_rank: parseInt(t.currentTarget.dataset.i) + 1
});
},
selectPhotos: function (t) {
if (this.data.isLongPress) this.data.isLongPress = !1; else {
var a = this;
i.selectPhotos(this.data.filePaths, t.currentTarget.dataset.idx, function (t) {
a.setData({
filePaths: t
});
});
}
},
removePhoto: function (t) {
var a = this;
this.data.isLongPress = !0, i.removePhoto(this.data.filePaths, t.currentTarget.dataset.idx, function (t) {
a.setData({
filePaths: t
});
});
},
submitComment: function () {
var a = this;
if (!a.data.service_rank || !a.data.goods_rank || !a.data.deliver_rank)
return getApp().my_warnning("请先打分",0,a);
if(a.data.content=="")
return getApp().my_warnning("请填写评价内容",0,a);
//this.uploadPhotos(function () {
var p_data= {
email: ' ',
is_show: 1,
goods_rank: a.data.goods_rank,
service_rank: a.data.service_rank,
deliver_rank: a.data.deliver_rank,
content: a.data.content,
goods_id: a.data.options.goods_id,
order_id: a.data.options.order_id,
user_id: oo.user_id,
store_id: os.stoid,
username: a.data.userinfo.nickname,
source_type:1
}
if(a.data.uploadPath){
p_data['weapp_img']=JSON.stringify(a.data.uploadPath);
}
if(a.data.is_anonymous){
p_data['is_anonymous']=1;
}
e.post("/api/weshop/comment/savecomment", {
data:p_data,
success: function (a) {
wx.setStorageSync("user:comment:update", !0), t.showSuccess("评论成功", function () {
wx.navigateBack();
});
}
});
//});
},
uploadPhotos: function (t, a) {
if (0 == this.data.imgs.length) return t();
if ("number" != typeof a) a = 0; else if (a >= this.data.imgs.length) return t();
var s = this;
e.uploadFile("/api/weshop/comment/uploadCommentImg", {
filePath: s.data.imgs[a],
name: "file",
success: function (e) {
console.log("uploadPhotos");
console.log(e.data);
if(e.data.code==0)
s.data.uploadPath[a] = e.data.data, s.uploadPhotos(t, a + 1);
}
});
},
//图片失败,默认图片
bind_bnerr2: function (e) {
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = a.imghost + "/public/images/default_goods_image_240.gif";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
// 上传图片
chooseImg: function (e) {
var that = this;
var imgs = this.data.imgs;
if (imgs.length >= 3){
if(this.data.lenMore==0){
this.setData({ lenMore: 1 });
}
return false;
}
var imgs = this.data.imgs;
wx.chooseImage({
// count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
getApp().request.uploadFile("/api/weshop/comment/uploadCommentImg", {
filePath: tempFilePaths[0],
name: "file",
success: function (e) {
if(e.data.code==0) {
that.data.uploadPath.push(e.data.data);
imgs.push(tempFilePaths[0]);
that.setData({
imgs: imgs
});
}
}
});
}
});
},
// 删除图片
deleteImg: function (e) {
var imgs = this.data.imgs;
var index = e.currentTarget.dataset.index;
imgs.splice(index, 1);
this.setData({
imgs: imgs
});
},
// 预览图片
previewImg: function (e) {
//获取当前图片的下标
var index = e.currentTarget.dataset.index;
//所有图片
var imgs = this.data.imgs;
wx.previewImage({
//当前显示图片
current: imgs[index],
//所有图片
urls: imgs
})
},
txtInpt:function (e) {
this.setData({
content: e.detail.value
})
}
});