account_back.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. var selectType = '',//选择类型
  2. suggestContent = '',
  3. teleContent = '',
  4. serverId = "",//储存上传后图片地址
  5. $action_btn = $("#action_btn");
  6. var d = dialog({contentType:'load', skin:'bk-popup'});
  7. var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'});
  8. $(function(){
  9. //从后台那边获取签名等信息
  10. var params = {};
  11. params.pageUrl = window.location.href;
  12. $.ajax(server + "weixin/getSign", {
  13. data: params,
  14. dataType: "json",
  15. type: "post",
  16. success: function(res){
  17. if (res.status == 200) {
  18. var t = res.data.timestamp;
  19. var noncestr = res.data.noncestr;
  20. var signature = res.data.signature;
  21. wx.config({
  22. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  23. appId: appId, // 必填,公众号的唯一标识
  24. timestamp: t, // 必填,生成签名的时间戳
  25. nonceStr: noncestr, // 必填,生成签名的随机串
  26. signature: signature,// 必填,签名,见附录1
  27. jsApiList: [
  28. 'chooseImage',
  29. 'uploadImage'
  30. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  31. });
  32. }
  33. else{
  34. dialog({
  35. title:'提示',
  36. skin:"ui-dialog ax-popup pror",
  37. content:"获取微信签名失败",
  38. ok: function (){}
  39. }).showModal();
  40. }
  41. }
  42. });
  43. })
  44. function chooseImage(){
  45. wx.chooseImage({
  46. count: 3-getImages().length,
  47. success: function (res) {
  48. for (var i in res.localIds) {
  49. appendFile(res.localIds[i]);
  50. }
  51. }
  52. });
  53. }
  54. function uploadImage(){
  55. var images = getImages();
  56. if (images.length == 0) {
  57. return;
  58. }
  59. var i = 0, length = images.length;
  60. serverId = "";
  61. function upload() {
  62. wx.uploadImage({
  63. localId: images[i],
  64. isShowProgressTips: 0,
  65. success: function (res) {
  66. i++;
  67. if(serverId.length == 0){
  68. serverId = res.serverId;
  69. }
  70. else{
  71. serverId =serverId + "," + res.serverId;
  72. }
  73. if (i < length) {
  74. upload();
  75. }
  76. if(i == length){
  77. doSubmit();
  78. }
  79. },
  80. fail: function (res) {
  81. dd.close();
  82. alert(JSON.stringify(res));
  83. }
  84. });
  85. }
  86. upload();
  87. }
  88. // 添加文件
  89. function appendFile(p) {
  90. var amount = getImages().length;
  91. if (amount >= 2) {
  92. $("#add_img_li").hide();
  93. }
  94. if(amount < 3){
  95. var $li = $('<li><img class="img-src" src="'+p+'" data-src="'+p+'" onclick="viewImg(this)" width="65" ><a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a></li>');
  96. var $add_img_li = $("#add_img_li");
  97. $add_img_li.before($li);
  98. }
  99. }
  100. //获取需要上传的图片
  101. function getImages() {
  102. var images=[];
  103. $("#img_ul").find(".img-src").each(function() {
  104. var imgSrc = $(this).data("src");
  105. images.push(imgSrc);
  106. });
  107. return images;
  108. }
  109. //查看图片
  110. function viewImg(dom) {
  111. var $img = $(dom);
  112. var thissrc = $img.attr("data-src");
  113. var mWid = $(window).width();
  114. var mHei = $(window).height();
  115. var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
  116. $("body").append(nHtml);
  117. $(".delimgpop").click(function() {
  118. $(this).remove()
  119. });
  120. };
  121. //删除图片
  122. function delImg(dom) {
  123. var $li = $(dom).parent();
  124. $li.remove();
  125. var amount = getImages().length;
  126. if(amount <= 2){
  127. $("#add_img_li").show();
  128. }
  129. return;
  130. }
  131. //微信sdk配置出错
  132. wx.error(function (res) {
  133. alert("wx.error:" + res.errMsg);
  134. });
  135. //提交
  136. function doSubmit() {
  137. var name = $("#name").val(),
  138. idcard = $("#idcard").val();
  139. var params = {
  140. description: suggestContent,
  141. type: selectType*1,
  142. phone: teleContent,
  143. name: name,
  144. idcard: idcard,
  145. images: serverId ? serverId: ""
  146. };
  147. sendPost("/patientFeedback/feedback/saveAppeal", params,'json','POST',queryFail,querySuccess);
  148. }
  149. function queryFail(res){
  150. dd.close();
  151. if (res && res.msg) {
  152. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:res.msg}).show();
  153. }
  154. }
  155. function querySuccess(res){
  156. dd.close();
  157. if(res.status == 200){
  158. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'感谢您的反馈'}).show();
  159. setTimeout(function(){
  160. mui.back();
  161. },1000)
  162. }else{
  163. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'提交失败'}).show();
  164. }
  165. }
  166. function validate(){
  167. var content = $.trim($("#question").val()),
  168. telephone = $.trim($('#phone').val()),
  169. name = $.trim($('#name').val()),
  170. idcard = $.trim($('#idcard').val());
  171. if(!selectType){
  172. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请选择类型'}).show();
  173. return false;
  174. }
  175. if(!content || content.length == 0){
  176. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'问题和意见不能为空'}).show();
  177. return false;
  178. }
  179. if(!name || name.length == 0){
  180. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入姓名'}).show();
  181. return false;
  182. }
  183. if(!idcard || idcard.length == 0){
  184. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入身份证号'}).show();
  185. return false;
  186. }else{
  187. 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)) {
  188. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'身份证号格式错误'}).show();
  189. return false;
  190. }
  191. }
  192. if(!telephone || telephone.length == 0){
  193. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'手机号码不能为空'}).show();
  194. return false;
  195. }else{
  196. if(!/^(17[0-9]|13[0-9]|14[0-9]|15[0-9]|18[0-9])\d{8}$/i.test(telephone)){
  197. dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请输入有效的手机号码'}).show();
  198. return false;
  199. }
  200. }
  201. return true;
  202. }
  203. //选择类型
  204. $('.j-select-type').on('tap',function(){
  205. mui('#popover').popover('toggle');
  206. var $this = $(this);
  207. $('#selected_name').text($this.find('a').text());
  208. selectType = $this.data('type');
  209. });
  210. //action 按钮
  211. $action_btn.on('tap', function(){
  212. suggestContent = $.trim($("#question").val()),
  213. teleContent = $.trim($('#phone').val());
  214. var isValid = validate();
  215. if(isValid){
  216. //先将新增的图片上传然后再处理其他业务
  217. dd.showModal();
  218. var images = getImages();
  219. if(images.length > 0){
  220. uploadImage();
  221. }
  222. else{
  223. serverId = '';
  224. doSubmit();
  225. }
  226. }
  227. })
  228. $("#goToHistory").on('click', function(){
  229. window.location.href = "account-back-list.html";
  230. })