jyy
2021-06-09 050a6e05bf85df074d24e9f5e06cc0d618019ccc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//index.js
//获取应用实例
const app = getApp()
var util = require('../../utils/util.js');
var api = require('../../utils/service-api.js');
var comReq = require('../../utils/common-request.js');
 
Page({
  data: {
    adNodes: [],
    distance: 0,
    size: 30,
    step: 1,
    interval: 20,
 
  },
 
 
  onLoad: function(options) {
 
 
    util.userLogin(function() {
      console.log("登录成功");
     
 
    });
 
 
    //获取首页所有的节点元素
   
      this.getAdNodes();
    //获取小程序码中的店铺id
 
    if (options.scene) {
      const shopId = decodeURIComponent(options.scene);
      //获取门店信息
      util.request({
        api: api.yuyue.findShopInfoById + "/" + shopId,
        callback: function (data) {
         
          app.shopInfo = data.mapInfo.shopInfo;
 
          wx.setNavigationBarTitle({
            title: app.shopInfo.shopShortName
          });
 
 
        },
        checkLogin: true,
      });
    }
 
 
  },
 
 
 
 
 
 
  onShow: function() {
   
    wx.setNavigationBarTitle({
      title: app.shopInfo.shopShortName
    });
 
 
 
  },
 
  changeShop() {
    wx.navigateTo({
      url: "/pages/yuyue/choseShop",
    });
  },
 
 
  getAdNodes: function() {
    console.log('加载广告');
    var _this = this;
    util.request({
      method: 'POST',
      api: api.ad.getAdPage,
      data: {
        "pageCode": "index",
      },
      callback: function(data) {
        let hasPmd = false;
        for (let i = 0; i < data.rows.length; i++) {
          let node = data.rows[i];
          //处理属性节点
          console.log(node.nodeAttribute);
          if (node.nodeAttribute != null) {
            node.nodeAttribute = JSON.parse(node.nodeAttribute);
          }
          if (node.nodeType == 5) {
            //处理跑马灯,一个页面只支持一个跑马灯
            var length = node.nodeValue.length * _this.data.size;
            _this.setData({
              length: length
            });
            hasPmd = true;
          }
 
        }
        _this.setData({
          adNodes: data.rows
        });
 
        if (hasPmd) {
          _this.scrollling();
        }
 
 
      }
    });
 
  },
 
  /**
   * 点击广告节点事件
   */
  clickAdnode(e) {
 
    var linkType = e.currentTarget.dataset.linktype;
    var linkUrl = e.currentTarget.dataset.linkurl;
    if (linkType == 1) {
      wx.switchTab({
        url: linkUrl,
        fail: function(e) {
          console.log(e);
        },
      });
    } else if (linkType == 2) {
      wx.navigateTo({
        url: linkUrl,
      })
    } else if (linkType == 3) {
      wx.navigateTo({
        url: "/pages/webView/webView?url=" + linkUrl,
      })
    }
  },
 
 
  scrollling: function() {
    var that = this;
 
 
    var interval = setInterval(function() {
 
      var maxscrollwidth = that.data.length;
 
      var left = that.data.distance;
 
      if (maxscrollwidth + left > 1) {
 
        that.setData({
          distance: left - that.data.step
        })
 
      } else {
 
        that.setData({
          distance: 0
        });
 
        clearInterval(interval);
 
        that.scrollling();
      }
 
    }, that.data.interval);
  },
 
 
  setShopTitle() {
    wx.setNavigationBarTitle({
      title: app.shopInfo.shopName
    });
  },
 
 
  //转发
  onShareAppMessage(res) {
 
  },
 
 
 
})