sanshitijiao.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. $(function(){
  2. //填充下拉框
  3. querySignType();
  4. /* 复选框兼容 */
  5. $(document).on("click", ".input-group-pack > input[type=checkbox]", function() {
  6. var $cpChk = $(this).parent();
  7. if ($(this).attr("checked") == "checked") {
  8. $cpChk.removeClass("checked");
  9. $(this).removeAttr("checked");
  10. } else {
  11. $cpChk.addClass("checked");
  12. $(this).attr("checked", true);
  13. }
  14. });
  15. //弹窗
  16. $('.broadcast-icon').on('click',function(){
  17. $('.broadcast-shadow-panel').removeClass('c-hide');
  18. });
  19. $('.win-cancle').on('click',function(){
  20. $('.broadcast-shadow-panel').addClass('c-hide');
  21. });
  22. //从后台那边获取签名等信息
  23. var params = {};
  24. params.pageUrl = server + "wx/html/zxwz/html/teachers-consult-commit.html";
  25. $.ajax(server + "weixin/getSign", {
  26. data: params,
  27. dataType: "json",
  28. type: "post",
  29. success: function(res){
  30. if (res.status == 200) {
  31. var t = res.data.timestamp;
  32. var noncestr = res.data.noncestr;
  33. var signature = res.data.signature;
  34. wx.config({
  35. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  36. appId: appId, // 必填,公众号的唯一标识
  37. timestamp: t, // 必填,生成签名的时间戳
  38. nonceStr: noncestr, // 必填,生成签名的随机串
  39. signature: signature,// 必填,签名,见附录1
  40. jsApiList: [
  41. 'chooseImage',
  42. 'uploadImage'
  43. ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  44. });
  45. }
  46. else{
  47. dialog({
  48. title:'提示',
  49. skin:"ui-dialog ax-popup pror",
  50. content:"获取微信签名失败",
  51. ok: function (){}
  52. }).showModal();
  53. window.location.href = "online-consulting.html";
  54. }
  55. }
  56. });
  57. //提交咨询
  58. $("#commit").click(function() {
  59. var data = {};
  60. data.when = $("#txtWhen").val();
  61. data.type = Number($("#txtTypeCode").val());
  62. if($("#txtContent").val() == null)
  63. data.symptoms = "";
  64. else
  65. data.symptoms = utf16toEntities($("#txtContent").val().replace(/\s+/g,""));
  66. data.voice = "";
  67. if (validate(data)) {
  68. //验证通过执行
  69. dd.showModal();
  70. var images = getImages();
  71. if(images.length == 0){
  72. doSubmit(data);
  73. }
  74. else{
  75. uploadImage(data);
  76. }
  77. }
  78. });
  79. });
  80. //查询签约类别
  81. function querySignType(){
  82. d.show();
  83. sendPost('patient/sign_status', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess);
  84. }
  85. function querySignTypeFailed(res) {
  86. d.close();
  87. if (res && res.msg) {
  88. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  89. } else {
  90. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取签约类别失败'}).show();
  91. }
  92. }
  93. function querySignTypeSuccess(res) {
  94. if (res.status == 200) {
  95. var arr_key=[];
  96. var arr_value=[];
  97. var sign = Number(res.data);
  98. if(sign == 1){
  99. arr_key=[1];
  100. arr_value=['三师团队'];
  101. }
  102. else if(sign == 2){
  103. arr_key=[2];
  104. arr_value=['家庭医生'];
  105. }
  106. else if(sign == 3){
  107. arr_key=[1,2];
  108. arr_value=['三师团队', '家庭医生'];
  109. }
  110. else{
  111. arr_key=[];
  112. arr_value=[];
  113. }
  114. //签约类型
  115. var option1 = {
  116. theme: 'ios',
  117. lang: 'zh',
  118. formatValue: function(d) {
  119. return d.join(',');
  120. },
  121. customWheels: true,
  122. wheels: [
  123. [{
  124. keys: arr_key,
  125. values: arr_value
  126. }]
  127. ],
  128. onSelect: function(valueText, inst) {
  129. var dd = eval("[" + valueText + "]");
  130. $('#txtTypeCode').val(dd[0].keys);
  131. $('#txtTypeName').val(dd[0].values);
  132. $('#lbl_doctor').html(getSignDoctor(res,dd[0].keys));
  133. }
  134. };
  135. $('#txtTypeName').mobiscroll(option1);
  136. $('#txtTypeCode').val(option1.wheels[0][0].keys[0]);
  137. $('#txtTypeName').val(option1.wheels[0][0].values[0]);
  138. $('#lbl_doctor').html(getSignDoctor(res,option1.wheels[0][0].keys[0]));
  139. //选择发病时间
  140. $('li.ill-time').mobiscroll({
  141. theme: 'ios',
  142. lang: 'zh',
  143. formatValue: function(d) {
  144. return d.join(',');
  145. },
  146. customWheels: true,
  147. wheels: [
  148. [{
  149. keys: ['0', '1', '2', '3', '4', '5'],
  150. values: ['最近24小时', '最近一周', '最近三个月', '最近一年', '一年以上', '不清楚']
  151. }]
  152. ],
  153. onSelect: function(valueText, inst) {
  154. var dd = eval("[" + valueText + "]");
  155. $('input[data-time=illTime]').val(dd[0].values);
  156. }
  157. });
  158. d.close();
  159. } else {
  160. querySignTypeFailed(res);
  161. }
  162. }
  163. //获取医生信息
  164. function getSignDoctor(data,type){
  165. var doctor_name = "";
  166. var doctor_type = "";
  167. switch(Number(type))
  168. {
  169. case 1:
  170. doctor_type = data.teamDoctors;
  171. break;
  172. case 2:
  173. doctor_type = data.familyDoctors;
  174. break;
  175. default:
  176. break;
  177. }
  178. for(var i=0; i < doctor_type.length; i++){
  179. doctor_name += doctor_type[i] + ",";
  180. }
  181. if(doctor_name.length > 0){
  182. doctor_name = doctor_name.substring(0, doctor_name.length-1);
  183. }
  184. return doctor_name;
  185. }
  186. //验证信息
  187. function validate(data) {
  188. if (data.type == '') {
  189. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择签约类别'}).show();
  190. return false;
  191. }
  192. if (data.when == '') {
  193. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择发病时间'}).show();
  194. return false;
  195. }
  196. if (data.symptoms.length < 10) {
  197. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请至少用10个字描述您的症状'}).show();
  198. return false;
  199. }
  200. if (data.symptoms.length > 500) {
  201. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请在500字以内完成您的症状描述'}).show();
  202. return false;
  203. }
  204. if(!$(".input-group-pack > input[type=checkbox]").attr("checked")){
  205. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请勾选"我已阅读咨询说明"'}).show();
  206. return false;
  207. }
  208. return true;
  209. }
  210. var serverId = "";
  211. function chooseImage(){
  212. wx.chooseImage({
  213. count: 9-getImages().length,
  214. success: function (res) {
  215. for (var i in res.localIds) {
  216. appendFile(res.localIds[i]);
  217. }
  218. }
  219. });
  220. }
  221. function uploadImage(data){
  222. var images = getImages();
  223. if (images.length == 0) {
  224. return;
  225. }
  226. var i = 0, length = images.length;
  227. serverId = "";
  228. function upload() {
  229. wx.uploadImage({
  230. localId: images[i],
  231. isShowProgressTips: 0,
  232. success: function (res) {
  233. i++;
  234. if(serverId.length == 0){
  235. serverId = res.serverId;
  236. }
  237. else{
  238. serverId =serverId + "," + res.serverId;
  239. }
  240. if (i < length) {
  241. upload();
  242. }
  243. if(i == images.length){
  244. doSubmit(data);
  245. }
  246. },
  247. fail: function (res) {
  248. alert(JSON.stringify(res));
  249. }
  250. });
  251. }
  252. upload();
  253. }
  254. // 添加文件
  255. function appendFile(p) {
  256. var amount = getImages().length;
  257. if (amount >= 8) {
  258. $("#add_img_li").hide();
  259. }
  260. if(amount < 9){
  261. var $li = $('<li>' + ' <img src="' + p + '" data-src="' + p + '" onclick="viewImg(this)">' + ' <a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a>' + '</li>');
  262. var $add_img_li = $("#add_img_li");
  263. $add_img_li.before($li);
  264. $("#image_tips").text(getImages().length + "/9");
  265. }
  266. }
  267. //获取需要上传的图片
  268. function getImages() {
  269. var images = [];
  270. $("#img_ul").find("img").each(function() {
  271. var imgSrc = $(this).attr("data-src");
  272. images.push(imgSrc);
  273. });
  274. return images;
  275. }
  276. //查看图片
  277. function viewImg(dom) {
  278. var $img = $(dom);
  279. var thissrc = $img.attr("data-src");
  280. var mWid = $(window).width();
  281. var mHei = $(window).height();
  282. 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>';
  283. $("body").append(nHtml);
  284. $(".delimgpop").click(function() {
  285. $(this).remove()
  286. });
  287. };
  288. //删除图片
  289. function delImg(dom) {
  290. var $li = $(dom).parent();
  291. $li.remove();
  292. $("#image_tips").text(getImages().length + "/9");
  293. var amount = getImages().length;
  294. if(amount <= 8){
  295. $("#add_img_li").show();
  296. }
  297. return;
  298. }
  299. //微信sdk配置出错
  300. wx.error(function (res) {
  301. alert("wx.error:" + res.errMsg);
  302. });
  303. //提交咨询
  304. function doSubmit(data) {
  305. data.mediaIds = serverId;
  306. sendPost('patient/consult/add', data, 'json', 'post', submitFailed, submitSuccess);
  307. }
  308. function submitFailed(res) {
  309. dd.close();
  310. if (res && res.msg) {
  311. dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  312. } else {
  313. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'提交失败'}).show();
  314. }
  315. }
  316. function submitSuccess(res) {
  317. if (res.status == 200) {
  318. dd.close();
  319. window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=http%3a%2f%2f" + weixinUrl + "%2f" + urlName + "%2fwx%2fhtml%2fzxwz%2fhtml%2fteachers-consulting-list.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  320. //window.location.href = "vedio-consulting-commit-success.html?type=2";
  321. } else {
  322. submitFailed(res);
  323. }
  324. }
  325. //function voicePop(n) {
  326. // $(".win-broadcast,.win-broadcast-mb").show();
  327. // $("#voice-finish").click(function() {
  328. // $("#voice" + n).show();
  329. // $(".win-broadcast,.win-broadcast-mb").hide();
  330. // });
  331. //}
  332. //
  333. //function voicePopClose() {
  334. // $(".win-broadcast,.win-broadcast-mb").hide();
  335. //}