// index/pages/progressdetail/progressdetail.js const app = getApp(); var utils = require("../../../utils/http"); const util = require("../../../utils/util") let page = 1; let casepage = 1; Page({ /** * 页面的初始数据 */ data: { cid: '', detail: {}, progresslist: [], showContent: false, datashow: false, dialog: false, showCaseStyle: false, showArea: false, showInput: false, type: 3, constructlist: [], caselist: [], imageArr: [], VRlinklist: [], caseTypelist: [], videolink: {}, constructnum: 0, allDataCount: 1, imgUrl: app.globalData.imgUrl, wshareshow: false, showVrOrVideo: false, devCaseShow: false, showArticle: '', activeType: '', caseTypeActive: '', dscTitle: '', dscDataMsg: {}, nowCaseStyleName: '', nowCaseStyleId: '', nowAreaName: '', nowAreaId: '', nowAreaStart: '', nowAreaEnd: '', casekeytext: '', showSortNum: 1, showType: 'vr', houseTypeActive: 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: [], ltype: '', viewMore: 3, devCaseData: [], }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (!!options.cid) { wx.showLoading({ title: '加载中...', }) this.setData({ cid: options.cid }) this.getBuildingProgressDetail(); this.buildingProgress(); this.constructfun(); this.caselistfun(); // this.getImageAndVRAndVideo('img'); this.getImageAndVRAndVideo('vr'); this.getImageAndVRAndVideo('video'); } if (options.type) { this.setData({ ltype: options.type }) } }, /** * 获取装修案例 */ 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() } }) }, /** * 排序 */ compare(property) { return function (a, b) { var value1 = a[property]; var value2 = b[property]; return value1 - value2; } }, /** * 搜索案例 */ searchCaselist(e) { let id = e.currentTarget.dataset.type; this.setData({ caseTypeActive: id }) this.caselistfun(); }, /** * 在施工地列表 */ constructfun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/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 }) } }) }, toggleClass(e) { let id = e.currentTarget.dataset.cid; if (id == this.data.showArticle) { this.setData({ showArticle: '' }) } else { this.setData({ showArticle: id }) } }, viewDevCase(e) { let id = e.currentTarget.dataset.id; var that = this; utils.$get({ url: app.globalData.webUrl + 'api/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 + 'api/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=565&vrlink=' + encodeURIComponent(vrlink) + '&uid=' + (app.globalData.shareuserid ? app.globalData.shareuserid : app.globalData.personMsg.id) + '&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=1', }) } }, 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, }) }, /** * 户型剖析 */ 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 }) }, /** * 询问报价 */ inquiry() { wx.showToast({ title: '员工无需询问', icon: 'none', duration: 1500 }) }, getImageAndVRAndVideo(type) { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/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 }) } } } }) }, 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 }) }, /** * 进入案例详情 */ casemsgtap: function (e) { wx.navigateTo({ url: '/index/pages/casemsg/casemsg?cid=' + e.currentTarget.dataset.cid, }) }, sitetap(e) { if (!this.data.ltype) { wx.navigateTo({ url: '/index/pages/constructsite/constructsite?cid=' + e.currentTarget.dataset.cid, }) } else { wx.navigateTo({ url: '/customer/pages/sitemsg/sitemsg?cid=' + e.currentTarget.dataset.cid + '&type=' + this.data.ltype, }) } }, getBuildingProgressDetail() { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/building/view', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid }, success: function (res) { if (res.data.code == 0) { let dataMsg = res.data.data; 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 }) wx.setNavigationBarTitle({ title: dataMsg.name, }) } setTimeout(() => { wx.hideLoading() }, 100) } }) }, openVRLink(e) { let type = e.currentTarget.dataset.type; if (type == 2) { let vrlink = e.currentTarget.dataset.vr; wx.navigateTo({ url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&uid=' + (app.globalData.shareuserid ? app.globalData.shareuserid : app.globalData.personMsg.id) + '&cty=building' + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.detail.id, }) } else { let id = e.currentTarget.dataset.id; let vrlink = e.currentTarget.dataset.vrlink; wx.navigateTo({ url: '/pages/other/other?type=565&vrlink=' + encodeURIComponent(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&aid=' + id, }) } }, /** * 风格类型获取 */ 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 }) }, searchCase() { this.setData({ showInput: false }) this.caselistfun(); }, dothis() { }, showAllContent() { let showContent = !this.data.showContent; this.setData({ showContent: showContent }) }, handleMore() { if (this.data.viewMore == this.data.progresslist.length) { this.setData({ viewMore: 3 }) } else { this.setData({ viewMore: this.data.progresslist.length }) } }, handleTips() { wx.showToast({ title: '员工不可催更新', icon: 'none', duration: 1500 }) }, /** * 放大图片 * @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, }) } }, /** * 顶部轮播切换 */ 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 }) }, handleFullPlay(e) { let videoId = e.currentTarget.dataset.id; var videoContext = this.selectComponent(`#${videoId}`); videoContext.requestFullScreen({ direction: 0 }) }, buildingProgress() { var that = this; utils.$post({ url: app.globalData.webUrl + 'api/building/progress', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid }, success: function (res) { if (res.data.code == '0') { let progress = res.data.data; that.setData({ progresslist: progress, datashow: true }) } } }) }, handleCollect(e) { const that = this; let detail = this.data.detail; let collect = that.data.detail.collected; let urllink = !collect ? app.globalData.webUrl + 'api/building/collect' : app.globalData.webUrl + 'api/building/collectCancel'; utils.$post({ url: urllink, header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid, }, success: (res) => { if (res.data.code == 0) { detail.collected = !collect; this.setData({ detail: detail }) wx.showToast({ title: res.data.msg, icon: 'none', duration: 1000 }) } } }) }, sharetap() { this.setData({ wshareshow: true }) }, setpostertap: function () { wx.navigateTo({ url: '/index/pages/setposter/setposter?type=building&aid=' + this.data.cid + "&listshare=", }) }, sendfriendtap() { this.sharelogtap(); }, shareurltap: function () { wx.showLoading({ title: '加载中...', }) util.schemefun('/share/pages/buildprogress/buildprogress', 'uid=' + app.globalData.personMsg.id + '&cid=' + this.data.cid + '&ctp=' + app.globalData.clientype + '&empid=' + app.globalData.personMsg.binded.id, this.data.cid, 'building', ''); this.sharelogtap(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.setData({ imgUrl: app.globalData.imgUrl, }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, setypetap(e) { this.setData({ type: e.currentTarget.dataset.type }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { const that = this; page = page * 1 + 1; utils.$post({ url: app.globalData.webUrl + 'api/building/construction', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { building_id: that.data.page, page: 1 }, success: function (res) { let constructlist = that.data.constructlist; if (res.data.code == 0) { constructlist = constructlist.concat(res.data.data); that.setData({ constructlist: constructlist, }) } } }) }, sharelogtap: function () { var that = this; this.setData({ nowflag: false, }) 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) { } }) }, /** * 用户点击右上角分享 */ 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: that.data.detail.name, imageUrl: that.data.detail.cover[0], path: '/share/pages/buildprogress/buildprogress?cid=' + that.data.cid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype + '&empid=' + app.globalData.personMsg.binded.id } } } })