mycaselist.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. const app=getApp(),utils=require("../../../utils/http"),util = require("../../../utils/util");;
  2. let casepage=1;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl:app.globalData.imgUrl,
  9. type:1,
  10. casestyletype: '',
  11. nowstyletext:'',
  12. square: [
  13. { id: 1, name: '60㎡以下', start: 0, end: 60 },
  14. { id: 2, name: '60㎡—90㎡', start: 60, end: 90 },
  15. { id: 3, name: '90㎡—110㎡', start: 90, end: 110 },
  16. { id: 4, name: '110㎡—140㎡', start: 110, end: 140 },
  17. { id: 5, name: '140㎡—170㎡', start: 140, end: 170 },
  18. { id: 6, name: '170㎡—210㎡', start: 170, end: 210 },
  19. { id: 7, name: '210㎡—240㎡', start: 210, end: 240 },
  20. { id: 8, name: '240㎡—270㎡', start: 240, end: 270 },
  21. { id: 9, name: '270㎡以上', start: 270, end: '' }
  22. ],
  23. nowsquare: '',
  24. nowstyleid: '',
  25. nowhousestyletext:'',
  26. nowcommunitytext:'',
  27. casestylelist:[],
  28. casestyletype:'',
  29. styleflag:false,
  30. housestyleflag:false,
  31. squareflag: false,
  32. square_start: '',//面积开始值
  33. square_end: '',//面积结束值
  34. communitylist:[],
  35. indexList:[],
  36. casekeytext:'',
  37. commu_id:'',
  38. filtrateflag:false,
  39. datashow:false,
  40. wshareshow:false,
  41. caselist: [],
  42. leftcaselist: [],
  43. rightcaselist: [],
  44. uploadedlist:[],
  45. islist: false,
  46. nowtype: 'materialCase',
  47. nowid: '',
  48. nowtitle:'',
  49. nowimg: '',
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad(options) {
  55. wx.hideShareMenu({
  56. menus: ['shareAppMessage', 'shareTimeline']
  57. })
  58. this.setData({
  59. imgUrl:app.globalData.imgUrl,
  60. })
  61. wx.showLoading({
  62. title: '加载中...',
  63. })
  64. this.housestylefun();
  65. this.communityfun();
  66. this.casestylefun();
  67. this.caselistfun();
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow() {
  78. },
  79. clearcommunitytap() {
  80. this.setData({
  81. nowcommunitytext: '',
  82. commu_id: ''
  83. })
  84. this.caselistfun();
  85. },
  86. allfiltratetap: function () {
  87. this.setData({
  88. filtrateflag: true,
  89. casetype: 1
  90. })
  91. },
  92. setcasekeywordtap: function (e) {
  93. this.setData({
  94. casekeytext: e.detail.value
  95. })
  96. },
  97. communitytap(e) {
  98. this.setData({
  99. commu_id: e.detail.item.target.dataset.cid,
  100. nowcommunitytext: e.detail.item.target.dataset.item.name,
  101. filtrateflag: false
  102. })
  103. this.caselistfun();
  104. },
  105. setypetap(e){
  106. this.setData({
  107. type:e.currentTarget.dataset.type
  108. })
  109. this.caselistfun();
  110. },
  111. editap(){
  112. wx.navigateTo({
  113. url: '/mycustomer/pages/editcase/editcase',
  114. })
  115. },
  116. gotocasetap(e){
  117. let uploadedlist=this.data.uploadedlist,idx=e.currentTarget.dataset.idx;
  118. if(uploadedlist[idx].del==1||uploadedlist[idx].publish==0){
  119. wx.navigateTo({
  120. url: '/mycustomer/pages/editcase/editcase?cid='+uploadedlist[idx].id,
  121. })
  122. }else{
  123. wx.navigateTo({
  124. url: '/index/pages/casemsg/casemsg?cid=' + uploadedlist[idx].id,
  125. })
  126. }
  127. },
  128. closefiltratetap: function () {
  129. this.setData({
  130. filtrateflag: false
  131. })
  132. },
  133. setsquaretap(e) {
  134. if (e.detail == "") {
  135. this.setData({
  136. squareflag: false
  137. })
  138. return false;
  139. }
  140. if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') {
  141. this.setData({
  142. nowsquare: e.detail.currentTarget.dataset.text,
  143. squareflag: false,
  144. square_start: this.data.square[e.detail.currentTarget.dataset.idx].start,//面积开始值
  145. square_end: this.data.square[e.detail.currentTarget.dataset.idx].end,//面积结束值
  146. })
  147. } else if (e.detail.currentTarget.dataset.idx == '-1') {
  148. this.setData({
  149. nowsquare: '',
  150. squareflag: false,
  151. square_start: '',//面积开始值
  152. square_end: '',//面积结束值
  153. })
  154. }
  155. this.caselistfun();
  156. },
  157. housestylefun: function () {
  158. var that = this;
  159. utils.$get({
  160. url: app.globalData.webUrl + 'api/material/housetypelist',
  161. header: {
  162. 'Authorization': 'bearer ' + app.globalData.token
  163. },
  164. data: {},
  165. success: function (res) {
  166. if (res.data.code == '0') {
  167. that.setData({
  168. housestylelist: res.data.data
  169. })
  170. }
  171. }
  172. })
  173. },
  174. sethousestyletap(e) {
  175. if (e.detail == "") {
  176. this.setData({
  177. housestyleflag: false
  178. })
  179. return false;
  180. }
  181. if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') {
  182. this.setData({
  183. nowstyleid: e.detail.currentTarget.dataset.text,
  184. housestyleflag: false,
  185. nowhousestyletext: this.data.housestylelist[e.detail.currentTarget.dataset.idx].name
  186. })
  187. } else if (e.detail.currentTarget.dataset.idx == '-1') {
  188. this.setData({
  189. nowstyleid: '',
  190. housestyleflag: false,
  191. nowhousestyletext: ''
  192. })
  193. }
  194. this.caselistfun();
  195. },
  196. casetypetap(e) {
  197. this.setData({
  198. casetype: e.currentTarget.dataset.type,
  199. styleflag: e.currentTarget.dataset.type == 1 ? true : '',
  200. housestyleflag: e.currentTarget.dataset.type == 3 ? true : '',
  201. squareflag: e.currentTarget.dataset.type == 2 ? true : '',
  202. filtrateflag: e.currentTarget.dataset.type == 4 ? true : false,
  203. })
  204. },
  205. casestylefun: function () {
  206. var that = this;
  207. utils.$get({
  208. url: app.globalData.webUrl + 'api/stylelist',
  209. header: {
  210. 'Authorization': 'bearer ' + app.globalData.token
  211. },
  212. data: {},
  213. success: function (res) {
  214. if (res.data.code == '0') {
  215. that.setData({
  216. casestylelist: res.data.data
  217. })
  218. }
  219. }
  220. })
  221. },
  222. setstyletap(e) {
  223. if (e.detail == "") {
  224. this.setData({
  225. styleflag: false
  226. })
  227. return false;
  228. }
  229. if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') {
  230. this.setData({
  231. casestyletype: e.detail.currentTarget.dataset.text,
  232. styleflag: false,
  233. nowstyletext: this.data.casestylelist[e.detail.currentTarget.dataset.idx].name
  234. })
  235. } else if (e.detail.currentTarget.dataset.idx == '-1') {
  236. this.setData({
  237. casestyletype: '',
  238. styleflag: false,
  239. nowstyletext: ''
  240. })
  241. }
  242. this.caselistfun();
  243. },
  244. caselistfun: function (e) {
  245. var that = this;
  246. if (!!e) {
  247. that.setData({
  248. filtrateflag: false
  249. })
  250. }
  251. casepage=1;
  252. utils.$get({
  253. url: app.globalData.webUrl + 'api/caselist',
  254. header: {
  255. 'Authorization': 'bearer ' + app.globalData.token
  256. },
  257. data: {
  258. uid: app.globalData.personMsg.id,
  259. page: 1,
  260. commu_id: that.data.commu_id,// 小区id
  261. style_id: that.data.casestyletype,//风格id
  262. square_start: that.data.square_start,//面积开始值
  263. square_end: that.data.square_end,//面积结束值
  264. keyword: that.data.casekeytext,
  265. housetype_id: that.data.nowstyleid,
  266. order: that.data.ordertype == 'time' ? 'addtime' : 'view_times',
  267. my_case:that.data.type==1?'publish':'all'
  268. },
  269. success: function (res) {
  270. that.setData({
  271. datashow: true
  272. })
  273. if (res.data.code == '0') {
  274. if(that.data.type==1){
  275. that.setData({
  276. caselist: res.data.data,
  277. leftcaselist: [],
  278. rightcaselist: [],
  279. datashow: true
  280. })
  281. that.caseimgload();
  282. }else{
  283. that.setData({
  284. uploadedlist:res.data.data
  285. })
  286. }
  287. }
  288. setTimeout(function () {
  289. wx.hideLoading()
  290. }, 1000)
  291. }, fail() {
  292. wx.hideLoading()
  293. }
  294. })
  295. },
  296. casecollectap: function (e) {
  297. var that = this;
  298. let caselist = '';
  299. if (e.currentTarget.dataset.type == 'rightcaselist') {
  300. caselist = that.data.rightcaselist;
  301. } else {
  302. caselist = that.data.leftcaselist;
  303. }
  304. utils.$post({
  305. url: app.globalData.webUrl + 'api/collect',
  306. header: {
  307. 'Authorization': 'bearer ' + app.globalData.token
  308. },
  309. data: {
  310. user_id: app.globalData.personMsg.id,
  311. content_type: "materialCase",
  312. content_id: e.currentTarget.dataset.cid
  313. },
  314. success: function (res) {
  315. if (res.data.code == '0') {
  316. wx.showToast({
  317. title: res.data.msg,
  318. icon: 'none',
  319. duration: 2000
  320. })
  321. caselist[e.currentTarget.dataset.idx].collected = !caselist[e.currentTarget.dataset.idx].collected;
  322. if (e.currentTarget.dataset.type == 'rightcaselist') {
  323. that.setData({
  324. rightcaselist: caselist
  325. })
  326. } else {
  327. that.setData({
  328. leftcaselist: caselist
  329. })
  330. }
  331. }
  332. }
  333. })
  334. },
  335. caseimgload: function () {
  336. var that = this;
  337. var leftlist = that.data.leftcaselist;
  338. var rightlist = that.data.rightcaselist;
  339. var indexlist = that.data.caselist;
  340. if (indexlist.length == 0) {
  341. return false;
  342. }
  343. if (!indexlist[0]) {
  344. return false;
  345. }
  346. if (leftlist.length == 0) {
  347. leftlist.push(indexlist[0]);
  348. indexlist.shift();
  349. that.setData({
  350. caselist: indexlist,
  351. leftcaselist: leftlist,
  352. rightcaselist: rightlist
  353. })
  354. } else {
  355. var leftheight, rightheight;
  356. wx.createSelectorQuery().in(this).select('#leftcasebox').boundingClientRect(function (res) {
  357. // if(!res){
  358. // return false;
  359. // }
  360. leftheight = res.height;
  361. wx.createSelectorQuery().in(that).select('#rightcasebox').boundingClientRect(function (rs) {
  362. // if(!rs){
  363. // return false;
  364. // }
  365. leftlist = that.data.leftcaselist;
  366. rightlist = that.data.rightcaselist;
  367. indexlist = that.data.caselist;
  368. rightheight = rs.height;
  369. if (!indexlist[0]) {
  370. return false;
  371. }
  372. if (leftheight > rightheight && (leftheight - rightheight) > 20) {
  373. rightlist.push(indexlist[0]);
  374. indexlist.shift();
  375. } else {
  376. leftlist.push(indexlist[0]);
  377. indexlist.shift();
  378. }
  379. that.setData({
  380. caselist: indexlist,
  381. leftcaselist: leftlist,
  382. rightcaselist: rightlist
  383. })
  384. }).exec();
  385. }).exec();
  386. }
  387. },
  388. communityfun: function (e) {
  389. var that = this;
  390. that.setData({
  391. casepage: 1,
  392. })
  393. utils.$get({
  394. url: app.globalData.webUrl + 'api/communitylist',
  395. header: {
  396. 'Authorization': 'bearer ' + app.globalData.token
  397. },
  398. data: {
  399. page: 1,
  400. sort: this.data.ordertype == 'time' ? '' : 'updatetime',
  401. from: '1'
  402. },
  403. success: function (res) {
  404. that.setData({
  405. datashow: true
  406. })
  407. let indexList = [], str = '';
  408. if (res.data.code == '0') {
  409. for (let i in res.data.data) {
  410. res.data.data[i].firstword = res.data.data[i].pinyin.slice(0, 1).toUpperCase();
  411. if (res.data.data[i].pinyin.slice(0, 1).toUpperCase() != str) {
  412. str = res.data.data[i].pinyin.slice(0, 1).toUpperCase() + '';
  413. indexList.push(str);
  414. }
  415. }
  416. that.setData({
  417. communitycaselist: res.data.data,
  418. indexList: indexList
  419. })
  420. that.communitygetCitys();
  421. }
  422. setTimeout(function () {
  423. wx.hideLoading()
  424. }, 1000)
  425. }, fail() {
  426. wx.hideLoading()
  427. }
  428. })
  429. },
  430. communitygetCitys() {
  431. const _this = this
  432. const cities = this.data.communitycaselist;
  433. // 按拼音排序
  434. cities.sort((c1, c2) => {
  435. let pinyin1 = c1.pinyin;
  436. let pinyin2 = c2.pinyin;
  437. return pinyin1.localeCompare(pinyin2)
  438. })
  439. // 添加首字母
  440. const map = new Map()
  441. for (const city of cities) {
  442. const alpha = city.pinyin.charAt(0).toUpperCase()
  443. if (!map.has(alpha)) map.set(alpha, [])
  444. map.get(alpha).push({ name: city.name, id: city.id })
  445. }
  446. const keys = []
  447. for (const key of map.keys()) {
  448. keys.push(key)
  449. }
  450. keys.sort()
  451. const list = []
  452. for (const key of keys) {
  453. list.push({
  454. alpha: key,
  455. subItems: map.get(key)
  456. })
  457. }
  458. for (let i = 0; i < list.length; i++) {
  459. list[i].subItems[0].case_num = '0';
  460. for (let k = 0; k < list[i].subItems.length; k++) {
  461. for (let j = 0; j < cities.length; j++) {
  462. if (list[i].subItems[k].name == cities[j].name) {
  463. list[i].subItems[k].case_num = cities[j].case_num;
  464. list[i].id = cities[j].id;
  465. }
  466. }
  467. }
  468. }
  469. _this.setData({ communitylist: list })
  470. },
  471. casemsgtap: function (e) {
  472. wx.navigateTo({
  473. url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid,
  474. })
  475. },
  476. casesharetap: function (e) {
  477. var that = this;
  478. that.setData({
  479. nowtype: 'materialCase',
  480. nowid: e.currentTarget.dataset.cid,
  481. nowtitle: e.currentTarget.dataset.title,
  482. nowimg: e.currentTarget.dataset.img,
  483. wshareshow: true,
  484. })
  485. },
  486. setpostertap: function () {
  487. let that = this;
  488. let type = that.data.nowtype, usrl = "";
  489. type = "materialCase";
  490. usrl = '&u=' + app.globalData.personMsg.id + '&c=' + that.data.commu_id + '&s=' + that.data.casestyletype + '&st=' + that.data.square_start + '&e=' + that.data.square_end + '&h=' + that.data.nowstyleid
  491. wx.navigateTo({
  492. url: '/index/pages/setposter/setposter?type=' + type + '&aid=' + this.data.nowid + "&listshare=" + usrl,
  493. })
  494. },
  495. sendfriendtap: function () {
  496. this.sharelogtap();
  497. },
  498. shareurltap: function () {
  499. let that = this;
  500. wx.showLoading({
  501. title: '加载中...',
  502. })
  503. util.schemefun('/share/pages/materialcase/materialcase', 'cid=' + that.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, that.data.nowid, 'materialCase', '');
  504. this.sharelogtap();
  505. },
  506. sharelogtap: function (e) {
  507. var that = this;
  508. utils.$post({
  509. url: app.globalData.webUrl + 'api/share/addlog',
  510. header: {
  511. 'Authorization': 'bearer ' + app.globalData.token
  512. },
  513. data: {
  514. id: that.data.nowid,
  515. type: that.data.nowtype
  516. },
  517. success: function (r) {
  518. }
  519. })
  520. },
  521. /**
  522. * 生命周期函数--监听页面隐藏
  523. */
  524. onHide() {
  525. },
  526. /**
  527. * 生命周期函数--监听页面卸载
  528. */
  529. onUnload() {
  530. },
  531. /**
  532. * 页面相关事件处理函数--监听用户下拉动作
  533. */
  534. onPullDownRefresh() {
  535. const that=this;
  536. casepage=1;
  537. utils.$get({
  538. url: app.globalData.webUrl + 'api/caselist',
  539. header: {
  540. 'Authorization': 'bearer ' + app.globalData.token
  541. },
  542. data: {
  543. uid: app.globalData.personMsg.id,
  544. page: 1,
  545. commu_id: that.data.commu_id,// 小区id
  546. style_id: that.data.casestyletype,//风格id
  547. square_start: that.data.square_start,//面积开始值
  548. square_end: that.data.square_end,//面积结束值
  549. keyword: that.data.casekeytext,
  550. housetype_id: that.data.nowstyleid,
  551. order: that.data.ordertype == 'time' ? 'addtime' : 'view_times',
  552. my_case:that.data.type==1?'publish':'all'
  553. },
  554. success: function (res) {
  555. wx.stopPullDownRefresh()
  556. if (res.data.code == '0') {
  557. if(that.data.type==1){
  558. that.setData({
  559. caselist: res.data.data,
  560. leftcaselist: [],
  561. rightcaselist: [],
  562. datashow: true
  563. })
  564. that.caseimgload();
  565. }else{
  566. that.setData({
  567. uploadedlist:res.data.data
  568. })
  569. }
  570. }
  571. }, fail() {
  572. wx.stopPullDownRefresh()
  573. }
  574. })
  575. },
  576. /**
  577. * 页面上拉触底事件的处理函数
  578. */
  579. onReachBottom() {
  580. const that=this;
  581. casepage=casepage*1+1;
  582. utils.$get({
  583. url: app.globalData.webUrl + 'api/caselist',
  584. header: {
  585. 'Authorization': 'bearer ' + app.globalData.token
  586. },
  587. data: {
  588. uid: app.globalData.personMsg.id,
  589. page: casepage,
  590. commu_id: that.data.commu_id,// 小区id
  591. style_id: that.data.casestyletype,//风格id
  592. square_start: that.data.square_start,//面积开始值
  593. square_end: that.data.square_end,//面积结束值
  594. keyword: that.data.casekeytext,
  595. housetype_id: that.data.nowstyleid,
  596. order: that.data.ordertype == 'time' ? 'addtime' : 'view_times',
  597. my_case:that.data.type==1?'publish':'all'
  598. },
  599. success: function (res) {
  600. wx.stopPullDownRefresh()
  601. if (res.data.code == '0') {
  602. if(that.data.type==1){
  603. let arrflag = false;
  604. let caselist = that.data.caselist;
  605. if (caselist.length != 0) {
  606. arrflag = true;
  607. }
  608. caselist = caselist.concat(res.data.data)
  609. that.setData({
  610. caselist: caselist
  611. })
  612. if (!arrflag) {
  613. that.caseimgload();
  614. }
  615. }else{
  616. let uploadedlist=that.data.uploadedlist;
  617. uploadedlist=uploadedlist.concat(res.data.data);
  618. that.setData({
  619. uploadedlist:uploadedlist
  620. })
  621. }
  622. }
  623. }, fail() {
  624. wx.stopPullDownRefresh()
  625. }
  626. })
  627. },
  628. /**
  629. * 用户点击右上角分享
  630. */
  631. onShareAppMessage() {
  632. this.sharelogtap();
  633. return {
  634. title: that.data.nowtitle,
  635. imageUrl: that.data.nowimg,
  636. path: '/share/pages/materialcase/materialcase?cid=' + that.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  637. }
  638. }
  639. })