index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. // pages/dynamic/index.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. tablebar: 5,
  10. theme_type: '',
  11. loadover: false,
  12. is_more: true,
  13. token: '',
  14. list: [],
  15. can_post: false,
  16. images: {}
  17. },
  18. down_post_id: 0, //最下面一篇帖子id
  19. up_post_id: 0, //最上面一篇帖子id
  20. post_id: 0, // 最后帖子id
  21. up_down: 1, // 1上拉加载,2下拉刷新加载
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. let that = this;
  27. wx.showLoading();
  28. wx.request({
  29. url: util.api() + 'index.php?s=/Apiindex/get_cur_theme_type',
  30. success: function (res) {
  31. if (res.data.code == 0) {
  32. that.setData({
  33. theme_type: res.data.type,
  34. loadover: true
  35. })
  36. }
  37. wx.hideLoading();
  38. }
  39. })
  40. let token = wx.getStorageSync('token');
  41. that.getQuanInfo(token);
  42. that.getAuth(token);
  43. that.setData({
  44. token: token
  45. });
  46. that.loadData();
  47. },
  48. /**
  49. * 获取圈子发布
  50. */
  51. getAuth: function (token) {
  52. let that = this;
  53. app.util.request({
  54. 'url': 'entry/wxapp/index',
  55. 'data': {
  56. controller: 'quan.get_quan_authority',
  57. 'token': token
  58. },
  59. success: function (res) {
  60. if (res.data.code == 0) {
  61. that.setData({
  62. can_post: true
  63. })
  64. }
  65. }
  66. })
  67. },
  68. /**
  69. * 加载圈子信息
  70. */
  71. getQuanInfo: function (token) {
  72. let that = this;
  73. app.util.request({
  74. 'url': 'entry/wxapp/index',
  75. 'data': {
  76. controller: 'quan.get_quan_info',
  77. 'token': token
  78. },
  79. success: function (res) {
  80. if (res.data.code == 0) {
  81. that.setData({
  82. quanInfo: res.data.data
  83. })
  84. }
  85. }
  86. })
  87. },
  88. /**
  89. * 加载圈子
  90. */
  91. loadData: function () {
  92. let that = this;
  93. if (that.up_down == 1) {
  94. that.post_id = that.down_post_id;
  95. } else {
  96. that.post_id = that.up_post_id;
  97. }
  98. app.util.request({
  99. 'url': 'entry/wxapp/index',
  100. 'data': {
  101. controller: 'quan.load',
  102. 'token': that.data.token,
  103. 'post_id': that.post_id,
  104. 'up_down': that.up_down
  105. },
  106. success: function (res) {
  107. if (res.data.code == 0) {
  108. that.down_post_id = res.data.down_post_id;
  109. that.up_post_id = res.data.up_post_id;
  110. let list = res.data.list;
  111. let oldlist = that.data.list;
  112. if (list.length<10){
  113. that.setData({ is_more: false })
  114. }
  115. if( that.up_down == 1 ) {
  116. that.setData({
  117. list: [...oldlist, ...list]
  118. })
  119. } else {
  120. that.setData({
  121. list: list
  122. })
  123. }
  124. } else {
  125. that.setData({
  126. is_more: false
  127. })
  128. }
  129. }
  130. })
  131. },
  132. /**
  133. * 图片预览
  134. */
  135. previewImg: function (e) {
  136. let imgIndex = e.currentTarget.dataset.imgidx;
  137. let listIndex = e.currentTarget.dataset.listidx;
  138. let imgArr = this.data.list[listIndex].content;
  139. wx.previewImage({
  140. current: imgArr[imgIndex],
  141. urls: imgArr,
  142. success: function (res) { },
  143. fail: function (res) {
  144. console.log('预览失败')
  145. }
  146. })
  147. },
  148. // 跳转发布
  149. goPost: function () {
  150. wx.navigateTo({
  151. url: '/Snailfish_shop/pages/dynamic/post/post',
  152. })
  153. },
  154. /**
  155. * 跳转商品
  156. */
  157. gotoGoods: function (e) {
  158. let id = e.currentTarget.dataset.gid;
  159. wx.navigateTo({
  160. url: '/Snailfish_shop/pages/goods/index?id='+id,
  161. })
  162. },
  163. /**
  164. * 图片信息获取
  165. */
  166. imageLoad: function (e) {
  167. var $width = e.detail.width,
  168. $height = e.detail.height,
  169. ratio = $width / $height;
  170. var viewWidth,viewHeight;
  171. if (ratio < 0.75){
  172. viewHeight = 400, viewWidth = 400*ratio;
  173. } else {
  174. viewWidth = 300,viewHeight = 300 / ratio;
  175. }
  176. var image = this.data.images;
  177. image[e.target.dataset.index] = {
  178. width: viewWidth,
  179. height: viewHeight
  180. }
  181. this.setData({
  182. images: image
  183. })
  184. },
  185. /**
  186. * 生命周期函数--监听页面初次渲染完成
  187. */
  188. onReady: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面显示
  192. */
  193. onShow: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面隐藏
  197. */
  198. onHide: function () {
  199. },
  200. goLink: function (event) {
  201. let link = event.currentTarget.dataset.link;
  202. wx.reLaunch({
  203. url: link
  204. })
  205. },
  206. // 下拉刷新
  207. pullRefresh: function () {
  208. let that = this;
  209. that.setData({
  210. is_more: true
  211. })
  212. this.up_down = 2;
  213. this.loadData();
  214. console.log('下拉刷新')
  215. },
  216. // 加载更多
  217. loadMore: function () {
  218. this.up_down = 1;
  219. if (this.data.is_more) this.loadData();
  220. console.log('加载更多')
  221. },
  222. /**
  223. * 生命周期函数--监听页面卸载
  224. */
  225. onUnload: function () {
  226. },
  227. /**
  228. * 用户点击右上角分享
  229. */
  230. onShareAppMessage: function () {
  231. var share_title = this.data.quan_share;
  232. return {
  233. title: share_title,
  234. path: 'Snailfish_shop/pages/dynamic/index',
  235. success: function (res) {
  236. // 转发成功
  237. },
  238. fail: function (res) {
  239. // 转发失败
  240. }
  241. }
  242. }
  243. })