materialcase.js 24 KB

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