Bez popisu

index.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. var myDate = new Date(), id, nowTime = new Date().getTime(), dataList;//获取系统当前时间
  2. var timeArr = [{
  3. time:new Date('2018-11-01 00:00'.replace(/-/ig,'/')).getTime(),
  4. img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_two.png',
  5. id:1
  6. },{
  7. time:new Date('2018-11-10 21:00'.replace(/-/ig,'/')).getTime(),
  8. img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_three.png',
  9. id:2
  10. },{
  11. time:new Date('2018-11-11 00:00'.replace(/-/ig,'/')).getTime(),
  12. img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_one.png',
  13. id:3
  14. }];
  15. $().ready(function () {
  16. writeLogH5({action:'wishList-home',channel:'H5',url:window.location.href});//埋点
  17. isWeixinEvent();//判断是否是微信端
  18. activeTbkPassword();//获取淘口令
  19. timeArr.forEach(function (item, index) {
  20. if(nowTime > item.time){
  21. $(".activityTime .changeTime .progress").css({'background':'url(' + item.img + ')','background-size':'100%'})
  22. id = item.id
  23. }
  24. })
  25. })
  26. //获取淘口令,淘宝链接
  27. function activeTbkPassword () {
  28. $.ajax({
  29. type:'post',
  30. url:'/api/v2/goods/activeTbkPassword',
  31. data:{
  32. flag:'wishlist'
  33. },
  34. dataType:'json',
  35. success:function (res) {
  36. if(res && res.errno == 0){
  37. dataList = res.rst.list
  38. }
  39. }
  40. })
  41. }
  42. //立即参与
  43. function goPartake (i) {
  44. if(i <= id && dataList.length >=id){
  45. //可以点击
  46. var url = dataList[0].url;
  47. var tkl = dataList[0].tbk_password;
  48. openTaobao(url,tkl)
  49. }else{
  50. //不可点击
  51. showMsg('【暂未开启】')
  52. }
  53. writeLogH5({action:'wishList-partake',channel:'H5',url:window.location.href});//埋点
  54. }
  55. //立即兑换
  56. function goCash (i) {
  57. if(i <= id && dataList.length >=id){
  58. //可以点击
  59. var url = dataList[1].url;
  60. var tkl = dataList[1].tbk_password;
  61. openTaobao(url,tkl)
  62. }else{
  63. //不可点击
  64. showMsg('【暂未开启】')
  65. }
  66. writeLogH5({action:'wishList-exchange',channel:'H5',url:window.location.href});//埋点
  67. }
  68. //立即下单
  69. function goOrder (i) {
  70. if(i <= id && dataList.length >=id){
  71. //可以点击
  72. var url = dataList[2].url;
  73. var tkl = dataList[2].tbk_password;
  74. openTaobao(url,tkl)
  75. }else{
  76. //不可点击
  77. showMsg('【暂未开启】')
  78. }
  79. writeLogH5({action:'wishList-order',channel:'H5',url:window.location.href});//埋点
  80. }
  81. // 打开淘宝
  82. function openTaobao (url,tkl) {
  83. var param = {"taobaoUrl" : url}
  84. param = JSON.stringify(param)
  85. try{
  86. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  87. window.webkit.messageHandlers.app_h5_open_taobao_url.postMessage(param);
  88. }
  89. if(navigator.userAgent.match(/android/i)){
  90. obj4H5.app_h5_open_taobao_url(param);
  91. }
  92. }catch(e){
  93. //TODO handle the exception
  94. copyPassword(tkl)
  95. }
  96. }
  97. //复制淘口令
  98. function copyPassword(tkl) {
  99. var data=tkl;
  100. copy_2.innerHTML = data;
  101. copy_1.setAttribute('value',data)
  102. if(Boolean(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))){
  103. //区分iPhone设备
  104. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  105. var Url2=document.getElementById("copy_2");//要复制的节点
  106. var range = document.createRange();
  107. //选中需要复制的节点
  108. range.selectNode(Url2);
  109. //执行选中元素
  110. window.getSelection().addRange(range);
  111. //执行copy操作
  112. var successful = document.execCommand("copy");
  113. //移除选中的元素
  114. window.getSelection().removeAllRanges();
  115. }else{
  116. var Url2=document.getElementById("copy_1");//要复制的节点
  117. Url2.select();//选择对象
  118. document.execCommand("Copy");//执行浏览器复制命令
  119. }
  120. showMsg('复制淘口令成功,请打开淘宝参与活动')
  121. }
  122. //分享到微信url
  123. function goShare () {
  124. writeLogH5({action:'wishList-shareWechat',channel:'H5',url:window.location.href});//分享埋点
  125. var param = {
  126. "shareImageUrl" : "https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/shareWechat.jpg",
  127. "shareTitle": "双11最不能错过的活动",
  128. "shareDescirpt":"参与立享折上折,最大优惠等着你!",
  129. "shareUrl":window.location.href,//详情链接
  130. "shareType":"1" //1:微信好友 2:朋友圈
  131. }
  132. param = JSON.stringify(param)
  133. try{
  134. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  135. window.webkit.messageHandlers.app_h5_wx_share_url.postMessage(param);
  136. }
  137. if(navigator.userAgent.match(/android/i)){
  138. obj4H5.app_h5_wx_share_url(param);
  139. }
  140. }catch(e){
  141. showMsg("先更新,再分享哦~")
  142. }
  143. }
  144. //H5页面埋点
  145. function writeLogH5 (data) {
  146. $.ajax({
  147. type:'post',
  148. url:'/api/v2/channel/writeLogH5',
  149. dataType:'json',
  150. data:data,
  151. success:function (res) {
  152. }
  153. })
  154. }
  155. //判断是否是微信浏览器
  156. function isWeixinEvent () {
  157. //判断是不是微信端,选择app方法获取token 还是后端提供
  158. if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){
  159. //微信
  160. $("#share").css("display","none");
  161. }else{
  162. //app端
  163. $("#share").css("display","block");
  164. }
  165. }
  166. //提示弹框
  167. function showMsg(msg) {
  168. var msgBox = $('.alert-info');
  169. msgBox.children('p').text(msg);
  170. msgBox.show();
  171. setTimeout(function() {
  172. msgBox.hide();
  173. }, 2000);
  174. }