add_comment.js
4 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
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");
Page({
data: {
url: a.url,
resourceUrl: a.resourceUrl,
iurl: a.imghost,
defaultPhoto: a.resourceUrl + "/static/images/camera.png",
filePaths: [],
uploadPath: [],
maxWord: 0,
is_anonymous: !1,
goods_rank: 0,
service_rank: 0,
deliver_rank: 0,
content: "",
options: null,
isLongPress: !1,
userinfo:null,
},
onLoad: function(a) {
var th=this;
console.log('onLoad');
console.log(a);
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 t.showWarning("请先打完分~");
this.uploadPhotos(function() {
e.post("/api/weshop/comment/savecomment", {
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
},
success: function(a) {
wx.setStorageSync("user:comment:update", !0), t.showSuccess("评论成功", function() {
wx.navigateBack();
});
}
});
});
},
uploadPhotos: function(t, a) {
if (0 == this.data.filePaths.length) return t();
if ("number" != typeof a) a = 0; else if (a >= this.data.filePaths.length) return t();
var s = this;
e.uploadFile("/api/user/upload_comment_img", {
filePath: s.data.filePaths[a],
name: "img_file",
success: function(e) {
s.data.uploadPath[a] = e.data.result, 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) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
}
});