shop.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // pages/shop/shop.js
  2. import { get } from "../../common/request.js"
  3. import pathmap from "../../common/pathmap"
  4. import stylemap from "../../common/stylemap"
  5. import share from "../../common/share"
  6. import { retCartData } from "../../data/car"
  7. var app = getApp();
  8. Page(Object.assign({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. offset:0,
  14. limit:10,
  15. lock:false,
  16. hasloadall:false,
  17. list:[]
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.setData({id:options.id})
  24. this.loadDetail();
  25. this.setData(stylemap);
  26. this.loadCars();
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. },
  58. /**
  59. * 用户点击右上角分享
  60. */
  61. onShareAppMessage: function () {
  62. },
  63. loadDetail:function(){
  64. var _self = this;
  65. get(pathmap.storeinfo, {
  66. store_id:this.data.id
  67. }, function (json) {
  68. _self.setData({
  69. info: json.data
  70. })
  71. })
  72. },
  73. makeCall:function(e){
  74. var number = e.currentTarget.dataset.phonenumber;
  75. wx.makePhoneCall({phoneNumber:number});
  76. },
  77. loadCars:function(){
  78. var _self = this;
  79. if(!this.data.lock&&!this.data.hasloadall){
  80. var para = {
  81. offset:this.data.offset,
  82. limit:this.data.limit,
  83. merchant_id:this.data.id
  84. }
  85. this.setData({
  86. lock:true
  87. })
  88. get(pathmap.searchcar, para, function (json) {
  89. var list = retCartData(json.data&&json.data.list)
  90. var nextoffset = _self.data.offset+_self.data.limit;
  91. var obj = {
  92. lock:false,
  93. list:_self.data.list.concat(list),
  94. total:json.data.total,
  95. offset:nextoffset
  96. }
  97. if(json.data.total<=nextoffset){
  98. obj.hasloadall=true
  99. }
  100. _self.setData(obj);
  101. })
  102. }
  103. }
  104. },share))