main.min.js 6.65 KB
"use strict";var queryObj=void 0;var getServerTimeApi="//m.yohobuy.com/activity/feature/getServerTimes";var getCouponApi="//m.yohobuy.com/activity/feature/couponSend";var UFO={app:null};function toVersion(){var b=arguments.length<=0||arguments[0]===undefined?"":arguments[0];
  var a=b.split(".").map(function(c){return Number(c)});if(!a[0]){a[0]=0}if(!a[1]){a[1]=0}if(!a[2]){a[2]=0}return a}function toNumber(a){var b=a[0]*10000;var c=a[1]*100;var d=a[2]*1;return b+c+d}function compare(b,a){if(b>a){return 1
}else{if(b<a){return -1}else{return 0}}}function verion(e,b){var d=toNumber(toVersion(e));var c=toNumber(toVersion(b));var a=compare(d,c);return a}$(document).ready(function(){queryObj=Utils.getQueryObj();
  try{var f=localStorage.getItem("_share_fromid_"+window.shareC.eventName);if(queryObj&&+queryObj.fid&&+queryObj.fid!==+f){if(queryObj.fid){localStorage.setItem("_share_fromid_"+window.shareC.eventName,queryObj.fid)
  }localStorage.removeItem("_share_preid_"+window.shareC.eventName);f=queryObj.fid}shareC&&(shareC.fid=f)}catch(o){console.log(o)}UFO.app=new Vue({el:"#mainContainer",data:{preid:0,env:"h5",uid:0,isShared:false,app_info:{uid:"0",app_version:"",client_type:"",session_key:""},fromPage:"iFP_SalesPromotion_h5",couponToken:{"token":["d8e0c1fb-ba6e-41e4-9bfb-43fe68ed280f","0a6e807d-7adf-4488-926d-3efba9940d1f","e80c44ae-1415-4c65-9785-66688d27c6b1"]},productData:[],serverTime:"",serverTimeNumber:0,isShowShare:false,isShowTips:false,tipsMessage:""},created:function g(){this.productData=productData;
    if(navigator.userAgent.match(/ANDROID/i)){this.fromPage="aFP_SalesPromotion_h5"}},mounted:function b(){if(queryObj.uid){this.uid=queryObj.uid}if(navigator.userAgent.match(/yohobuy/i)){this.env="app"}else{if(navigator.userAgent.match(/miniprogram/i)){window.__wxjs_environment="miniprogram";
    this.weixinJSReady()}else{if(!window.WeixinJSBridge||!window.WeixinJSBridge.invoke){document.addEventListener("WeixinJSBridgeReady",this.weixinJSReady,false)}}}this.yo_sdk=window.yo_sdk;this.preshare();
    this.getParams();this.getResource()},methods:{preshare:function n(){try{var w=this;var u=localStorage.getItem("_share_preid_"+window.shareC.eventName);if(u){this.preid=u;this.setShareLink(u);return}$.ajax({url:"//action.yoho.cn/api/share/preshare?callback=?",dataType:"jsonp",data:{eventName:shareC.eventName,shareUrl:shareC.shareUrl,fid:shareC.fid||0},success:function x(y){if(y){w.preid=y.preid||0;
    localStorage.setItem("_share_preid_"+window.shareC.eventName,w.preid);w.setShareLink(y.preid)}}})}catch(v){console.log(v)}},setShareLink:function m(u){shareC.link=document.location.href.split("?")[0]+"?fid="+u;
    share&&share()},weixinJSReady:function r(){if(window.__wxjs_environment==="miniprogram"){this.env="miniprogram"}},jumpToMiniapp:function p(v){var u=decodeURIComponent(v.currentTarget.dataset.url);var w=Utils.getQueryObj(u);
    if(w["openby:yohobuy"]){if(this.env==="miniprogram"){wx.miniProgram.navigateTo({url:"/pages/common/webback?url="+encodeURIComponent(u)})}}else{if(u.indexOf("mp.weixin.qq.com")>0){wx.miniProgram.navigateTo({url:"/pages/webview/webview?url="+encodeURIComponent(u)})
    }}},goLogin:function e(){var v=this;var y=window.yohoInterface;if(this.env==="app"&&y){var x={method:"get.uid"};var w=function w(z){if(!parseInt(z,10)){if(v.yo_sdk.goLogin){v.yo_sdk.goLogin()}}else{v.app_info.uid=v.uid=z;
    y.triggerEvent(function(A){v.app_info.session_key=A;v.checkShared()},function(){},{method:"get.sessionId"});v.setShareC(+z)}};var u=function u(){};y.triggerEvent(w,u,x)}else{if(v.yo_sdk.goLogin){v.yo_sdk.goLogin()
  }}},setShareC:function k(u){var v=this;shareC.uid=u;if(this.preid){$.ajax({url:"//action.yoho.cn/api/share/collect?callback=?",dataType:"jsonp",data:{uid:u,fid:this.preid}})}else{setTimeout(function(){v.setShareC(u)
  },500)}},getParams:function s(){var w=this.uid=Utils.getCookie("app_uid")||queryObj.uid||"0";var u=Utils.getCookie("app_session_key")||queryObj.session_key||"";var v=Utils.getCookie("app_version")||queryObj.app_version||"";
    var x=Utils.getCookie("app_client_type")||queryObj.app_client_type||"";this.app_info={uid:w,session_key:u,app_version:v,client_type:x};if(w&&w!=="0"){this.setShareC(+w)}},checkShared:function q(){var u=this;
    if(!this.isShared){if(this.env==="app"){(function(){var x=false;var w=Utils.getCookie("app_vercode");var v=Utils.getCookie("app_version")||queryObj.app_version||"";if(verion(v,"6.9.5")>=0||w){x=true}document.addEventListener("deviceready",function(){var y=window.yohoInterface;
      window.successShare=function(){u.getCoupon()};y.triggerEvent(function(){},function(){},{method:"go.showshareaction",arguments:{title:"【有货UFO】320元优惠券打包送你,用券下单更划算",desc:"618火热来袭,全实物鉴定助你入手潮流好物!超万件商品券后直降¥160,买热门尖货就在有货UFO!",imgUrl:document.location.href.split("?")[0].replace(/\/index\d{0,}\.html/,"")+"/share/logo.jpg",link:window.shareC&&shareC.link||document.location.href.split("?")[0],hideType:["4","5","6","7","8","9"],isCareCallBack:"1"}});
      if(!x){setTimeout(u.getCoupon,5000)}})})()}else{this.showShare();if(this.env==="miniprogram"){setTimeout(this.getCoupon,5000)}}}else{this.getCoupon()}},getCoupon:function h(){var u=this;var w=this.couponToken["token"].join(",");
    if(this.app_info.uid){var v={token:w,uid:this.uid,coupontype:"ufo",app:this.app_info};$.ajax({url:getCouponApi+"?callback=?",type:"get",dataType:"jsonp",data:v,success:function x(y){if(y.code===200){u.showMessage("领券成功")
    }else{if(y.code===401){u.showMessage("您已领取过该优惠券")}else{if(y.code===403){u.showMessage("目前券已领完,请稍后再试")}else{u.showMessage(y.message)}}}u.hideShare()}})}},getResource:function a(){var u=this;$(".products-list a").each(function(){if(u.env==="miniprogram"){$(this).on("click",u.jumpToMiniapp)
  }else{$(this).attr("href",$(this).data("url"));$(this).attr("target","_blank")}})},getServerTime:function t(){var v=this;$.ajax({url:getServerTimeApi+"?callback=?",type:"get",dataType:"jsonp",data:{},success:function w(z){if(z){var B=new Date(z*1000);
    v.serverTimeNumber=B.getTime();var y=B.getFullYear();var A=B.getMonth()+1<10?"0"+(B.getMonth()+1):B.getMonth();var x=B.getDate()<10?"0"+B.getDate():B.getDate();v.serverTime=[y,A,x].join("-")}},error:function u(B){var A=new Date();
    var y=A.getFullYear();var z=A.getMonth()+1<10?"0"+(A.getMonth()+1):A.getMonth();var x=A.getDate();v.serverTime=[y,z,x].join("-")}})},showMessage:function j(u){this.tipsMessage=u;this.isShowTips=true},showShare:function d(){this.isShowShare=true
  },hideShare:function i(){this.isShowShare=false},closeTips:function l(){this.tipsMessage="";this.isShowTips=false},refresh:function c(){document.location.reload()}}})});