article.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //var api = require("../../api.js"), app = getApp(),
  2. var is_loading_more = !1,
  3. is_no_more = !1;
  4. var api = require('../../utils/api.js');
  5. Page({
  6. data: {
  7. page: 1,
  8. video_list: [],
  9. article_list: [],
  10. url: "",
  11. hide: "hide",
  12. show: !1,
  13. animationData: {},
  14. show_video: null,
  15. tabList: [{
  16. tab: 'video',
  17. title: '视频'
  18. }, {
  19. tab: 'article',
  20. title: '文章'
  21. }],
  22. selectedTab: 'video',
  23. selectedVideoIndex: null,
  24. selectedVideoUrl: '',
  25. showVideo: false
  26. },
  27. onLoad: function(a) {
  28. // app.pageOnLoad(this);
  29. this.loadMoreGoodsList('both');
  30. },
  31. swiperTab: function(e) {
  32. var that = this;
  33. // console.log(e);
  34. if (e.detail.currentItemId != 'video') {
  35. this.setData({
  36. show_video: null,
  37. show: !0
  38. });
  39. }
  40. that.setData({
  41. selectedTab: e.detail.currentItemId
  42. });
  43. },
  44. clickTab: function(e) {
  45. var that = this;
  46. // console.log(e)
  47. if (e.target.dataset.current != 'video') {
  48. this.setData({
  49. show_video: null,
  50. show: !0
  51. });
  52. }
  53. if (this.data.selectedTab === e.target.dataset.current) {
  54. return false;
  55. } else {
  56. that.setData({
  57. selectedTab: e.target.dataset.current
  58. })
  59. }
  60. },
  61. onReady: function() {},
  62. onShow: function() {
  63. // app.pageOnShow(this);
  64. },
  65. onHide: function() {
  66. var context = wx.createVideoContext("video_" + this.data.show_video)
  67. context.stop()
  68. this.setData({
  69. show_video: null,
  70. show: !0
  71. });
  72. },
  73. onUnload: function() {},
  74. onPullDownRefresh: function() {},
  75. loadMoreGoodsList: function(tab) {
  76. var tab = tab || this.data.selectedTab;
  77. var o = this;
  78. // if (!is_loading_more) {
  79. // o.setData({
  80. // show_loading_bar: !0
  81. // }), is_loading_more = !0;
  82. var i = o.data.page;
  83. // var v = [{
  84. // "id":"234",
  85. // "title":"小程序项目整体介绍",
  86. // "url":"http://m1.beiyuesi.com/2.mp4",
  87. // "sort":"9",
  88. // "is_delete":"0",
  89. // "addtime":"1515120216",
  90. // "store_id":"20926",
  91. // "pic_url":"https://u5.9026.com/addons/swdz_mall/core/web/uploads/image/f0/f0734ad93d46497483344846864596a4.jpg",
  92. // "content":"想要自己开发APP,却备受组建开发团队的困扰更别说高昂的开发费用与漫长的开",
  93. // "type":"0",
  94. // "time":"01月05日",
  95. // "show":-1
  96. // },
  97. // {
  98. // "id": "235",
  99. // "title": "小程序模版介绍",
  100. // "url": "http://m1.beiyuesi.com/1.mp4",
  101. // "sort": "99",
  102. // "is_delete": "0",
  103. // "addtime": "1515120395",
  104. // "store_id": "20926",
  105. // "pic_url": "https://u5.9026.com/addons/swdz_mall/core/web/uploads/image/0e/0e739254177172e4b815d75f88da77b4.png",
  106. // "content": "小程序是腾讯旗下继朋友圈、公众号之后推出的又一款战略级的产品。是线下实体店实体零售转型升级、实现新突破的利器。小程序比公众号更容易传播和裂变,比传统电商更容易获客和成交,比朋友圈微商更专业和可信",
  107. // "type": "0",
  108. // "time": "01月05日",
  109. // "show": -1
  110. // },
  111. // ];
  112. wx.showLoading({
  113. title: '加载中',
  114. })
  115. wx.request({
  116. url: api.getMoreVideosAndArticlesUrl,
  117. method: 'GET',
  118. data: {
  119. 'video_offset': o.data.video_list.length,
  120. 'article_offset': o.data.article_list.length,
  121. 'type': tab
  122. },
  123. success: res => {
  124. if (res.data.status == 'success') {
  125. if (res.data.type != 'both' && res.data.list.length <= 0) {
  126. wx.showToast({
  127. title: '到底了',
  128. icon: 'none',
  129. duration: 800
  130. })
  131. } else {
  132. if (res.data.type == 'video') {
  133. var t = o.data.video_list.concat(res.data.list);
  134. o.setData({
  135. video_list: t,
  136. page: i + 1
  137. });
  138. } else if (res.data.type == 'article') {
  139. var t = o.data.article_list.concat(res.data.list);
  140. o.setData({
  141. article_list: t,
  142. page: i + 1
  143. });
  144. } else if (res.data.type == 'both') {
  145. var t = o.data.video_list.concat(res.data.video_list);
  146. o.setData({
  147. video_list: t,
  148. page: i + 1
  149. });
  150. var t = o.data.article_list.concat(res.data.article_list);
  151. o.setData({
  152. article_list: t,
  153. page: i + 1
  154. });
  155. }
  156. }
  157. }
  158. },
  159. complete: res => {
  160. wx.hideLoading()
  161. }
  162. })
  163. // app.request({
  164. // url: api.default.video_list,
  165. // data: {
  166. // page: i
  167. // },
  168. // success: function (a) {
  169. // 0 == a.data.list.length && (is_no_more = !0);
  170. // var t = o.data.video_list.concat(a.data.list);
  171. // o.setData({
  172. // video_list: t,
  173. // page: i + 1
  174. // });
  175. // },
  176. // complete: function () {
  177. // is_loading_more = !1, o.setData({
  178. // show_loading_bar: !1
  179. // });
  180. // }
  181. // });
  182. // }
  183. },
  184. play: function(a) {
  185. var url = a.currentTarget.dataset.url;
  186. var title = a.currentTarget.dataset.title;
  187. wx.navigateTo({
  188. url: '/pages/video/index?url=' + url + '&title=' + title,
  189. })
  190. // wx.createVideoContext("video_" + this.data.show_video).pause(), this.setData({
  191. // show_video: t,
  192. // show: !0
  193. // });
  194. },
  195. onReachBottom: function() {
  196. this.loadMoreGoodsList();
  197. // is_no_more || this.loadMoreGoodsList();
  198. },
  199. more: function(a) {
  200. var t = this,
  201. o = a.target.dataset.index,
  202. i = t.data.video_list,
  203. e = wx.createAnimation({
  204. duration: 1e3,
  205. timingFunction: "ease"
  206. });
  207. this.animation = e, -1 != i[o].show ? (e.rotate(0).step(), i[o].show = -1) : (e.rotate(0).step(),
  208. i[o].show = 0), t.setData({
  209. video_list: i,
  210. animationData: this.animation.export()
  211. });
  212. },
  213. redirectToArticle: function(e) {
  214. let id = e.currentTarget.dataset.id;
  215. wx.navigateTo({
  216. url: '/pages/article-detail/index?id=' + id
  217. })
  218. }
  219. });