feedback.js 6.9 KB

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