beerWall.js 4.0 KB

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