var app = getApp(); var utils = require("../../../utils/http"); let time = 0; var timer = null; var designTimer = null; Page({ /** * 页面的初始数据 */ data: { top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, siteobj: {}, cid: '', companyName: '', scrollTop: 0, canIUseGetUserProfile: false, loadflag: false, shareobj: {}, employeeflag: false,//false是用户,true是员工 companyobj: {}, loginFlag: false, phoneFlag: false, showAction: false, type:'', designPlan: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; time = 0; if(options.type){ this.setData({ type:options.type }) } if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } wx.showLoading({ title: '加载中...', }) that.setData({ top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, }) wx.hideHomeButton() 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.cid, shareuserid: obj.uid, customerFlag: true }) app.globalData.clientype = obj.ctp; app.globalData.shareuserid = obj.uid; } else { this.setData({ cid: options.cid, shareuserid: options.uid, customerFlag: true }) app.globalData.clientype = options.ctp; app.globalData.shareuserid = options.uid; } this.login(); }, 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() } }) }, login: function () { var that = this; wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2session', data: { code: data.code, share: app.globalData.shareuserid, client_type:app.globalData.clientype }, success: function (r) { if (r.data.code == '0') { app.globalData.sharepersonobj = r.data.share; app.globalData.token = r.data.token; that.setData({ shareobj: app.globalData.sharepersonobj, companyName: r.data.company }) that.sharecompany(); 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 != '游客')) { that.setData({ loginFlag: false, employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false }) app.globalData.personMsg = r.data.user; app.globalData.userflag = false; //有个人信息 var nickname = r.data.user.nickname; var phone = r.data.user.phone; app.globalData.phone = false; //没有手机号 if (r.data.user.phone == '') { that.setData({ phoneFlag: false, mobileflag: true }) wx.hideLoading(); app.globalData.phone = false; //没有手机号 } else { that.setData({ mobileflag: false, phoneFlag: false }) app.globalData.phone = true; //有手机号 } } else { wx.hideLoading(); that.setData({ loginFlag: true, phoneFlag: false }) } setTimeout(function () { wx.hideLoading() }, 500) that.houseinfofun(); } else { that.setData({ phoneFlag: false }) that.houseinfofun(); setTimeout(function () { wx.hideLoading() }, 500) } } }) } } }) }, cancelGetPhone() { designTimer = setTimeout(() => { this.setData({ designPlan: true }) },4000) }, houseinfofun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/construction/view', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.cid }, success: function (res) { if (res.data.code == '0') { that.setData({ siteobj: res.data.data }) } setTimeout(function () { wx.hideLoading(); }, 500) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, openVRLink(e) { let type = e.currentTarget.dataset.type; let vrlink = escape(e.currentTarget.dataset.vr); wx.navigateTo({ url: '/pages/other/other?type=vr&vrurl=' + vrlink + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&cty=construction' + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.cid, }) }, 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链接列表 }) }, /** * 前往个人名片 */ toPageNameCard() { wx.navigateTo({ url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share', }) }, /** * 关闭免费设计方案弹窗 */ closeDesigntap(e) { if (designTimer) { clearTimeout(designTimer); } if (e.detail.type == 'success') { this.setData({ designPlan: false }) } else { this.setData({ designPlan: false }) } }, operateBtn() { this.setData({ showAction: false }) }, callphonetap: function () { wx.makePhoneCall({ phoneNumber: app.globalData.sharepersonobj.phone }) }, golastap: function () { let arr = getCurrentPages(); wx.navigateBack() }, goindextap: function () { wx.reLaunch({ url: '/pages/index/index?state=1', }) }, getPhoneNumberTap: function (res) { var that = this; if (res.detail.errMsg == 'getPhoneNumber:ok') { that.setData({ phoneFlag: false, }) 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') { app.globalData.phone = true; that.setData({ phoneFlag: false, }) } } }) } }, looktap(e) { wx.previewImage({ current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接 urls: this.data.siteobj.step_list[e.currentTarget.dataset.idx].data.img // 需要预览的图片 http 链接列表 }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { timer = setInterval(function () { time = time * 1 + 1; }, 1000) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { if (designTimer) { clearTimeout(designTimer); } 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: 'Construction', time: time, }, success: function (res) { } }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { if (designTimer) { clearTimeout(designTimer); } this.visitimefun(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { title: that.data.siteobj.name, imageUrl: that.data.siteobj.cover, path: '/share/pages/constructsite/constructsite?cid=' + that.data.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype } } })