index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. const util = require('../../../utils/util.js');
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. statusBarHeight: 0,
  8. navheight: 0,
  9. pagetop: 0,
  10. scrollTop: 0,
  11. numop: 0,
  12. key: 1,
  13. paramsDetail: {
  14. pageSize: 10
  15. },
  16. pageIndex: 1,
  17. topImgText: [], //顶部数组
  18. allActivePhoto: [], //活动相册所有数据
  19. activePhoto: [], //活动相册9条数据
  20. activityRecord: [],
  21. url: '',
  22. historyTitle: '',
  23. historyBgImage: '',
  24. topHeight: 47,
  25. aid: '',
  26. isshare: 0, //不是分享页面进入
  27. },
  28. // 点击左上返回
  29. back() {
  30. wx.navigateBack({
  31. delta: 1,
  32. })
  33. },
  34. backJT() {
  35. wx.navigateBack({
  36. delta: 1,
  37. })
  38. },
  39. // 相册记录切换
  40. changeType(e) {
  41. let key = e.currentTarget.dataset.key
  42. let that = this
  43. if (key == 1) {
  44. this.getActivityPhoto()
  45. }
  46. if (key == 2) {
  47. that.data.paramsDetail.articleType = 1
  48. let data = that.data.paramsDetail
  49. util.ajax({
  50. func: 'v2/article/product_system/history/list',
  51. data,
  52. method: 'POST'
  53. }, ({
  54. data,
  55. code
  56. }) => {
  57. if (code == 0) {
  58. that.setData({
  59. activityRecord: data
  60. })
  61. }
  62. })
  63. }
  64. this.setData({
  65. key
  66. })
  67. },
  68. backHome: function () {
  69. wx.reLaunch({
  70. url: '/pages/home/index'
  71. })
  72. },
  73. onLoad(options) {
  74. console.log(options);
  75. if (options.isshare == 1) {
  76. console.log('是分享进入');
  77. this.setData({
  78. 'isshare': options.isshare
  79. })
  80. }
  81. wx.showShareMenu({
  82. withShareTicket: true,
  83. //设置下方的Menus菜单,才能够让发送给朋友与分享到朋友圈两个按钮可以点击
  84. menus: ["shareAppMessage", "shareTimeline"]
  85. })
  86. this.data.paramsDetail.psId = options.psId
  87. this.data.paramsDetail.articleType = this.data.key
  88. this.setData({
  89. aid: options.aid,
  90. // 状态栏的高度
  91. statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'] + 'px',
  92. // 胶囊的高度 也就是自定导航栏的高度
  93. navheight: wx.getMenuButtonBoundingClientRect()['height'] + 'px',
  94. // 状态栏加导航栏的高度 加上下的padding的高度 12
  95. pagetop: wx.getMenuButtonBoundingClientRect()['height'] + wx.getSystemInfoSync()['statusBarHeight'] + 12 + 'px',
  96. })
  97. console.log(this.data.statusBarHeight);
  98. this.getTopImgText()
  99. this.getActivityPhoto()
  100. // console.log(this.data.statusBarHeight)
  101. // console.log(this.data.navheight)
  102. // console.log(this.data.pagetop)
  103. },
  104. onPageScroll(e) { //页面滚动就会触发
  105. let height = this.data.statusBarHeight
  106. this.setData({
  107. scrollTop: e.scrollTop,
  108. topHeight: parseInt(height)
  109. })
  110. // console.log(this.data.topHeight);
  111. },
  112. // 获取顶部图文信息
  113. getTopImgText() {
  114. console.log(this.data.paramsDetail);
  115. let that = this
  116. util.ajax({
  117. func: 'v2/article/product_system/history/info',
  118. data: this.data.paramsDetail,
  119. method: 'POST'
  120. }, ({
  121. data,
  122. code
  123. }) => {
  124. if (code == 0) {
  125. // console.log(data);
  126. that.setData({
  127. topImgText: data,
  128. historyTitle: data.historyTitle,
  129. historyBgImage: data.historyBgImage
  130. })
  131. }
  132. })
  133. },
  134. // 获取活动相册信息
  135. getActivityPhoto(p) {
  136. let that = this
  137. that.data.paramsDetail.articleType = 0
  138. // that.data.paramsDetail.pageSize = 10
  139. // that.data.paramsDetail.pageIndex = 0
  140. console.log(that.data.paramsDetail);
  141. util.ajax({
  142. func: 'v2/article/product_system/history/list',
  143. data: that.data.paramsDetail,
  144. method: 'POST'
  145. }, ({
  146. data,
  147. code
  148. }) => {
  149. if (code == 0) {
  150. // console.log(data);
  151. that.data.allActivePhoto = data
  152. data.forEach((item, index) => {
  153. if (index < 9) {
  154. that.data.activePhoto.push(item)
  155. }
  156. });
  157. that.setData({
  158. activePhoto: data
  159. })
  160. // console.log(that.data.activePhoto);
  161. }
  162. })
  163. },
  164. //下拉刷新
  165. onReachBottom: function (e) { //触底开始下一页
  166. // var that = this;
  167. // that.data.pageIndex = that.data.pageIndex + 1; //获取当前页数并+1
  168. // that.setData({
  169. // pageIndex: that.data.pageIndex
  170. // })
  171. // console.log(that.data.pageIndex);
  172. // that.getActivityPhoto(that.data.pageIndex); //重新调用请求获取下一页数据
  173. // console.log(this.data.allActivePhoto);
  174. const {
  175. allActivePhoto,
  176. activePhoto
  177. } = this.data;
  178. const start = activePhoto.length;
  179. const end = Math.min(start + 6, allActivePhoto.length - 1);
  180. if (activePhoto.length == allActivePhoto.length) {
  181. return;
  182. }
  183. for (let i = start; i <= end; i++) {
  184. activePhoto.push(allActivePhoto[i])
  185. }
  186. this.setData({
  187. activePhoto
  188. })
  189. },
  190. // 分享给朋友
  191. onShareAppMessage(options) {
  192. console.log(options);
  193. return {
  194. title: this.data.historyTitle,
  195. path: '/pages/product/Previous/index?psId=' + this.data.paramsDetail.psId + '&isshare=1',
  196. imageUrl: this.data.historyBgImage
  197. }
  198. },
  199. //分享到朋友圈
  200. onShareTimeline: function () {
  201. return {
  202. title: this.data.historyTitle,
  203. imageUrl: this.data.historyBgImage
  204. }
  205. },
  206. //图片预览
  207. previewImage(e) {
  208. let urls = []
  209. let imgUrl = e.currentTarget.dataset.imgurl
  210. let act = this.data.allActivePhoto
  211. act.forEach((e) => {
  212. if (e.type == 4) {
  213. urls.push(e.logo)
  214. }
  215. })
  216. // urls.push(imgUrl)
  217. wx.previewImage({
  218. current: e.currentTarget.dataset.imgurl, // 当前显示图片的http链接
  219. urls,
  220. })
  221. // console.log(urls);
  222. },
  223. //视频播放
  224. previewVideo(e) {
  225. console.log(e);
  226. wx.previewMedia({
  227. sources: [{
  228. url: e.currentTarget.dataset.vdurl, //视频播放路径
  229. type: 'video' //video视频 image图片
  230. }]
  231. })
  232. },
  233. channelVideo(e) {
  234. console.log(e);
  235. let feedId = e.currentTarget.dataset.vdnum
  236. let finderUserName = e.currentTarget.dataset.uname
  237. console.log(feedId);
  238. console.log(finderUserName);
  239. wx.openChannelsActivity({
  240. finderUserName,
  241. feedId,
  242. success: function (res) {
  243. console.log(res)
  244. },
  245. complete: function () {
  246. console.log('调用');
  247. }
  248. })
  249. },
  250. //推文跳转
  251. tweet(e) {
  252. console.log(e);
  253. let url = e.currentTarget.dataset.content
  254. let title = e.currentTarget.dataset.title
  255. wx.navigateTo({
  256. url: '/pages/public/swiper/web?url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title),
  257. })
  258. },
  259. })