activity-detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var pagetype=56;
  3. var unionId,
  4. taskCode;
  5. var actObj = {};
  6. var activityId, taskId;
  7. (function(){
  8. var swiperLength=$(".hdjl-swiper .swiper-wrapper").children().length;
  9. if(swiperLength>=3){
  10. var swiper = new Swiper('.hdjl-swiper', {
  11. pagination: '.swiper-pagination',
  12. paginationClickable: true,
  13. spaceBetween: 15,
  14. slidesPerView:3
  15. });
  16. }
  17. })();
  18. (function(){
  19. checkUserAgent();
  20. var useAgent=JSON.parse(window.localStorage.getItem(agentName));
  21. var request=GetRequest();
  22. var activity_id=request['activity_id']||'';
  23. var userData=[];
  24. initPage();
  25. getUnionId();
  26. function initPage(){
  27. var params={
  28. page:1,
  29. size:1,
  30. task:JSON.stringify({"id":activity_id}),
  31. }
  32. sendPost('patient/healthBank/selectTask', params, 'json', 'post',function(){
  33. airDialog("系统繁忙,请稍后再试!")
  34. },function(res){
  35. if(res.status==200){
  36. actObj = res.data && res.data.detailModelList && res.data.detailModelList[0] || [];
  37. taskCode = actObj.taskDOS && actObj.taskDOS[0] && actObj.taskDOS[0].taskCode || "";
  38. activityId = actObj.taskPatientDetailDOS && actObj.taskPatientDetailDOS[0] && actObj.taskPatientDetailDOS[0].activityId || "";
  39. taskId = actObj.taskPatientDetailDOS && actObj.taskPatientDetailDOS[0] && actObj.taskPatientDetailDOS[0].taskId || "";
  40. var html =template('page_tmpl',{activity:actObj})
  41. $('.activity-detail').html(html);
  42. var swiperLength=$(".hdjl-swiper .swiper-wrapper").children().length;
  43. if(swiperLength>=3){
  44. var swiper = new Swiper('.hdjl-swiper', {
  45. pagination: '.swiper-pagination',
  46. paginationClickable: true,
  47. spaceBetween: 15,
  48. slidesPerView:3
  49. });
  50. }
  51. // getUserList()
  52. actObj && (!actObj.taskPatientDetailDOS.length) && getUserList();
  53. }else{
  54. $('.activity-swiper').find('.div-no-info').removeClass('c-hide');
  55. }
  56. })
  57. }
  58. function getUserList(){
  59. sendPost('patient/healthBank/selectByOpenId', {}, 'json', 'post',function(){
  60. airDialog("系统繁忙,请稍后再试!");
  61. },function(res){
  62. if(res.status==200){
  63. userData = res.data && res.data.patientList || [];
  64. $('.user-select').append(template('user_option_tmpl',{data:userData}))
  65. var item=userData[0];
  66. $('.select-user-info').html(template('user_info_tmpl',{item:item}))
  67. }else{
  68. airDialog(res.msg||"获取报名列表失败")
  69. }
  70. })
  71. }
  72. $('.user-select').on('change',function(){
  73. $('.select-user-info').html(template('user_info_tmpl',{item:userData[$(event.target).children('option:selected').index()]}))
  74. });
  75. // 报名
  76. $('.activity-detail').on('click','.join',function(){
  77. showModel();
  78. });
  79. // 活动入口
  80. $('.activity-detail').on('click','.act-into',function(){
  81. var nowTimes = new Date().getTime();
  82. var times = Date.parse(new Date(actObj.startTime.replace(/-/g, "/")));
  83. if(nowTimes < times) {
  84. airDialog("本活动将于 " + actObj.startTime + " 时间开放,请按时参加~")
  85. } else {
  86. // 小程序jssdk参数配置
  87. var appid = "wx0e663ce069b5170c",
  88. secret = "02de788ffea28f2aa3b9bf10312ab05e";
  89. $jssdk = new JSSDK(appid, secret);
  90. console.log($jssdk)
  91. $signPackage = $jssdk.GetSignPackage();
  92. // 尝试跳转
  93. var programUrl = "pages/index/index?activityId=" + activityId + "&taskId=" + taskId;
  94. wx.miniProgram.navigateTo({url: programUrl})
  95. // airDialog("恭喜您!活动入口消息已发送至公众号,请关闭健康银行前去参加~")
  96. }
  97. });
  98. $('.i-modal-close, .i-modal-layer').on('click',function(){
  99. hideModel();
  100. });
  101. // 阻止滑动
  102. $(".i-modal").on("touchmove", function(e) {
  103. e.preventDefault();
  104. });
  105. $('.comfirm-btn').on('click',function(){
  106. hideModel();
  107. var select=$('.user-select').children('option:selected')
  108. var patientId=select.data('code');
  109. var patientIdcard=select.data('card');
  110. var params={
  111. taskPatientDetail:JSON.stringify({
  112. "saasId":"dev",
  113. "patientId":patientId,
  114. "patientIdcard":patientIdcard,
  115. "doctorId":"",
  116. "activityId":activity_id,
  117. "unionId": unionId,
  118. "taskCode": taskCode
  119. })
  120. }
  121. sendPost('patient/healthBank/attendTask', params, 'json', 'post',function(){
  122. airDialog("系统繁忙,请稍后再试!");
  123. },function(res){
  124. airDialog(res.data && res.data.message || res.msg);
  125. if(!res.data.message) initPage();
  126. })
  127. })
  128. function hideModel(){
  129. $(".comfirm-info").fadeOut();
  130. $('body').removeClass("i-modal-open");
  131. }
  132. function showModel(){
  133. $(".comfirm-info").fadeIn();
  134. $('body').addClass("i-modal-open");//禁止屏幕滚动
  135. }
  136. })();
  137. function getUnionId(){
  138. var openid = JSON.parse(window.localStorage.getItem("OpenidAgent")).openid;
  139. var url = "weixin/getUnionidByOpenid",
  140. params = {
  141. openid: openid
  142. };
  143. sendPost(url, params, 'json', 'GET', function(res){
  144. airDialog(res.msg);
  145. }, function(res){
  146. if(res.status == 200){
  147. unionId = res.unionid;
  148. }else{
  149. airDialog(res.msg);
  150. }
  151. })
  152. }
  153. function airDialog(content){
  154. dialog({contentType:'tipsbox',top:true, skin:'bk-popup' , content:content}).show();
  155. }
  156. template.helper("getBigImage", function(str){
  157. if(str){
  158. return getImgUrl(str);
  159. }else{
  160. return "../images/morenhuodong_banner02_img.png";
  161. }
  162. })