videolist.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. const app = getApp();
  2. var utils = require("../../../utils/http"),
  3. page = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgUrl: app.globalData.imgUrl,
  10. videotext: '',
  11. videolist: [],
  12. leftlist: [],
  13. rightlist: [],
  14. titlist: [],
  15. secondtitlist: [],
  16. nowTagText: '',
  17. firsTitext: '',
  18. datashow: false,
  19. videotop: 80,
  20. top: app.globalData.statusBarHeight,
  21. hgt: app.globalData.titleBarHeight,
  22. loginFlag: false,
  23. mobileflag: false,
  24. canIUseGetUserProfile: false,
  25. companyobj: {},
  26. showAction: false,
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. wx.hideHomeButton()
  33. if (wx.getUserProfile) {
  34. this.setData({
  35. canIUseGetUserProfile: true
  36. })
  37. }
  38. if (!!options.scene) {
  39. options = unescape(options.scene);
  40. let arr = options.split('&');
  41. let obj = {};
  42. for (let i = 0; i < arr.length; i++) {
  43. let arr1 = arr[i].split('=');
  44. obj[arr1[0]] = arr1[1];
  45. }
  46. this.setData({
  47. firsTitext: obj.ftext,
  48. nowTagText: obj.nText
  49. })
  50. app.globalData.clientype = obj.ctp;
  51. app.globalData.shareuserid = obj.uid;
  52. } else {
  53. this.setData({
  54. firsTitext: options.ftext,
  55. nowTagText: options.nText
  56. })
  57. app.globalData.clientype = options.ctp;
  58. app.globalData.shareuserid = options.uid;
  59. }
  60. },
  61. //用户同意隐私协议
  62. agreePrivacy() {
  63. wx.showLoading({
  64. title: '加载中...',
  65. })
  66. this.login();
  67. },
  68. sharecompany: function () {
  69. const that = this;
  70. utils.$post({
  71. url: app.globalData.webUrl + 'client/index/content_belong_company',
  72. header: {
  73. 'Authorization': 'bearer ' + app.globalData.token
  74. },
  75. data: {
  76. client_type: app.globalData.clientype,
  77. uid: app.globalData.shareuserid
  78. },
  79. success: function (res) {
  80. if (res.data.code == '0') {
  81. app.globalData.companyobj = res.data.data;
  82. that.setData({
  83. companyobj: res.data.data
  84. })
  85. }
  86. },
  87. complete(res) {
  88. wx.hideLoading()
  89. }
  90. })
  91. },
  92. login: function () {
  93. var that = this;
  94. wx.login({
  95. success: function (data) {
  96. if (data.errMsg == 'login:ok') {
  97. utils.$post({
  98. url: app.globalData.webUrl + 'api/users/code2session',
  99. data: {
  100. code: data.code,
  101. share: app.globalData.shareuserid,
  102. client_type: app.globalData.clientype
  103. },
  104. success: function (r) {
  105. if (r.data.code == '0') {
  106. app.globalData.sharepersonobj = r.data.share ? r.data.share : r.data.user;
  107. app.globalData.token = r.data.token;
  108. that.videotitfun();
  109. that.setData({
  110. shareobj: app.globalData.sharepersonobj
  111. })
  112. that.sharecompany();
  113. if (!!r.data.user.phone) {
  114. app.globalData.sharename = !!r.data.share ? r.data.share.nickname : r.data.user.nickname;
  115. app.globalData.personMsg = r.data.user;
  116. app.globalData.userflag = false; //有个人信息
  117. var nickname = r.data.user.nickname;
  118. var phone = r.data.user.phone;
  119. app.globalData.phone = false; //没有手机号
  120. that.setData({
  121. loginFlag: false,
  122. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  123. })
  124. if (r.data.user.phone == '') {
  125. wx.hideLoading();
  126. app.globalData.phone = false; //没有手机号
  127. that.setData({
  128. phoneFlag: true,
  129. articlelogin: false
  130. })
  131. } else {
  132. app.globalData.phone = true; //有手机号
  133. that.setData({
  134. phoneFlag: false,
  135. })
  136. }
  137. that.videofun();
  138. } else {
  139. that.videofun();
  140. wx.hideLoading();
  141. that.setData({
  142. loginFlag: true,
  143. articlelogin: false
  144. })
  145. }
  146. }
  147. }
  148. })
  149. }
  150. }
  151. })
  152. },
  153. videofun: function () {
  154. this.videodata();
  155. },
  156. videotitfun: function () {
  157. var that = this;
  158. wx.showLoading({
  159. title: '加载中...',
  160. })
  161. utils.$post({
  162. url: app.globalData.webUrl + 'api/video/type',
  163. header: {
  164. 'Authorization': 'bearer ' + app.globalData.token
  165. },
  166. data: {},
  167. success: function (res) {
  168. wx.hideLoading();
  169. if (res.data.code == 0) {
  170. that.setData({
  171. titlist: res.data.data,
  172. })
  173. if (!!that.data.firsTitext) {
  174. that.setData({
  175. videotop: '168',//顶部padding
  176. })
  177. for (let item of res.data.data) {
  178. if (item.id == that.data.firsTitext) {
  179. that.setData({
  180. secondtitlist: item.sonLabel
  181. })
  182. }
  183. }
  184. }
  185. }
  186. }
  187. })
  188. },
  189. videodata: function () {
  190. var that = this;
  191. that.setData({
  192. datashow: true,
  193. })
  194. page = 1;
  195. utils.$post({
  196. url: app.globalData.webUrl + 'client/video/list',
  197. header: {
  198. 'Authorization': 'bearer ' + app.globalData.token
  199. },
  200. data: {
  201. type: that.data.firsTitext,
  202. label: that.data.nowTagText,
  203. page: 1,
  204. limit: "10",
  205. keyword: ''
  206. },
  207. success: function (res) {
  208. if (res.data.code == 0) {
  209. that.setData({
  210. videolist: res.data.data,
  211. leftlist: [],
  212. rightlist: []
  213. })
  214. setTimeout(function () {
  215. that.videoimgload();
  216. }, 50)
  217. }
  218. setTimeout(function () {
  219. wx.hideLoading();
  220. }, 1000)
  221. }
  222. })
  223. },
  224. videoimgload: function () {
  225. var that = this;
  226. var leftlist = that.data.leftlist;
  227. var rightlist = that.data.rightlist;
  228. var videolist = that.data.videolist;
  229. if (videolist.length == 0) {
  230. return false;
  231. }
  232. let vidoemsg = videolist[0];
  233. if (!vidoemsg) {
  234. that.setData({
  235. videolist: [],
  236. })
  237. return false;
  238. }
  239. if (leftlist.length == 0) {
  240. leftlist.push(vidoemsg);
  241. videolist.shift();
  242. that.setData({
  243. videolist: videolist,
  244. leftlist: leftlist,
  245. rightlist: rightlist
  246. })
  247. } else {
  248. var leftheight, rightheight;
  249. setTimeout(() => {
  250. wx.createSelectorQuery().select('.leftvideolistbox').boundingClientRect(function (res) {
  251. leftheight = res.height;
  252. wx.createSelectorQuery().select('.rightvideolistbox').boundingClientRect(function (rs) {
  253. leftlist = that.data.leftlist;
  254. rightlist = that.data.rightlist;
  255. rightheight = rs.height;
  256. if (leftheight <= rightheight) {
  257. leftlist.push(vidoemsg);
  258. videolist.shift();
  259. } else {
  260. rightlist.push(vidoemsg);
  261. videolist.shift();
  262. }
  263. that.setData({
  264. videolist: videolist,
  265. leftlist: leftlist,
  266. rightlist: rightlist
  267. })
  268. }).exec();
  269. }).exec();
  270. }, 100)
  271. }
  272. },
  273. firsttap: function (e) {
  274. var that = this;
  275. if (e.currentTarget.dataset.fid != '') {
  276. that.setData({
  277. firsTitext: e.currentTarget.dataset.fid,
  278. nowTagText: '',
  279. videotop: '168',//顶部padding
  280. secondtitlist: that.data.titlist[e.currentTarget.dataset.idx].sonLabel
  281. })
  282. } else {
  283. that.setData({
  284. firsTitext: e.currentTarget.dataset.fid,
  285. nowTagText: '',
  286. videotop: '80',//顶部padding
  287. secondtitlist: []
  288. })
  289. }
  290. this.videodata()
  291. },
  292. childtypetap: function (e) {
  293. this.setData({
  294. nowTagText: e.currentTarget.dataset.sid,
  295. })
  296. this.videodata();
  297. },
  298. videoTap: function (e) {
  299. wx.navigateTo({
  300. url: "/share/pages/videoshare/videoshare?vid=" + e.currentTarget.dataset.vid + '&userid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  301. });
  302. },
  303. golastap: function () {
  304. wx.navigateBack()
  305. },
  306. goindextap: function () {
  307. wx.reLaunch({
  308. url: '/pages/index/index?state=1',
  309. })
  310. },
  311. toPageNameCard() {
  312. wx.navigateTo({
  313. url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share',
  314. })
  315. },
  316. /**
  317. * 生命周期函数--监听页面初次渲染完成
  318. */
  319. onReady: function () {
  320. },
  321. /**
  322. * 生命周期函数--监听页面显示
  323. */
  324. onShow: function () {
  325. },
  326. /**
  327. * 生命周期函数--监听页面隐藏
  328. */
  329. onHide: function () {
  330. },
  331. /**
  332. * 生命周期函数--监听页面卸载
  333. */
  334. onUnload: function () {
  335. },
  336. /**
  337. * 页面相关事件处理函数--监听用户下拉动作
  338. */
  339. onPullDownRefresh: function () {
  340. var that = this;
  341. page = 1;
  342. utils.$post({
  343. url: app.globalData.webUrl + 'client/video/list',
  344. header: {
  345. 'Authorization': 'bearer ' + app.globalData.token
  346. },
  347. data: {
  348. type: that.data.firsTitext,
  349. label: that.data.nowTagText,
  350. page: 1,
  351. limit: "10",
  352. keyword: ''
  353. },
  354. success: function (res) {
  355. wx.stopPullDownRefresh()
  356. if (res.data.code == 0) {
  357. that.setData({
  358. videolist: res.data.data,
  359. leftlist: [],
  360. rightlist: []
  361. })
  362. setTimeout(function () {
  363. that.videoimgload();
  364. }, 50)
  365. }
  366. }
  367. })
  368. },
  369. /**
  370. * 页面上拉触底事件的处理函数
  371. */
  372. onReachBottom: function () {
  373. let that = this;
  374. page = page * 1 + 1;
  375. wx.showLoading({
  376. title: '加载中...',
  377. })
  378. utils.$post({
  379. url: app.globalData.webUrl + 'client/video/list',
  380. header: {
  381. 'Authorization': 'bearer ' + app.globalData.token
  382. },
  383. data: {
  384. type: that.data.firsTitext,
  385. label: that.data.nowTagText,
  386. page: page,
  387. limit: "10",
  388. user_id: app.globalData.personMsg.id
  389. },
  390. success: function (res) {
  391. setTimeout(function () {
  392. wx.hideLoading()
  393. }, 1200)
  394. if (res.data.code == 0) {
  395. var arr = res.data.data;
  396. var arrflag = false;
  397. var videolist = that.data.videolist;
  398. if (videolist.length != 0) {
  399. arrflag = true;
  400. }
  401. for (var i = 0; i < arr.length; i++) {
  402. videolist.push(arr[i]);
  403. }
  404. that.setData({
  405. videolist: videolist,
  406. })
  407. if (!arrflag) {
  408. that.videoimgload();
  409. }
  410. }
  411. }
  412. })
  413. },
  414. /**
  415. * 用户点击右上角分享
  416. */
  417. onShareAppMessage: function () {
  418. let that = this;
  419. return {
  420. title: app.globalData.personMsg.binded.name + "的视频素材",
  421. imageUrl: app.globalData.imgUrl + "xcx/videoposter.png",
  422. path: '/share/pages/videolist/videolist?uid=' + app.globalData.personMsg.id + '&ftext=' + that.data.firsTitext + '&nText=' + that.data.nowTagText + '&ctp=' + app.globalData.clientype
  423. }
  424. }
  425. })