rate-controller.js
5.74 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
/**
* 订单评价
*/
define(
"order/rate-controller",
[
'mk7/controller',
'mk7/url',
'mk7/utils',
'mk7/uploadjs',
],
function(ctrl, url, utils, uploadjs) {
var $$ = Dom7;
var t7 = Template7;
var ctrl = new ctrl();
var submitURL = 'order/customer/submit-rate';
var uploadURL = '/user/default/upload-file';
ctrl.run = function () {
var me = this;
me.id = me.params.id;
me.sn = me.params.sn;
me.imgLimit = 4;
me.setPageTitle("评价");
me.loadPage();
}
ctrl.bindEvents = function () {
var me = this;
console.log("bindEvents");
me.starClickEvent();
me.submitEvent();
me.uploadImgEvent();
}
ctrl.loadPage = function(){
var me = this;
me.render({servicePhone:window.$site.servicePhone});
}
ctrl.starClickEvent = function() {
$$('#rate').on('click', '.img-star',function(e) {
var id = $$(this).attr('data-id');
var parentBox = $$(this).parent('.star-div');
var stars = parentBox.find('.img-star')
$$.each(stars, function(i,n){
var cid = $$(n).attr('data-id');
if ((cid*1) <= id) {
$$(n).addClass('star-on');
var rateText = parentBox.find('.rate-text');
var txt = $$(n).attr('data-txt');
rateText.html(txt);
} else {
$$(n).removeClass('star-on');
}
})
})
}
ctrl.uploadImgEvent = function() {
var me = this;
$$('#rate #upload-btn').change(function () {
if ('' == $$(this).val() || null == $$(this).val()) {
return;
}
var uploadParent = $$(this).parents('li');
uploadjs.uploadFile({
selector: '#upload-btn',
url: url.to(uploadURL),
processAppendTo: '#rate',
success: function (response, e) {
try {
if (response.success) {
var imgUrl = response.tmpUrl;
$$('<li class="upload-li up-img"><div data="' + response.tmpFile + '" data-url="' + imgUrl + '" class="upload-item" style="background-image:url(' + response.tmpMinUrl + ')">' + '</div><span class="del-img"></span></li>').insertBefore(uploadParent);
if (me.imgLimit == $$('#rate #image-list').find('.up-img').length) {
$$('#rate .upload-btn-li').hide();
}
} else {
utils.toast({content: response.message, closeDelay: 5000});
}
} catch (ex) {
console.log(ex)
utils.toast({content: '出错', closeDelay: 5000});
}
}
});
})
$$('#rate #image-list').on('click', '.del-img', function(e){
$$(this).parent().remove();
if (me.imgLimit >= $$('#rate #image-list').find('.up-img').length) {
$$('#rate .upload-btn-li').show();
}
})
}
ctrl.getUploadImgs = function() {
var images = $$('#rate #image-list').find('.up-img');
var returnImg = [];
if (images.length == 0 ) {
return [];
}
$$.each(images, function(i, n){
var img = $$(n).find('.upload-item');
returnImg.push(img.attr('data'))
})
return returnImg;
}
ctrl.submitEvent = function() {
var me = this;
$$('#rate .submit-btn').click(function(e){
var comment = utils.trim($$('#rate .text-content').val());
var qualityStars = $$('#rate .quality-box .img-star')
var qualityStar = 0;
$$.each(qualityStars, function(i,n){
if($$(n).hasClass('star-on')) {
qualityStar++
}
})
var effectStars = $$('#rate .effect-box .img-star')
var effectStar = 0;
$$.each(effectStars, function(i,n){
if($$(n).hasClass('star-on')) {
effectStar++
}
})
var serviceStars = $$('#rate .service-box .img-star')
var serviceStar = 0;
$$.each(serviceStars, function(i,n){
if($$(n).hasClass('star-on')) {
serviceStar++
}
})
var images = me.getUploadImgs();
var pData = me.csrf({
comment:comment,
id:me.id,
qualityStar:qualityStar,
effectStar:effectStar,
serviceStar:serviceStar,
images:images
});
utils.httpPost(url.to(submitURL), pData, function(res) {
if (res.success) {
window.location.replace(url.to('order/customer#customer-order/'+me.id+'/'+me.sn));
} else {
utils.toast({content:res.message});
}
}, true)
})
}
return ctrl;
}
);