/** * 获取当天 * @param {*} str * @returns */ function getToday(str) { return str.replace(/year/gi, curruYear).replace(/month/gi, currMonth).replace(/date/gi, currDate); } /** * 处理区域选则 */ function areaCodeDomHandle() { $('[data-form-areacode]').on('click', function (e) { const selectDom = $(e.currentTarget).children('[data-areacode-select]'); selectDom[selectDom.is(':hidden') ? 'fadeIn' : 'fadeOut'](); }); $('[data-areacode-select]>li').on('click', function (e) { e.stopPropagation(); $('[data-areacode-value]').text('+' + e.currentTarget.children[0].textContent); $(e.currentTarget.parentNode).fadeOut(); }); } /** * * @param {JQuery<HTMLElement>} $dom jq dom * @param {string} text 可有可无 */ function copyWx($dom, _text) { let wx = ''; let text = ''; if (typeof $dom === 'string') { wx = $dom; } else if ($dom) { wx = $dom.parents('[id*=-popup]').find('.wx').text(); if (!wx) wx = $dom.attr('data-copy-wx'); if (!wx) wx = $dom.attr('data-to-wx'); } if (!wx) return; if (typeof _text === 'string') { text = _text; } else if ($dom && $dom.attr('data-wx-alter')) { text = $dom.attr('data-wx-alter'); } const element = document.createElement('input'); element.value = wx; document.body.append(element); element.select(); document.execCommand('Copy'); document.body.removeChild(element); alert(text || '复制成功!'); } function showSuccessModal() { var successPopup = document.querySelector('[id^=success-popup]'); if (successPopup) { const dynamicWeChatImg = $(successPopup).find('.dynamic-wechat-img'); const dynamicWeChat = $(successPopup).find('.dynamic-wechat'); // 动态二维码and动态微信 if ( (dynamicWeChatImg.length || dynamicWeChat.length) && window.pageData && window.pageData.weChatGroupID ) { const result = (Fn && Fn.IpRecord && Fn.IpRecord.GetCurrentWeChat(Number(window.pageData.weChatGroupID))) || {}; if (result.Id) { result.Qrcode && dynamicWeChatImg.attr('src', result.Qrcode); result.Wechat && dynamicWeChat.text(result.Wechat); Fn.IpRecord.AddUserRecord(result.Id, Fn.User.GetUserUIDBySenSors()); } } $(successPopup).fadeIn() } else { if (toPayCourse()) { return false } } } function toPayCourse() { // handle pay if (window.defaultPay && window.payConfig) { if (window.defaultPay.value || window.payConfig.value) { let value = window.defaultPay.value; let sort = window.defaultPay.sort; if (window.payConfig.value) { value = window.payConfig.value; sort = window.payConfig.sort; } if (!value) return; if (window.paytype == 'wechat' && sort === 'order') { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { toHref( 'https://www.acadsoc.com.cn/WebNew/user/MobilePay/AuthResponse.aspx?id=' + value + '&payid=4', ); } else { toHref( 'https://www.acadsoc.com.cn/WebNew/user/MobilePay/MobilePay.aspx?DesCid=' + value + '&RedPack=0&payid=11', ); } } else if (window.paytype == 'alipay' && sort === 'order') { toHref( 'https://www.acadsoc.com.cn/WebNew/user/MobilePay/MobilePay.aspx?DesCid=' + value + '&RedPack=0&payid=10', ); } else { toHref(value); } return false; } } return true; } // 阻止返回 function holdBack() { if (sessionStorage.getItem('mini_chat_show')) { return sessionStorage.removeItem('mini_chat_show'); } $('[id*=back-popup]').fadeIn(); history.pushState(null, null, document.URL); } // 监听客服,阻止弹出返回弹窗 function listenerChat() { if (!document.getElementById('mini_chat')) { setTimeout(() => { listenerChat(); }, 1500); } else { const obs = new MutationObserver((_target) => { if ($('#mini_chat').css('display') === 'block') { sessionStorage.setItem('mini_chat_show', 1); } }); obs.observe(document.getElementById('mini_chat'), { attributes: true }); } } function openModal(dom, _selector) { const id = $(dom).attr('data-popup-id'); const popup = $('#register-popup-' + id); const attrs = dom.attributes; // 更改字符 for (let i = 0; i < attrs.length; i++) { const name = attrs[i].name; const value = decodeURI(attrs[i].value); if (name.indexOf('data-popup-hash-') !== -1) { const ele = popup.find('[data-modal-hash=' + name.split('data-popup-hash-')[1] + ']'); if (!value) continue; if (value === 'false') { ele.hide(); continue; } else if (value === 'true') { ele.show(); continue; } if (!ele[0]) continue; setDomParams(ele[0], value); } } popup.fadeIn(); } function setDomParams(dom, value) { var ele = $(dom); switch (dom.nodeName) { case 'IMG': case 'VIDEO': if (ele.attr('src') !== value) { ele.attr('src', value); } break; case 'INPUT': if (ele.attr('placeholder') !== value) { ele.attr('placeholder', value); } break; default: if (ele.html() !== value) { ele.html(getToday(value)); } break; } } function toHref(href) { window.open(href); } $(function () { listenerChat(); areaCodeDomHandle(); }); window.registerCallback = function () { showSuccessModal(); };