123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516 |
- /*封装一些公用的事件或者公用的方法*/
- /*定义的一个命名空间*/
- 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()
- }
- }
- //is_coupon 是否有券
- 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');
- var selectGoodThingsList = [];//精选好物数据
- var selectGoodThingsPage = 1;//精选好物的分页
- var red_active_status = 0,red_active_money = 0;//是否是红包活动商品
- var commission_price = 0;//返利
- window.onload = function () {
- goodsAndStockList();//精选好物
- $(window).scroll(function(){
- if(selectGoodThingsList.length != 0 && ($(window).scrollTop() >= $(document).height()-$(window).height())){
- //到达底部加载数据
- if($(".loading").css('display') == 'none'){
- selectGoodThingsPage ++ ;
- goodsAndStockList();//精选好物
- }
- }
- });
- writeLogH5({action:'SG-details',channel:'H5',url:window.location.href});//商品详情埋点
- _czc.push(["_trackEvent",'猎豆详情页','页面',]);
- $(".loading").show();
- axios.post('/api/v2/goods/tdetail', {
- goods_id: goods_id,
- is_coupon: is_coupon,
- user_id: user_id
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- $(".loading").hide();
- var res = response.data, data = null, html = '', imgList = [], swiperStr = '',
- pointStr = '', len = 0,sourceImg = '',commodityDetailDiscount = '',quan_small = '';
- 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(data.shop_type == 1){
- //天猫
- sourceImg = '<img src="img/tianmao.png"/>';
- }else if(data.shop_type == 0){
- sourceImg = '<img src="img/taobao.png"/>'
- }
- if(data.red_active_status == 1){//红包
- red_active_status = 1;
- red_active_money = data.red_active_money;
- commodityDetailDiscount += `<li class="redEnvelopes">
- <div class="redEnvelopes_01">
- <img src="img/redEnvelopes.png"/>
- <span>${data.red_active_money}元红包</span>
- </div>
- <p>下载App下单可得${data.red_active_money}元红包</p>
- </li>`
- }
- commission_price = data.commission_price;//返利金额
- // if(data.commission_price){//返利
- // commodityDetailDiscount += `<li class="rebate">
- // <div class="rebate_01">
- // 返 ¥${data.commission_price}
- // </div>
- // <p>下载App购买可返¥${data.commission_price}</p>
- // </li>`
- // }
- if(data.is_coupon == 1){//券
- commodityDetailDiscount += `<li class="discount_coupon">
- <div class="rebate_01">
- 券 ${data.coupon_price}元
- </div>
- <p>数量有限 先到先领</p>
- </li>`
- quan_small = `<div class="quan_small"><i>券</i><span>${data.coupon_price}元</span></div>`
- }
- html = `<div class="details-wrapper-con">
- <h5 class="price">
- <div>
- <em>¥${data.discount_price}</em>
- <span class="before-price">原价${data.price}元</span>
- <span class="quantity"> 月销 ${data.volume}</span>
- </div>
- ${quan_small}
- </h5>
- <div class="info">
- <p class="elli desc">${sourceImg}${data.title}</p>
- </div>
- <ul class="discount">
- ${commodityDetailDiscount}
- </ul>
- </div>`;
- if(data.shop){
- html += `<div class="shop_info">
- <img src="${data.shop.pic_path}"/>
- <div class="shop_detail">
- <h3>${data.shop.title}</h3>
- <div class="shop_evaluate">
- 商品描述:${data.shop.item_score}${data.shop.item_score_pre == 1 ? '<span>低</span> ': (data.shop.item_score_pre == 2 ? '<span>平</span> ' : (data.shop.item_score_pre == 3 ? '<span>高</span> ' : ''))}
- 服务态度:${data.shop.service_score}${data.shop.service_score_pre == 1 ? '<span>低</span> ': (data.shop.service_score_pre == 2 ? '<span>平</span> ' : (data.shop.service_score_pre == 3 ? '<span>高</span> ' : ''))}
- 发货速度:${data.shop.delivery_score}${data.shop.delivery_score_pre == 1 ? '<span>低</span>': (data.shop.delivery_score_pre == 2 ? '<span>平</span>' : (data.shop.delivery_score_pre == 3 ? '<span>高</span>' : ''))}
- </div>
- </div>
- </div>`
- }
-
- 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);
- $(".loading").hide();
- });
- 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;
- copy_1.value = data;
- document.getElementsByClassName('coupon_purchase_bottom')[0].addEventListener('click', function () {
- toCopy("copy_1","copy_2",function () {
- $(".coupon_purchase_mask").show();
- if(red_active_status == 1){//红包活动商品
- $(".coupon_purchase_mask .coupon_purchase_mask_con h3").html('可得' + red_active_money + '元红包')
- }else{
- $(".coupon_purchase_mask .coupon_purchase_mask_con h3").html('可返' + commission_price + '元')
- }
- });
- }, 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 closeMask () {
- //关闭弹款
- $(".coupon_purchase_mask").hide();
- }
- //获取手机验证码
- 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) {
-
- });
- }
- function goodsAndStockList () {
- //首页商品广告位混合页 精选好物
- if(selectGoodThingsPage != 1){//为了确定tdetail接口返回数据后按钮才可点击
- $(".loading").show();
- }
- axios.post('/api/v2/goods/goodsAndStockList', {
- 'page':selectGoodThingsPage,
- "category_id":13,
- "is_has_coupon":1,
- "sort":1,
- "stype":0
- },{
- headers:{
- source:6000
- }
- })
- .then(function (response) {
- console.log(response)
- if(selectGoodThingsPage != 1){
- $(".loading").hide();
- }
- var res = response.data, data = null;
- if (res.errno == 0) {
- var selectGoodThingsListHtml= '';
- if(selectGoodThingsList.length == 0){
- selectGoodThingsList = res.rst;
- }else{
- selectGoodThingsList = [...selectGoodThingsList,...res.rst];
- }
- selectGoodThingsList.forEach(function (item,index){
- if(item.goods){
- var shop_type_img = '',commodityDiscount = '';
- if(item.goods.shop_type == 1){
- shop_type_img = '<img src="img/tianmao.png"/>'//天猫
- }else if(item.goods.shop_type == 0){
- shop_type_img = '<img src="img/taobao.png"/>'//淘宝
- }
- if(item.goods.red_active_status == 1){//红包
- commodityDiscount += `<div class="red"><img src="img/redEnvelopes.png"/> ${item.goods.red_active_money}元红包</div>`
- }
- if(item.goods.commission_price){//返利
- commodityDiscount += `<div class="rebate">
- 返 ${item.goods.commission_price} 元
- </div>`
- }
- if(item.goods.is_coupon == 1){//券
- commodityDiscount += `<div class="quan">
- <em>券</em>
- <span>${item.goods.coupon_price}元</span>
- </div>`
- }
- selectGoodThingsListHtml += `<li onclick="goCommodityDetail(${item.goods.goods_id},${item.goods.is_coupon})">
- <img class="commodity-img" src="${item.goods.img}"/>
- <div class="commodity-info">
- <p class="title">${item.goods.title}</p>
- <div class="commodity-shop">
- ${shop_type_img}
- <span>${item.goods.shop_title}</span>
- </div>
- <div class="commodity-price">
- <span>¥${item.goods.discount_price}</span>
- 月销 ${item.goods.volume}
- </div>
- <div class="commodity-discount">
- ${commodityDiscount}
- </div>
- </div>
- </li>`
- }
- })
- document.getElementsByClassName('select-good-things-list')[0].innerHTML= selectGoodThingsListHtml;
- }
- })
- .catch(function (error) {
- if(selectGoodThingsPage != 1){
- $(".loading").hide();
- }
- });
- }
- function goCommodityDetail (goods_id,is_coupon) {
- //去商品详情页
- window.location.href='/coupon-share/index.html?goods_id=' + goods_id + '&is_coupon=' + is_coupon + '&user_id=' + user_id + '&union_id=' + union_id
- }
|