caselist.js 19 KB

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