123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- $(function () {
- var _tel, _vfy
- let timer, count = 59
- const CHECKBXOX_SELECTOR = 'input[type="checkbox"]'
- const exerciseBookList = $('.select_wrokbook_content_con .select_dlist_box') // 练习册tabs
- let accessToken,userStatus,userState
- // 弹出练习册选择页
- $('#wrap_footer_btn').click(function (event) {
- $('.wrap_select').show();
- // 清空原选择
- $('#telphone').val('');
- $('#verify').val('');
- _tel = $('#telphone').val()
- if (_tel != '') {
- $('.select_register_yzm_tip2').hide();
- $('.select_register_yzm_tip1').show();
- }else{
- $('.select_register_yzm_tip1').hide();
- $('.select_register_yzm_tip2').show();
- }
- $("#telphone").focus(function(){
- $('.select_register_yzm_tip2').hide();
- $('.select_register_yzm_tip1').show();
- });
- $("#telphone").blur(function(){
- _tel = $('#telphone').val();
- if (!phoneVerify(_tel)) {
- layerNotify('手机号格式错误!', 1.52)
- return false
- }
- })
- //点击获取验证码
- $('#sendyzm').click(function () {
- const sendButton = $('#sendyzm');
- _tel = $('#telphone').val();
- if (_tel === '') {
- layerNotify('请输入手机号码', 1.38)
- return false
- }
- if (!phoneVerify(_tel)) {
- layerNotify('手机号格式错误!', 1.52)
- return false
- }
- if (_tel) {
- $('.select_register_yzm_tip2').hide();
- $('.select_register_yzm_tip1').show();
- // 发起Ajax请求
- $.ajax({
- url: sysUrl+"/weixin/activity/sendCode",
- type: "post",
- dataType: "json",
- ansyc: false,
- data: {
- phoneNum: _tel
- },
- success:function(data) {
- if(data && data.code == 999){
- layerNotify('验证码发送成功!',2)
- sendButton.prop('disabled', true)
- $('#sendyzm').html('重新发送(' + count + ')')
- timer = setInterval(function () {
- $('#sendyzm').html('重新发送(' + --count + ')')
- if (!count) {
- count = 59
- sendButton.prop('disabled', false)
- $('#sendyzm').html('重新发送')
- clearInterval(timer)
- }
- }, 1000)
- }else{
- layerNotify(data.msg, 3)
- }
- },
- error: function (error) {
- console.log(error)
- }
- })
- }
- })
- });
- // 切换科目
- $('#select_tlist_ul li').click(function(){
- var index = $('#select_tlist_ul li').index(this);
- $(this).addClass('ton').siblings().removeClass('ton');
- $('.select_wrokbook_content_con div.select_dlist_box').eq(index).show().siblings().hide();
- });
- $('.select_wrokbook_content_con').on('click', ({ target }) => {
- // console.log(target)
- // 点击练习册的复选框
- if (target.tagName === 'INPUT' && target.type === 'checkbox') {
- const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
- // console.log($(target).val());
- console.log(currentCheckedLength);
- if(currentCheckedLength>0 && codeCheck){
- $('.select_payment_btn').prop('disabled', false)
- }else{
- $('.select_payment_btn').prop('disabled', true)
- }
- }
- });
- $('#verify').bind('input propertychange', function() {
- checkCode();
- });
- function checkCode(){
- var code = $("#verify").val();
- _tel = $('#telphone').val();
- if(_tel == ''){
- layerNotify('请输入电话号码!',2)
- return;
- }
- if(code.length===6){
- $("#verify").unbind();
- $.ajax({
- url: sysUrl+"/weixin/activity/checkCode",
- type: "post",
- dataType: "json",
- ansyc: false,
- data: {
- phoneNum: _tel,
- msgCode: code,
- type:type
- },
- success:function(data) {
- if(data && data.code == 999){
- layerNotify('验证码正确!')
- codeCheck = true;
- const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
- if(currentCheckedLength >0){
- $('.select_payment_btn').prop('disabled', false);
- }
- }else{
- layerNotify(data.msg,3)
- }
- $("#verify").bind('input propertychange',function () {
- checkCode();
- });
- },
- error: function (error) {
- console.log(error)
- $("#verify").bind('input propertychange',function () {
- checkCode();
- });
- }
- })
- }
- }
- //点击 免费报名
- $('.select_payment_btn').click(function () {
- const selectedValues = doGetCheckedIds()
- const currentCheckedLength = $(CHECKBXOX_SELECTOR + ':checked').length
- if(currentCheckedLength<1){
- return layerNotify('请至少选择一个练习册', 1.8)
- }
- console.log(selectedValues);
- pay(selectedValues);
- })
- //获取数据函数
- function doGetCheckedIds() {
- const _cacheData = {
- type: type,
- list: []
- }
- exerciseBookList.each((i, item) => {
- _cacheData.list[i] = {
- subject: item.dataset.subject,
- bookList: [...$(item).find('input[type="checkbox"]:checked').map((_, it) => it.value)]
- }
- })
- return _cacheData
- }
- function layerNotify(content, time = 2) {
- parent.layer.open({
- skin: 'msg',
- content,
- time,
- })
- }
- function phoneVerify(da) {
- var myreg = /^1[3456789]\d{9}$/
- return myreg.test(da)
- }
- function pay(selectedValues) {
- var know = '9.9体验活动';
- var details="小塾学伴9.9体验活动";
- $('.select_payment_btn').prop('disabled', true)
- $.ajax({
- url : sysUrl+"/weixin/payment/payService",
- type : 'post',
- data : {
- 'salesPriceId':salesPriceId,//购买类型id
- 'number':1,//数量
- 'libId' :libId,
- 'know' : know,
- 'details' : details,
- 'phone':$('#telphone').val(),
- 'school':JSON.stringify(selectedValues),
- 'isBuy':1,
- 'vipStatus':1
- },
- dataType: 'json',
- success: function(data){
- if(data && data.code == 999){
- var payInfo = eval(data.data); //数组
- var orderNo=payInfo.orderNo;
- WeixinJSBridge.invoke('getBrandWCPayRequest',{
- "appId" : payInfo.appId, //公众号名称,由商户传入
- "timeStamp": payInfo.timeStamp, //时间戳,自 1970 年以来的秒数
- "nonceStr" : payInfo.nonceStr, //随机串
- "package" : payInfo.packageValue, //商品包信息
- "signType" : payInfo.signType, //微信签名方式'MD5'
- "paySign" : payInfo.paySign //微信签名
- },function(res){
- if(res.err_msg == "get_brand_wcpay_request:ok" ) {
- $('.wrap_select').hide();
- $('#wrap_success'+type).show();
- // document.getElementById('success_img_id').setAttribute("src",imgurl+"/activity/images/qrcode"+type+".png");
- // $("#success_img_id").attr("src",imgurl + "/activity/images/qrcode"+type+".png");
- }else{
- $('.select_payment_btn').prop('disabled', false)
- }
- });
- }else{
- layerNotify("数据加载失败,请稍后再试!","2");
- $('.select_payment_btn').prop('disabled', false)
- }
- },
- error: function(XMLHttpRequest,textStatus,errorThrown) {
- layerNotify("网络或系统故障,请稍后再试!","2");
- $('.select_payment_btn').prop('disabled', false)
- }
- });
- }
- })
|