activity.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. $(function () {
  2. var _tel, _vfy
  3. let timer, count = 59
  4. const CHECKBXOX_SELECTOR = 'input[type="checkbox"]'
  5. const exerciseBookList = $('.select_wrokbook_content_con .select_dlist_box') // 练习册tabs
  6. let accessToken,userStatus,userState
  7. // 弹出练习册选择页
  8. $('#wrap_footer_btn').click(function (event) {
  9. $('.wrap_select').show();
  10. // 清空原选择
  11. $('#telphone').val('');
  12. $('#verify').val('');
  13. _tel = $('#telphone').val()
  14. if (_tel != '') {
  15. $('.select_register_yzm_tip2').hide();
  16. $('.select_register_yzm_tip1').show();
  17. }else{
  18. $('.select_register_yzm_tip1').hide();
  19. $('.select_register_yzm_tip2').show();
  20. }
  21. $("#telphone").focus(function(){
  22. $('.select_register_yzm_tip2').hide();
  23. $('.select_register_yzm_tip1').show();
  24. });
  25. $("#telphone").blur(function(){
  26. _tel = $('#telphone').val();
  27. if (!phoneVerify(_tel)) {
  28. layerNotify('手机号格式错误!', 1.52)
  29. return false
  30. }
  31. })
  32. //点击获取验证码
  33. $('#sendyzm').click(function () {
  34. const sendButton = $('#sendyzm');
  35. _tel = $('#telphone').val();
  36. if (_tel === '') {
  37. layerNotify('请输入手机号码', 1.38)
  38. return false
  39. }
  40. if (!phoneVerify(_tel)) {
  41. layerNotify('手机号格式错误!', 1.52)
  42. return false
  43. }
  44. if (_tel) {
  45. $('.select_register_yzm_tip2').hide();
  46. $('.select_register_yzm_tip1').show();
  47. // 发起Ajax请求
  48. $.ajax({
  49. url: sysUrl+"/weixin/activity/sendCode",
  50. type: "post",
  51. dataType: "json",
  52. ansyc: false,
  53. data: {
  54. phoneNum: _tel
  55. },
  56. success:function(data) {
  57. if(data && data.code == 999){
  58. layerNotify('验证码发送成功!')
  59. sendButton.prop('disabled', true)
  60. $('#sendyzm').html('重新发送(' + count + ')')
  61. timer = setInterval(function () {
  62. $('#sendyzm').html('重新发送(' + --count + ')')
  63. if (!count) {
  64. count = 59
  65. sendButton.prop('disabled', false)
  66. $('#sendyzm').html('重新发送')
  67. clearInterval(timer)
  68. }
  69. }, 1000)
  70. }else{
  71. layerNotify(data.msg, 1.52)
  72. }
  73. },
  74. error: function (error) {
  75. console.log(error)
  76. }
  77. })
  78. }
  79. })
  80. });
  81. // 切换科目
  82. $('#select_tlist_ul li').click(function(){
  83. var index = $('#select_tlist_ul li').index(this);
  84. $(this).addClass('ton').siblings().removeClass('ton');
  85. $('.select_wrokbook_content_con div.select_dlist_box').eq(index).show().siblings().hide();
  86. });
  87. $('.select_wrokbook_content_con').on('click', ({ target }) => {
  88. // console.log(target)
  89. // 点击练习册的复选框
  90. if (target.tagName === 'INPUT' && target.type === 'checkbox') {
  91. const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
  92. // console.log($(target).val());
  93. console.log(currentCheckedLength);
  94. if(currentCheckedLength > 0 && codeCheck){
  95. $('.select_payment_btn').prop('disabled', false)
  96. }else{
  97. $('.select_payment_btn').prop('disabled', true)
  98. }
  99. }
  100. });
  101. $('#verify').bind('input propertychange', function() {
  102. checkCode();
  103. });
  104. function checkCode(){
  105. var code = $("#verify").val();
  106. _tel = $('#telphone').val();
  107. if(_tel == ''){
  108. layerNotify('请输入电话号码!',2)
  109. return;
  110. }
  111. if(code.length===6){
  112. $("#verify").unbind();
  113. $.ajax({
  114. url: sysUrl+"/weixin/activity/checkCode",
  115. type: "post",
  116. dataType: "json",
  117. ansyc: false,
  118. data: {
  119. phoneNum: _tel,
  120. msgCode: code
  121. },
  122. success:function(data) {
  123. if(data && data.code == 999){
  124. layerNotify('验证码正确!')
  125. codeCheck = true;
  126. const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
  127. if(currentCheckedLength>1){
  128. $('.select_payment_btn').prop('disabled', false);
  129. }
  130. }else{
  131. layerNotify(data.msg)
  132. }
  133. $("#verify").bind('input propertychange',function () {
  134. checkCode();
  135. });
  136. },
  137. error: function (error) {
  138. console.log(error)
  139. $("#verify").bind('input propertychange',function () {
  140. checkCode();
  141. });
  142. }
  143. })
  144. }
  145. }
  146. //点击 免费报名
  147. $('.select_payment_btn').click(function () {
  148. const selectedValues = doGetCheckedIds()
  149. const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
  150. if(currentCheckedLength<1){
  151. return layerNotify('请至少选择一个练习册', 1.8)
  152. }
  153. console.log(selectedValues);
  154. pay(selectedValues);
  155. })
  156. //获取数据函数
  157. function doGetCheckedIds() {
  158. const _cacheData = {
  159. type: type,
  160. list: []
  161. }
  162. exerciseBookList.each((i, item) => {
  163. _cacheData.list[i] = {
  164. subject: item.dataset.subject,
  165. bookList: [...$(item).find('input[type="checkbox"]:checked').map((_, it) => it.value)]
  166. }
  167. })
  168. return _cacheData
  169. }
  170. function layerNotify(content, time = 2) {
  171. parent.layer.open({
  172. skin: 'msg',
  173. content,
  174. time,
  175. })
  176. }
  177. function phoneVerify(da) {
  178. var myreg = /^1[3456789]\d{9}$/
  179. return myreg.test(da)
  180. }
  181. function pay(selectedValues) {
  182. var know = '19.9体验活动';
  183. var details="小塾学伴19.9体验活动";
  184. $('.select_payment_btn').prop('disabled', true)
  185. $.ajax({
  186. url : sysUrl+"/weixin/payment/payService",
  187. type : 'post',
  188. data : {
  189. 'salesPriceId':salesPriceId,//购买类型id
  190. 'number':1,//数量
  191. 'libId' :libId,
  192. 'know' : know,
  193. 'details' : details,
  194. 'phone':$('#telphone').val(),
  195. 'school':JSON.stringify(selectedValues),
  196. 'isBuy':1,
  197. 'vipStatus':1
  198. },
  199. dataType: 'json',
  200. success: function(data){
  201. if(data && data.code == 999){
  202. var payInfo = eval(data.data); //数组
  203. var orderNo=payInfo.orderNo;
  204. WeixinJSBridge.invoke('getBrandWCPayRequest',{
  205. "appId" : payInfo.appId, //公众号名称,由商户传入
  206. "timeStamp": payInfo.timeStamp, //时间戳,自 1970 年以来的秒数
  207. "nonceStr" : payInfo.nonceStr, //随机串
  208. "package" : payInfo.packageValue, //商品包信息
  209. "signType" : payInfo.signType, //微信签名方式'MD5'
  210. "paySign" : payInfo.paySign //微信签名
  211. },function(res){
  212. if(res.err_msg == "get_brand_wcpay_request:ok" ) {
  213. $('.wrap_select').hide();
  214. $('#wrap_success'+type).show();
  215. // document.getElementById('success_img_id').setAttribute("src",imgurl+"/activity/images/qrcode"+type+".png");
  216. // $("#success_img_id").attr("src",imgurl + "/activity/images/qrcode"+type+".png");
  217. }else{
  218. $('.select_payment_btn').prop('disabled', false)
  219. }
  220. });
  221. }else{
  222. layerNotify("数据加载失败,请稍后再试!","2");
  223. $('.select_payment_btn').prop('disabled', false)
  224. }
  225. },
  226. error: function(XMLHttpRequest,textStatus,errorThrown) {
  227. layerNotify("网络或系统故障,请稍后再试!","2");
  228. $('.select_payment_btn').prop('disabled', false)
  229. }
  230. });
  231. }
  232. })