casemsg.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. // index/pages/casemsg/casemsg.js
  2. const app = getApp();
  3. var utils = require("../../../utils/http")
  4. const util = require("../../../utils/util")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. top: app.globalData.statusBarHeight,
  11. hgt: app.globalData.titleBarHeight,
  12. imgUrl: app.globalData.imgUrl,
  13. communityht: '',
  14. cid: '',
  15. casemsgobj: {},
  16. page: 1,
  17. personMsg: app.globalData.personMsg,
  18. wshareshow: false,
  19. caselist: [],
  20. leftcaselist: [],
  21. rightcaselist: [],
  22. companyobj: app.globalData.companyobj,
  23. showAddress: false,
  24. imgarr: [],
  25. type: '',
  26. priceflag: false,
  27. swiperIndex:0,
  28. tab: [{
  29. name: 'VR案例',
  30. type: 'vr',
  31. count: 0
  32. }, {
  33. name: '视频案例',
  34. type: 'video',
  35. count: 0
  36. }],
  37. activeType: '',
  38. ltype:'',//不为空是从名片中点击进去
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. var that = this;
  45. wx.showLoading({
  46. title: '加载中...',
  47. })
  48. that.setData({
  49. cid: options.cid,
  50. companyobj: app.globalData.companyobj,
  51. ltype:options.ltype?options.ltype:''
  52. })
  53. that.casemsgfun();
  54. },
  55. setypetap(e) {
  56. this.setData({
  57. type: e.currentTarget.dataset.type
  58. })
  59. },
  60. priceshowtap() {
  61. this.setData({
  62. priceflag: true
  63. })
  64. },
  65. closepricetap() {
  66. this.setData({
  67. priceflag: false
  68. })
  69. },
  70. showAddressName(e) {
  71. let type = e.currentTarget.dataset.type;
  72. if (type == 'hide') {
  73. this.setData({
  74. showAddress: false
  75. })
  76. } else {
  77. this.setData({
  78. showAddress: true
  79. })
  80. }
  81. },
  82. designertap(){
  83. if(!!this.data.casemsgobj.designer_id){
  84. wx.navigateTo({
  85. url: '/customer/pages/designermsg/designermsg?did='+this.data.casemsgobj.designer_id+"&sid="+this.data.casemsgobj.designer_id+'&type='+(this.data.ltype?1:2)
  86. })
  87. }
  88. },
  89. prelook(e) {
  90. let arr = [];
  91. for (let i in this.data.imgarr) {
  92. arr.push(app.globalData.imgUrl + this.data.imgarr[i].img);
  93. }
  94. wx.previewImage({
  95. current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接
  96. urls: arr // 需要预览的图片 http 链接列表
  97. })
  98. },
  99. presharelooktap() {
  100. if (!app.globalData.personMsg.binded.qrcode) {
  101. wx.showToast({
  102. title: "您的微信二维码为空,请上传二维码!",
  103. icon: 'none',
  104. duration: 2000
  105. })
  106. return false;
  107. }
  108. wx.previewImage({
  109. current: app.globalData.imgUrl + app.globalData.personMsg.binded.qrcode, // 当前显示图片的http链接
  110. urls: [app.globalData.imgUrl + app.globalData.personMsg.binded.qrcode]// 需要预览的图片http链接列表
  111. })
  112. },
  113. opintap() {
  114. wx.showToast({
  115. title: '员工不能预约!',
  116. icon: 'none',
  117. duration: 2000
  118. })
  119. },
  120. swiperChange (e) {
  121. let type = e.detail.currentItemId.split('-')[0];
  122. this.setData({
  123. activeType: type
  124. })
  125. },
  126. sharecardtap: function () {
  127. wx.navigateTo({
  128. url: '/index/pages/namecard/namecard'
  129. })
  130. },
  131. handleSwitch(e) {
  132. let type = e.currentTarget.dataset.type;
  133. let swiperIndex=0;
  134. if (type == 'vr') {
  135. swiperIndex = 0;
  136. } else if (type == 'video') {
  137. swiperIndex = !!this.data.casemsgobj.vr_case?1:0;
  138. }
  139. this.setData({
  140. swiperIndex: swiperIndex,
  141. activeType: type,
  142. })
  143. },
  144. casemsgfun: function () {
  145. var that = this;
  146. utils.$get({
  147. url: app.globalData.webUrl + 'api/casedetail',
  148. header: {
  149. 'Authorization': 'bearer ' + app.globalData.token
  150. },
  151. data: {
  152. id: this.data.cid,
  153. uid: app.globalData.personMsg.id,
  154. },
  155. success: function (res) {
  156. let tab=that.data.tab;
  157. if (res.data.code == '0') {
  158. wx.setNavigationBarTitle({
  159. title: res.data.data.title
  160. })
  161. if(!!res.data.data.video_case){
  162. tab[1].count=1;
  163. that.setData({
  164. tab: tab,
  165. activeType:'video'
  166. })
  167. }
  168. if(!!res.data.data.vr_case){
  169. tab[0].count=1;
  170. that.setData({
  171. tab: tab,
  172. activeType:'vr'
  173. })
  174. }
  175. if (!res.data.data.desc) {
  176. if (!res.data.data.real_case) {
  177. that.setData({
  178. type: ''
  179. })
  180. } else {
  181. that.setData({
  182. type: 2
  183. })
  184. }
  185. } else {
  186. if (res.data.data.desc != '<p><br></p>') {
  187. that.setData({
  188. type: 1
  189. })
  190. } else {
  191. that.setData({
  192. type: 2
  193. })
  194. }
  195. }
  196. that.setData({
  197. casemsgobj: res.data.data,
  198. caselist: res.data.data.designer_related_cases,
  199. })
  200. if (res.data.data.from == 1) {
  201. that.setData({
  202. imgarr: JSON.parse(res.data.data.img_content)
  203. })
  204. }
  205. if (that.data.caselist.length > 0) {
  206. that.imgload();
  207. }
  208. }
  209. wx.hideLoading()
  210. }
  211. })
  212. },
  213. openVRLink(e) {
  214. let type = e.currentTarget.dataset.type;
  215. if (type == 1) {
  216. let vrlink = this.data.casemsgobj.vr_case;
  217. wx.navigateTo({
  218. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.casemsgobj.id,
  219. })
  220. } else {
  221. let vrlink = e.currentTarget.dataset.vrlink;
  222. let aid = e.currentTarget.dataset.id;
  223. wx.navigateTo({
  224. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&aid=' + aid,
  225. })
  226. }
  227. },
  228. imgload: function () {
  229. var that = this;
  230. var leftlist = that.data.leftcaselist;
  231. var rightlist = that.data.rightcaselist;
  232. var indexlist = that.data.caselist;
  233. if (indexlist.length == 0) {
  234. return false;
  235. }
  236. if (leftlist.length == 0) {
  237. leftlist.push(indexlist[0]);
  238. indexlist.shift();
  239. that.setData({
  240. caselist: indexlist,
  241. leftcaselist: leftlist,
  242. rightcaselist: rightlist
  243. })
  244. } else {
  245. var leftheight, rightheight;
  246. const query = wx.createSelectorQuery()
  247. query.select('.leftcasebox').boundingClientRect();
  248. query.exec(function (res) {
  249. leftheight = res[0].height;
  250. const queryright = wx.createSelectorQuery()
  251. queryright.select('.rightcasebox').boundingClientRect();
  252. queryright.exec(function (rs) {
  253. leftlist = that.data.leftcaselist;
  254. rightlist = that.data.rightcaselist;
  255. indexlist = that.data.caselist;
  256. rightheight = rs[0].height;
  257. if (leftheight <= rightheight) {
  258. leftlist.push(indexlist[0]);
  259. indexlist.shift();
  260. } else {
  261. rightlist.push(indexlist[0]);
  262. indexlist.shift();
  263. }
  264. that.setData({
  265. caselist: indexlist,
  266. leftcaselist: leftlist,
  267. rightcaselist: rightlist
  268. })
  269. })
  270. })
  271. }
  272. },
  273. callphonetap: function () {
  274. wx.makePhoneCall({
  275. phoneNumber: app.globalData.personMsg.phone //仅为示例,并非真实的电话号码
  276. })
  277. },
  278. sendfriendtap() {
  279. this.addsharetap();
  280. },
  281. addsharetap: function () {
  282. let that = this;
  283. utils.$post({
  284. url: app.globalData.webUrl + 'api/share/addlog',
  285. header: {
  286. 'Authorization': 'bearer ' + app.globalData.token
  287. },
  288. data: {
  289. id: that.data.cid,
  290. type: 'materialCase',
  291. },
  292. success: function (r) {}
  293. })
  294. },
  295. setpostertap: function () {
  296. wx.navigateTo({
  297. url: '/index/pages/setposter/setposter?type=materialCase&aid=' + this.data.cid + "&listshare=",
  298. })
  299. },
  300. casemsgtap: function (e) {
  301. wx.redirectTo({
  302. url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid
  303. })
  304. },
  305. precasetap: function () {
  306. if (!this.data.casemsgobj.preid) {
  307. wx.showToast({
  308. title: '已经第一篇了!',
  309. icon: 'none',
  310. duration: 2000
  311. })
  312. return false
  313. }
  314. wx.redirectTo({
  315. url: '/index/pages/casemsg/casemsg?cid=' + this.data.casemsgobj.preid
  316. })
  317. },
  318. nextcasetap: function () {
  319. if (!this.data.casemsgobj.nextid) {
  320. wx.showToast({
  321. title: '已经到头了!',
  322. icon: 'none',
  323. duration: 2000
  324. })
  325. return false
  326. }
  327. wx.redirectTo({
  328. url: '/index/pages/casemsg/casemsg?cid=' + this.data.casemsgobj.nextid
  329. })
  330. },
  331. collectap: function () {
  332. var that = this;
  333. var casemsgobj = that.data.casemsgobj;
  334. utils.$post({
  335. url: app.globalData.webUrl + 'api/collect',
  336. header: {
  337. 'Authorization': 'bearer ' + app.globalData.token
  338. },
  339. data: {
  340. user_id: app.globalData.personMsg.id,
  341. content_type: "materialCase",
  342. content_id: that.data.cid
  343. },
  344. success: function (res) {
  345. if (res.data.code == '0') {
  346. wx.showToast({
  347. title: res.data.msg,
  348. icon: 'none',
  349. duration: 2000
  350. })
  351. casemsgobj.collected = !casemsgobj.collected;
  352. that.setData({
  353. casemsgobj: casemsgobj
  354. })
  355. }
  356. }
  357. })
  358. },
  359. casesharetap: function () {
  360. this.setData({
  361. wshareshow: true
  362. })
  363. },
  364. shareurltap: function () {
  365. wx.showLoading({
  366. title: '加载中...',
  367. })
  368. this.addsharetap();
  369. util.schemefun('/share/pages/materialcase/materialcase', 'cid=' + this.data.cid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, this.data.cid, 'materialCase', '');
  370. },
  371. /**
  372. * 生命周期函数--监听页面初次渲染完成
  373. */
  374. onReady: function () {
  375. },
  376. lasttap: function () {
  377. wx.navigateBack()
  378. },
  379. /**
  380. * 生命周期函数--监听页面显示
  381. */
  382. onShow: function () {
  383. },
  384. otherlistfun: function () {
  385. var that = this;
  386. var page = that.data.page;
  387. page = page * 1 + 1;
  388. utils.$post({
  389. url: app.globalData.webUrl + 'api/designercases',
  390. header: {
  391. 'Authorization': 'bearer ' + app.globalData.token
  392. },
  393. data: {
  394. page: page,
  395. limit: 4,
  396. designer_id: that.data.casemsgobj.designer_id,
  397. material_case_id:this.data.cid
  398. },
  399. success: function (res) {
  400. that.setData({
  401. page: page
  402. })
  403. if (res.data.code == '0') {
  404. // caselist:indexlist,
  405. // leftcaselist:leftlist,
  406. // rightcaselist:rightlist
  407. var caselist = that.data.caselist;
  408. var arrflag = false;
  409. if (res.data.data.length == 0) {
  410. wx.showToast({
  411. title: '暂无更多数据',
  412. icon: 'none',
  413. duration: 2000
  414. })
  415. } else {
  416. if (caselist.length != 0) {
  417. arrflag = true;
  418. }
  419. console.log(caselist)
  420. caselist = caselist.concat(res.data.data);
  421. that.setData({
  422. caselist: caselist
  423. });
  424. if (!arrflag) {
  425. that.imgload();
  426. }
  427. }
  428. }
  429. }
  430. })
  431. },
  432. /**
  433. * 生命周期函数--监听页面隐藏
  434. */
  435. onHide: function () {
  436. },
  437. /**
  438. * 生命周期函数--监听页面卸载
  439. */
  440. onUnload: function () {
  441. },
  442. /**
  443. * 页面相关事件处理函数--监听用户下拉动作
  444. */
  445. onPullDownRefresh: function () {
  446. },
  447. /**
  448. * 页面上拉触底事件的处理函数
  449. */
  450. onReachBottom: function () {
  451. },
  452. /**
  453. * 用户点击右上角分享
  454. */
  455. onShareAppMessage: function () {
  456. this.addsharetap();
  457. var img = this.data.casemsgobj.cover_img;
  458. img = img.replace('http://o.nczyzs.com/', 'https://o.nczyzs.com/');
  459. return {
  460. title: this.data.casemsgobj.title,
  461. imageUrl: img,
  462. path: '/share/pages/materialcase/materialcase?cid=' + this.data.cid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  463. }
  464. }
  465. })