caselist.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. const app = getApp();
  2. const util = require("../../../utils/util");
  3. var utils = require("../../../utils/http"),
  4. casepage = 1;
  5. let time = 0,timer = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. nowstyle: '',
  12. stylelist: [],
  13. square_start: '', //面积开始值
  14. square_end: '', //面积结束值
  15. nowcommunity: '',
  16. communitylist: [],
  17. nowhousetype: '',
  18. housetypelist: [],
  19. imgUrl: app.globalData.imgUrl,
  20. caselist: [],
  21. keyword: '',
  22. datashow: false,
  23. loginFlag:false,
  24. phoneFlag:false,
  25. isAgree: false,
  26. canIUseGetUserProfile: false,
  27. shareobj:{},
  28. employeeflag:false,//false是用户,true是员工
  29. top:app.globalData.statusBarHeight,
  30. hgt:app.globalData.titleBarHeight,
  31. companyobj:{},
  32. nowcommunitname:'',
  33. typearr:[
  34. {id:1,name:'效果案例',type:1},
  35. {id:2,name:'实景案例',type:2}
  36. ],
  37. noweffect:''
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. const that=this;
  44. wx.hideHomeButton();
  45. time=0;
  46. this.setData({
  47. top:app.globalData.statusBarHeight,
  48. hgt:app.globalData.titleBarHeight,
  49. })
  50. if(!!options.scene){
  51. options=unescape(options.scene);
  52. let arr=options.split('&');
  53. let obj={};
  54. for(let i=0;i<arr.length;i++){
  55. let arr1=arr[i].split('=');
  56. obj[arr1[0]]=arr1[1];
  57. }
  58. this.setData({
  59. nowstyle: obj.s,
  60. square_start: obj.st, //面积开始值
  61. square_end: obj.e, //面积结束值
  62. nowcommunity: obj.c,
  63. nowhousetype: obj.h
  64. })
  65. app.globalData.clientype=obj.ctp;
  66. app.globalData.shareuserid = obj.u;
  67. }else{
  68. this.setData({
  69. nowstyle: options.s,
  70. square_start: options.st, //面积开始值
  71. square_end: options.e, //面积结束值
  72. nowcommunity: options.c,
  73. nowhousetype: options.h
  74. })
  75. app.globalData.clientype=options.ctp;
  76. app.globalData.shareuserid = options.u;
  77. }
  78. if (wx.getUserProfile) {
  79. this.setData({
  80. canIUseGetUserProfile: true
  81. })
  82. }
  83. },
  84. //用户同意隐私协议
  85. agreePrivacy() {
  86. this.setData({
  87. isAgree: true
  88. })
  89. wx.showLoading({
  90. title: '加载中...',
  91. })
  92. this.login();
  93. },
  94. sharecompany:function (){
  95. const that=this;
  96. utils.$post({
  97. url: app.globalData.webUrl + 'client/index/content_belong_company',
  98. header: {
  99. 'Authorization':'bearer '+app.globalData.token
  100. },
  101. data:{
  102. client_type:app.globalData.clientype,
  103. uid: app.globalData.shareuserid
  104. },
  105. success: function (res) {
  106. if(res.data.code=='0'){
  107. app.globalData.companyobj=res.data.data;
  108. app.globalData.currentUserId = res.data.data.employee_id;
  109. that.setData({
  110. companyobj:res.data.data
  111. })
  112. }
  113. },
  114. complete(res) {
  115. wx.hideLoading()
  116. }
  117. })
  118. },
  119. login: function () {
  120. var that = this;
  121. wx.login({
  122. success: function (data) {
  123. if (data.errMsg == 'login:ok') {
  124. utils.$post({
  125. method: "POST", //TESTAPIURL APIURL/users/auth
  126. url: app.globalData.webUrl + 'api/users/code2session',
  127. data: {
  128. code: data.code,
  129. share: app.globalData.shareuserid,
  130. client_type:app.globalData.clientype
  131. },
  132. success: function (r) {
  133. if (r.data.code == '0') {
  134. app.globalData.sharepersonobj = r.data.share;
  135. app.globalData.token = r.data.token;
  136. that.sharecompany();
  137. if (r.data.share) {
  138. app.globalData.vrString = r.data.share.str;
  139. }
  140. that.setData({
  141. shareobj:app.globalData.sharepersonobj
  142. })
  143. util.toolfun(1);
  144. app.globalData.companyname=r.data.company;
  145. app.globalData.official_openid = r.data.official_openid;
  146. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  147. if (!!r.data.user.phone) {
  148. that.setData({
  149. datashow: true,
  150. loginFlag: false,
  151. phoneFlag:false,
  152. employeeflag:(!!r.data.user.binded&&r.data.user.binded.state=='在职')?true:false
  153. })
  154. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  155. app.globalData.currentUserId = r.data.user.binded.id;
  156. }
  157. app.globalData.personMsg = r.data.user;
  158. app.globalData.userflag = false; //有个人信息
  159. app.globalData.phone = true; //有手机号
  160. that.unreadMsg();
  161. } else {
  162. that.unreadMsg();
  163. wx.hideLoading();
  164. that.setData({
  165. loginFlag: false,
  166. phoneFlag: true
  167. })
  168. }
  169. } else {
  170. setTimeout(function () {
  171. wx.hideLoading()
  172. }, 500)
  173. }
  174. }
  175. })
  176. }
  177. }
  178. })
  179. },
  180. prelooktap(){
  181. if(!app.globalData.sharepersonobj.qrcode){
  182. wx.showToast({
  183. title: "当前专属客服的二维码为空!",
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. return false;
  188. }
  189. wx.previewImage({
  190. current: app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  191. urls: [app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  192. })
  193. },
  194. unreadMsg:function(){
  195. this.casestylefun();
  196. this.housestylefun();
  197. this.casecommunityfun();
  198. this.caselistfun();
  199. },
  200. golastap:function(){
  201. wx.navigateBack({
  202. delta: 1,
  203. success:function(r){
  204. },
  205. fail:function(r){
  206. wx.reLaunch({
  207. url: '/pages/index/index?state=1',
  208. })
  209. },
  210. })
  211. },
  212. goindextap:function(){
  213. if(!this.data.employeeflag){
  214. wx.reLaunch({
  215. url: '/pages/index/index?state=1',
  216. })
  217. }else{
  218. wx.reLaunch({
  219. url: '/pages/consoledesk/consoledesk',
  220. })
  221. }
  222. },
  223. openVRLink(e) {
  224. let vrlink = e.currentTarget.dataset.vrlink;
  225. let id = e.currentTarget.dataset.id;
  226. wx.navigateTo({
  227. url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&aid=' + id,
  228. })
  229. },
  230. opencommunitytap:function(){
  231. this.setData({
  232. communityflag:true,
  233. })
  234. },
  235. dothis:function(){},
  236. colsecommunitytap:function(){
  237. this.setData({
  238. communityflag:false
  239. })
  240. },
  241. seteffectap(e){
  242. this.setData({
  243. noweffect:e.currentTarget.dataset.type
  244. })
  245. this.caselistfun();
  246. },
  247. casecommunityfun: function () {
  248. var that = this;
  249. utils.$get({
  250. url: app.globalData.webUrl + 'api/communitylist',
  251. header: {
  252. 'Authorization': 'bearer ' + app.globalData.token
  253. },
  254. data: {},
  255. success: function (res) {
  256. if (res.data.code == '0') {
  257. for(let i=0;i<res.data.data.length;i++){
  258. if(res.data.data[i].id==that.data.nowcommunity){
  259. that.setData({
  260. nowcommunitname:res.data.data[i].name
  261. })
  262. }
  263. }
  264. that.setData({
  265. communitylist: res.data.data
  266. })
  267. }
  268. that.getCitys();
  269. }
  270. })
  271. },
  272. getCitys() {
  273. const _this = this
  274. const cities = this.data.communitylist;
  275. // 按拼音排序
  276. cities.sort((c1, c2) => {
  277. let pinyin1 = c1.pinyin;
  278. let pinyin2 = c2.pinyin;
  279. return pinyin1.localeCompare(pinyin2)
  280. })
  281. // 添加首字母
  282. const map = new Map()
  283. for (const city of cities) {
  284. const alpha = city.pinyin.charAt(0).toUpperCase()
  285. if (!map.has(alpha)) map.set(alpha, [])
  286. map.get(alpha).push({ name: city.name,id: city.id})
  287. }
  288. const keys = []
  289. for (const key of map.keys()) {
  290. keys.push(key)
  291. }
  292. keys.sort()
  293. const list = []
  294. for (const key of keys) {
  295. list.push({
  296. alpha: key,
  297. subItems: map.get(key)
  298. })
  299. }
  300. for(let i=0;i<list.length;i++){
  301. for(let k=0;k<list[i].subItems.length;k++){
  302. for(let j=0;j<cities.length;j++){
  303. if(list[i].subItems[k].name==cities[j].name){
  304. list[i].subItems[k].case_num=cities[j].case_num;
  305. list[i].id=cities[j].id;
  306. }
  307. }
  308. }
  309. }
  310. _this.setData({list:list})
  311. },
  312. onChoose(e) {
  313. var that=this;
  314. that.setData({
  315. nowcommunity:e.detail.item.currentTarget.dataset.cid,
  316. nowcommunitname:e.detail.item.currentTarget.dataset.item.name,
  317. communityflag:false
  318. })
  319. that.caselistfun();
  320. },
  321. casestylefun: function () {
  322. var that = this;
  323. utils.$get({
  324. url: app.globalData.webUrl + 'api/stylelist',
  325. header: {
  326. 'Authorization': 'bearer ' + app.globalData.token
  327. },
  328. data: {},
  329. success: function (res) {
  330. if (res.data.code == '0') {
  331. that.setData({
  332. stylelist: res.data.data
  333. })
  334. }
  335. }
  336. })
  337. },
  338. callphonetap:function(){
  339. console.log()
  340. wx.makePhoneCall({
  341. phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
  342. })
  343. },
  344. housestylefun: function () {
  345. var that = this;
  346. utils.$get({
  347. url: app.globalData.webUrl + 'api/material/housetypelist',
  348. header: {
  349. 'Authorization': 'bearer ' + app.globalData.token
  350. },
  351. data: {},
  352. success: function (res) {
  353. if (res.data.code == '0') {
  354. that.setData({
  355. housetypelist: res.data.data
  356. })
  357. }
  358. }
  359. })
  360. },
  361. selectareatap: function (e) {
  362. this.setData({
  363. square_start: e.currentTarget.dataset.start,
  364. square_end: e.currentTarget.dataset.end,
  365. })
  366. this.caselistfun();
  367. },
  368. caselistfun: function (e) {
  369. var that = this;
  370. casepage = 1;
  371. wx.showLoading({
  372. title: '加载中...',
  373. })
  374. utils.$get({
  375. url: app.globalData.webUrl + 'client/caselist',
  376. header: {
  377. 'Authorization': 'bearer ' + app.globalData.token
  378. },
  379. data: {
  380. page: 1,
  381. uid: app.globalData.personMsg.id,
  382. commu_id: that.data.nowcommunity, // 小区id
  383. style_id: that.data.nowstyle, //风格id
  384. square_start: that.data.square_start, //面积开始值
  385. square_end: that.data.square_end, //面积结束值
  386. keyword: that.data.keyword,
  387. housetype_id: that.data.nowhousetype,
  388. case_type:this.data.noweffect,
  389. },
  390. success: function (res) {
  391. that.setData({
  392. datashow: true
  393. })
  394. if (res.data.code == '0') {
  395. that.setData({
  396. caselist: res.data.data
  397. })
  398. }
  399. setTimeout(function () {
  400. wx.hideLoading()
  401. }, 1000)
  402. },
  403. fail() {
  404. wx.hideLoading()
  405. }
  406. })
  407. },
  408. setstyletap: function (e) {
  409. this.setData({
  410. nowstyle: e.currentTarget.dataset.type
  411. })
  412. this.caselistfun();
  413. },
  414. setcommunitytap: function (e) {
  415. this.setData({
  416. nowcommunity: e.currentTarget.dataset.type
  417. })
  418. this.caselistfun();
  419. },
  420. sethousetypetap: function (e) {
  421. this.setData({
  422. nowhousetype: e.currentTarget.dataset.type
  423. })
  424. this.caselistfun();
  425. },
  426. casemsgtap: function (e) {
  427. wx.navigateTo({
  428. url: '/share/pages/materialcase/materialcase?type=3&cid=' + e.currentTarget.dataset.cid+'&uid='+app.globalData.shareuserid+'&ctp='+app.globalData.clientype
  429. })
  430. },
  431. /**
  432. * 生命周期函数--监听页面初次渲染完成
  433. */
  434. onReady: function () {
  435. },
  436. /**
  437. * 生命周期函数--监听页面显示
  438. */
  439. onShow: function () {
  440. this.setData({
  441. top:app.globalData.statusBarHeight,
  442. hgt:app.globalData.titleBarHeight,
  443. })
  444. timer = setInterval(function () {
  445. time = time * 1 + 1;
  446. }, 1000)
  447. },
  448. /**
  449. * 生命周期函数--监听页面隐藏
  450. */
  451. onHide: function () {
  452. if (timer) {
  453. clearInterval(timer)
  454. }
  455. this.setimetap();
  456. },
  457. setimetap(){
  458. if (!this.data.isAgree) {
  459. return false;
  460. }
  461. const that = this;
  462. utils.$post({
  463. url: app.globalData.webUrl + 'client/index/visit_due_time',
  464. header: {
  465. 'Authorization': 'bearer ' + app.globalData.token
  466. },
  467. data: {
  468. id: that.data.companyobj.employee_id,
  469. pipe_type: 'toolAll',
  470. time: time,
  471. },
  472. success: function (res) {
  473. }
  474. })
  475. },
  476. /**
  477. * 生命周期函数--监听页面卸载
  478. */
  479. onUnload: function () {
  480. this.setimetap();
  481. },
  482. /**
  483. * 页面相关事件处理函数--监听用户下拉动作
  484. */
  485. onPullDownRefresh: function () {
  486. var that = this;
  487. casepage = 1;
  488. wx.showLoading({
  489. title: '加载中...',
  490. })
  491. utils.$get({
  492. url: app.globalData.webUrl + 'client/caselist',
  493. header: {
  494. 'Authorization': 'bearer ' + app.globalData.token
  495. },
  496. data: {
  497. page: 1,
  498. uid: app.globalData.personMsg.id,
  499. commu_id: that.data.nowcommunity, // 小区id
  500. style_id: that.data.nowstyle, //风格id
  501. square_start: that.data.square_start, //面积开始值
  502. square_end: that.data.square_end, //面积结束值
  503. keyword: that.data.keyword,
  504. housetype_id: that.data.nowhousetype,
  505. case_type:this.data.noweffect,
  506. },
  507. success: function (res) {
  508. wx.stopPullDownRefresh()
  509. if (res.data.code == '0') {
  510. that.setData({
  511. caselist: res.data.data
  512. })
  513. }
  514. setTimeout(function () {
  515. wx.hideLoading()
  516. }, 1000)
  517. }
  518. })
  519. },
  520. /**
  521. * 页面上拉触底事件的处理函数
  522. */
  523. onReachBottom: function () {
  524. var that = this;
  525. casepage = casepage * 1 + 1;
  526. wx.showLoading({
  527. title: '加载中...',
  528. })
  529. utils.$get({
  530. url: app.globalData.webUrl + 'client/caselist',
  531. header: {
  532. 'Authorization': 'bearer ' + app.globalData.token
  533. },
  534. data: {
  535. page: casepage,
  536. uid: app.globalData.personMsg.id,
  537. commu_id: that.data.nowcommunity, // 小区id
  538. style_id: that.data.nowstyle, //风格id
  539. square_start: that.data.square_start, //面积开始值
  540. square_end: that.data.square_end, //面积结束值
  541. keyword: that.data.keyword,
  542. housetype_id: that.data.nowhousetype,
  543. case_type:this.data.noweffect,
  544. },
  545. success: function (res) {
  546. let caselist = that.data.caselist;
  547. if (res.data.code == '0') {
  548. caselist = caselist.concat(res.data.data);
  549. that.setData({
  550. caselist: caselist
  551. })
  552. }
  553. setTimeout(function () {
  554. wx.hideLoading()
  555. }, 1000)
  556. }
  557. })
  558. },
  559. addsharetap: function (type) {
  560. let that = this;
  561. utils.$post({
  562. url: app.globalData.webUrl + 'api/share/addlog',
  563. header: {
  564. 'Authorization': 'bearer ' + app.globalData.token
  565. },
  566. data: {
  567. id: '0',
  568. type: type,
  569. },
  570. success: function (r) {}
  571. })
  572. },
  573. /**
  574. * 用户点击右上角分享
  575. */
  576. onShareAppMessage: function () {
  577. let that = this;
  578. that.addsharetap('toolAll');
  579. return {
  580. title: app.globalData.personMsg.binded.name + "的装修案例",
  581. imageUrl: app.globalData.imgUrl+"xcx/caseposter.jpg",
  582. path: '/share/pages/caselist/caselist?u=' + app.globalData.personMsg.id +'&c=' + that.data.nowcommunity + '&s=' + that.data.nowstyle + '&st=' + that.data.square_start+'&ctp='+app.globalData.clientype + '&e=' + that.data.square_end + '&h=' + that.data.nowhousetype
  583. }
  584. }
  585. })