const app = getApp(); var utils = require("../../../utils/http"); const util = require("../../../utils/util"); let page = 1; Page({ /** * 页面的初始数据 */ data: { ordertype: 'time', imgUrl: app.globalData.imgUrl, list: [], filtrateflag: false, nowfirst: '', nowtitbtn: '', nowtitle: '', nowimg: '', bType: '', titlist: [], indexList: [], constructlist: [], casecommunitylist: [], site_id: '', sitename: '', datashow: false, type: '', wshareshow:false, nowtype: '', nowid: '', nowtitle: '', nowimg: '', islist: false, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.showLoading({ title: '加载中...', }) if (options.type) { this.setData({ type: options.type }) } if (!!options.ty) { wx.hideShareMenu(); this.setData({ bType: options.ty }) } this.constructfun(); }, setordertypetap(e) { this.setData({ ordertype: e.currentTarget.dataset.type }) wx.showLoading({ title: '加载中...', }) this.constructfun(); }, allfiltratetap: function () { this.setData({ filtrateflag: true }) }, constructfun() { this.casecommunityfun(); const that = this; page = 1; utils.$post({ url: app.globalData.webUrl + 'client/construction/index', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: 1, limit: 10, community_id: this.data.site_id, order: this.data.ordertype == 'time' ? 'new' : 'hot' }, success: function (res) { wx.hideLoading(); that.setData({ datashow: true }) if (res.data.code == 0) { that.setData({ constructlist: res.data.data, }) } } }) }, onChoose(e) { var that = this; that.setData({ site_id: e.detail.item.currentTarget.dataset.cid, sitename: e.detail.item.currentTarget.dataset.item.name }) wx.showLoading({ title: '加载中...', }) that.constructfun(); }, deltap(e) { var that = this; that.setData({ site_id: '', sitename: '' }) wx.showLoading({ title: '加载中...', }) that.constructfun(); }, casecommunityfun: function () { var that = this; utils.$get({ url: app.globalData.webUrl + 'api/construction/communitylist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { that.setData({ casecommunitylist: res.data.data }) that.getCitys(); } } }) }, sitetap(e) { wx.navigateTo({ url: '/customer/pages/sitemsg/sitemsg?cid=' + e.currentTarget.dataset.cid + '&type=' + this.data.type + '&ty=' + this.data.bType, }) }, getCitys() { const _this = this const cities = this.data.casecommunitylist; // 按拼音排序 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++) { 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].construction_count; list[i].id = cities[j].id; } } } } _this.setData({ list: list }) }, setpostertap: function () { wx.navigateTo({ url: '/index/pages/setposter/setposter?type=Construction&aid=' + this.data.nowid + "&listshare=", }) }, sitesharetap(e) { var that = this; let num = e.currentTarget.dataset.idx; let str = this.data.constructlist[num]; that.setData({ nowtype: 'Construction', nowid: str.id, nowtitle: str.name, nowimg: str.cover_share_img?str.cover_share_img:str.cover, islist: false, wshareshow: true }) }, sendfriendtap() { this.addsharetap1(); }, addsharetap1: function () { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.nowid, type: 'Construction', }, success: function (r) {} }) }, shareurltap: function () { wx.showLoading({ title: '加载中...', }) this.addsharetap1(); util.schemefun('/share/pages/constructsite/constructsite', 'cid=' + this.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, this.data.nowid, 'Construction', ''); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, closefiltratetap: function () { this.setData({ filtrateflag: false }) }, dothis: function () {}, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { this.constructfun(); wx.stopPullDownRefresh(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { const that = this; page = page * 1 + 1; utils.$post({ url: app.globalData.webUrl + 'client/construction/index', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: page, limit: 10, community_id: this.data.site_id, order: this.data.ordertype == 'time' ? 'new' : 'hot' }, success: function (res) { wx.hideLoading(); let constructlist = that.data.constructlist; if (res.data.code == 0) { constructlist = that.data.constructlist; constructlist = constructlist.concat(res.data.data); that.setData({ constructlist: constructlist, }) } } }) }, addsharetap: function (type) { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: '0', type: type, }, success: function (r) {} }) }, shareaddlog:function(){ var that=this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization':'bearer '+app.globalData.token }, data: { id:that.data.nowid, type:'Construction' }, success: function (r) { } }) }, /** * 用户点击右上角分享 */ onShareAppMessage: function(e) { if(e.from=='button'){ this.shareaddlog(); return { title: this.data.nowtitle, imageUrl: this.data.nowimg, path: '/share/pages/constructsite/constructsite?cid='+this.data.nowid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype } }else{ this.addsharetap('toolAll'); return { title: '在施工地-'+app.globalData.companyobj.company_name, imageUrl: app.globalData.imgUrl + 'xcx/aaa/constructcover.png', path: '/share/pages/constructsitelist/constructsitelist?uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype } } } })