videolist.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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/code2sessionmini',
  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.phone) {
  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. that.videofun();
  137. wx.hideLoading();
  138. that.setData({
  139. loginFlag: true,
  140. articlelogin: false
  141. })
  142. }
  143. }
  144. }
  145. })
  146. }
  147. }
  148. })
  149. },
  150. videofun:function(){
  151. this.videodata();
  152. },
  153. videotitfun: function () {
  154. var that = this;
  155. wx.showLoading({
  156. title: '加载中...',
  157. })
  158. utils.$post({
  159. url: app.globalData.webUrl + 'api/video/type',
  160. header: {
  161. 'Authorization': 'bearer ' + app.globalData.token
  162. },
  163. data: {},
  164. success: function (res) {
  165. wx.hideLoading();
  166. if (res.data.code == 0) {
  167. that.setData({
  168. titlist: res.data.data,
  169. })
  170. if(!!that.data.firsTitext){
  171. that.setData({
  172. videotop:'168',//顶部padding
  173. })
  174. for(let item of res.data.data){
  175. if(item.id==that.data.firsTitext){
  176. that.setData({
  177. secondtitlist:item.sonLabel
  178. })
  179. }
  180. }
  181. }
  182. }
  183. }
  184. })
  185. },
  186. videodata: function () {
  187. var that = this;
  188. that.setData({
  189. datashow: true,
  190. })
  191. page=1;
  192. utils.$post({
  193. url: app.globalData.webUrl + 'client/video/list',
  194. header: {
  195. 'Authorization': 'bearer ' + app.globalData.token
  196. },
  197. data: {
  198. type: that.data.firsTitext,
  199. label: that.data.nowTagText,
  200. page: 1,
  201. limit: "10",
  202. keyword: ''
  203. },
  204. success: function (res) {
  205. if (res.data.code == 0) {
  206. that.setData({
  207. videolist: res.data.data,
  208. leftlist: [],
  209. rightlist: []
  210. })
  211. setTimeout(function () {
  212. that.videoimgload();
  213. }, 50)
  214. }
  215. setTimeout(function () {
  216. wx.hideLoading();
  217. }, 1000)
  218. }
  219. })
  220. },
  221. videoimgload:function(){
  222. var that=this;
  223. var leftlist=that.data.leftlist;
  224. var rightlist=that.data.rightlist;
  225. var videolist=that.data.videolist;
  226. if(videolist.length==0){
  227. return false;
  228. }
  229. let vidoemsg=videolist[0];
  230. if(!vidoemsg){
  231. that.setData({
  232. videolist:[],
  233. })
  234. return false;
  235. }
  236. if(leftlist.length==0){
  237. leftlist.push(vidoemsg);
  238. videolist.shift();
  239. that.setData({
  240. videolist:videolist,
  241. leftlist:leftlist,
  242. rightlist:rightlist
  243. })
  244. }else{
  245. var leftheight,rightheight;
  246. setTimeout(() => {
  247. wx.createSelectorQuery().select('.leftvideolistbox').boundingClientRect(function(res){
  248. leftheight=res.height;
  249. wx.createSelectorQuery().select('.rightvideolistbox').boundingClientRect(function(rs){
  250. leftlist=that.data.leftlist;
  251. rightlist=that.data.rightlist;
  252. rightheight=rs.height;
  253. if(leftheight<=rightheight){
  254. leftlist.push(vidoemsg);
  255. videolist.shift();
  256. }else{
  257. rightlist.push(vidoemsg);
  258. videolist.shift();
  259. }
  260. that.setData({
  261. videolist:videolist,
  262. leftlist:leftlist,
  263. rightlist:rightlist
  264. })
  265. }).exec();
  266. }).exec();
  267. },100)
  268. }
  269. },
  270. firsttap:function(e){
  271. var that=this;
  272. if(e.currentTarget.dataset.fid!=''){
  273. that.setData({
  274. firsTitext:e.currentTarget.dataset.fid,
  275. nowTagText:'',
  276. videotop:'168',//顶部padding
  277. secondtitlist:that.data.titlist[e.currentTarget.dataset.idx].sonLabel
  278. })
  279. }else{
  280. that.setData({
  281. firsTitext:e.currentTarget.dataset.fid,
  282. nowTagText:'',
  283. videotop:'80',//顶部padding
  284. secondtitlist:[]
  285. })
  286. }
  287. this.videodata()
  288. },
  289. childtypetap:function(e){
  290. this.setData({
  291. nowTagText:e.currentTarget.dataset.sid,
  292. })
  293. this.videodata();
  294. },
  295. videoTap:function(e){
  296. wx.navigateTo({
  297. url: "/share/pages/videoshare/videoshare?vid=" + e.currentTarget.dataset.vid+'&userid='+app.globalData.shareuserid+'&ctp='+app.globalData.clientype
  298. });
  299. },
  300. golastap:function(){
  301. wx.navigateBack()
  302. },
  303. goindextap:function(){
  304. wx.reLaunch({
  305. url: '/pages/index/index?state=1',
  306. })
  307. },
  308. toPageNameCard () {
  309. wx.navigateTo({
  310. url: '/share/pages/shareCard/shareCard?uid='+ app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share',
  311. })
  312. },
  313. /**
  314. * 生命周期函数--监听页面初次渲染完成
  315. */
  316. onReady: function () {
  317. },
  318. /**
  319. * 生命周期函数--监听页面显示
  320. */
  321. onShow: function () {
  322. },
  323. /**
  324. * 生命周期函数--监听页面隐藏
  325. */
  326. onHide: function () {
  327. },
  328. /**
  329. * 生命周期函数--监听页面卸载
  330. */
  331. onUnload: function () {
  332. },
  333. /**
  334. * 页面相关事件处理函数--监听用户下拉动作
  335. */
  336. onPullDownRefresh: function () {
  337. var that = this;
  338. page=1;
  339. utils.$post({
  340. url: app.globalData.webUrl + 'client/video/list',
  341. header: {
  342. 'Authorization': 'bearer ' + app.globalData.token
  343. },
  344. data: {
  345. type: that.data.firsTitext,
  346. label: that.data.nowTagText,
  347. page: 1,
  348. limit: "10",
  349. keyword: ''
  350. },
  351. success: function (res) {
  352. wx.stopPullDownRefresh()
  353. if (res.data.code == 0) {
  354. that.setData({
  355. videolist: res.data.data,
  356. leftlist: [],
  357. rightlist: []
  358. })
  359. setTimeout(function () {
  360. that.videoimgload();
  361. }, 50)
  362. }
  363. }
  364. })
  365. },
  366. /**
  367. * 页面上拉触底事件的处理函数
  368. */
  369. onReachBottom: function () {
  370. let that=this;
  371. page=page*1+1;
  372. wx.showLoading({
  373. title: '加载中...',
  374. })
  375. utils.$post({
  376. url: app.globalData.webUrl + 'client/video/list',
  377. header: {
  378. 'Authorization':'bearer '+app.globalData.token
  379. },
  380. data: {
  381. type: that.data.firsTitext,
  382. label:that.data.nowTagText,
  383. page: page,
  384. limit: "10",
  385. user_id:app.globalData.personMsg.id
  386. },
  387. success: function (res) {
  388. setTimeout(function(){
  389. wx.hideLoading()
  390. },1200)
  391. if(res.data.code==0){
  392. var arr=res.data.data;
  393. var arrflag=false;
  394. var videolist=that.data.videolist;
  395. if(videolist.length!=0){
  396. arrflag=true;
  397. }
  398. for(var i=0;i<arr.length;i++){
  399. videolist.push(arr[i]);
  400. }
  401. that.setData({
  402. videolist:videolist,
  403. })
  404. if(!arrflag){
  405. that.videoimgload();
  406. }
  407. }
  408. }
  409. })
  410. },
  411. /**
  412. * 用户点击右上角分享
  413. */
  414. onShareAppMessage: function () {
  415. let that=this;
  416. return {
  417. title: app.globalData.personMsg.binded.name+"的视频素材",
  418. imageUrl:app.globalData.imgUrl+"xcx/videoposter.png",
  419. path: '/share/pages/videolist/videolist?uid='+app.globalData.personMsg.id+'&ftext='+that.data.firsTitext+'&nText='+that.data.nowTagText+'&ctp='+app.globalData.clientype
  420. }
  421. }
  422. })