decorateguidemsg.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. const app = getApp(),utils = require("../../utils/http");
  2. let videoContext=null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. top: app.globalData.statusBarHeight,
  9. hgt: app.globalData.titleBarHeight,
  10. imgUrl: app.globalData.imgUrl,
  11. companyobj: app.globalData.companyobj,
  12. communityht: '',
  13. cid: '',
  14. casemsgobj: {},
  15. page: 1,
  16. shareid: '',
  17. loginFlag: true,
  18. mobileflag: false,
  19. canIUseGetUserProfile: false,
  20. contentmsg: '',
  21. articlelogin: true,
  22. datashow: false,
  23. mobile: false,
  24. personMsg: app.globalData.personMsg,
  25. caselist: [],
  26. leftcaselist: [],
  27. rightcaselist: [],
  28. sharepersonMsg: app.globalData.sharepersonobj,
  29. employeeflag: false, //false是用户,true是员工
  30. showAddress: false,
  31. imgarr: [],
  32. type: '',//为空就是从微官网进来的,否则就是从工具中进来
  33. ctype: '',
  34. priceflag: false,
  35. swiperIndex:0,
  36. tab: [{
  37. name: 'VR案例',
  38. type: 'vr',
  39. count: 0
  40. }, {
  41. name: '视频案例',
  42. type: 'video',
  43. count: 0
  44. }],
  45. activeType: '',
  46. useversion:app.globalData.useversion,
  47. playflag: 2,//1是播放中,2是暂停
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (options) {
  53. var that = this;
  54. wx.showLoading({
  55. title: '加载中...',
  56. })
  57. if (!!options.scene && !that.data.cid) {
  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. this.setData({
  66. cid: obj.cid,
  67. })
  68. app.globalData.clientype = obj.cli;
  69. that.logindata();
  70. } else {
  71. this.setData({
  72. cid: options.cid,
  73. companyobj: app.globalData.companyobj,
  74. employeeflag: (!!app.globalData.personMsg.binded && app.globalData.personMsg.binded.state == '在职') ? true : false
  75. })
  76. that.casemsgfun('1');
  77. }
  78. if (options.type) {
  79. this.setData({
  80. type: options.type
  81. })
  82. }
  83. this.setData({
  84. personMsg: app.globalData.personMsg,
  85. sharepersonMsg: app.globalData.sharepersonobj,
  86. top: app.globalData.statusBarHeight,
  87. hgt: app.globalData.titleBarHeight,
  88. imgUrl: app.globalData.imgUrl,
  89. companyobj: app.globalData.companyobj,
  90. })
  91. wx.showLoading({
  92. title: '加载中...',
  93. })
  94. },
  95. logindata: function () {
  96. var that = this;
  97. wx.showLoading();
  98. wx.login({
  99. success: function (data) {
  100. if (data.errMsg == 'login:ok') {
  101. utils.$post({
  102. url: app.globalData.webUrl + 'api/users/code2sessionmini',
  103. data: {
  104. client_type: that.data.clientype,
  105. code: data.code,
  106. },
  107. success: function (r) {
  108. if (r.data.code == '0') {
  109. app.globalData.sharepersonobj = r.data.share;
  110. app.globalData.token = r.data.token;
  111. that.sharecompany();
  112. that.casemsgfun('1');
  113. if (!!r.data.user.phone) {
  114. app.globalData.use_id = r.data.user.id;
  115. app.globalData.personMsg = r.data.user;
  116. that.setData({
  117. datashow: true,
  118. mobileflag: false
  119. })
  120. } else {
  121. wx.hideLoading();
  122. that.setData({
  123. articlelogin: false,
  124. loginFlag: true,
  125. mobileflag:true,
  126. })
  127. }
  128. }
  129. wx.hideLoading();
  130. }
  131. })
  132. }
  133. wx.hideLoading();
  134. }
  135. })
  136. },
  137. designertap(){
  138. if(!!this.data.casemsgobj.designer_id){
  139. if(this.data.type){
  140. wx.navigateTo({
  141. url: '/customer/pages/designermsg/designermsg?did='+this.data.casemsgobj.designer_id+"&sid="+this.data.casemsgobj.designer_id+'&type=1'
  142. })
  143. }else{
  144. wx.navigateTo({
  145. url: '/share/pages/designermsg/designermsg?did='+this.data.casemsgobj.designer_id+"&type=3"
  146. })
  147. }
  148. }
  149. },
  150. sharecompany: function () {
  151. const that = this;
  152. utils.$post({
  153. url: app.globalData.webUrl + 'client/index/content_belong_company',
  154. header: {
  155. 'Authorization': 'bearer ' + app.globalData.token
  156. },
  157. data: {
  158. client_type: app.globalData.clientype,
  159. uid: app.globalData.shareuserid
  160. },
  161. success: function (res) {
  162. if (res.data.code == '0') {
  163. app.globalData.currentUserId = res.data.data.employee_id;
  164. app.globalData.companyobj=res.data.data;
  165. that.setData({
  166. companyobj: res.data.data
  167. })
  168. }
  169. },
  170. complete(res) {
  171. wx.hideLoading()
  172. }
  173. })
  174. },
  175. phonrtap: function () {
  176. wx.makePhoneCall({
  177. phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
  178. })
  179. },
  180. priceshowtap() {
  181. this.setData({
  182. priceflag: true
  183. })
  184. },
  185. swiperChange (e) {
  186. let type = e.detail.currentItemId.split('-')[0];
  187. this.setData({
  188. activeType: type
  189. })
  190. },
  191. closepricetap() {
  192. this.setData({
  193. priceflag: false
  194. })
  195. },
  196. videotap() {
  197. videoContext = this.selectComponent('#myVideo');
  198. videoContext.play();
  199. wx.showLoading()
  200. },
  201. bindprogress() {
  202. wx.hideLoading();
  203. this.setData({
  204. playflag: 1
  205. })
  206. },
  207. setypetap(e) {
  208. this.setData({
  209. ctype: e.currentTarget.dataset.type
  210. })
  211. },
  212. prelookimgtap() {
  213. if (!app.globalData.sharepersonobj.qrcode) {
  214. wx.showToast({
  215. title: "当前专属客服的二维码为空!",
  216. icon: 'none',
  217. duration: 2000
  218. })
  219. return false;
  220. }
  221. wx.previewImage({
  222. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  223. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode] // 需要预览的图片http链接列表
  224. })
  225. },
  226. pricetap: function () {
  227. wx.navigateTo({
  228. url: '/customer/pages/figureprice/figureprice',
  229. })
  230. },
  231. designTap: function () {
  232. wx.navigateTo({
  233. url: '/customer/pages/findesign/findesign',
  234. })
  235. },
  236. handleSwitch(e) {
  237. let type = e.currentTarget.dataset.type;
  238. let swiperIndex=0;
  239. if (type == 'vr') {
  240. swiperIndex = 0;
  241. } else if (type == 'video') {
  242. swiperIndex = !!this.data.casemsgobj.vr_case?1:0;
  243. }
  244. this.setData({
  245. swiperIndex: swiperIndex,
  246. activeType: type,
  247. })
  248. },
  249. openVRLink(e) {
  250. let type = e.currentTarget.dataset.type;
  251. if (type == 1) {
  252. let vrlink = this.data.casemsgobj.vr_case;
  253. wx.navigateTo({
  254. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.casemsgobj.id,
  255. })
  256. } else {
  257. let vrlink = e.currentTarget.dataset.vrlink;
  258. let aid = e.currentTarget.dataset.id;
  259. wx.navigateTo({
  260. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype + '&aid=' + aid,
  261. })
  262. }
  263. },
  264. casemsgfun: function (type) {
  265. var that = this;
  266. utils.$get({
  267. url: app.globalData.webUrl + 'client/casedetail',
  268. header: {
  269. 'Authorization': 'bearer ' + app.globalData.token
  270. },
  271. data: {
  272. id: that.data.cid
  273. },
  274. success: function (res) {
  275. setTimeout(function () {
  276. wx.hideLoading()
  277. }, 500)
  278. let tab=that.data.tab;
  279. if (res.data.code == '0') {
  280. wx.setNavigationBarTitle({
  281. title: res.data.data.title
  282. })
  283. if (!res.data.data.desc) {
  284. if (!res.data.data.real_case) {
  285. that.setData({
  286. ctype: ''
  287. })
  288. } else {
  289. that.setData({
  290. ctype: 2
  291. })
  292. }
  293. } else {
  294. if (res.data.data.desc != '<p><br></p>') {
  295. that.setData({
  296. ctype: 1
  297. })
  298. } else {
  299. that.setData({
  300. ctype: 2
  301. })
  302. }
  303. }
  304. if(!!res.data.data.video_case){
  305. tab[1].count=1;
  306. that.setData({
  307. tab: tab,
  308. activeType:'video'
  309. })
  310. }
  311. if(!!res.data.data.vr_case){
  312. tab[0].count=1;
  313. that.setData({
  314. tab: tab,
  315. activeType:'vr'
  316. })
  317. }
  318. let length = res.data.data.desc.length / 3;
  319. let str = res.data.data.desc.substring(0, length);
  320. that.setData({
  321. casemsgobj: res.data.data,
  322. contentmsg: str,
  323. caselist: res.data.data.designer_related_cases,
  324. leftcaselist: [],
  325. rightcaselist: [],
  326. })
  327. if (res.data.data.from == 1) {
  328. that.setData({
  329. imgarr: JSON.parse(res.data.data.img_content)
  330. })
  331. }
  332. var article = res.data.data.desc;
  333. that.setData({
  334. contentmsg: str
  335. })
  336. if (res.data.data.designer_related_cases.length > 0) {
  337. that.imgload();
  338. }
  339. }
  340. }
  341. })
  342. },
  343. prelook(e) {
  344. let arr = [];
  345. for (let i in this.data.imgarr) {
  346. arr.push(app.globalData.imgUrl + this.data.imgarr[i].img);
  347. }
  348. wx.previewImage({
  349. current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接
  350. urls: arr // 需要预览的图片 http 链接列表
  351. })
  352. },
  353. showAddressName(e) {
  354. let type = e.currentTarget.dataset.type;
  355. if (type == 'hide') {
  356. this.setData({
  357. showAddress: false
  358. })
  359. } else {
  360. this.setData({
  361. showAddress: true
  362. })
  363. }
  364. },
  365. getPhoneNumberTap: function (res) {
  366. var that = this;
  367. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  368. utils.$post({
  369. url: app.globalData.webUrl + 'api/users/setUserMobile',
  370. data: {
  371. encryptedData: res.detail.encryptedData,
  372. iv: res.detail.iv
  373. },
  374. header: {
  375. 'Authorization': 'bearer ' + app.globalData.token
  376. },
  377. success: function (r) {
  378. if (r.data.code == '0') {
  379. // wx.showLoading({
  380. // title: '加载中',
  381. // })
  382. if (res.currentTarget.dataset.type == 1) {
  383. that.orderfun();
  384. }
  385. app.globalData.phone = true;
  386. } else {
  387. that.setData({
  388. errorText: r.data.msg,
  389. errorflag: true
  390. })
  391. }
  392. }
  393. })
  394. }
  395. },
  396. orderfun() {
  397. const that = this;
  398. utils.$post({
  399. url: app.globalData.webUrl + 'client/material/designer_reserve',
  400. header: {
  401. 'Authorization': 'bearer ' + app.globalData.token
  402. },
  403. data: {
  404. id:that.data.cid,
  405. designer_id:that.data.casemsgobj.designer_id?that.data.casemsgobj.designer_id:'',
  406. type:'materialCase',
  407. share_uid:app.globalData.shareuserid
  408. },
  409. success: function (res) {
  410. if (res.data.code == '0') {
  411. wx.showToast({
  412. title: res.data.msg,
  413. icon: "none",
  414. duration: 2000
  415. });
  416. }
  417. }
  418. })
  419. },
  420. imgload: function () {
  421. var that = this;
  422. var leftlist = that.data.leftcaselist;
  423. var rightlist = that.data.rightcaselist;
  424. var indexlist = that.data.caselist;
  425. if (indexlist.length == 0) {
  426. return false;
  427. }
  428. if (leftlist.length == 0) {
  429. leftlist.push(indexlist[0]);
  430. indexlist.shift();
  431. that.setData({
  432. caselist: indexlist,
  433. leftcaselist: leftlist,
  434. rightcaselist: rightlist
  435. })
  436. } else {
  437. var leftheight, rightheight;
  438. const query = wx.createSelectorQuery()
  439. query.select('.leftcasebox').boundingClientRect();
  440. query.exec(function (res) {
  441. leftheight = res[0].height;
  442. const queryright = wx.createSelectorQuery()
  443. queryright.select('.rightcasebox').boundingClientRect();
  444. queryright.exec(function (rs) {
  445. leftlist = that.data.leftcaselist;
  446. rightlist = that.data.rightcaselist;
  447. indexlist = that.data.caselist;
  448. rightheight = rs[0].height;
  449. if (leftheight <= rightheight) {
  450. leftlist.push(indexlist[0]);
  451. indexlist.shift();
  452. } else {
  453. rightlist.push(indexlist[0]);
  454. indexlist.shift();
  455. }
  456. that.setData({
  457. caselist: indexlist,
  458. leftcaselist: leftlist,
  459. rightcaselist: rightlist
  460. })
  461. })
  462. })
  463. }
  464. },
  465. casemsgtap: function (e) {
  466. wx.redirectTo({
  467. url: '/pages/decorateguidemsg/decorateguidemsg?cid=' + e.currentTarget.dataset.cid + "&uid=" + app.globalData.shareuserid
  468. })
  469. },
  470. precasetap: function () {
  471. if (!this.data.casemsgobj.preid) {
  472. wx.showToast({
  473. title: '已经第一篇了!',
  474. icon: 'none',
  475. duration: 2000
  476. })
  477. return false
  478. }
  479. wx.redirectTo({
  480. url: '/share/pages/materialcase/materialcase?type=3&cid=' + this.data.casemsgobj.preid + '&uid=' + this.data.shareid
  481. })
  482. },
  483. nextcasetap: function () {
  484. if (!this.data.casemsgobj.nextid) {
  485. wx.showToast({
  486. title: '已经到头了!',
  487. icon: 'none',
  488. duration: 2000
  489. })
  490. return false
  491. }
  492. wx.redirectTo({
  493. url: '/share/pages/materialcase/materialcase?type=3&cid=' + this.data.casemsgobj.nextid + '&uid=' + this.data.shareid
  494. })
  495. },
  496. /**
  497. * 生命周期函数--监听页面初次渲染完成
  498. */
  499. onReady: function () {
  500. },
  501. lasttap: function () {
  502. wx.reLaunch({
  503. url: '/pages/index/index'
  504. })
  505. },
  506. /**
  507. * 生命周期函数--监听页面显示
  508. */
  509. onShow: function () {
  510. this.setData({
  511. personMsg: app.globalData.personMsg,
  512. sharepersonMsg: app.globalData.sharepersonobj,
  513. top: app.globalData.statusBarHeight,
  514. hgt: app.globalData.titleBarHeight,
  515. imgUrl: app.globalData.imgUrl,
  516. companyobj: app.globalData.companyobj,
  517. })
  518. },
  519. otherlistfun: function () {
  520. var that = this;
  521. var page = that.data.page;
  522. page = page * 1 + 1;
  523. utils.$post({
  524. url: app.globalData.webUrl + 'client/designercases',
  525. header: {
  526. 'Authorization': 'bearer ' + app.globalData.token
  527. },
  528. data: {
  529. page: page,
  530. limit: 4,
  531. designer_id: that.data.casemsgobj.designer_id,
  532. material_case_id:this.data.cid
  533. },
  534. success: function (res) {
  535. that.setData({
  536. page: page
  537. })
  538. if (res.data.code == '0') {
  539. var caselist = that.data.caselist;
  540. var arrflag = false;
  541. if (res.data.data.length == 0) {
  542. wx.showToast({
  543. title: '暂无更多数据',
  544. icon: 'none',
  545. duration: 2000
  546. })
  547. } else {
  548. if (caselist.length != 0) {
  549. arrflag = true;
  550. }
  551. caselist = caselist.concat(res.data.data);
  552. that.setData({
  553. caselist: caselist
  554. });
  555. if (!arrflag) {
  556. that.imgload();
  557. }
  558. }
  559. }
  560. }
  561. })
  562. },
  563. /**
  564. * 生命周期函数--监听页面隐藏
  565. */
  566. onHide: function () {
  567. },
  568. /**
  569. * 生命周期函数--监听页面卸载
  570. */
  571. onUnload: function () {
  572. },
  573. /**
  574. * 页面相关事件处理函数--监听用户下拉动作
  575. */
  576. onPullDownRefresh: function () {
  577. },
  578. /**
  579. * 页面上拉触底事件的处理函数
  580. */
  581. onReachBottom: function () {
  582. },
  583. addsharetap: function () {
  584. let that = this;
  585. utils.$post({
  586. url: app.globalData.webUrl + 'api/share/addlog',
  587. header: {
  588. 'Authorization': 'bearer ' + app.globalData.token
  589. },
  590. data: {
  591. id: that.data.cid,
  592. type: 'materialCase',
  593. },
  594. success: function (r) {}
  595. })
  596. },
  597. /**
  598. * 用户点击右上角分享
  599. */
  600. onShareAppMessage: function () {
  601. this.addsharetap();
  602. var img = this.data.casemsgobj.cover_share_img?this.data.casemsgobj.cover_share_img:this.data.casemsgobj.cover_img;
  603. img = img.replace('http://o.nczyzs.com/', 'https://o.nczyzs.com/');
  604. return {
  605. title: this.data.casemsgobj.title,
  606. imageUrl: img,
  607. path: '/share/pages/materialcase/materialcase?cid=' + this.data.cid + '&uid=' + (app.globalData.sharepersonobj&&app.globalData.sharepersonobj.id?app.globalData.sharepersonobj.id:app.globalData.personMsg.id) + '&ctp=' + app.globalData.clientype
  608. }
  609. }
  610. })