var uploadImages = [],
imgUrls = [],
selectType = '',
img_count = 0,
$action_btn = $("#action_btn");
mui.init();
mui.plusReady(function(){
var self = plus.webview.currentWebview();
bindEvents();
});
function getPhoto(url){
uploadImages.push(url);
fillImage(url);
}
function fillImage(url){
img_count ++;
var html = '
'+
'
';
$("#img_wrap").append(html);
}
//上传图片
var upload_count = 0;
function uploadImg(cb){
var len = uploadImages.length;
if(upload_count < len){
var task = plus.uploader.createUpload(server + "/upload/image", {
method: "post"
}, function(t, sta) {
if(sta == 200) {
var msg = t.responseText;
var oImg = JSON.parse(msg);
var imgUrl = oImg.urls;
var re = new RegExp("\\\\", "g");
imgUrl = imgUrl.replace(re, "/");
imgUrls.push(imgUrl);
uploadImg(cb);
} else {
mui.toast("上传图片失败!");
plus.nativeUI.closeWaiting();
}
});
var url = uploadImages[upload_count];
upload_count ++;
task.addFile(url, {});
task.start();
}else{
cb();
}
}
function validate(){
var content = $.trim($("#question").val()),
telephone = $.trim($('#phone').val()),
name = $.trim($('#name').val()),
idcard = $.trim($('#idcard').val());
if(!selectType){
mui.toast("请选择类型");
return false;
}
if(!content || content.length == 0){
mui.toast("问题和意见不能为空");
return false;
}
if(!name || name.length == 0){
mui.toast("请输入姓名");
return false;
}
if(!idcard || idcard.length == 0){
mui.toast("请输入身份证号");
return false;
}else{
if (!/^[1-9][0-9]{5}(19[0-9]{2}|200[0-9]|2010)(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])[0-9]{3}[0-9xX]$/i.test(idcard)) {
mui.toast("身份证号格式错误");
return false;
}
}
if(!telephone || telephone.length == 0){
mui.toast("手机号码不能为空");
return false;
}else{
if(!isphone(telephone)){
mui.toast("请输入有效的手机号码");
return false;
}
}
return true;
}
function bindEvents(){
//输入框内容限制
$("#question").on('keyup', function(){
var text = $(this).val();
$("#text_count").text(text.length);
});
$("#add_pic").on('click', function(){
if(img_count < 3){
getAutoRecCompressImageLocalPath(getPhoto,3-img_count);
}else{
dialog({
contentType: 'tipsbox',
skin: 'bk-popup',
content: '最多只能上传3张图片',
closeTime: 2000
}).showModal();
}
});
//图片删除功能
$(document).on('tap', '.delete-icon', function(){
var $this = $(this);
//获得图片路径
var url = $this.parent().find(".upload_img").attr("src");
for(var i=0; i