decorateguidemsg.js 21 KB

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