videoshare.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. var app=getApp();
  2. var utils=require("../../../utils/http");
  3. var customerflag=false,videoContext={};
  4. let time=0;
  5. var timer = null;
  6. var designTimer = null;
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. imgUrl: app.globalData.imgUrl,
  13. videoUrl:'',
  14. title:'志远装饰',
  15. btflag:false,
  16. loginFlag:false,
  17. phoneFlag:false,
  18. errorText:'请求错误!',
  19. oneButton: [{text: '确定'}],
  20. ght:'100%',
  21. headimgurl: "",
  22. nickname: "",
  23. vid: "",
  24. star_num: "",
  25. shareuserid: "",
  26. customerFlag: true,
  27. videoflag:false,
  28. playBtn:true,
  29. videoObj:{},
  30. mobileflag:false,
  31. autoplay:false,
  32. covercustomerFlag:true,
  33. canIUseGetUserProfile: false,
  34. loadflag:false,
  35. imgsrc:'',
  36. shareobj:{},
  37. top:app.globalData.statusBarHeight,
  38. hgt:app.globalData.titleBarHeight,
  39. employeeflag:false,//false是用户,true是员工
  40. companyobj:{},
  41. showDsc: false,
  42. priceflag: false,
  43. designPlan: false
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. var that=this;
  50. if (wx.getUserProfile) {
  51. this.setData({
  52. canIUseGetUserProfile: true
  53. })
  54. }
  55. time=0;
  56. wx.hideHomeButton();
  57. if(!!options.scene){
  58. options=unescape(options.scene);
  59. let arr=options.split('&');
  60. let obj={};
  61. for(let i=0;i<arr.length;i++){
  62. let arr1=arr[i].split('=');
  63. obj[arr1[0]]=arr1[1];
  64. }
  65. that.setData({
  66. vid:obj.vid
  67. })
  68. app.globalData.clientype=obj.ctp;
  69. app.globalData.shareuserid=obj.userid;
  70. }else{
  71. that.setData({
  72. vid:options.vid
  73. })
  74. app.globalData.clientype=options.ctp;
  75. app.globalData.shareuserid=options.userid;
  76. }
  77. this.setData({
  78. top:app.globalData.statusBarHeight,
  79. hgt:app.globalData.titleBarHeight,
  80. })
  81. wx.showLoading({
  82. title: '加载中',
  83. })
  84. that.login();
  85. },
  86. showdscMsg: function () {
  87. if (this.data.videoObj.description.length > 28) {
  88. this.data.showDsc = !this.data.showDsc;
  89. this.setData({
  90. showDsc: this.data.showDsc
  91. })
  92. }
  93. },
  94. /**
  95. * 弹出报价弹窗
  96. */
  97. priceshowtap() {
  98. this.setData({
  99. priceflag: true
  100. })
  101. },
  102. /**
  103. * 关闭报价弹窗
  104. */
  105. closepricetap() {
  106. this.setData({
  107. priceflag: false
  108. })
  109. },
  110. closeDesigntap(e) {
  111. if (designTimer) {
  112. clearTimeout(designTimer);
  113. }
  114. if (e.detail.type == 'success') {
  115. this.setData({
  116. designPlan: false
  117. })
  118. } else {
  119. this.setData({
  120. designPlan: false
  121. })
  122. }
  123. },
  124. sharecompany:function (){
  125. const that=this;
  126. utils.$post({
  127. url: app.globalData.webUrl + 'client/index/content_belong_company',
  128. header: {
  129. 'Authorization':'bearer '+app.globalData.token
  130. },
  131. data:{
  132. client_type:app.globalData.clientype,
  133. uid: app.globalData.shareuserid
  134. },
  135. success: function (res) {
  136. if(res.data.code=='0'){
  137. app.globalData.companyobj=res.data.data;
  138. that.setData({
  139. companyobj:res.data.data
  140. })
  141. }
  142. },
  143. complete(res) {
  144. wx.hideLoading()
  145. }
  146. })
  147. },
  148. login:function(){
  149. var that=this;
  150. wx.login({
  151. success: function (data) {
  152. if (data.errMsg == 'login:ok') {
  153. utils.$post({
  154. url: app.globalData.webUrl + 'api/users/code2session',
  155. data: {
  156. code:data.code,
  157. share: app.globalData.shareuserid,
  158. client_type:app.globalData.clientype
  159. },
  160. success: function (r) {
  161. if(r.data.code=='0'){
  162. app.globalData.token=r.data.token;
  163. app.globalData.sharepersonobj=r.data.share ;
  164. that.setData({
  165. shareobj:r.data.share
  166. })
  167. that.sharecompany();
  168. app.globalData.personMsg=r.data.user;
  169. 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!='游客')){
  170. that.setData({
  171. loginFlag:false,
  172. employeeflag:(!!r.data.user.binded&&r.data.user.binded.state=='在职')?true:false
  173. })
  174. app.globalData.use_id=r.data.user.id;
  175. app.globalData.userflag=false;//有个人信息
  176. var nickname=r.data.user.nickname;
  177. var phone=r.data.user.phone;
  178. app.globalData.phone=false;//没有手机号
  179. if(r.data.user.phone==''){
  180. that.videofun();
  181. app.globalData.phone=false;//没有手机号
  182. that.setData({
  183. phoneFlag:true,
  184. mobileflag: true,
  185. })
  186. }else{
  187. app.globalData.phone=true;//有手机号
  188. that.setData({
  189. phoneFlag:false,
  190. mobileflag: false
  191. })
  192. var obj={
  193. detail:1
  194. }
  195. that.videofun(obj);
  196. }
  197. }else{
  198. that.videofun();
  199. wx.hideLoading();
  200. that.setData({
  201. errorflag:true,
  202. loginFlag:true,
  203. phoneFlag:false
  204. })
  205. }
  206. }
  207. }
  208. })
  209. }
  210. }
  211. })
  212. },
  213. cancelGetPhone() {
  214. designTimer = setTimeout(() => {
  215. this.setData({
  216. designPlan: true
  217. })
  218. },4000)
  219. },
  220. /**
  221. * 生命周期函数--监听页面初次渲染完成
  222. */
  223. onReady: function () {
  224. },
  225. prelooktap(){
  226. if(!app.globalData.sharepersonobj.qrcode){
  227. wx.showToast({
  228. title: "当前专属客服的二维码为空!",
  229. icon: 'none',
  230. duration: 2000
  231. })
  232. return false;
  233. }
  234. wx.previewImage({
  235. current: app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  236. urls: [app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  237. })
  238. },
  239. callphonetap:function(){
  240. wx.makePhoneCall({
  241. phoneNumber: app.globalData.sharepersonobj.phone
  242. })
  243. },
  244. videofun:function(type){
  245. var that=this;
  246. if(!!type&&type.detail=='1'){
  247. that.setData({
  248. articlelogin:true,
  249. phoneFlag:false,
  250. mobileflag: false,
  251. })
  252. }
  253. utils.$post({
  254. url: app.globalData.webUrl + 'client/video/info',
  255. header: {
  256. 'Authorization':'bearer '+app.globalData.token
  257. },
  258. data: {
  259. video_id: that.data.vid,
  260. user: app.globalData.shareuserid,
  261. },
  262. success: function (r) {
  263. setTimeout(function(){
  264. wx.hideLoading()
  265. },600)
  266. if(r.data.code=='0'){
  267. r.data.data.description = r.data.data.title + '#' + r.data.data.description + '#';
  268. that.setData({
  269. title:r.data.data.title,
  270. videoObj:r.data.data,
  271. loadflag:true,
  272. customerFlag:false,
  273. })
  274. videoContext=that.selectComponent("#myVideo1");
  275. wx.setNavigationBarTitle({
  276. title: r.data.data.title
  277. })
  278. that.setData({
  279. imgsrc:r.data.data.cover?r.data.data.cover:r.data.data.video_url+'?x-oss-process=video/snapshot,t_100,f_jpg,w_500,m_fast',
  280. })
  281. if(!!type&&type.detail=='1'){
  282. that.setData({
  283. autoplay:true
  284. })
  285. videoContext.play();
  286. }
  287. }
  288. }
  289. })
  290. },
  291. bindplay:function(e){
  292. setTimeout(function(){
  293. wx.hideLoading();
  294. },1000)
  295. videoContext.play();
  296. },
  297. bindended:function(e){
  298. var that=this;
  299. videoContext.play();
  300. },
  301. lookvidoefun(){
  302. videoContext.play();
  303. },
  304. getUserInfoTap:function(res){
  305. var that=this;
  306. wx.showLoading();
  307. if(res.detail.errMsg=='getUserInfo:ok'){
  308. utils.$post({
  309. method: "POST",//TESTAPIURL APIURL/users/auth
  310. url: app.globalData.webUrl + 'api/users/setUserInfo',
  311. data: {
  312. encryptedData:res.detail.encryptedData,
  313. iv:res.detail.iv,
  314. rawData:res.detail.rawData,
  315. signature:res.detail.signature,
  316. },
  317. header: {
  318. 'Authorization':'bearer '+app.globalData.token
  319. },
  320. success: function (r) {
  321. if(r.data.code=='0'){
  322. that.loginfun();
  323. that.setData({
  324. loginFlag:false,
  325. autoplay:true,
  326. phoneFlag:false
  327. })
  328. videoContext.play();
  329. app.globalData.userflag=true;//有个人信息
  330. }else{
  331. if(r.data.code=='403'){
  332. that.login();
  333. return false
  334. }
  335. wx.showToast({
  336. title: r.data.msg,
  337. icon: "none",
  338. duration:2000
  339. });
  340. }
  341. }
  342. })
  343. }
  344. },
  345. getUserProfile:function(){
  346. var that=this;
  347. wx.getUserProfile({
  348. lang:'zh_CN',
  349. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  350. success: (res) => {
  351. if(res.errMsg=="getUserProfile:ok"){
  352. wx.showLoading();
  353. utils.$post({
  354. method: "POST",//TESTAPIURL APIURL/users/auth
  355. url: app.globalData.webUrl + 'api/users/setUserInfo',
  356. data: {
  357. encryptedData:res.encryptedData,
  358. iv:res.iv,
  359. rawData:res.rawData,
  360. signature:res.signature,
  361. },
  362. header: {
  363. 'Authorization':'bearer '+app.globalData.token
  364. },
  365. success: function (r) {
  366. setTimeout(res=>{
  367. wx.hideLoading()
  368. },500)
  369. if(r.data.code=='0'){
  370. that.loginfun();
  371. that.setData({
  372. loginFlag:false,
  373. phoneFlag:false,
  374. autoplay:true,
  375. })
  376. videoContext.play();
  377. app.globalData.userflag=true;//有个人信息
  378. }else{
  379. if(r.data.code=='403'){
  380. that.login();
  381. return false
  382. }
  383. wx.showToast({
  384. title: r.data.msg,
  385. icon: "none",
  386. duration:2000
  387. });
  388. }
  389. }
  390. })
  391. }
  392. }
  393. })
  394. },
  395. loginfun(){
  396. var that=this;
  397. wx.login({
  398. success: function (data) {
  399. if (data.errMsg == 'login:ok') {
  400. utils.$post({
  401. url: app.globalData.webUrl + 'api/users/code2session',
  402. data: {
  403. code: data.code,
  404. share: app.globalData.shareuserid,
  405. client_type:app.globalData.clientype
  406. },
  407. success: function (r) {
  408. if(r.data.code=='0'){
  409. app.globalData.sharepersonobj = r.data.share;
  410. app.globalData.token=r.data.token;
  411. if(r.data.user!=null&&(!!r.data.user.headimgurl&&r.data.user.headimgurl!=""||!!r.data.user.nickname&&r.data.user.nickname!="")){
  412. that.setData({
  413. employeeflag:(!!r.data.user.binded&&r.data.user.binded.state=='在职')?true:false
  414. })
  415. app.globalData.personMsg=r.data.user;
  416. app.globalData.use_id=r.data.user.id;
  417. app.globalData.userflag=false;//有个人信息
  418. if(r.data.user.phone==''){
  419. designTimer = setTimeout(() => {
  420. that.setData({
  421. designPlan: true
  422. })
  423. },4000)
  424. }
  425. }
  426. }
  427. }
  428. })
  429. }
  430. }
  431. })
  432. },
  433. getPhoneNumberTap:function(res){
  434. var that=this;
  435. // var obj={
  436. // detail:1
  437. // }
  438. // that.lookvidoefun();
  439. if(res.detail.errMsg=='getPhoneNumber:ok'){
  440. this.setData({
  441. articlelogin:true,
  442. phoneFlag:false,
  443. })
  444. utils.$post({
  445. url: app.globalData.webUrl + 'api/users/setUserMobile',
  446. data: {
  447. encryptedData:res.detail.encryptedData,
  448. iv:res.detail.iv
  449. },
  450. header: {
  451. 'Authorization':'bearer '+app.globalData.token
  452. },
  453. success: function (r) {
  454. if(r.data.code=='0'){
  455. app.globalData.phone=true;
  456. that.setData({
  457. phoneFlag:false
  458. })
  459. if(!res.target.dataset.type){
  460. that.setData({
  461. autoplay:true
  462. })
  463. videoContext.play();
  464. }else{
  465. that.signup(r.data.mobile);
  466. }
  467. }else{
  468. that.setData({
  469. errorText:r.data.msg,
  470. errorflag:true
  471. })
  472. }
  473. }
  474. })
  475. }
  476. },
  477. signup:function(mobile){
  478. const that=this;
  479. utils.$post({
  480. url: app.globalData.webUrl + 'client/index/signUp',
  481. data: {
  482. name:'',
  483. remark:'',
  484. mobile:mobile,
  485. type:'video',
  486. id:that.data.vid,
  487. },
  488. header: {
  489. 'Authorization':'bearer '+app.globalData.token
  490. },
  491. success: function (r) {
  492. if(r.data.code=='0'){
  493. }
  494. }
  495. })
  496. },
  497. clickzanTap:function(){
  498. var that=this;
  499. var videoObj=that.data.videoObj;
  500. utils.$post({
  501. url: app.globalData.webUrl + 'client/video/star',
  502. header: {
  503. 'Authorization':'bearer '+app.globalData.token
  504. },
  505. data:{
  506. video_id: that.data.vid,
  507. },
  508. success: function (res) {
  509. wx.showToast({
  510. title: res.data.msg,
  511. icon: "none",
  512. duration:2000
  513. });
  514. if (res.data.code == '0') {
  515. if(res.data.msg=='点赞成功'){
  516. videoObj.star_num = videoObj.star_num * 1 + 1;
  517. videoObj.stared=1;
  518. }else{
  519. videoObj.star_num = videoObj.star_num * 1 - 1;
  520. videoObj.stared=0;
  521. }
  522. that.setData({
  523. videoObj:videoObj
  524. })
  525. }
  526. }
  527. })
  528. },
  529. golastap:function(){
  530. let arr=getCurrentPages();
  531. if(arr.length==1){
  532. wx.reLaunch({
  533. url: '/pages/index/index?state=1',
  534. })
  535. }else if(arr[arr.length-2].__route__=='share/pages/videolist/videolist'){
  536. wx.navigateBack()
  537. }else{
  538. wx.reLaunch({
  539. url: '/pages/index/index?state=1',
  540. })
  541. }
  542. },
  543. goindextap:function(){
  544. wx.reLaunch({
  545. url: '/pages/index/index?state=1',
  546. })
  547. },
  548. sharelogtap:function(){
  549. var that=this;
  550. utils.$post({
  551. url: app.globalData.webUrl + 'api/share/addlog',
  552. header: {
  553. 'Authorization':'bearer '+app.globalData.token
  554. },
  555. data: {
  556. id:that.data.vid,
  557. type:'video'
  558. },
  559. success: function (r) {
  560. }
  561. })
  562. },
  563. /**
  564. * 生命周期函数--监听页面显示
  565. */
  566. onShow: function (options) {
  567. this.setData({
  568. top:app.globalData.statusBarHeight,
  569. hgt:app.globalData.titleBarHeight,
  570. })
  571. timer = setInterval(function(){
  572. time=time*1+1;
  573. },1000)
  574. },
  575. /**
  576. * 生命周期函数--监听页面隐藏
  577. */
  578. onHide: function () {
  579. if (designTimer) {
  580. clearTimeout(designTimer);
  581. }
  582. if (timer) {
  583. clearInterval(timer);
  584. }
  585. this.visitimefun();
  586. },
  587. visitimefun(){
  588. const that=this;
  589. utils.$post({
  590. url: app.globalData.webUrl + 'client/index/visit_due_time',
  591. header: {
  592. 'Authorization':'bearer '+app.globalData.token
  593. },
  594. data:{
  595. id:that.data.vid,
  596. pipe_type:'video',
  597. time:time,
  598. },
  599. success: function (res) {
  600. }
  601. })
  602. },
  603. /**
  604. * 生命周期函数--监听页面卸载
  605. */
  606. onUnload: function () {
  607. if (designTimer) {
  608. clearTimeout(designTimer);
  609. }
  610. this.visitimefun();
  611. },
  612. /**
  613. * 页面相关事件处理函数--监听用户下拉动作
  614. */
  615. onPullDownRefresh: function () {
  616. },
  617. /**
  618. * 页面上拉触底事件的处理函数
  619. */
  620. onReachBottom: function () {
  621. },
  622. /**
  623. * 用户点击右上角分享
  624. */
  625. onShareAppMessage: function () {
  626. var that=this;
  627. that.sharelogtap();
  628. videoContext.pause();
  629. var video_url=this.data.imgsrc;
  630. return {
  631. title: that.data.title,
  632. imageUrl:video_url,
  633. path: '/share/pages/videoshare/videoshare?vid='+that.data.vid+'&userid='+app.globalData.shareuserid+'&ctp='+app.globalData.clientype
  634. }
  635. }
  636. })