123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- 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 = '<div class="add-img2"><img class="upload_img" src="'+url+'" width="65" height="65">'+
- '<div class="delete-icon"><img src="../images/delete_icon.png" width="18"></div></div>';
- $("#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<imgUrls.length; i++) {
- if(imgUrls[i] == url) {
- imgUrls.splice(i, 1);
- break;
- }
- }
- for(var j=0; j<uploadImages.length; j++){
- if(uploadImages[j] == url){
- uploadImages.splice(j, 1);
- break;
- }
- }
- img_count --;
- $this.parent().remove();
- });
- //选择类型
- $('.j-select-type').on('tap',function(){
- var $this = $(this);
- $('#selected_name').text($this.find('a').text());
- selectType = $this.data('type');
- })
-
- //action 按钮
- $action_btn.on('tap', function(){
- var content = $.trim($("#question").val()),
- telephone = $.trim($('#phone').val()),
- name = $.trim($('#name').val()),
- idcard = $.trim($('#idcard').val());
-
- var isValid = validate();
- if(isValid){
- //先将新增的图片上传然后再处理其他业务
- plus.nativeUI.showWaiting();
- var params = {};
- params.description = content;
- params.type = selectType*1;
- params.name = name;
- params.idcard = idcard;
- params.phone = telephone;
- uploadImg(function(){
- params.images = imgUrls ? imgUrls.join(","): "";
- sendPost('doctorFeedback/feedback/saveAppeal', params, null, function(res){
- if(res.status == 200){
- mui.toast('感谢您的反馈');
- setTimeout(function(){
- mui.back();
- },1000)
- }else{
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }, 'POST', '', true);
- })
- }
- });
-
- //申诉记录按钮
- $(".header-link").on('click', function(){
- openWebview('account-back-list.html');
- })
- }
|