videoshare.js 24 KB

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