Page({ dever: getApp().dever, data: { test : 1 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var self = this; // 初始化购物车 self.dever.carts(self, 'carts.save', 'carts/index'); var success = function(data, res) { self.dever.setList(self, data.product); }; self.dever.request('main.api.home', {}, {success: success}); /* //test - begin var list = new Array(); for(var i=1; i<4; i++){ var item = new Object(); item.id = i; item.pic = '/static/img/item-'+(1+Math.round(Math.random()*1))+'.png'; item.name = i+'盒有机韭菜'; item.price = i*20; list.push(item); } this.dever.setList(this, list); this.dever.stopPullDown(); //test - end */ }, view: function (event) { if (typeof (event) == 'object') { var id = event.currentTarget.dataset.id } else { var id = event } this.dever.location('view/index?id=' + id); }, addCarts: function (event){ if (typeof (event) == 'object') { var id = event.currentTarget.dataset.id } else { var id = event } this.dever.location('carts/index?id=' + id); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { this.dever.startPullDown(this); }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, pay: function () { var params = {}; wx.request({ url: 'https://api.nongchanghezi.com/product/?l=api.buy&signature=MzIxZGN4MnNzOVRWS0NVTk9ybDlNWDdySEpLTnJ6OVRzVWgyVHpVUDVTQ1hsVzlsTGlzZDFxcVE=&product_id=1&num=5&name=test&mobile=15810090845&address=11', data: params, method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT // header: {}, // 设置请求的 header header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (res) { //注意:可以对参数解密等处理 console.log(res); res.data.data = res.data.data.pay; wx.requestPayment({ 'timeStamp': res.data.data.time, 'nonceStr': res.data.data.nonce_str, 'package': 'prepay_id=' + res.data.data.prepay_id, 'signType': res.data.data.sign_type, 'paySign': res.data.data.sign, 'success': function (res) { console.log(res); }, 'fail': function (res) { console.log(res); } }) }, fail: function () { }, complete: function () { // complete } }) }, })