namecard.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. var app = getApp();
  2. var utils = require("../../../utils/http");
  3. let evpage = 1, casepage = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. top: app.globalData.statusBarHeight,
  10. hgt: app.globalData.titleBarHeight,
  11. imgUrl: app.globalData.imgUrl,
  12. mineinfo: {},
  13. logcount: 0,
  14. imgarr: [],
  15. type: 1,
  16. evidencetype: '',
  17. evidencelist: [],
  18. leftevidencelist: [],
  19. rightevidencelist: [],
  20. catetype: '',
  21. datashow: true,
  22. nowstyle: '',
  23. stylelist: [],
  24. square_start: '', //面积开始值
  25. square_end: '', //面积结束值
  26. nowcommunity: '',
  27. communitylist: [],
  28. nowhousetype: '',
  29. housetypelist: [],
  30. caselist: [],
  31. keyword: '',
  32. datashow: false,
  33. loginFlag: true,
  34. mobileflag: false,
  35. canIUseGetUserProfile: false,
  36. shareobj: {},
  37. employeeflag: false,//false是用户,true是员工
  38. communityflag: false,
  39. nowcommunitname: '',
  40. typearr:[
  41. {id:1,name:'效果案例',type:1},
  42. {id:2,name:'实景案例',type:2}
  43. ],
  44. noweffect:'',
  45. prelook:'',
  46. timeline:app.globalData.timeline
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. if(options.type=='share'){
  53. this.setData({
  54. prelook:"share"
  55. })
  56. wx.reLaunch({
  57. url:'/share/pages/shareCard/shareCard?uid=' + options.uid + '&empid=' + options.empid + '&ctp=' + options.ctp,
  58. })
  59. }
  60. this.setData({
  61. top: app.globalData.statusBarHeight,
  62. hgt: app.globalData.titleBarHeight,
  63. imgUrl: app.globalData.imgUrl,
  64. timeline:app.globalData.timeline
  65. })
  66. this.mineinfo();
  67. this.evidenceCate();
  68. this.evidencelist();
  69. this.casestylefun();
  70. this.housestylefun();
  71. this.casecommunityfun();
  72. this.caselistfun();
  73. },
  74. seteffectap(e){
  75. this.setData({
  76. noweffect:e.currentTarget.dataset.type
  77. })
  78. this.caselistfun();
  79. },
  80. mineinfo() {
  81. const that = this;
  82. utils.$post({
  83. url: app.globalData.webUrl + 'api/card/info',
  84. header: {
  85. 'Authorization': 'bearer ' + app.globalData.token
  86. },
  87. data: {},
  88. success: function (res) {
  89. wx.hideLoading();
  90. if (res.data.code == 0) {
  91. that.setData({
  92. mineinfo: res.data.data,
  93. logcount: res.data.logcount,
  94. imgarr: res.data.log
  95. })
  96. }
  97. }
  98. })
  99. },
  100. searchplacetap() {
  101. if (!this.data.mineinfo.company_vr_address) {
  102. wx.navigateTo({
  103. url: '/pages/noneData/noneData?type=1',
  104. })
  105. return false;
  106. }
  107. app.globalData.vraddress = this.data.mineinfo.company_vr_address;
  108. wx.navigateTo({
  109. url: '/pages/other/other?type=111&ctp='+app.globalData.clientype+'&uid='+(app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&aid=' + this.data.mineinfo.employee_id + '&cty=employeeCard',
  110. })
  111. },
  112. setliketap() {
  113. var that = this;
  114. utils.$get({
  115. url: app.globalData.webUrl + 'api/card/like',
  116. header: {
  117. 'Authorization': 'bearer ' + app.globalData.token
  118. },
  119. data: {
  120. employee_id: app.globalData.currentUserId
  121. },
  122. success: function (res) {
  123. let mineinfo = that.data.mineinfo;
  124. if (res.data.code == '0') {
  125. mineinfo.likes = mineinfo.likes * 1 + 1;
  126. that.setData({
  127. mineinfo: mineinfo
  128. })
  129. }
  130. }
  131. })
  132. },
  133. setypetap(e) {
  134. this.setData({
  135. type: e.target.dataset.num
  136. })
  137. if (e.target.dataset.num == 3) {
  138. this.evidencelist();
  139. }
  140. },
  141. openVRLink(e) {
  142. let id = e.currentTarget.dataset.id;
  143. let vrlink = e.currentTarget.dataset.vrlink;
  144. wx.navigateTo({
  145. url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&aid=' + id,
  146. })
  147. },
  148. preimgtap() {
  149. if (!this.data.mineinfo.qrcode) {
  150. wx.showToast({
  151. title: '员工二维码为空!',
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. return false;
  156. }
  157. let img = app.globalData.imgUrl + '/' + this.data.mineinfo.qrcode;
  158. wx.previewImage({
  159. current: img, // 当前显示图片的 http 链接
  160. urls: [img] // 需要预览的图片 http 链接列表
  161. })
  162. },
  163. copytap() {
  164. if (!this.data.mineinfo.wx) {
  165. wx.showToast({
  166. title: '员工微信为空!',
  167. icon: 'none',
  168. duration: 2000
  169. })
  170. return false;
  171. }
  172. wx.setClipboardData({
  173. data: this.data.mineinfo.wx,
  174. success(res) {
  175. }
  176. })
  177. },
  178. callphonetap() {
  179. wx.makePhoneCall({
  180. phoneNumber: this.data.mineinfo.phone //仅为示例,并非真实的电话号码
  181. })
  182. },
  183. viewAuthorization() {
  184. return new Promise(function(resolve,reject) {
  185. wx.getSetting({
  186. success (res) {
  187. if(res.authSetting['scope.addPhoneContact']){
  188. resolve({authorize:true})
  189. }else{
  190. wx.openSetting({
  191. success (res) {
  192. if(res.authSetting['scope.addPhoneContact']){
  193. wx.authorize({
  194. scope: 'scope.addPhoneContact',
  195. success: function (res) {
  196. console.log('success:', res);
  197. resolve({authorize:true})
  198. },
  199. fail: function (error) {
  200. console.log('error:', error);
  201. reject({authorize:false})
  202. }
  203. })
  204. }else{
  205. wx.authorize({
  206. scope: 'scope.addPhoneContact',
  207. success: function (res) {
  208. console.log('success:', res);
  209. resolve({authorize:true})
  210. },
  211. fail: function (error) {
  212. console.log('error:', error);
  213. reject({authorize:false})
  214. }
  215. })
  216. }
  217. },
  218. fail(){
  219. wx.authorize({
  220. scope: 'scope.addPhoneContact',
  221. success: function (res) {
  222. console.log('success:', res);
  223. resolve({authorize:true})
  224. },
  225. fail: function (error) {
  226. console.log('error:', error);
  227. reject({authorize:false})
  228. }
  229. })
  230. }
  231. })
  232. }
  233. }
  234. })
  235. })
  236. },
  237. async savenumtap() {
  238. let res = await this.viewAuthorization();
  239. if (res.authorize) {
  240. wx.addPhoneContact({
  241. firstName: this.data.mineinfo.name,
  242. photoFilePath: this.data.mineinfo.headimgurl,
  243. mobilePhoneNumber: this.data.mineinfo.phone,
  244. weChatNumber: this.data.mineinfo.wx,
  245. addressStreet: this.data.mineinfo.company_address,
  246. organization: this.data.mineinfo.company_name,
  247. title: this.data.mineinfo.position
  248. })
  249. return;
  250. } else {
  251. wx.openSetting({
  252. success: function (ress) { },
  253. fail: function (err) { },
  254. })
  255. }
  256. },
  257. evidenceCate: function () {
  258. var that = this;
  259. utils.$get({
  260. url: app.globalData.webUrl + 'api/material/evidenceCate',
  261. header: {
  262. 'Authorization': 'bearer ' + app.globalData.token
  263. },
  264. data: {},
  265. success: function (res) {
  266. that.setData({
  267. evidencetype: res.data.data
  268. })
  269. }
  270. })
  271. },
  272. setevitap(e) {
  273. this.setData({
  274. catetype: e.currentTarget.dataset.eid
  275. })
  276. this.evidencelist();
  277. },
  278. evidencelist: function () {
  279. const that = this;
  280. evpage = 1;
  281. utils.$get({
  282. url: app.globalData.webUrl + 'api/evidencelist',
  283. header: {
  284. 'Authorization': 'bearer ' + app.globalData.token
  285. },
  286. data: {
  287. uid: app.globalData.personMsg.id,
  288. page: 1,
  289. cate: that.data.catetype,
  290. },
  291. success: function (res) {
  292. setTimeout(function () {
  293. wx.hideLoading()
  294. }, 1000)
  295. if (res.data.code == '0') {
  296. that.setData({
  297. evidencelist: res.data.data,
  298. leftevidencelist: [],
  299. rightevidencelist: [],
  300. datashow: true
  301. })
  302. that.imgload();
  303. }
  304. },
  305. fail() {
  306. wx.hideLoading()
  307. }
  308. })
  309. },
  310. publictap: function (e) {
  311. wx.navigateTo({
  312. url: '/index/pages/publicpraisemsg/publicpraisemsg?eid=' + e.currentTarget.dataset.eid + "&title=" + e.currentTarget.dataset.title+'&ltype=12',
  313. })
  314. },
  315. imgload: function () {
  316. var that = this;
  317. var leftlist = that.data.leftevidencelist;
  318. var rightlist = that.data.rightevidencelist;
  319. var indexlist = that.data.evidencelist;
  320. if (indexlist.length == 0) {
  321. return false;
  322. }
  323. if (!indexlist[0]) {
  324. return false;
  325. }
  326. if (leftlist.length == 0) {
  327. leftlist.push(indexlist[0]);
  328. indexlist.shift();
  329. that.setData({
  330. evidencelist: indexlist,
  331. leftevidencelist: leftlist,
  332. rightevidencelist: rightlist
  333. })
  334. } else {
  335. var leftheight, rightheight;
  336. wx.createSelectorQuery().select('.leftpublicpraisebox').boundingClientRect(function (res) {
  337. leftheight = res.height;
  338. wx.createSelectorQuery().select('.rightpublicpraisebox').boundingClientRect(function (rs) {
  339. leftlist = that.data.leftevidencelist;
  340. rightlist = that.data.rightevidencelist;
  341. indexlist = that.data.evidencelist;
  342. rightheight = rs.height;
  343. if (leftheight <= rightheight) {
  344. leftlist.push(indexlist[0]);
  345. indexlist.shift();
  346. } else {
  347. rightlist.push(indexlist[0]);
  348. indexlist.shift();
  349. }
  350. that.setData({
  351. evidencelist: indexlist,
  352. leftevidencelist: leftlist.filter(v => v),
  353. rightevidencelist: rightlist.filter(v => v)
  354. })
  355. }).exec();
  356. }).exec();
  357. }
  358. },
  359. casestylefun: function () {
  360. var that = this;
  361. utils.$get({
  362. url: app.globalData.webUrl + 'api/stylelist',
  363. header: {
  364. 'Authorization': 'bearer ' + app.globalData.token
  365. },
  366. data: {},
  367. success: function (res) {
  368. if (res.data.code == '0') {
  369. that.setData({
  370. stylelist: res.data.data
  371. })
  372. }
  373. }
  374. })
  375. },
  376. housestylefun: function () {
  377. var that = this;
  378. utils.$get({
  379. url: app.globalData.webUrl + 'api/material/housetypelist',
  380. header: {
  381. 'Authorization': 'bearer ' + app.globalData.token
  382. },
  383. data: {},
  384. success: function (res) {
  385. if (res.data.code == '0') {
  386. that.setData({
  387. housetypelist: res.data.data
  388. })
  389. }
  390. }
  391. })
  392. },
  393. onChoose(e) {
  394. var that = this;
  395. that.setData({
  396. nowcommunity: e.detail.item.currentTarget.dataset.cid,
  397. nowcommunitname: e.detail.item.currentTarget.dataset.item.name,
  398. communityflag: false
  399. })
  400. wx.showLoading({
  401. title: '加载中...',
  402. })
  403. that.caselistfun();
  404. },
  405. casecommunityfun: function () {
  406. var that = this;
  407. utils.$get({
  408. url: app.globalData.webUrl + 'api/communitylist',
  409. header: {
  410. 'Authorization': 'bearer ' + app.globalData.token
  411. },
  412. data: {},
  413. success: function (res) {
  414. if (res.data.code == '0') {
  415. that.setData({
  416. communitylist: res.data.data
  417. })
  418. }
  419. that.getCitys();
  420. }
  421. })
  422. },
  423. getCitys() {
  424. const _this = this
  425. const cities = this.data.communitylist;
  426. // 按拼音排序
  427. cities.sort((c1, c2) => {
  428. let pinyin1 = c1.pinyin;
  429. let pinyin2 = c2.pinyin;
  430. return pinyin1.localeCompare(pinyin2)
  431. })
  432. // 添加首字母
  433. const map = new Map()
  434. for (const city of cities) {
  435. const alpha = city.pinyin.charAt(0).toUpperCase()
  436. if (!map.has(alpha)) map.set(alpha, [])
  437. map.get(alpha).push({ name: city.name, id: city.id })
  438. }
  439. const keys = []
  440. for (const key of map.keys()) {
  441. keys.push(key)
  442. }
  443. keys.sort()
  444. const list = []
  445. for (const key of keys) {
  446. list.push({
  447. alpha: key,
  448. subItems: map.get(key)
  449. })
  450. }
  451. for (let i = 0; i < list.length; i++) {
  452. for (let k = 0; k < list[i].subItems.length; k++) {
  453. for (let j = 0; j < cities.length; j++) {
  454. if (list[i].subItems[k].name == cities[j].name) {
  455. list[i].subItems[k].case_num = cities[j].case_num;
  456. list[i].id = cities[j].id;
  457. }
  458. }
  459. }
  460. }
  461. _this.setData({ list: list })
  462. },
  463. selectareatap: function (e) {
  464. this.setData({
  465. square_start: e.currentTarget.dataset.start,
  466. square_end: e.currentTarget.dataset.end,
  467. })
  468. this.caselistfun();
  469. },
  470. caselistfun: function (e) {
  471. var that = this;
  472. casepage = 1;
  473. utils.$get({
  474. url: app.globalData.webUrl + 'api/caselist',
  475. header: {
  476. 'Authorization': 'bearer ' + app.globalData.token
  477. },
  478. data: {
  479. page: 1,
  480. uid: app.globalData.personMsg.id,
  481. commu_id: that.data.nowcommunity, // 小区id
  482. style_id: that.data.nowstyle, //风格id
  483. square_start: that.data.square_start, //面积开始值
  484. square_end: that.data.square_end, //面积结束值
  485. keyword: that.data.keyword,
  486. housetype_id: that.data.nowhousetype,
  487. case_type:this.data.noweffect,
  488. },
  489. success: function (res) {
  490. that.setData({
  491. datashow: true
  492. })
  493. if (res.data.code == '0') {
  494. that.setData({
  495. caselist: res.data.data,
  496. })
  497. }
  498. setTimeout(function () {
  499. wx.hideLoading()
  500. }, 1000)
  501. },
  502. fail() {
  503. wx.hideLoading()
  504. }
  505. })
  506. },
  507. setstyletap: function (e) {
  508. this.setData({
  509. nowstyle: e.currentTarget.dataset.type
  510. })
  511. this.caselistfun();
  512. },
  513. setcommunitytap: function (e) {
  514. this.setData({
  515. nowcommunity: e.currentTarget.dataset.type,
  516. // communityflag:true,
  517. nowcommunitname: e.currentTarget.dataset.text,
  518. })
  519. this.caselistfun();
  520. },
  521. opencommunitytap: function () {
  522. this.setData({
  523. communityflag: true,
  524. })
  525. },
  526. dothis: function () { },
  527. colsecommunitytap: function () {
  528. this.setData({
  529. communityflag: false
  530. })
  531. },
  532. sethousetypetap: function (e) {
  533. this.setData({
  534. nowhousetype: e.currentTarget.dataset.type
  535. })
  536. this.caselistfun();
  537. },
  538. casemsgtap: function (e) {
  539. wx.navigateTo({
  540. url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid+"&ltype=3",
  541. })
  542. },
  543. /**
  544. * 生命周期函数--监听页面初次渲染完成
  545. */
  546. onReady: function () {
  547. },
  548. /**
  549. * 生命周期函数--监听页面显示
  550. */
  551. onShow: function () {
  552. this.setData({
  553. top: app.globalData.statusBarHeight,
  554. hgt: app.globalData.titleBarHeight,
  555. imgUrl: app.globalData.imgUrl,
  556. timeline:app.globalData.timeline
  557. })
  558. },
  559. backTap: function () {
  560. wx.navigateBack();
  561. },
  562. /**
  563. * 生命周期函数--监听页面隐藏
  564. */
  565. onHide: function () {
  566. },
  567. /**
  568. * 生命周期函数--监听页面卸载
  569. */
  570. onUnload: function () {
  571. },
  572. /**
  573. * 页面相关事件处理函数--监听用户下拉动作
  574. */
  575. onPullDownRefresh: function () {
  576. },
  577. /**
  578. * 页面上拉触底事件的处理函数
  579. */
  580. onReachBottom: function () {
  581. const that = this;
  582. if (this.data.type == 3) {
  583. evpage = evpage * 1 + 1;
  584. utils.$get({
  585. url: app.globalData.webUrl + 'api/evidencelist',
  586. header: {
  587. 'Authorization': 'bearer ' + app.globalData.token
  588. },
  589. data: {
  590. uid: app.globalData.personMsg.id,
  591. page: evpage,
  592. cate: that.data.catetype,
  593. },
  594. success: function (res) {
  595. if (res.data.code == '0') {
  596. let evidencelist = that.data.evidencelist;
  597. var arrflag = false
  598. if (evidencelist.length != 0) {
  599. arrflag = true;
  600. }
  601. for (let i = 0; i < res.data.data.length; i++) {
  602. evidencelist.push(res.data.data[i])
  603. }
  604. that.setData({
  605. evidencelist: evidencelist
  606. })
  607. if (!arrflag) {
  608. that.imgload();
  609. }
  610. }
  611. }
  612. })
  613. } else if (this.data.type == 2) {
  614. casepage = casepage * 1 + 1;
  615. utils.$get({
  616. url: app.globalData.webUrl + 'api/caselist',
  617. header: {
  618. 'Authorization': 'bearer ' + app.globalData.token
  619. },
  620. data: {
  621. page: casepage,
  622. uid: app.globalData.personMsg.id,
  623. commu_id: that.data.nowcommunity, // 小区id
  624. style_id: that.data.nowstyle, //风格id
  625. square_start: that.data.square_start, //面积开始值
  626. square_end: that.data.square_end, //面积结束值
  627. keyword: that.data.keyword,
  628. housetype_id: that.data.nowhousetype,
  629. case_type:this.data.noweffect,
  630. },
  631. success: function (res) {
  632. let caselist = that.data.caselist;
  633. if (res.data.code == '0') {
  634. caselist = caselist.concat(res.data.data);
  635. that.setData({
  636. caselist: caselist
  637. })
  638. }
  639. setTimeout(function () {
  640. wx.hideLoading()
  641. }, 1000)
  642. }
  643. })
  644. }
  645. },
  646. addsharetap: function (type) {
  647. let that = this;
  648. utils.$post({
  649. url: app.globalData.webUrl + 'api/share/addlog',
  650. header: {
  651. 'Authorization': 'bearer ' + app.globalData.token
  652. },
  653. data: {
  654. id: '0',
  655. type: type,
  656. },
  657. success: function (r) {}
  658. })
  659. },
  660. /**
  661. * 用户点击右上角分享
  662. */
  663. onShareAppMessage() {
  664. var that = this;
  665. that.addsharetap('card');
  666. app.globalData.shareuserid = app.globalData.personMsg.id;
  667. wx.showShareMenu({
  668. withShareTicket: true,
  669. menus: ['shareAppMessage', 'shareTimeline']
  670. })
  671. return {
  672. title: this.data.mineinfo.name + "的个人名片",
  673. imageUrl: app.globalData.imgUrl + "/xcx/sharenamecard.png",
  674. path: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.personMsg.binded.id + '&ctp=' + app.globalData.clientype,
  675. };
  676. },
  677. onShareTimeline: function () {
  678. var that = this;
  679. that.addsharetap('card');
  680. app.globalData.shareuserid = app.globalData.personMsg.id;
  681. return {
  682. title: this.data.mineinfo.name + "的个人名片",
  683. query:'uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.personMsg.binded.id + '&ctp=' + app.globalData.clientype+'&type=share',
  684. imageUrl: app.globalData.imgUrl + "/xcx/sharenamecard.png",
  685. }
  686. },
  687. })