index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. Page({
  2. dever: getApp().dever,
  3. data: {
  4. test : 1
  5. },
  6. /**
  7. * 生命周期函数--监听页面加载
  8. */
  9. onLoad: function (options) {
  10. var self = this;
  11. // 初始化购物车
  12. self.dever.carts(self, 'carts.save', 'carts/index');
  13. var success = function(data, res)
  14. {
  15. self.dever.setList(self, data.product);
  16. };
  17. self.dever.request('main.api.home', {}, {success: success});
  18. /*
  19. //test - begin
  20. var list = new Array();
  21. for(var i=1; i<4; i++){
  22. var item = new Object();
  23. item.id = i;
  24. item.pic = '/static/img/item-'+(1+Math.round(Math.random()*1))+'.png';
  25. item.name = i+'盒有机韭菜';
  26. item.price = i*20;
  27. list.push(item);
  28. }
  29. this.dever.setList(this, list);
  30. this.dever.stopPullDown();
  31. //test - end
  32. */
  33. },
  34. view: function (event) {
  35. if (typeof (event) == 'object') {
  36. var id = event.currentTarget.dataset.id
  37. } else {
  38. var id = event
  39. }
  40. this.dever.location('view/index?id=' + id);
  41. },
  42. addCarts: function (event){
  43. if (typeof (event) == 'object') {
  44. var id = event.currentTarget.dataset.id
  45. } else {
  46. var id = event
  47. }
  48. this.dever.location('carts/index?id=' + id);
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面隐藏
  62. */
  63. onHide: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面卸载
  67. */
  68. onUnload: function () {
  69. },
  70. /**
  71. * 页面相关事件处理函数--监听用户下拉动作
  72. */
  73. onPullDownRefresh: function () {
  74. this.dever.startPullDown(this);
  75. },
  76. /**
  77. * 用户点击右上角分享
  78. */
  79. onShareAppMessage: function () {
  80. },
  81. pay: function () {
  82. var params = {};
  83. wx.request({
  84. url: 'https://api.nongchanghezi.com/product/?l=api.buy&signature=MzIxZGN4MnNzOVRWS0NVTk9ybDlNWDdySEpLTnJ6OVRzVWgyVHpVUDVTQ1hsVzlsTGlzZDFxcVE=&product_id=1&num=5&name=test&mobile=15810090845&address=11',
  85. data: params,
  86. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  87. // header: {}, // 设置请求的 header
  88. header: { 'content-type': 'application/x-www-form-urlencoded' },
  89. success: function (res) {
  90. //注意:可以对参数解密等处理
  91. console.log(res);
  92. res.data.data = res.data.data.pay;
  93. wx.requestPayment({
  94. 'timeStamp': res.data.data.time,
  95. 'nonceStr': res.data.data.nonce_str,
  96. 'package': 'prepay_id=' + res.data.data.prepay_id,
  97. 'signType': res.data.data.sign_type,
  98. 'paySign': res.data.data.sign,
  99. 'success': function (res) {
  100. console.log(res);
  101. },
  102. 'fail': function (res) {
  103. console.log(res);
  104. }
  105. })
  106. },
  107. fail: function () {
  108. },
  109. complete: function () {
  110. // complete
  111. }
  112. })
  113. },
  114. })