beerCircles.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // pages/beerCircles/beerCircles.js
  2. const request = require("../../utils/request.js");
  3. const login = require("../../utils/login.js");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. handleStatus: true,
  10. parmas:{
  11. productId: null,
  12. contListType: 2,
  13. lastContentId: null
  14. },
  15. contentList: [],
  16. contentId: null
  17. },
  18. toaddArticle() {
  19. login.ifLogin('../pushArticle/pushArticle?productId='+this.data.parmas.productId)
  20. },
  21. contentlikeFun(event) {
  22. let that = this;
  23. let contentId = event.currentTarget.dataset.cid;
  24. let index = event.currentTarget.dataset.idx;
  25. request.postData(
  26. 'app/op/like',
  27. {recordType: 'ContentLike', outBusiId: contentId},
  28. res => {
  29. // that.getContentList();
  30. that.data.contentList[index].like = true;
  31. that.data.contentList[index].likeCount++;
  32. that.setData({
  33. contentList: that.data.contentList
  34. })
  35. },
  36. res => {
  37. console.log(res)
  38. }
  39. )
  40. },
  41. contentCellikeFun(event) {
  42. let that = this;
  43. let contentId = event.currentTarget.dataset.cid;
  44. let index = event.currentTarget.dataset.idx;
  45. request.postData(
  46. 'app/op/like/cancel',
  47. {recordType: 'ContentLike', outBusiId: contentId},
  48. res => {
  49. // that.getContentList();
  50. that.data.contentList[index].like = false;
  51. that.data.contentList[index].likeCount--;
  52. that.setData({
  53. contentList: that.data.contentList
  54. })
  55. },
  56. res => {
  57. console.log(res)
  58. }
  59. )
  60. },
  61. getContentList() {
  62. let that = this;
  63. request.getData(
  64. 'app/cont/content/list',
  65. that.data.parmas,
  66. res => {
  67. let arr = res.data.data;
  68. arr.forEach((item, index, array) => {
  69. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  70. item.scale = scale ? scale : 1;
  71. })
  72. that.setData({
  73. contentList: arr
  74. })
  75. },
  76. res => {
  77. console.log(res)
  78. }
  79. )
  80. },
  81. handleShow(event) {
  82. let contentId = event.currentTarget.dataset.cid ? event.currentTarget.dataset.cid : null;
  83. this.setData({
  84. handleStatus: !this.data.handleStatus,
  85. contentId: contentId
  86. })
  87. },
  88. toCirclesDetail(event) {
  89. let contentId = event.currentTarget.dataset.cid;
  90. login.ifLogin('../circlesDetail/circlesDetail?contentId=' + contentId)
  91. },
  92. toReport() {
  93. login.ifLogin('../report/report?targetType=Content&targetId=' + this.data.contentId)
  94. },
  95. /**
  96. * 生命周期函数--监听页面加载
  97. */
  98. onLoad(options) {
  99. this.data.parmas.productId = options.productId;
  100. this.setData({
  101. parmas: this.data.parmas,
  102. })
  103. wx.setNavigationBarTitle({
  104. title: options.name,
  105. })
  106. // this.getContentList()
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow() {
  117. this.setData({
  118. handleStatus: true
  119. })
  120. this.getContentList()
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload() {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh() {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom() {
  141. let that = this;
  142. that.data.parmas.lastContentId = Number(that.data.contentList[that.data.contentList.length-1].contentId);
  143. request.getData(
  144. 'app/cont/content/list',
  145. that.data.parmas,
  146. res => {
  147. if(res.data.data.length > 0) {
  148. let arr = res.data.data;
  149. arr.forEach((item, index, array) => {
  150. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  151. item.scale = scale ? scale : 1;
  152. })
  153. that.setData({
  154. contentList: that.data.contentList.concat(arr)
  155. })
  156. }
  157. },
  158. res => {
  159. console.log(res)
  160. }
  161. )
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage() {
  167. }
  168. })