videolist.js 14 KB

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