videoshare.js 23 KB

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