feedback.js 4.6 KB

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