alliance-page.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. 'use strict';
  2. // loading组件
  3. var LoadingWrap = {
  4. name: 'Loading',
  5. render: function render(h) {
  6. return h('div', { class: ['loading-wrap'] }, [h('img', { attrs: { src: '/img/alliance-page/loading.gif', alt: 'loading' } })]);
  7. }
  8. };
  9. function remove(el) {
  10. el.removeChild(el.instance.$el);
  11. }
  12. function append(el) {
  13. el.appendChild(el.instance.$el);
  14. }
  15. // 定义 loading 指令
  16. var loadingDirective = {
  17. inserted: function inserted(el, binding) {
  18. // 创建 loading 组件构造函数
  19. var LoadingCtor = Vue.extend(LoadingWrap);
  20. // new 一个 loading组件实例
  21. var loadingInstance = new LoadingCtor();
  22. // 组件挂载
  23. el.instance = loadingInstance.$mount();
  24. // 传入值为 true 时才展示
  25. if (binding.value) {
  26. // 将组件挂载到绑定指令的元素上
  27. append(el);
  28. }
  29. },
  30. update: function update(el, binding) {
  31. // 值更新时进行操作
  32. if (binding.value !== binding.oldValue) {
  33. binding.value ? append(el) : remove(el);
  34. }
  35. }
  36. };
  37. // vue实例
  38. var zplm = new Vue({
  39. el: '#zplm',
  40. directives: {
  41. loading: loadingDirective
  42. },
  43. data: {
  44. isPc: $(window).width() > 768,
  45. authCardVisible: false,
  46. statementVisible: false,
  47. showStatementContent: false,
  48. wechatVisible: true,
  49. showMask: false,
  50. isRequest: true,
  51. // 产品id
  52. productId: '',
  53. //产品参数对象
  54. productAuthInfo: {},
  55. //错误信息
  56. errorMessage: '',
  57. // 定时器
  58. timer: null
  59. },
  60. computed: {
  61. // 封面图 主图
  62. coverImage: function coverImage() {
  63. return this.isPc ? this.productAuthInfo.pcImage : this.productAuthInfo.appletsImage;
  64. },
  65. // 授权机构
  66. authOrigin: function authOrigin() {
  67. return this.productAuthInfo.agentFlag !== 0 ? this.productAuthInfo.shopName : this.productAuthInfo.brandName;
  68. },
  69. // 不换行
  70. noWarp: function noWarp() {
  71. if (this.isPc && this.productAuthInfo.paramList.length > 1) return { 'white-space': 'nowrap' };
  72. return '';
  73. }
  74. },
  75. created: function created() {
  76. this.getProductId();
  77. this.fetchProductAuthInfo();
  78. },
  79. filters: {
  80. // 处理sn码
  81. snCode: function snCode(code) {
  82. if (!code) return '';
  83. return code.replace(/^(\w{2})\w+(\w{4})$/, "$1******$2");
  84. }
  85. },
  86. methods: {
  87. // 获取商品id
  88. getProductId: function getProductId() {
  89. var productId = window.location.pathname.split('-')[1].split('.')[0];
  90. this.productId = parseInt(productId);
  91. },
  92. // 获取授权信息
  93. fetchProductAuthInfo: function fetchProductAuthInfo() {
  94. var that = this;
  95. var data = {productId:that.productId}
  96. $.ajax({
  97. url: 'https://zplma.caimei365.com/wx/auth/product/details',
  98. data: data,
  99. xhrFields: {//此处为跨域后台保持session一致,切勿删除!!!
  100. withCredentials: true
  101. },
  102. type: 'GET',
  103. dataType: "json",
  104. async: false,
  105. // contentType: contentType,
  106. contentType: 'application/json;charset=UTF-8',
  107. }).then(res => {
  108. // 获取授权信息失败
  109. if (res.code) {
  110. that.isRequest = false;
  111. return that.errorMessage = res.msg;
  112. }
  113. // 获取授权信息成功
  114. that.productAuthInfo = res.data;
  115. that.isRequest = false;
  116. })
  117. setTimeout(function(){
  118. if(that.isRequest){
  119. that.isRequest = false;
  120. location.href = '/404.html'
  121. }
  122. }, 10000)
  123. },
  124. // 显示授权牌
  125. handleShowAuthCard: function handleShowAuthCard() {
  126. this.authCardVisible = !this.authCardVisible;
  127. this.showMask = !this.showMask;
  128. },
  129. // 显示声明弹窗
  130. handleShowStatement: function handleShowStatement() {
  131. var that = this;
  132. this.statementVisible = !this.statementVisible;
  133. this.showMask = !this.showMask;
  134. this.timer = setTimeout(function () {
  135. that.showStatementContent = !that.showStatementContent;
  136. }, 800);
  137. },
  138. // 显示微信二维码
  139. handleShowWechat: function handleShowWechat() {
  140. this.wechatVisible = !this.wechatVisible;
  141. }
  142. }
  143. });