index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. //test - begin
  19. var list = new Array();
  20. for(var i=1; i<4; i++){
  21. var item = new Object();
  22. item.id = i;
  23. item.pic = '/static/img/item-'+(1+Math.round(Math.random()*1))+'.png';
  24. item.name = i+'盒有机韭菜';
  25. item.price = i*20;
  26. list.push(item);
  27. }
  28. this.dever.setList(this, list);
  29. this.dever.stopPullDown();
  30. //test - end
  31. },
  32. view: function (event) {
  33. if (typeof (event) == 'object') {
  34. var id = event.currentTarget.dataset.id
  35. } else {
  36. var id = event
  37. }
  38. this.dever.location('view/index?id=' + id);
  39. },
  40. addCarts: function (event){
  41. if (typeof (event) == 'object') {
  42. var id = event.currentTarget.dataset.id
  43. } else {
  44. var id = event
  45. }
  46. this.dever.location('carts/index?id=' + id);
  47. },
  48. /**
  49. * 生命周期函数--监听页面初次渲染完成
  50. */
  51. onReady: function () {
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. this.dever.startPullDown(this);
  73. },
  74. /**
  75. * 用户点击右上角分享
  76. */
  77. onShareAppMessage: function () {
  78. },
  79. })