feedback.js 7.0 KB

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