const app=getApp(),utils=require("../../../utils/http"),util = require("../../../utils/util");; let casepage=1; Page({ /** * 页面的初始数据 */ data: { imgUrl:app.globalData.imgUrl, type:1, casestyletype: '', nowstyletext:'', square: [ { id: 1, name: '60㎡以下', start: 0, end: 60 }, { id: 2, name: '60㎡—90㎡', start: 60, end: 90 }, { id: 3, name: '90㎡—110㎡', start: 90, end: 110 }, { id: 4, name: '110㎡—140㎡', start: 110, end: 140 }, { id: 5, name: '140㎡—170㎡', start: 140, end: 170 }, { id: 6, name: '170㎡—210㎡', start: 170, end: 210 }, { id: 7, name: '210㎡—240㎡', start: 210, end: 240 }, { id: 8, name: '240㎡—270㎡', start: 240, end: 270 }, { id: 9, name: '270㎡以上', start: 270, end: '' } ], nowsquare: '', nowstyleid: '', nowhousestyletext:'', nowcommunitytext:'', casestylelist:[], casestyletype:'', styleflag:false, housestyleflag:false, squareflag: false, square_start: '',//面积开始值 square_end: '',//面积结束值 communitylist:[], indexList:[], casekeytext:'', commu_id:'', filtrateflag:false, datashow:false, wshareshow:false, caselist: [], leftcaselist: [], rightcaselist: [], uploadedlist:[], islist: false, nowtype: 'materialCase', nowid: '', nowtitle:'', nowimg: '', }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.hideShareMenu({ menus: ['shareAppMessage', 'shareTimeline'] }) this.setData({ imgUrl:app.globalData.imgUrl, }) wx.showLoading({ title: '加载中...', }) this.housestylefun(); this.communityfun(); this.casestylefun(); this.caselistfun(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, clearcommunitytap() { this.setData({ nowcommunitytext: '', commu_id: '' }) this.caselistfun(); }, allfiltratetap: function () { this.setData({ filtrateflag: true, casetype: 1 }) }, setcasekeywordtap: function (e) { this.setData({ casekeytext: e.detail.value }) }, communitytap(e) { this.setData({ commu_id: e.detail.item.target.dataset.cid, nowcommunitytext: e.detail.item.target.dataset.item.name, filtrateflag: false }) this.caselistfun(); }, setypetap(e){ this.setData({ type:e.currentTarget.dataset.type }) this.caselistfun(); }, editap(){ wx.navigateTo({ url: '/mycustomer/pages/editcase/editcase', }) }, gotocasetap(e){ let uploadedlist=this.data.uploadedlist,idx=e.currentTarget.dataset.idx; if(uploadedlist[idx].del==1||uploadedlist[idx].publish==0){ wx.navigateTo({ url: '/mycustomer/pages/editcase/editcase?cid='+uploadedlist[idx].id, }) }else{ wx.navigateTo({ url: '/index/pages/casemsg/casemsg?cid=' + uploadedlist[idx].id, }) } }, closefiltratetap: function () { this.setData({ filtrateflag: false }) }, setsquaretap(e) { if (e.detail == "") { this.setData({ squareflag: false }) return false; } if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') { this.setData({ nowsquare: e.detail.currentTarget.dataset.text, squareflag: false, square_start: this.data.square[e.detail.currentTarget.dataset.idx].start,//面积开始值 square_end: this.data.square[e.detail.currentTarget.dataset.idx].end,//面积结束值 }) } else if (e.detail.currentTarget.dataset.idx == '-1') { this.setData({ nowsquare: '', squareflag: false, square_start: '',//面积开始值 square_end: '',//面积结束值 }) } this.caselistfun(); }, housestylefun: function () { var that = this; utils.$get({ url: app.globalData.webUrl + 'api/material/housetypelist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { that.setData({ housestylelist: res.data.data }) } } }) }, sethousestyletap(e) { if (e.detail == "") { this.setData({ housestyleflag: false }) return false; } if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') { this.setData({ nowstyleid: e.detail.currentTarget.dataset.text, housestyleflag: false, nowhousestyletext: this.data.housestylelist[e.detail.currentTarget.dataset.idx].name }) } else if (e.detail.currentTarget.dataset.idx == '-1') { this.setData({ nowstyleid: '', housestyleflag: false, nowhousestyletext: '' }) } this.caselistfun(); }, casetypetap(e) { this.setData({ casetype: e.currentTarget.dataset.type, styleflag: e.currentTarget.dataset.type == 1 ? true : '', housestyleflag: e.currentTarget.dataset.type == 3 ? true : '', squareflag: e.currentTarget.dataset.type == 2 ? true : '', filtrateflag: e.currentTarget.dataset.type == 4 ? true : false, }) }, casestylefun: function () { var that = this; utils.$get({ url: app.globalData.webUrl + 'api/stylelist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { that.setData({ casestylelist: res.data.data }) } } }) }, setstyletap(e) { if (e.detail == "") { this.setData({ styleflag: false }) return false; } if (e.detail.currentTarget.dataset.type == 1 && e.detail.currentTarget.dataset.idx != '-1') { this.setData({ casestyletype: e.detail.currentTarget.dataset.text, styleflag: false, nowstyletext: this.data.casestylelist[e.detail.currentTarget.dataset.idx].name }) } else if (e.detail.currentTarget.dataset.idx == '-1') { this.setData({ casestyletype: '', styleflag: false, nowstyletext: '' }) } this.caselistfun(); }, caselistfun: function (e) { var that = this; if (!!e) { that.setData({ filtrateflag: false }) } casepage=1; utils.$get({ url: app.globalData.webUrl + 'api/caselist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: 1, commu_id: that.data.commu_id,// 小区id style_id: that.data.casestyletype,//风格id square_start: that.data.square_start,//面积开始值 square_end: that.data.square_end,//面积结束值 keyword: that.data.casekeytext, housetype_id: that.data.nowstyleid, order: that.data.ordertype == 'time' ? 'addtime' : 'view_times', my_case:that.data.type==1?'publish':'all' }, success: function (res) { that.setData({ datashow: true }) if (res.data.code == '0') { if(that.data.type==1){ that.setData({ caselist: res.data.data, leftcaselist: [], rightcaselist: [], datashow: true }) that.caseimgload(); }else{ that.setData({ uploadedlist:res.data.data }) } } setTimeout(function () { wx.hideLoading() }, 1000) }, fail() { wx.hideLoading() } }) }, casecollectap: function (e) { var that = this; let caselist = ''; if (e.currentTarget.dataset.type == 'rightcaselist') { caselist = that.data.rightcaselist; } else { caselist = that.data.leftcaselist; } utils.$post({ url: app.globalData.webUrl + 'api/collect', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { user_id: app.globalData.personMsg.id, content_type: "materialCase", content_id: e.currentTarget.dataset.cid }, success: function (res) { if (res.data.code == '0') { wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) caselist[e.currentTarget.dataset.idx].collected = !caselist[e.currentTarget.dataset.idx].collected; if (e.currentTarget.dataset.type == 'rightcaselist') { that.setData({ rightcaselist: caselist }) } else { that.setData({ leftcaselist: caselist }) } } } }) }, caseimgload: function () { var that = this; var leftlist = that.data.leftcaselist; var rightlist = that.data.rightcaselist; var indexlist = that.data.caselist; if (indexlist.length == 0) { return false; } if (!indexlist[0]) { return false; } if (leftlist.length == 0) { leftlist.push(indexlist[0]); indexlist.shift(); that.setData({ caselist: indexlist, leftcaselist: leftlist, rightcaselist: rightlist }) } else { var leftheight, rightheight; wx.createSelectorQuery().in(this).select('#leftcasebox').boundingClientRect(function (res) { // if(!res){ // return false; // } leftheight = res.height; wx.createSelectorQuery().in(that).select('#rightcasebox').boundingClientRect(function (rs) { // if(!rs){ // return false; // } leftlist = that.data.leftcaselist; rightlist = that.data.rightcaselist; indexlist = that.data.caselist; rightheight = rs.height; if (!indexlist[0]) { return false; } if (leftheight > rightheight && (leftheight - rightheight) > 20) { rightlist.push(indexlist[0]); indexlist.shift(); } else { leftlist.push(indexlist[0]); indexlist.shift(); } that.setData({ caselist: indexlist, leftcaselist: leftlist, rightcaselist: rightlist }) }).exec(); }).exec(); } }, communityfun: function (e) { var that = this; that.setData({ casepage: 1, }) utils.$get({ url: app.globalData.webUrl + 'api/communitylist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: 1, sort: this.data.ordertype == 'time' ? '' : 'updatetime', from: '1' }, success: function (res) { that.setData({ datashow: true }) let indexList = [], str = ''; if (res.data.code == '0') { for (let i in res.data.data) { res.data.data[i].firstword = res.data.data[i].pinyin.slice(0, 1).toUpperCase(); if (res.data.data[i].pinyin.slice(0, 1).toUpperCase() != str) { str = res.data.data[i].pinyin.slice(0, 1).toUpperCase() + ''; indexList.push(str); } } that.setData({ communitycaselist: res.data.data, indexList: indexList }) that.communitygetCitys(); } setTimeout(function () { wx.hideLoading() }, 1000) }, fail() { wx.hideLoading() } }) }, communitygetCitys() { const _this = this const cities = this.data.communitycaselist; // 按拼音排序 cities.sort((c1, c2) => { let pinyin1 = c1.pinyin; let pinyin2 = c2.pinyin; return pinyin1.localeCompare(pinyin2) }) // 添加首字母 const map = new Map() for (const city of cities) { const alpha = city.pinyin.charAt(0).toUpperCase() if (!map.has(alpha)) map.set(alpha, []) map.get(alpha).push({ name: city.name, id: city.id }) } const keys = [] for (const key of map.keys()) { keys.push(key) } keys.sort() const list = [] for (const key of keys) { list.push({ alpha: key, subItems: map.get(key) }) } for (let i = 0; i < list.length; i++) { list[i].subItems[0].case_num = '0'; for (let k = 0; k < list[i].subItems.length; k++) { for (let j = 0; j < cities.length; j++) { if (list[i].subItems[k].name == cities[j].name) { list[i].subItems[k].case_num = cities[j].case_num; list[i].id = cities[j].id; } } } } _this.setData({ communitylist: list }) }, casemsgtap: function (e) { wx.navigateTo({ url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid, }) }, casesharetap: function (e) { var that = this; that.setData({ nowtype: 'materialCase', nowid: e.currentTarget.dataset.cid, nowtitle: e.currentTarget.dataset.title, nowimg: e.currentTarget.dataset.img, wshareshow: true, }) }, setpostertap: function () { let that = this; let type = that.data.nowtype, usrl = ""; type = "materialCase"; 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 wx.navigateTo({ url: '/index/pages/setposter/setposter?type=' + type + '&aid=' + this.data.nowid + "&listshare=" + usrl, }) }, sendfriendtap: function () { this.sharelogtap(); }, shareurltap: function () { let that = this; wx.showLoading({ title: '加载中...', }) util.schemefun('/share/pages/materialcase/materialcase', 'cid=' + that.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, that.data.nowid, 'materialCase', ''); this.sharelogtap(); }, sharelogtap: function (e) { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.nowid, type: that.data.nowtype }, success: function (r) { } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { const that=this; casepage=1; utils.$get({ url: app.globalData.webUrl + 'api/caselist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: 1, commu_id: that.data.commu_id,// 小区id style_id: that.data.casestyletype,//风格id square_start: that.data.square_start,//面积开始值 square_end: that.data.square_end,//面积结束值 keyword: that.data.casekeytext, housetype_id: that.data.nowstyleid, order: that.data.ordertype == 'time' ? 'addtime' : 'view_times', my_case:that.data.type==1?'publish':'all' }, success: function (res) { wx.stopPullDownRefresh() if (res.data.code == '0') { if(that.data.type==1){ that.setData({ caselist: res.data.data, leftcaselist: [], rightcaselist: [], datashow: true }) that.caseimgload(); }else{ that.setData({ uploadedlist:res.data.data }) } } }, fail() { wx.stopPullDownRefresh() } }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { const that=this; casepage=casepage*1+1; utils.$get({ url: app.globalData.webUrl + 'api/caselist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: casepage, commu_id: that.data.commu_id,// 小区id style_id: that.data.casestyletype,//风格id square_start: that.data.square_start,//面积开始值 square_end: that.data.square_end,//面积结束值 keyword: that.data.casekeytext, housetype_id: that.data.nowstyleid, order: that.data.ordertype == 'time' ? 'addtime' : 'view_times', my_case:that.data.type==1?'publish':'all' }, success: function (res) { wx.stopPullDownRefresh() if (res.data.code == '0') { if(that.data.type==1){ let arrflag = false; let caselist = that.data.caselist; if (caselist.length != 0) { arrflag = true; } caselist = caselist.concat(res.data.data) that.setData({ caselist: caselist }) if (!arrflag) { that.caseimgload(); } }else{ let uploadedlist=that.data.uploadedlist; uploadedlist=uploadedlist.concat(res.data.data); that.setData({ uploadedlist:uploadedlist }) } } }, fail() { wx.stopPullDownRefresh() } }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { this.sharelogtap(); return { title: that.data.nowtitle, imageUrl: that.data.nowimg, path: '/share/pages/materialcase/materialcase?cid=' + that.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype } } })