123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- /*封装一些公用的事件或者公用的方法*/
- /*定义的一个命名空间*/
- window.my = {};
- /* 获取url参数 */
- my.getURLCode = function (){
- var search = location.search.length > 0 ? location.search.substring(1) : '',
- args = {},
- items = search.length ? search.split('&') : [],
- item = null,
- name = null,
- value = null,
- i = 0,
- len = items.length,
- data = '';
- for (i = 0; i < len; i++) {
- item = items[i].split('=');
- name = decodeURIComponent(item[0]);
- value = decodeURIComponent(item[1]);
- if (item.length) {args[name] = value }
- }
- return args;
- }
- /*copy to clipboard*/
- function toCopy(copy01,copy02,cb) {
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- //区分iPhone设备
- window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
- var Url2=document.getElementById(copy02);//要复制文字的节点
- var range = document.createRange();
- // 选中需要复制的节点
- range.selectNode(Url2);
- // 执行选中元素
- window.getSelection().addRange(range);
- // 执行 copy 操作
- var successful = document.execCommand('copy');
- // 移除选中的元素
- window.getSelection().removeAllRanges();
-
- cb();
- }else{
- var Url2=document.getElementById(copy01);//要复制文字的节点
- Url2.select(); // 选择对象
- document.execCommand("Copy"); // 执行浏览器复制命令
- cb()
- }
- }
- var args = my.getURLCode();
- var goods_id = args['goods_id'] || 0,
- is_coupon = args['is_coupon'] || 0,
- user_id = args['user_id'] || 0;
- union_id = args['union_id'] || 0;
- var btn = document.querySelector('.btn-wrapper .btn');
- window.onload = function () {
- writeLogH5({action:'SG-details',channel:'H5',url:window.location.href});//商品详情埋点
- _czc.push(["_trackEvent",'猎豆详情页','页面',]);
- axios.post('/api/v2/goods/tdetail', {
- goods_id: goods_id,
- is_coupon: is_coupon,
- user_id: user_id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- var res = response.data, data = null, html = '', imgList = [], swiperStr = '', pointStr = '', len = 0;
- var swiper = document.querySelector('.swiper-container .swiper-wrapper'),
- point = document.querySelector('.swiper-wrapper .swiper-point'),
- detailsWrapper = document.querySelector('.details-wrapper'),
- copy_2 = document.getElementById("copy_2"),
- copy_1 = document.getElementById("copy_1");
- copyName_1 = document.getElementById("copyName_1");
- copyName_2 = document.getElementById("copyName_2");
- // toast = document.getElementById("toast")
-
- // console.log(swiper);
- if (res.errno == 0) {
- data = res.rst.data;
- imgList = res.rst.data.small_img;
- len = imgList.length;
- if (len > 0) {
- for (var i = 0; i < len; i++) {
- swiperStr += '<div class="swiper-slide"><img src="'+ imgList[i] +'"></div>';
- }
- }
- if (is_coupon == 1) {
- html = '<h5 class="price"><span>券后 ¥</span><em>'+ data.discount_price +'</em><span class="icon icon-price">券 '+ data.coupon_price
- +'元</span></h5><div class="info"><p class="before-price">价格 <span>'+ data.price +'</span></p><p class="quantity"> 月销 '+ data.volume +'</p></div><p class="elli desc">'+ data.title +'</p>';
- }else{
- html = '<h5 class="price"><span>折后 ¥</span><em>'+ data.discount_price +'</em></h5><div class="info"><p class="before-price">价格 <span>'+ data.price +'</span></p><p class="quantity"> 月销 '+ data.volume +'</p></div><p class="elli desc">'+ data.title +'</p>';
- }
- // if(data.commission_price){
- // var btn_yj = document.getElementsByClassName("btn2")[0].getElementsByTagName("span")[0];
- // btn_yj.innerHTML = " " + data.commission_price + " 元"
- // }
-
- copyName_2.innerHTML = data.title;
- // console.log(copy_1);
- copyName_1.value = data.title;
-
- detailsWrapper.innerHTML = html;
- swiper.innerHTML = swiperStr;
- var mySwiper = new Swiper ('.swiper-container', {
- autoplay: 3000,
- loop: true,
- pagination: '.swiper-pagination',
- })
-
- var titleName = document.getElementsByClassName("details-wrapper")[0].getElementsByClassName("desc")[0];
- titleName.addEventListener('click', function () {
- toCopy("copyName_1","copyName_2",function () {
- showMsg("商品复制成功")
- });
- }, false)
- }
- })
- .catch(function (error) {
- console.log(error);
- });
- axios.post('/api/v2/adzoneCreate/h5CopyOfTheNaughtyPassword', {
- goods_id: goods_id,
- is_coupon: is_coupon,
- user_id: user_id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- console.log(response)
- var res = response.data, data = null;
- if (res.errno == 0) {
- data = res.rst.data;
- copy_2.innerHTML = data;
- // console.log(copy_1);
- copy_1.value = data;
- btn.addEventListener('click', function () {
- console.log('test');
- // toast.classList.add('show');
- toCopy("copy_1","copy_2",function () {
- var mask = document.getElementsByClassName('mask')[0];
- mask.style.visibility='visible';
- });
- // setTimeout(function () {
- // toast.classList.remove('show');
- // toast.classList.add('hide')
- // }, 2000)
- }, false)
- }
- })
- .catch(function (error) {
- console.log(error);
- });
- }
- //gxl
- var isClickFlag = true;//是否可以点击获取验证码
- var copyName = document.getElementsByClassName("copyName");
- var copyNameArr = Array.prototype.slice.call(copyName);
- copyNameArr.forEach(function (item, index) {
- item.addEventListener('click', function () {
- toCopy("copyName_1","copyName_2",function () {
- window.location.href="http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou"
- });
- }, false)
- })
- //获取手机验证码
- function getYzm () {
- var phoneNumber = getIdHtml("phone").value;
- var ttl = new Date().getTime();
- var sign = hex_md5('phone=' + phoneNumber + '&ttl=' + ttl + 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL');
- if(phoneNumber.length != 11){
- showMsg('请正确输入手机号');
- return;
- }
- if(!isClickFlag){
- return;
- }
- axios.post('/api/v2/users/sendCode', {
- phone: phoneNumber,
- ttl: ttl,
- sign: sign,
- union_id: union_id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- var res = response.data,wait_time;
- if (res.errno == 0 && res.rst.success) {
- wait_time = res.rst.wait_time;
- var time = setInterval(function () {
- wait_time--;
- getClassHtml('yzmButton').innerHTML = wait_time + 's';
- isClickFlag = false;//不可获取验证码
- if(wait_time == 0){
- clearInterval(time);
- getClassHtml('yzmButton').innerHTML = '获取验证码';
- isClickFlag = true;//可以获取验证码
- }
- },1000)
- }else if(res.errno == 0 && !res.rst.success){
- showMsg('请稍后再试哦~')
- }else if(res.errno == '1011'){//errno==1011 该手机号已绑定其他微信
- showMsg(res.err);
- }
- })
- .catch(function (error) {
- showMsg('请稍后再试哦~')
- });
- }
- //注册事件
- function registerEvent () {
- if(getIdHtml("phone").value.length != 11){
- showMsg('请正确输入手机号');
- return;
- }
- if((getIdHtml('yzm').value).trim().length == 0){
- showMsg('请输入手机验证码')
- return;
- }
- //验证注册
- axios.post('/api/v2/users/loginCode', {
- phone: getIdHtml("phone").value,
- code: getIdHtml('yzm').value,
- union_id: union_id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- var res = response.data;
- if (res.errno == 0) {
- writeLogH5({action:'SG-success',channel:'H5',url:window.location.href});//未注册手机注册成功埋点
- _czc.push(["_trackEvent",'猎豆详情页','手机注册成功',]);
- var mask = document.getElementById('registerMask');
- mask.style.visibility='hidden';
- document.getElementById('registerSuccess').style.visibility='visible';
- copyEvent(res.rst.user_id);//获取淘口令接口
- }else{
- showMsg(res.err);
- }
- })
- .catch(function (error) {
- showMsg('请稍后再试哦~')
- });
- }
- //获取淘口令接口
- function copyEvent (id) {
- axios.post('/api/v2/adzoneCreate/h5CopyOfTheNaughtyPassword', {
- goods_id: goods_id,
- is_coupon: is_coupon,
- user_id: id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- var res = response.data, data = null;
- if (res.errno == 0) {
- data = res.rst.data;
- var copy1 = getIdHtml("copy1");
- var copy2 = getIdHtml("copy2");
- copy2.innerHTML = data;
- copy1.value = data;
- getIdHtml("copyRegisterTkl").addEventListener('click', function () {
- toCopy("copy1","copy2",function () {
- showMsg('复制成功');
- });
- }, false)
- }
- })
- .catch(function (error) {
- console.log(error);
- });
- }
- //点击赚佣金购买
- function makeMoney(){
- if(union_id == 0){
- var mask = document.getElementsByClassName('mask')[1];
- mask.style.visibility='visible';
- return;//union_id为空
- }
- axios.get('/api/v2/user/h5ShareIfregist', {
- headers:{
- source:6000,
- unionid:union_id
- }
- })
- .then(function (response) {
- var res = response.data;
- if (res.errno == 0) {
- if (res.rst.code == 10000) {
- //未注册
- getClassHtml('alert-info').style.top='4.35rem';
- getIdHtml('registerMask').style.visibility='visible';
- writeLogH5({action:'SG-register',channel:'H5',url:window.location.href});//未注册手机注册埋点
- _czc.push(["_trackEvent",'猎豆详情页','手机注册弹框',]);
- }else{
- document.getElementsByClassName('mask')[1].style.visibility='visible';
- }
- }else{
- document.getElementsByClassName('mask')[1].style.visibility='visible';
- }
- })
- .catch(function (error) {
- document.getElementsByClassName('mask')[1].style.visibility='visible';
- });
- }
- function closeMake () {
- var mask = document.getElementById('registerMask');
- mask.style.visibility='hidden';
- document.getElementById('registerSuccess').style.visibility='hidden';
- getClassHtml('alert-info').style.top='9.35rem';
- }
- //封装 id标签
- function getIdHtml (name){
- return document.getElementById(name)
- }
- //封装 class标签
- function getClassHtml (name){
- return document.getElementsByClassName(name)[0]
- }
- /**
- * [showMsg 提示各种错误信息,3s后消失]
- */
- function showMsg(msg) {
- var msgBox = document.getElementsByClassName('alert-info')[0];
- msgBox.getElementsByTagName("p")[0].innerHTML=msg;
- msgBox.style.display="block";
- setTimeout(function() {
- msgBox.style.display="none";
- }, 1000);
- }
- //埋点
- function writeLogH5 (data) {
- axios.post('/api/v2/channel/writeLogH5', data,{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- })
- .catch(function (error) {
-
- });
- }
|