account_back.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. var uploadImages = [],
  2. imgUrls = [],
  3. selectType = '',
  4. img_count = 0,
  5. $action_btn = $("#action_btn");
  6. mui.init();
  7. mui.plusReady(function(){
  8. var self = plus.webview.currentWebview();
  9. bindEvents();
  10. });
  11. function getPhoto(url){
  12. uploadImages.push(url);
  13. fillImage(url);
  14. }
  15. function fillImage(url){
  16. img_count ++;
  17. var html = '<div class="add-img2"><img class="upload_img" src="'+url+'" width="65" height="65">'+
  18. '<div class="delete-icon"><img src="../images/delete_icon.png" width="18"></div></div>';
  19. $("#img_wrap").append(html);
  20. }
  21. //上传图片
  22. var upload_count = 0;
  23. function uploadImg(cb){
  24. var len = uploadImages.length;
  25. if(upload_count < len){
  26. var task = plus.uploader.createUpload(server + "/upload/image", {
  27. method: "post"
  28. }, function(t, sta) {
  29. if(sta == 200) {
  30. var msg = t.responseText;
  31. var oImg = JSON.parse(msg);
  32. var imgUrl = oImg.urls;
  33. var re = new RegExp("\\\\", "g");
  34. imgUrl = imgUrl.replace(re, "/");
  35. imgUrls.push(imgUrl);
  36. uploadImg(cb);
  37. } else {
  38. mui.toast("上传图片失败!");
  39. plus.nativeUI.closeWaiting();
  40. }
  41. });
  42. var url = uploadImages[upload_count];
  43. upload_count ++;
  44. task.addFile(url, {});
  45. task.start();
  46. }else{
  47. cb();
  48. }
  49. }
  50. function validate(){
  51. var content = $.trim($("#question").val()),
  52. telephone = $.trim($('#phone').val()),
  53. name = $.trim($('#name').val()),
  54. idcard = $.trim($('#idcard').val());
  55. if(!selectType){
  56. mui.toast("请选择类型");
  57. return false;
  58. }
  59. if(!content || content.length == 0){
  60. mui.toast("问题和意见不能为空");
  61. return false;
  62. }
  63. if(!name || name.length == 0){
  64. mui.toast("请输入姓名");
  65. return false;
  66. }
  67. if(!idcard || idcard.length == 0){
  68. mui.toast("请输入身份证号");
  69. return false;
  70. }else{
  71. 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)) {
  72. mui.toast("身份证号格式错误");
  73. return false;
  74. }
  75. }
  76. if(!telephone || telephone.length == 0){
  77. mui.toast("手机号码不能为空");
  78. return false;
  79. }else{
  80. if(!isphone(telephone)){
  81. mui.toast("请输入有效的手机号码");
  82. return false;
  83. }
  84. }
  85. return true;
  86. }
  87. function bindEvents(){
  88. //输入框内容限制
  89. $("#question").on('keyup', function(){
  90. var text = $(this).val();
  91. $("#text_count").text(text.length);
  92. });
  93. $("#add_pic").on('click', function(){
  94. if(img_count < 3){
  95. getAutoRecCompressImageLocalPath(getPhoto,3-img_count);
  96. }else{
  97. dialog({
  98. contentType: 'tipsbox',
  99. skin: 'bk-popup',
  100. content: '最多只能上传3张图片',
  101. closeTime: 2000
  102. }).showModal();
  103. }
  104. });
  105. //图片删除功能
  106. $(document).on('tap', '.delete-icon', function(){
  107. var $this = $(this);
  108. //获得图片路径
  109. var url = $this.parent().find(".upload_img").attr("src");
  110. for(var i=0; i<imgUrls.length; i++) {
  111. if(imgUrls[i] == url) {
  112. imgUrls.splice(i, 1);
  113. break;
  114. }
  115. }
  116. for(var j=0; j<uploadImages.length; j++){
  117. if(uploadImages[j] == url){
  118. uploadImages.splice(j, 1);
  119. break;
  120. }
  121. }
  122. img_count --;
  123. $this.parent().remove();
  124. });
  125. //选择类型
  126. $('.j-select-type').on('tap',function(){
  127. var $this = $(this);
  128. $('#selected_name').text($this.find('a').text());
  129. selectType = $this.data('type');
  130. })
  131. //action 按钮
  132. $action_btn.on('tap', function(){
  133. var content = $.trim($("#question").val()),
  134. telephone = $.trim($('#phone').val()),
  135. name = $.trim($('#name').val()),
  136. idcard = $.trim($('#idcard').val());
  137. var isValid = validate();
  138. if(isValid){
  139. //先将新增的图片上传然后再处理其他业务
  140. plus.nativeUI.showWaiting();
  141. var params = {};
  142. params.description = content;
  143. params.type = selectType*1;
  144. params.name = name;
  145. params.idcard = idcard;
  146. params.phone = telephone;
  147. uploadImg(function(){
  148. params.images = imgUrls ? imgUrls.join(","): "";
  149. sendPost('doctorFeedback/feedback/saveAppeal', params, null, function(res){
  150. if(res.status == 200){
  151. mui.toast('感谢您的反馈');
  152. setTimeout(function(){
  153. mui.back();
  154. },1000)
  155. }else{
  156. mui.toast(res.msg);
  157. }
  158. plus.nativeUI.closeWaiting();
  159. }, 'POST', '', true);
  160. })
  161. }
  162. });
  163. //申诉记录按钮
  164. $(".header-link").on('click', function(){
  165. openWebview('account-back-list.html');
  166. })
  167. }