2019-09-06 23:53:10 +08:00

216 lines
11 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mui.plusReady(function() {
var token = localStorage.getItem('token');
var self = plus.webview.currentWebview();
var data_order_id = self.data_order_id;
mui.ajax(hyhUrl('app/Orders/getOrderAppraise'), { 
headers: { 
"HYH-Token": token
},
data: {
oId: data_order_id
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data);
if(data.status == 1) {
data = data.data
var html = '';
var i =0;
$.each(data.Rows, function() {
if(this.appraise == null) {
html += '<div class="con_1"data-goodsId="' + this.goodsId + '"data-goodsSpecId="' + this.goodsSpecId + '"data-orderId="' + this.orderId + '"data-orderGoodsId="' + this.id + '"><div class="describe"><div class="des_img"><img src="' + hyhImgUrl(this.goodsImg) + '"/></div><p>' + this.goodsName + '</p></div><div class="row"data-class="goodsScore"data-goodsScore="0"><p>商品评分</p><div class="star"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="row"data-class="serviceScore"data-serviceScore="0"><p>服务评分</p><div class="star"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="row"data-class="timeScore"data-timeScore="0"><p>时效评分</p><div class="star"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="purchase"><textarea class="content"name=""rows=""cols=""placeholder="分享你的购买心得"></textarea><div class="up_out"><div id="ossfile' + i + '" class="ossfile clearfix" data-num="' + i + '">你的浏览器不支持flash,Silverlight或者HTML5</div><div id="container' + i + '" class="container" data-num="' + i + '"><a id="selectfiles' + i + '" href="javascript:void(0);" class="btn selectfiles" data-num="' + i + '">选择图片</a></div></div></div><button class="tijiao">提交评价</button></div>'
i++;
} else {
html += '<div class="con_1"data-goodsId="' + this.goodsId + '"data-goodsSpecId="' + this.goodsSpecId + '"data-orderId="' + data.orderId + '"data-orderGoodsId="' + this.orderId + '"><div class="describe"><div class="des_img"><img src="' + hyhImgUrl(this.goodsImg) + '"/></div><p>' + this.goodsName + '</p></div><div class="row"data-class="goodsScore"data-goodsScore="' + this.appraise.goodsScore + '"><p>商品评分</p><div class="star"data-isPj="1"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="row"data-class="serviceScore"data-serviceScore="' + this.appraise.serviceScore + '"><p>服务评分</p><div class="star"data-isPj="1"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="row"data-class="timeScore"data-timeScore="' + this.appraise.timeScore + '"><p>时效评分</p><div class="star"data-isPj="1"><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div><div class="star_a"><div class="star_off"></div></div></div></div><div class="purchase_"><p>' + this.appraise.content + '</p>'
$.each(this.appraise.images, function() {
html+='<img src="'+ hyhImgUrl(this) +'"/>'
});
html+='</div></div>';
}
});
$('.con').html(html)
$('.star').each(function() {
if($(this).attr('data-isPj') == 1) {
var num = +$(this).parent().attr('data-' + $(this).parent().attr('data-class')) - 1
$(this).children().eq(num).children().addClass('star_on').removeClass('star_off')
$(this).children().eq(num).prevAll().children().addClass('star_on').removeClass('star_off')
$(this).children().eq(num).nextAll().children().addClass('star_off').removeClass('star_on')
}
})
var btnArr = [];
$('.selectfiles').each(function(num) {
btnArr.push($(this).attr('id'));
})
$.each(btnArr, function(i, n) {
var self = this.toString();
var that = document.getElementById(this);
var uploader = new plupload.Uploader({
runtimes: 'html5,flash,silverlight,html4',
browse_button: self,
//multi_selection: false,
// container: document.getElementById('container'),
flash_swf_url: '../lib/plupload-2.1.2/js/Moxie.swf',
silverlight_xap_url: '../lib/plupload-2.1.2/js/Moxie.xap',
url: 'http://oss.aliyuncs.com',
dir:'appraises',
filters: {
mime_types: [ //只允许上传图片和zip,rar文件
{
title: "Image files",
extensions: "jpg,gif,png,bmp"
},
{
title: "Zip files",
extensions: "zip,rar"
}
],
max_file_size: '10mb', //最大只能上传10mb的文件
prevent_duplicates: true //不允许选取重复文件
},
init: {
PostInit: function() {
document.getElementsByClassName('ossfile')[i].innerHTML = '';
// document.getElementById('postfiles').onclick = function() {
// set_upload_param(uploader, '', false);
// return false;
// };
uploader.bind('FilesAdded', function() {
set_upload_param(uploader, '', false,'appraises');
return false;
});
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
document.getElementsByClassName('ossfile')[i].innerHTML += '<div class="files_out" id="'+ file.id +'"><b></b>' +
'<div class="progress"><div class="progress-bar" style="width: 60px"></div></div>' +
'</div>';
});
},
BeforeUpload: function(up, file) {
check_object_radio();
set_upload_param(up, file.name, true);
},
UploadProgress: function(up, file) {
var d = document.getElementById(file.id);
d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
var prog = d.getElementsByTagName('div')[0];
var progBar = prog.getElementsByTagName('div')[0]
progBar.style.width = 2 * file.percent + 'px';
progBar.setAttribute('aria-valuenow', file.percent);
},
FileUploaded: function(up, file, info) {
if(info.status == 200) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<img data-src="' + get_uploaded_object_name(file.name) + '" src="' + hyhImgUrl(get_uploaded_object_name(file.name)) + '" />';
} else {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = info.response;
}
},
Error: function(up, err) {
if(err.code == -600) {
alert("\n选择的文件太大了");
} else if(err.code == -601) {
alert("\n选择的文件后缀不对");
} else if(err.code == -602) {
alert("\n这个文件已经上传过一遍了");
} else {
alert("\nError xml:" + err.response);
}
}
}
});
uploader.init();
});
} else {
console.log(data.status)
}
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(type);      
}  
}); 
$('.con').on('tap', '.star_a', function() {
if($(this).parent().attr('data-isPj') == 1) {
return;
}
$(this).children().addClass('star_on').removeClass('star_off');
$(this).prevAll().children().addClass('star_on').removeClass('star_off');
$(this).nextAll().children().addClass('star_off').removeClass('star_on');
$(this).parent().parent().attr('data-' + $(this).parent().parent().attr('data-class'), $(this).index() + 1);
})
$('.con').on('tap', '.tijiao', function() {
var goodsId = $(this).parent().attr('data-goodsId');
var goodsSpecId = $(this).parent().attr('data-goodsSpecId');
var orderId = $(this).parent().attr('data-orderId');
var orderGoodsId = $(this).parent().attr('data-orderGoodsId');
var timeScore = $(this).siblings('.row[data-class*=timeScore]').attr('data-timeScore');
var goodsScore = $(this).siblings('.row[data-class*=goodsScore]').attr('data-goodsScore');
var serviceScore = $(this).siblings('.row[data-class*=serviceScore]').attr('data-serviceScore');
var content = $(this).siblings('.purchase').children('textarea').val();
var that = $(this);
var imagesArr=[];
$(this).siblings('.purchase').children('.up_out').children('.ossfile').children('.files_out').children('b').children('img').each(function(){
imagesArr.push($(this).attr('data-src'))
})
var images = imagesArr.join(',');
if(timeScore == 0 || serviceScore == 0 || serviceScore == 0) {
alert('评分必须1-5分之间!');
return;
}
if(content.length < 3) {
alert('评论最少3个字!');
return;
}
that.attr('disabled', 'disabled');
mui.ajax(hyhUrl('app/Goodsappraises/add'), { 
headers: { 
"HYH-Token": token
},
data: {
goodsId: goodsId,
goodsSpecId: goodsSpecId,
orderId: orderId,
orderGoodsId: orderGoodsId,
timeScore: timeScore,
goodsScore: goodsScore,
serviceScore: serviceScore,
content: content,
images:images
},
dataType: 'json', //服务器返回json格式数据  
type: 'post', //HTTP请求类型  
timeout: 10000, //超时时间设置为10秒  
success: function(data) {           //服务器返回响应,根据响应结果,分析是否登录成功;  
var data = toJson(data);
alert(data.msg)
if(data.status == 1) {
location.reload();
} else {
console.log(data.status)
}
that.removeAttr('disabled');
},
error: function(xhr, type, errorThrown) {           //异常处理;  
// alert(type);      
}  
}); 
})
})