-
Notifications
You must be signed in to change notification settings - Fork 5
/
doComment.html
276 lines (246 loc) · 8.61 KB
/
doComment.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">
<title>发表评论</title>
<link rel="shortcut icon" href="img/foodie.ico" />
<link href="AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
<link href="AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">
<link href="css/personal.css" rel="stylesheet" type="text/css">
<link href="css/appstyle.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="makeComments">
<div class="nav-table">
<div class="long-title"><span class="all-goods" style="font-weight: bold;">用户中心</span></div>
</div>
<b class="line"></b>
<div class="center">
<div class="col-main">
<div class="main-wrap">
<div class="user-comment">
<!--标题 -->
<div class="am-cf am-padding">
<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">发表评论</strong> /
<small>Make Comments</small></div>
</div>
<hr />
<div class="comment-main">
<div class="comment-list" v-for="(orderItem, index) in orderItemList">
<div class="item-pic">
<a href="javascript:void(0);" class="J_MakePoint">
<img :src="orderItem.itemImg" class="itempic">
</a>
</div>
<div class="item-title">
<div class="item-name">
<a href="javascript:void(0);">
<p class="item-basic-info">{{orderItem.itemName}}</p>
</a>
</div>
<div class="item-info">
<div class="info-little">
<span style="color: gray;font-size:14px;">规格:{{orderItem.itemSpecName}}</span>
</div>
</div>
</div>
<div class="clear"></div>
<div class="item-comment">
<textarea placeholder="您的评价将会对其他小伙伴们提供很大帮助哟~" v-model="orderItem.content" maxlength="64"></textarea>
</div>
<div class="item-opinion">
<li @click="makeComment(orderItem.id, 1)" :id="'good_'+orderItem.id"><i class="op1"></i>好评</li>
<li @click="makeComment(orderItem.id, 2)" :id="'normal_'+orderItem.id"><i class="op2"></i>中评</li>
<li @click="makeComment(orderItem.id, 3)" :id="'bad_'+orderItem.id"><i class="op3"></i>差评</li>
</div>
</div>
<div class="info-btn">
<div class="am-btn am-btn-danger" @click="saveComments">发表评论</div>
</div>
</div>
</div>
</div>
<!--底部-->
<div class="footer ">
<div class="footer-hd ">
<p>
<a href="https://github.com/dsying" target="_blank">Github</a>
<b>|</b>
<a href="https://juejin.im/user/5b0e60f6f265da08f0339162" target="_blank">掘金社区</a>
</p>
</div>
<div class="footer-bd ">
<p><em></em></p>
</div>
</div>
</div>
<aside class="menu">
<ul>
<li class="person">
<span style="font-weight: bold;">
<a href="center.html">个人中心</a>
</span>
</li>
<li class="person">
<a href="#">个人资料</a>
<ul>
<li> <a href="userinfo.html">我的信息</a></li>
<li> <a href="address.html">收货地址</a></li>
</ul>
</li>
<li class="person">
<a href="#">我的交易</a>
<ul>
<li><a href="order.html">订单管理</a></li>
<li class="active"><a href="comment.html">我的评价</a></li>
</ul>
</li>
</ul>
</aside>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$(".comment-list .item-opinion li").click(function () {
$(this).prevAll().children('i').removeClass("active");
$(this).nextAll().children('i').removeClass("active");
$(this).children('i').addClass("active");
});
})
</script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript">
var index = new Vue({
el: "#makeComments",
data: {
userIsLogin: false,
userInfo: {},
flowerList: [], // 评价等级list
orderItemList: [],
},
created() {
// var me = this;
// 通过cookie判断用户是否登录
app.judgeUserLoginStatus(this);
var orderId = app.getUrlParam("orderId");
// 如果orderId为空,跳转到错误页面
if (orderId == null || orderId == undefined || orderId == '') {
app.goErrorPage();
return;
}
this.orderId = orderId;
// 渲染评论页内容
this.renderItemComment(orderId);
},
methods: {
saveComments() {
var orderItemList = this.orderItemList;
// console.log(orderItemList);
// 判断每项元素是否有评论等级
// 判断每项元素是否包含评论内容
for (var i = 0 ; i < orderItemList.length ; i ++) {
var tempItem = orderItemList[i];
if (tempItem.commentLevel == "" || tempItem.commentLevel == undefined || tempItem.commentLevel == null) {
alert("每个商品都需要一朵小花噢~");
return;
}
if (tempItem.content == "" || tempItem.content == undefined || tempItem.content == null) {
alert("每个商品都需要您宝贵的评论噢~");
return;
}
}
// 保存评论
var userInfo = this.userInfo;
// 请求后端获得最新数据
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.post(
serverUrl + '/comments?userId=' + userInfo.id + "&orderId=" + this.orderId,
orderItemList,
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
// var orderItemList = res.data.data;
// console.log(orderItemList);
alert("评论成功!");
window.location.href = "order.html";
} else if (res.data.status == 500) {
alert(res.data.msg);
}
});
},
makeComment(orderItemId, level) {
var orderItemList = this.orderItemList;
for (var i = 0 ; i < orderItemList.length ; i ++) {
var tempId = orderItemList[i].id;
if (tempId == orderItemId) {
orderItemList[i].commentLevel = level;
}
}
// console.log(orderItemList);
this.orderItemList = orderItemList;
var liId = "";
if (level == 1) {
liId = "good_" + orderItemId;
} else if (level == 2) {
liId = "normal_" + orderItemId;
} else if (level == 3) {
liId = "bad_" + orderItemId;
}
var goodLiId = "good_" + orderItemId;
var normalLiId = "normal_" + orderItemId;
var badLiId = "bad_" + orderItemId;
// 判断评价等级,先把所有的颜色去掉,然后再在当前点击的上面标记颜色
var goodDomLi = document.getElementById(goodLiId);
var normalDomLi = document.getElementById(normalLiId);
var badDomLi = document.getElementById(badLiId);
goodDomLi.children[0].classList.remove("active");
normalDomLi.children[0].classList.remove("active");
badDomLi.children[0].classList.remove("active");
var domLi = document.getElementById(liId);
var classList = domLi.children[0].classList;
classList.add("active");
// console.log(domLi.children[0].classList);
},
// 获取订单商品详情
renderItemComment(orderId) {
var userInfo = this.userInfo;
// 请求后端获得最新数据
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.get(
serverUrl + '/orders/items?userId=' + userInfo.id + "&orderId=" + orderId,
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
var orderItemList = res.data.data;
// console.log(orderItemList);
this.orderItemList = orderItemList;
for (var i = 0 ; i < orderItemList.length ; i ++) {
orderItemList[i].commentLevel = 0;
orderItemList[i].commentId = 0;
}
} else if (res.data.status == 500) {
alert(res.data.msg);
}
});
},
}
});
</script>
</body>
</html>