caselist.js 18 KB

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