// share/pages/buildprogress/buildprogress.js const app = getApp(); var utils = require("../../../utils/http"); let time = 0; var timer = null, page = 1; var casepage = 1; var designTimer = null; Page({ /** * 页面的初始数据 */ data: { showAction: false, loginFlag: false, canIUseGetUserProfile: false, showContent: false, datashow: false, showAddress: false, dialog: false, showCaseStyle: false, showArea: false, showInput: false, cid: '', clientype: '', dscTitle: '', dscDataMsg: {}, nowCaseStyleName: '', nowCaseStyleId: '', nowAreaName: '', nowAreaId: '', nowAreaStart: '', nowAreaEnd: '', casekeytext: '', scrollTop: 0, detail: {}, companyobj: {}, progresslist: [], sharepersonMsg: {}, personMsg:app.globalData.personMsg, type: 3, constructlist: [], constructnum: 0, imgUrl: app.globalData.imgUrl, caselist: [], caseTypelist: [], imageArr: [], VRlinklist: [], videolink: {}, allDataCount: 1, caseTypeActive: '', showVrOrVideo: false, devCaseShow: false, showArticle: '', activeType: '', showSortNum: 1, showType: 'vr', houseTypeActive: 0, swiperIndex: 0, showVideoNum: 1, currentVideoIndex: 0, tab: [{ name: '楼盘实景', type: '', count: 1 }, { name: '效果图', type: 'img', count: 0 }, { name: '楼盘VR', type: 'vr', count: 0 }, { name: '楼盘视频', type: 'video', count: 0 }], square: [ { id: '', name: '全部', start: '', end: '' }, { 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: '' } ], houseTypeTab: [], houseTypeArr: ['全部', '一居', '二居', '三居', '四居', '五居', '六居', '七居', '八居', '别墅'], houseTypelists: [], houseTypeItemlist: [], devCaselist: [], designPlan: false, viewMore: 3, devCaseData: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { time = 0; if (!options.type) { wx.hideHomeButton(); } if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } if (!!options.scene) { options = unescape(options.scene); let arr = options.split('&'); let obj = {}; for (let i = 0; i < arr.length; i++) { let arr1 = arr[i].split('='); obj[arr1[0]] = arr1[1]; } this.setData({ cid: obj.c, clientype: obj.t }) app.globalData.clientype = obj.t; app.globalData.shareuserid = obj.u; app.globalData.sharempid = obj.e; } else { if (!!options.cid) { this.setData({ cid: options.cid }) } if (!!options.ctp) { this.setData({ clientype: options.ctp }) app.globalData.clientype = options.ctp; } if (!!options.uid) { app.globalData.shareuserid = options.uid; } if (!!options.empid) { app.globalData.sharempid = options.empid; } } this.logindata() }, logindata: function () { var that = this; wx.showLoading(); wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2session', data: { client_type: that.data.clientype, code: data.code, share: app.globalData.shareuserid }, success: function (r) { if (r.data.code == '0') { app.globalData.sharepersonobj = r.data.share; app.globalData.token = r.data.token; that.sharecompany(); that.getBuildingProgressDetail(); that.setData({ sharepersonMsg: app.globalData.sharepersonobj, }) 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 != '游客')) { app.globalData.use_id = r.data.user.id; app.globalData.personMsg = r.data.user; app.globalData.userflag = false; //有个人信息 var nickname = r.data.user.nickname; var phone = r.data.user.phone; that.setData({ loginFlag: false, datashow: true, personMsg:r.data.user }) if (r.data.user.phone != '') { app.globalData.personMsg = r.data.user; that.setData({ mobileflag: false, phoneFlag: false }) } else { that.setData({ mobileflag: true, phoneFlag: true }) } } else { wx.hideLoading(); that.setData({ articlelogin: false, loginFlag: true }) } } else { wx.hideLoading(); that.setData({ articlelogin: false, loginFlag: true }) } } }) } else { wx.hideLoading(); that.setData({ articlelogin: false, loginFlag: true }) } } }) }, cancelGetPhone() { designTimer = setTimeout(() => { this.setData({ designPlan: true }) },4000) }, sharecompany: function () { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/content_belong_company', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { client_type: app.globalData.clientype, uid: app.globalData.shareuserid }, success: function (res) { if (res.data.code == '0') { app.globalData.companyobj=res.data.data; app.globalData.currentUserId = res.data.data.employee_id; that.setData({ companyobj: res.data.data }) } }, complete(res) { wx.hideLoading() } }) }, getImageAndVRAndVideo(type) { var that = this; utils.$post({ url: app.globalData.webUrl + 'client/building/progress', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid, type: type, }, success: function (res) { if (res.data.code == '0') { if (type == 'img') { let imgs = []; res.data.data.forEach(v => { if (v.img && v.img.length > 0) { imgs.push(...v.img); } }) that.data.tab[1].count = imgs.length; that.setData({ imageArr: imgs, tab: that.data.tab }) } else if (type == 'vr') { let vrlist = []; res.data.data.forEach(v => { if (v.vr && v.vr.length > 0) { vrlist.push(...v.vr); } }) that.data.tab[2].count = vrlist.length; that.setData({ VRlinklist: vrlist, tab: that.data.tab }) } else { let videoArr = res.data.data.map(v => { return { video: v.video, cover: v.img.length ? v.img[0] : '' } }); that.data.tab[3].count = res.data.data.length; that.setData({ videolink: videoArr, tab: that.data.tab }) } } } }) }, /** * 获取案例数据 */ caselistfun: function (e) { var that = this; casepage = 1; utils.$get({ url: app.globalData.webUrl + 'api/building/material_case', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: 1, room: that.data.caseTypeActive, building_id: that.data.cid, // style_id: that.data.nowCaseStyleId, // square_start: that.data.nowAreaStart, // square_end: that.data.nowAreaEnd, // keyword: that.data.casekeytext }, success: function (res) { that.setData({ datashow: true }) if (res.data.code == '0') { let caseType = res.data.data.housetype_list.map(v => { return { name: that.data.houseTypeArr[v.room], id: v.room, count: v.count } }); that.setData({ caselist: res.data.data.list, caseTypelist: caseType.length ? caseType.sort(that.compare("id")) : [] }) } setTimeout(function () { wx.hideLoading() }, 1000) }, fail() { wx.hideLoading() } }) }, closeDesigntap(e) { if (designTimer) { clearTimeout(designTimer); } if (e.detail.type == 'success') { this.setData({ designPlan: false }) } else { this.setData({ designPlan: false }) } }, /** * 排序 */ compare(property) { return function (a, b) { var value1 = a[property]; var value2 = b[property]; return value1 - value2; } }, viewDevCase(e) { let id = e.currentTarget.dataset.id; var that = this; utils.$get({ url: app.globalData.webUrl + 'client/building/dev_case_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: id, }, success: function (res) { if (res.data.code == '0') { that.setData({ devCaselist: res.data.data, devCaseShow: true }) } else { wx.showToast({ title: res.data.msg, icon: 'none', duration: 1500 }) } } }) }, devCaseDetail(e) { let id = e.currentTarget.dataset.id; let type = e.currentTarget.dataset.type; if (type == 1) { var that = this; utils.$get({ url: app.globalData.webUrl + 'client/building/dev_case_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: id, }, success: function (res) { if (res.data.code == '0') { let vrlink = res.data.data.vr_link; if (vrlink) { wx.navigateTo({ url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&uid=' + app.globalData.shareuserid + '&cty=building' + '&ctp=' + app.globalData.clientype + '&aid=' + that.data.detail.id, }) } else { wx.showToast({ title: '未上传VR链接', icon: 'none', duration: 1500 }) } } else { wx.showToast({ title: res.data.msg, icon: 'none', duration: 1500 }) } } }) } else { wx.navigateTo({ url: '/index/pages/viewcase/viewcase?cid=' + id + '&type=2' + '&ctp=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid, }) } }, /** * 搜索案例 */ searchCaselist(e) { let id = e.currentTarget.dataset.type; this.setData({ caseTypeActive: id }) this.caselistfun(); }, /** * 前往案例详情 */ casemsgtap: function (e) { wx.navigateTo({ url: '/share/pages/materialcase/materialcase?type=3&cid=' + e.currentTarget.dataset.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype }) }, /** * 前往个人名片 */ toPageNameCard() { wx.navigateTo({ url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share', }) }, callphonetap: function () { console.log() wx.makePhoneCall({ phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码 }) }, swiperChange(e) { let currentItemId = e.detail.currentItemId; if (currentItemId.indexOf('img') > -1) { let index = currentItemId.split('-')[1]; let type = currentItemId.split('-')[0]; this.setData({ activeType: type, showSortNum: parseInt(index) + 1, allDataCount: this.data.imageArr.length }) } if (currentItemId.indexOf('vr') > -1) { let index = currentItemId.split('-')[1]; let type = currentItemId.split('-')[0]; this.setData({ activeType: type, showSortNum: parseInt(index) + 1, allDataCount: this.data.VRlinklist.length }) } if (currentItemId.indexOf('video') > -1) { let index = currentItemId.split('-')[1]; let type = currentItemId.split('-')[0]; this.setData({ activeType: type, showSortNum: parseInt(index) + 1, allDataCount: this.data.videolink.length }) } if (currentItemId.indexOf('cover') > -1) { this.setData({ activeType: '', showSortNum: 1, allDataCount: 1 }) } }, swiperVideoChange(e) { this.setData({ showVideoNum: parseInt(e.detail.current) + 1 }) }, /** * 风格类型获取 */ 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') { res.data.data.unshift({ name: '全部', id: '' }) that.setData({ casestylelist: res.data.data }) } } }) }, chooseCaseStyle(e) { let id = e.currentTarget.dataset.id; let name = e.currentTarget.dataset.name; this.setData({ nowCaseStyleName: name, nowCaseStyleId: id, showCaseStyle: false }) this.caselistfun(); }, chooseArea(e) { let id = e.currentTarget.dataset.id; let name = e.currentTarget.dataset.name; let start = e.currentTarget.dataset.start; let end = e.currentTarget.dataset.end; this.setData({ nowAreaName: name, nowAreaId: id, nowAreaStart: start, nowAreaEnd: end, showArea: false }) this.caselistfun(); }, setcasekeywordtap: function (e) { this.setData({ casekeytext: e.detail.value }) }, closeMask() { this.setData({ showVrOrVideo: false, dialog: false, showArea: false, showCaseStyle: false, showInput: false, devCaseShow: false }) }, handleCaseStyle() { this.setData({ showCaseStyle: true }) }, handleShowArea() { this.setData({ showArea: true }) }, handleShowInput() { this.data.showInput = !this.data.showInput; this.setData({ showInput: this.data.showInput }) }, handleMore() { if (this.data.viewMore == this.data.progresslist.length) { this.setData({ viewMore: 3 }) } else { this.setData({ viewMore: this.data.progresslist.length }) } }, searchCase() { this.setData({ showInput: false }) this.caselistfun(); }, dothis() { }, prelooktap() { if (!app.globalData.sharepersonobj.qrcode) { wx.showToast({ title: "当前专属客服的二维码为空!", icon: 'none', duration: 2000 }) return false; } wx.previewImage({ current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接 urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表 }) }, setypetap(e) { this.setData({ type: e.currentTarget.dataset.type }) }, getBuildingProgressDetail(e) { var that = this; utils.$post({ url: app.globalData.webUrl + 'client/building/view', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid }, success: function (res) { if (res.data.code == 0) { wx.hideLoading(); let dataMsg = res.data.data; dataMsg.update_time = dataMsg.update_time ? dataMsg.update_time.split(' ')[0] : ''; dataMsg.areastr = dataMsg.area_list.map(v => `${v}㎡`).join('/'); dataMsg.content = dataMsg.content.replace(/\r|\n/ig, ""); let houseTypeArry = []; let devCaselist = []; if (dataMsg.housetype && Object.keys(dataMsg.housetype).length > 0) { Object.keys(dataMsg.housetype).forEach(v => { houseTypeArry.push({ name: that.data.houseTypeArr[v], id: v, count: dataMsg.housetype[v].length, list: dataMsg.housetype[v] }) }) if (houseTypeArry.length) { houseTypeArry[0].list.forEach(v => { if (v.devcase && v.devcase.length) { devCaselist.push(...v.devcase) } }) } } that.data.tab[1].count = dataMsg.cover.length; that.setData({ detail: dataMsg, imageArr: dataMsg.cover, tab: that.data.tab, houseTypelists: houseTypeArry.length ? houseTypeArry.sort(that.compare("id")) : [], houseTypeItemlist: houseTypeArry.length ? houseTypeArry[0].list : [], devCaseData: devCaselist }) if (that.data.detail.name) { wx.setNavigationBarTitle({ title: that.data.detail.name, }) } } else { setTimeout(() => { wx.hideLoading(); }, 1500) } } }) this.buildingProgress(); // this.getImageAndVRAndVideo('img'); this.getImageAndVRAndVideo('vr'); this.getImageAndVRAndVideo('video'); this.caselistfun(); this.constructfun(); // this.casestylefun(); }, houseTypeDsc(e) { let index = e.currentTarget.dataset.index; let title = e.currentTarget.dataset.title; let room = e.currentTarget.dataset.room; this.setData({ dscDataMsg: this.data.houseTypeItemlist[index], dscTitle: room == 9 ? '别墅' : title, dialog: true }) }, constructfun() { const that = this; page = 1; utils.$post({ url: app.globalData.webUrl + 'client/building/construction', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { building_id: that.data.cid, page: 1 }, success: function (res) { that.setData({ constructlist: res.data.data, constructnum: res.data.count }) } }) }, sitetap(e) { wx.navigateTo({ url: '/share/pages/constructsite/constructsite?type=3&cid=' + e.currentTarget.dataset.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype, }) }, getPhoneNumberTap(res) { let type = res.currentTarget.dataset.type; let that = this; if (res.detail.errMsg == 'getPhoneNumber:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/setUserMobile', data: { encryptedData: res.detail.encryptedData, iv: res.detail.iv }, header: { 'Authorization': 'bearer ' + app.globalData.token }, success: function (r) { if (r.data.code == '0') { if (type == "update") { that.urgeUpdateData(); } else { that.signUpClient(r.data.mobile); } } else { wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } }, urgeUpdateData() { var that = this; utils.$post({ url: app.globalData.webUrl + 'client/building/urge', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { employee_id: app.globalData.sharempid, building_id: that.data.cid }, success: function (res) { if (res.data.code == 0) { wx.showToast({ title: '催更成功', icon: 'success', duration: 1500 }) } } }) }, signUpClient(phone) { var that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/signUp', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { mobile: phone, type: 'building', id: that.data.cid, }, success: function (res) { if (res.data.code == 0) { wx.showToast({ title: '恭喜您报名成功,稍后会有服务顾问跟您联系', icon: 'none', duration: 1500 }) } } }) }, /** * 切换 */ handleSwitch(e) { let type = e.currentTarget.dataset.type; let count = e.currentTarget.dataset.count; let swiperIndex = 0; if (type == 'img') { swiperIndex = 1; } else if (type == 'vr') { swiperIndex = this.data.imageArr.length + 1; } else if (type == 'video') { swiperIndex = this.data.imageArr.length + this.data.VRlinklist.length + 1; } else { swiperIndex = 0; } this.setData({ swiperIndex: swiperIndex, activeType: type, allDataCount: count, showSortNum: 1, }) }, toggleClass(e) { let id = e.currentTarget.dataset.cid; if (id == this.data.showArticle) { this.setData({ showArticle: '' }) } else { this.setData({ showArticle: id }) } }, handleFullPlay(e) { let videoId = e.currentTarget.dataset.id; var videoContext = this.selectComponent(`#${videoId}`); videoContext.requestFullScreen({ direction: 0 }) }, /** * 户型切换 */ handlelist(e) { let type = e.currentTarget.dataset.type; let idx = e.currentTarget.dataset.index; let devCaselist = []; this.data.houseTypelists[idx].list.forEach(v => { if (v.devcase && v.devcase.length) { devCaselist.push(...v.devcase); } }) this.setData({ houseTypeActive: type, houseTypeItemlist: this.data.houseTypelists[idx].list, devCaseData: devCaselist }) }, /** * 放大图片 * @param {*} e */ previewImage(e) { let type = e.currentTarget.dataset.type; if (type == 'cover') { let imgUrl = e.currentTarget.dataset.img; if (imgUrl) { wx.previewImage({ current: imgUrl, urls: [imgUrl] }) } else { wx.showToast({ title: '暂无图片展示', icon: 'none', }) } } else if (type == 'image') { let imgUrl = e.currentTarget.dataset.img; wx.previewImage({ current: imgUrl, urls: this.data.imageArr }) } else if (type == 'vr') { this.setData({ showVrOrVideo: true, showType: 'vr' }) } else if (type == 'video') { this.setData({ showVrOrVideo: true, showType: 'video', currentVideoIndex: this.data.showSortNum - 1 < 0 ? 0 : (this.data.showSortNum - 1), showVideoNum: this.data.showSortNum }) } else if (type == 'himg') { let idx = e.currentTarget.dataset.index; let imgUrl = e.currentTarget.dataset.img; wx.previewImage({ current: imgUrl, urls: this.data.houseTypeItemlist[idx].house_img, }) } else { let imgUrl = e.currentTarget.dataset.img; let index = e.currentTarget.dataset.index; var arr = this.data.progresslist[index].img; wx.previewImage({ current: imgUrl, urls: arr, }) } }, openVRLink(e) { let type = e.currentTarget.dataset.type; if (type == 2) { let vrlink = e.currentTarget.dataset.vr; wx.navigateTo({ url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&uid=' + app.globalData.shareuserid + '&cty=building' + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.detail.id, }) } else { let aid = e.currentTarget.dataset.id; let vrlink = e.currentTarget.dataset.vrlink; wx.navigateTo({ url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&aid=' + aid, }) } }, showAllContent() { let showContent = !this.data.showContent; this.setData({ showContent: showContent }) }, buildingProgress() { var that = this; utils.$post({ url: app.globalData.webUrl + 'client/building/progress', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid }, success: function (res) { let progress = res.data.data; that.setData({ progresslist: progress, datashow: true, }) } }) }, /** * 展示地址 */ showAddressName(e) { let type = e.currentTarget.dataset.type; if (type == 'hide') { this.setData({ showAddress: false }) } else { this.setData({ showAddress: true }) } }, operateBtn() { this.setData({ showAction: false }) }, sharelogtap: function () { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid, type: 'building' }, success: function (r) { } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ imgUrl: app.globalData.imgUrl, }) timer = setInterval(function () { time = time * 1 + 1; }, 1000) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { if (timer) { clearInterval(timer) } this.visitimefun(); }, visitimefun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/visit_due_time', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid, pipe_type: 'building', time: time, }, success: function (res) { } }) }, /** * 生命周期函数--监听页面卸载 */ onUnload() { this.visitimefun(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { const that = this; if (!!app.globalData.token) { page = page * 1 + 1; utils.$post({ url: app.globalData.webUrl + 'client/building/construction', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { building_id: that.data.cid, page: page }, success: function (res) { let constructlist = that.data.constructlist; if (res.data.code == 0) { constructlist = constructlist.concat(res.data.data); that.setData({ constructlist: constructlist, }) } } }) } }, /** * 用户点击右上角分享 */ onShareAppMessage(e) { const that = this; let type = e.target ? e.target.dataset.type : ''; let id = e.target ? e.target.dataset.id : ''; if (type == "progress") { return { title: that.data.detail.name + '-楼盘进度', imageUrl: that.data.detail.cover[0], path: '/share/pages/buildShare/buildShare?cid=' + id + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&empid=' + app.globalData.personMsg.binded.id } } else { this.sharelogtap(); return { title: this.data.detail.name, imageUrl: this.data.detail.cover[0], path: '/share/pages/buildprogress/buildprogress?cid=' + this.data.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&empid=' + app.globalData.sharempid } } } })