personHome.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // pages/personHome/personHome.js
  2. var app = getApp();
  3. const request = require("../../utils/request.js");
  4. const login = require("../../utils/login.js");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. info: {},
  11. userId: null,//当前用户
  12. beVisitedUserId: null,
  13. contentList: [],
  14. handleStatus: true,
  15. contentId: null
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. if(options.userId) {
  22. this.setData({
  23. userId: app.globalData.userInfo.userId,
  24. beVisitedUserId: options.userId
  25. })
  26. }else{
  27. this.setData({
  28. userId: app.globalData.userInfo.userId,
  29. beVisitedUserId: app.globalData.userInfo.userId,
  30. })
  31. }
  32. this.getInfo();
  33. this.getContentList();
  34. },
  35. /**
  36. * 生命周期函数--监听页面初次渲染完成
  37. */
  38. onReady() {
  39. },
  40. /**
  41. * 生命周期函数--监听页面显示
  42. */
  43. onShow() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面隐藏
  47. */
  48. onHide() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面卸载
  52. */
  53. onUnload() {
  54. },
  55. /**
  56. * 页面相关事件处理函数--监听用户下拉动作
  57. */
  58. onPullDownRefresh() {
  59. },
  60. /**
  61. * 页面上拉触底事件的处理函数
  62. */
  63. onReachBottom() {
  64. let that = this;
  65. let lastContentId = Number(that.data.contentList[that.data.contentList.length-1].contentId);
  66. request.getData(
  67. 'app/cont/content/mine',
  68. {beVisitedUserId: that.data.beVisitedUserId,lastContentId: lastContentId},
  69. res => {
  70. if(res.data.data.length > 0) {
  71. let arr = res.data.data;
  72. arr.forEach((item, index, array) => {
  73. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  74. item.scale = scale ? scale : 1;
  75. })
  76. that.setData({
  77. contentList: that.data.contentList.concat(arr)
  78. })
  79. }
  80. },
  81. res => {
  82. console.log(res)
  83. }
  84. )
  85. },
  86. /**
  87. * 用户点击右上角分享
  88. */
  89. onShareAppMessage(Object) {
  90. if(Object.from == 'button') {
  91. let title = Object.target.dataset.item.content
  92. let contentId = Object.target.dataset.item.contentId
  93. let imageUrl = Object.target.dataset.item.imgUrlList[0]
  94. return {
  95. title: title,
  96. imageUrl: imageUrl,
  97. path: '/pages/circlesDetail/circlesDetail?contentId=' + contentId
  98. }
  99. }
  100. },
  101. focusFun() {
  102. let that = this;
  103. request.postData(
  104. 'app/user/home/focus',
  105. {focusUserId: that.data.beVisitedUserId},
  106. res => {
  107. that.getInfo();
  108. wx.showToast({
  109. title: '关注成功',
  110. icon: 'success',
  111. duration: 2000
  112. })
  113. },
  114. res => {
  115. console.log(res)
  116. }
  117. )
  118. },
  119. unfocusFun() {
  120. let that = this;
  121. request.postData(
  122. 'app/user/home/unfocus',
  123. {unfocusUserId: that.data.beVisitedUserId},
  124. res => {
  125. that.getInfo();
  126. wx.showToast({
  127. title: '已取消关注',
  128. icon: 'success',
  129. duration: 2000
  130. })
  131. },
  132. res => {
  133. console.log(res)
  134. }
  135. )
  136. },
  137. toCirclesDetail(event) {
  138. let contentId = event.currentTarget.dataset.cid;
  139. login.ifLogin('../circlesDetail/circlesDetail?contentId=' + contentId)
  140. },
  141. handleShow(event) {
  142. let contentId = event.currentTarget.dataset.cid ? event.currentTarget.dataset.cid : null;
  143. this.setData({
  144. handleStatus: !this.data.handleStatus,
  145. contentId: contentId
  146. })
  147. },
  148. toReport() {
  149. login.ifLogin('../report/report?targetType=Content&targetId=' + this.data.contentId)
  150. },
  151. contentCellikeFun(event) {
  152. let that = this;
  153. let contentId = event.currentTarget.dataset.cid;
  154. let index = event.currentTarget.dataset.idx;
  155. request.postData(
  156. 'app/op/like/cancel',
  157. {recordType: 'ContentLike', outBusiId: contentId},
  158. res => {
  159. // that.getContentList();
  160. that.data.contentList[index].like = false;
  161. that.data.contentList[index].likeCount--;
  162. that.setData({
  163. contentList: that.data.contentList
  164. })
  165. },
  166. res => {
  167. console.log(res)
  168. }
  169. )
  170. },
  171. contentlikeFun(event) {
  172. let that = this;
  173. let contentId = event.currentTarget.dataset.cid;
  174. let index = event.currentTarget.dataset.idx;
  175. request.postData(
  176. 'app/op/like',
  177. {recordType: 'ContentLike', outBusiId: contentId},
  178. res => {
  179. // that.getContentList();
  180. that.data.contentList[index].like = true;
  181. that.data.contentList[index].likeCount++;
  182. that.setData({
  183. contentList: that.data.contentList
  184. })
  185. },
  186. res => {
  187. console.log(res)
  188. }
  189. )
  190. },
  191. getContentList() {
  192. let that = this;
  193. request.getData(
  194. 'app/cont/content/mine',
  195. {beVisitedUserId: that.data.beVisitedUserId},
  196. res => {
  197. let arr = res.data.data;
  198. arr.forEach((item, index, array) => {
  199. let scale = request.getUrlKey(item.imgUrlList[0], 'scale');
  200. item.scale = scale ? scale : 1;
  201. })
  202. that.setData({
  203. contentList: arr
  204. })
  205. },
  206. res => {
  207. console.log(res)
  208. }
  209. )
  210. },
  211. getInfo() {
  212. let that = this;
  213. request.getData(
  214. 'app/user/home/info',
  215. {beVisitedUserId: that.data.beVisitedUserId},
  216. res => {
  217. that.setData({
  218. info: res.data.data
  219. })
  220. },
  221. res => {
  222. console.log(res)
  223. }
  224. )
  225. },
  226. back() {
  227. wx.navigateBack({
  228. delta: 1
  229. })
  230. },
  231. })