namecard.js 23 KB

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