beerWall.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // pages/beerShop/beerShop.js
  2. const app = getApp();
  3. const request = require("../../utils/request.js");
  4. const login = require("../../utils/login.js");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. head_item: 0,
  11. choice_show: false,
  12. beerTypeId: null,
  13. breweryId: null,
  14. lastProductId: null,
  15. breweryTagList: [],
  16. styleList: [],
  17. productDataList: []
  18. },
  19. toBeerDetail(event) {
  20. wx.navigateTo({
  21. url: '../beerDetail/beerDetail?productId=' + event.currentTarget.dataset.pid
  22. })
  23. // login.ifLogin('../beerDetail/beerDetail?productId=' + event.currentTarget.dataset.pid)
  24. },
  25. getProductList() {
  26. let that = this;
  27. let breweryId = that.data.breweryId;
  28. let beerTypeId = that.data.beerTypeId;
  29. request.getData(
  30. 'app/product/list',
  31. {breweryId: breweryId, beerTypeId: beerTypeId},
  32. res => {
  33. that.setData({
  34. productDataList: res.data.data
  35. })
  36. },
  37. res => {
  38. console.log(res)
  39. }
  40. )
  41. },
  42. bindHead(event) {
  43. let id = event.currentTarget.dataset.id;
  44. if(this.data.head_item == id) {
  45. this.setData({
  46. head_item: 0,
  47. choice_show: false
  48. })
  49. }else{
  50. this.setData({
  51. head_item: id,
  52. choice_show: true
  53. })
  54. }
  55. },
  56. choiceShow() {
  57. this.setData({
  58. choice_show: false,
  59. head_item: 0,
  60. })
  61. },
  62. chooseStyle(e) {
  63. let id = e.currentTarget.dataset.id;
  64. if(this.data.beerTypeId == id) {
  65. this.setData({
  66. beerTypeId: null,
  67. choice_show: false,
  68. head_item: 0
  69. })
  70. }else{
  71. this.setData({
  72. beerTypeId: id,
  73. choice_show: false,
  74. head_item: 0
  75. })
  76. }
  77. this.getProductList();
  78. },
  79. chooseBrewery(e) {
  80. let id = e.currentTarget.dataset.id;
  81. if(this.data.breweryId == id) {
  82. this.setData({
  83. breweryId: null,
  84. choice_show: false,
  85. head_item: 0
  86. })
  87. }else{
  88. this.setData({
  89. breweryId: id,
  90. choice_show: false,
  91. head_item: 0
  92. })
  93. }
  94. this.getProductList();
  95. },
  96. getTagData() {
  97. let that = this;
  98. request.getData(
  99. 'app/tag/filtrate/list',{},
  100. res => {
  101. let breweryTagList = res.data.data.breweryTagList;
  102. breweryTagList.unshift({
  103. breaweryName: '全部',
  104. breweryId: null
  105. })
  106. let styleList = res.data.data.styleList;
  107. styleList.unshift({
  108. beerTypeName: '全部',
  109. beerTypeId: null
  110. })
  111. that.setData({
  112. breweryTagList: breweryTagList,
  113. styleList: styleList
  114. })
  115. },
  116. res => {
  117. console.log(res)
  118. }
  119. )
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. let that = this;
  126. that.getTagData();
  127. that.getProductList();
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  139. this.getTabBar().setData({
  140. selected: 1,
  141. unreadMsgNum: app.globalData.userInfo?app.globalData.userInfo.unreadMsgNum:0
  142. })
  143. }
  144. },
  145. /**
  146. * 生命周期函数--监听页面隐藏
  147. */
  148. onHide: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面卸载
  152. */
  153. onUnload: function () {
  154. },
  155. /**
  156. * 页面相关事件处理函数--监听用户下拉动作
  157. */
  158. onPullDownRefresh: function () {
  159. },
  160. /**
  161. * 页面上拉触底事件的处理函数
  162. */
  163. onReachBottom: function () {
  164. let that = this;
  165. let breweryId = that.data.breweryId;
  166. let beerTypeId = that.data.beerTypeId;
  167. let lastProductId = Number(that.data.productDataList[that.data.productDataList.length-1].productId);
  168. request.getData(
  169. 'app/product/list',
  170. {breweryId: breweryId,beerTypeId: beerTypeId, lastProductId: lastProductId},
  171. res => {
  172. that.setData({
  173. productDataList: that.data.productDataList.concat(res.data.data)
  174. })
  175. },
  176. res => {
  177. console.log(res)
  178. }
  179. )
  180. },
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function () {
  185. },
  186. })