circles.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // pages/circles/circles.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. handleStatus: true,
  11. parmas:{
  12. contListType: 1,
  13. lastContentId: null
  14. },
  15. contentList: [],
  16. contentId: null
  17. },
  18. toPersonHome(event) {
  19. let userId = event.currentTarget.dataset.userid;
  20. login.ifLogin('../personHome/personHome?userId=' + userId)
  21. },
  22. contentlikeFun(event) {
  23. let that = this;
  24. let contentId = event.currentTarget.dataset.cid;
  25. let index = event.currentTarget.dataset.idx;
  26. request.postData(
  27. 'app/op/like',
  28. {recordType: 'ContentLike', outBusiId: contentId},
  29. res => {
  30. // that.getContentList();
  31. that.data.contentList[index].like = true;
  32. that.data.contentList[index].likeCount++;
  33. that.setData({
  34. contentList: that.data.contentList
  35. })
  36. },
  37. res => {
  38. console.log(res)
  39. }
  40. )
  41. },
  42. contentCellikeFun(event) {
  43. let that = this;
  44. let contentId = event.currentTarget.dataset.cid;
  45. let index = event.currentTarget.dataset.idx;
  46. request.postData(
  47. 'app/op/like/cancel',
  48. {recordType: 'ContentLike', outBusiId: contentId},
  49. res => {
  50. // that.getContentList();
  51. that.data.contentList[index].like = false;
  52. that.data.contentList[index].likeCount--;
  53. that.setData({
  54. contentList: that.data.contentList
  55. })
  56. },
  57. res => {
  58. console.log(res)
  59. }
  60. )
  61. },
  62. getContentList() {
  63. let that = this;
  64. request.getData(
  65. 'app/cont/content/list',
  66. that.data.parmas,
  67. res => {
  68. let arr = res.data.data;
  69. arr.forEach((item, index, array) => {
  70. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  71. item.scale = scale ? scale : 1;
  72. })
  73. that.setData({
  74. contentList: arr
  75. })
  76. },
  77. res => {
  78. console.log(res)
  79. }
  80. )
  81. },
  82. bindItem(event) {
  83. this.data.parmas.contListType = event.currentTarget.dataset.id;
  84. this.data.parmas.lastContentId = null;
  85. this.setData({
  86. parmas: this.data.parmas
  87. })
  88. wx.pageScrollTo({
  89. scrollTop: 0,
  90. duration: 500
  91. })
  92. this.getContentList();
  93. },
  94. handleShow(event) {
  95. let contentId = event.currentTarget.dataset.cid ? event.currentTarget.dataset.cid : null;
  96. this.setData({
  97. handleStatus: !this.data.handleStatus,
  98. contentId: contentId
  99. })
  100. },
  101. toaddArticle() {
  102. login.ifLogin('../pushArticle/pushArticle')
  103. },
  104. toCirclesDetail(event) {
  105. let contentId = event.currentTarget.dataset.cid;
  106. login.ifLogin('../circlesDetail/circlesDetail?contentId=' + contentId)
  107. },
  108. toReport() {
  109. login.ifLogin('../report/report?targetType=Content&targetId=' + this.data.contentId)
  110. },
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad(options) {
  115. this.getContentList()
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow() {
  126. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  127. this.getTabBar().setData({
  128. selected: 2,
  129. unreadMsgNum: app.globalData.userInfo?app.globalData.userInfo.unreadMsgNum:0
  130. })
  131. }
  132. this.setData({
  133. handleStatus: true
  134. })
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide() {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload() {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh() {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom() {
  155. let that = this;
  156. that.data.parmas.lastContentId = Number(that.data.contentList[that.data.contentList.length-1].contentId);
  157. request.getData(
  158. 'app/cont/content/list',
  159. that.data.parmas,
  160. res => {
  161. if(res.data.data.length > 0) {
  162. let arr = res.data.data;
  163. arr.forEach((item, index, array) => {
  164. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  165. item.scale = scale ? scale : 1;
  166. })
  167. that.setData({
  168. contentList: that.data.contentList.concat(arr)
  169. })
  170. }
  171. },
  172. res => {
  173. console.log(res)
  174. }
  175. )
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage(Object) {
  181. if(Object.from == 'button') {
  182. let title = Object.target.dataset.item.content
  183. let contentId = Object.target.dataset.item.contentId
  184. let imageUrl = Object.target.dataset.item.imgUrlList[0]
  185. return {
  186. title: title,
  187. imageUrl: imageUrl,
  188. path: '/pages/circlesDetail/circlesDetail?contentId=' + contentId
  189. }
  190. }
  191. },
  192. onShareTimeline() {
  193. }
  194. })