Sanakey
2020-08-13 d98d05000c3d14e1f12a7754ebeea11ec1fa0f0b
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
// pages/detail/detail.js
var listData = require('../../data/test-data.js');
var WxParse = require('../../src/wxParse/wxParse.js');
var Quantity = require('../template/cart-input/cart-input-template.js');
var utils = require("../../utils/util.js")
var app = getApp();
 
var matcode = "";
var currentIndex = "";
 
Page(Object.assign({}, Quantity, {
 
  /**
   * 页面的初始数据
   */
  data: {
    isShow: false,
    Quantity: {
      quantity: 1,
      min: 1,
      max: 999999
    },
    clientHeight: "100%",
    overflow: "visible",
    list: [],
    //所有详情图片的高度  (必须)
    imgHeightsList:[],
    //图片宽度 
    // imgwidth: 750,
    // //默认  (必须)
    current: 0, //当前所在滑块的 index
    scrollLeft: 0, //滚动条的位置,一个选项卡宽度是90(自定义来自css),按比例90*n设置位置
    navlist: [],
    newMsg: '',
    // conlist: [
    //   {
    //     images: ["https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801132&di=5e568130a99adfe7a3c77a857ea93afd&imgtype=0&src=http%3A%2F%2Fimg.redocn.com%2Fsheji%2F20150512%2Ftaobaohuazhuangpinshangpinxiangqingyesheji_4321666.jpg",
    //       "https://upload-images.jianshu.io/upload_images/2464047-d97a7be761c51cf1.jpg"
    //     ]
    //   },
 
    //   {
    //   images: ["https://s1.ax2x.com/2018/09/27/5HcbnX.jpg", "https://upload-images.jianshu.io/upload_images/2464047-d97a7be761c51cf1.jpg",
    //     ]
    //   },
      
    //   {
    //     images: ["https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801130&di=5e9bf568bd91ec4e0465c244f2ed50a7&imgtype=0&src=http%3A%2F%2Fa.vpimg3.com%2Fupload%2Fmerchandise%2F190729%2Fshk-4045787141382-110_2.jpg",
    //       "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1538123801132&di=92284712efd718621a825712d5f2cf04&imgtype=0&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F40%2F02%2F93bOOOPICb8_1024.jpg"
    //     ]
    //   },
    //   {
    //     images: ["https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1566978673,1265238851&fm=26&gp=0.jpg"
    //     ]
    //   },
    //   {
    //     images: [
    //       "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1193292794,3586818293&fm=26&gp=0.jpg"
    //     ]
    //   }
 
    // ]
 
 
  },
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    let id = options.id;
    let index = options.index;
    currentIndex = index;
 
    this.setData({
      current: index,
      MatCode: id
    })
 
 
 
    wx.request({
      url: utils.getUrl('/shopping/getMatCodeList.do?' + 'fromdata=7'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      success: res=> {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        
        this.setData({
          navlist: res.data.list,
          scrollLeft: index * 90
        })
        
        
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/getMatCodeList.do');
      }
    })
 
 
    // matcode = options.id;
    // var that = this;
    wx.showLoading({
      mask: false,
      title: '加载中',
    })
    // option接收其他页面传递过来的值,?后面的变量名id
    wx.request({
      url: utils.getUrl('/shopping/getMatCode.do?matcode=' + options.id),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      method: "GET",
      success: res=> {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        this.setData({
          goodsItem: res.data.list,
        })
        WxParse.wxParse('article', 'html', res.data.list.Description, this, 5);
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/getMatCode.do');
      }
 
    });
 
    /**
     * WxParse.wxParse(bindName , type, data, target,imagePadding)
     * 1.bindName绑定的数据名(必填)
     * 2.type可以为html或者md(必填)
     * 3.data为传入的具体数据(必填)
     * 4.target为Page对象,一般为this(必填)
     * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)
     */
 
 
 
    // option接收其他页面传递过来的值,?后面的变量名id
  },
  /*查看图片*/
  viewImg: function(e) {
    var src = e.currentTarget.dataset.src;
    // console.log(src)
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: [src] // 需要预览的图片http链接列表
    })
  },
 
 
  // 隐藏层滑入
  showLayer: function() {
    var that = this;
    utils.showLayer(that, "translateY", 300, 0);
  },
 
  // 隐藏层滑出
  hideLayer: function() {
    var that = this;
    utils.hideLayer(that, "translateY", 500);
  },
 
  buyTap: function (event) {
 
    if (this.data.isShow) {
      this.hideLayer();
    } else {
      this.showLayer();
    }
  },
  handleZanQuantityChange(e) {
    var componentId = e.componentId;
    var quantity = e.quantity;
    this.setData({
      [`${componentId}.quantity`]: quantity,
      price: (this.data.goodsItem.price * quantity).toFixed(2)
 
    });
  },
 
  // 加入购物车触发事件
  addCart: function() {
    //获取数量,价格,商品名称,id,封面图
    var num = this.data.Quantity.quantity;
    var id = this.data.goodsItem.MatCode;
 
    wx.showLoading({
      title: '加载中',
    })
 
    wx.request({
      url: utils.getUrl('/shopping/cart.do?m=add&action=goshop'),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      data: {
        matcode: id,
        quantity: num
      },
      success: function (res) {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        wx.switchTab({
          url: '../cart/cart'
        });
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/cart.do');
      }
    })
 
 
 
 
    this.hideLayer();
 
  },
  
 
 
  //tab切换
  tab: function(event) {
    this.setData({
      current: event.target.dataset.current
    })
    //锚点处理
    this.setData({
      scrollLeft: event.target.dataset.current * 90
    })
 
    wx.showLoading({
      mask: false,
      title: '加载中',
    })
    // option接收其他页面传递过来的值,?后面的变量名id
    wx.request({
      url: utils.getUrl('/shopping/getMatCode.do?matcode=' + event.currentTarget.dataset.matcode),
      header: {
        "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID')
      },
      method: "GET",
      success: res => {
        wx.hideLoading();
        if(!utils.requestError(res)){
          return false;
        }
        this.setData({
          goodsItem: res.data.list,
        })
        WxParse.wxParse('article', 'html', res.data.list.Description, this, 5);
 
      },
      fail: function (errmsg) {
        utils.requestFail(errmsg,'/shopping/getMatCode.do');
      }
 
    });
  },
  // //滑动事件
  // eventchange: function(event) {
 
  //   this.setData({
  //     current: event.detail.current
  //   })
  //   //锚点处理
  //   this.setData({
  //     scrollLeft: event.detail.current * 90
  //   })
  // },
 
//  
  imageLoad: function (e) {
    // //获取图片真实宽度
    // var imgwidth = e.detail.width,
    //   imgheight = e.detail.height,
    //   //宽高比  
    //   ratio = imgwidth / imgheight;
    // // console.log(imgwidth, imgheight)
    // //计算的高度值  
    // var viewHeight = 750 / ratio;
    // var imgheight = viewHeight;
    // var imgheights = this.data.imgheights;
    // //把每一张图片的对应的高度记录到数组里  
    // imgheights[e.target.dataset.id] = imgheight;
    // this.setData({
    //   imgheights: imgheights
    // })
 
    // console.log(this.data.imgheights)
 
    var query = wx.createSelectorQuery();
    //选择id
    var that = this;
    var imgHeightsList = [];
    query.selectAll('.cosmo-img').boundingClientRect(function (rect) {
 
      for(let i = 0; i<rect.length;i++){
        imgHeightsList.push(rect[i].height)
      }
      that.setData({
        imgHeightsList: imgHeightsList
      })
      
    }).exec();
 
    // query.select('.cosmo-img').boundingClientRect()
    // query.exec(function (res) {
    //   //res就是 所有标签为mjltest的元素的信息 的数组
    //   console.log(res);
    //   //取高度
    //   // console.log(res[0].height);
    // })
  },
 
  // 提交fromid
  formIdSubmit: function (e) {
    // utils.formIdSubmit(e, this);
    wx.navigateTo({
      url: '../message/message',
    })
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // 发送行为信息
    if (app.globalData.FromUserId) {
      utils.userBehavior('ViewProductDetail', {matcode:this.data.MatCode});
    }
    
    
    // var that = this;
    // // 显示对方发来的最新消息
    // app.globalData.newMsgCallback = onMessage => {
    //   console.log('消息页监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data))
    //   utils.msgTimer(that);
    // }
    //
    // // 页面显示时更新未读消息的值
    // utils.refreshUnreadMsgNum(this);
 
  },
 
  /**
  * 用户点击右上角分享(index.js)
  */
  // onShareAppMessage: function (ops) {
    // if (ops.from === 'button') {
    //   // 来自页面内转发按钮
    //   console.log(ops.target)
    // }
    // return {
    //   title: 'pages/idCard/idCard?FromOpenId=' + app.globalData.openID + '&FromUserId=' + app.globalData.FromUserId || '我的分享123',
    //   path: 'pages/idCard/idCard?FromOpenId=' + app.globalData.openID + '&FromUserId=' + app.globalData.FromUserId,
    //   success: function (res) {
    //     // 转发成功
    //     console.log("转发成功:" + JSON.stringify(res));
    //     // utils.showModal(res)
    //   },
    //   fail: function (res) {
    //     // 转发失败
    //     console.log("转发失败:" + JSON.stringify(res));
    //   }
    // }
 
  // }
 
 
}))