var app = getApp(); var utils = require("../../../utils/http"); var time = 0; var timer = null; var designTimer = null; Page({ /** * 页面的初始数据 */ data: { top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, companyName: '', webUrl: '', aid: '', scrollTop: 0, title: '志远装饰', showAddress: false, showAction: false, loginFlag: false, phoneFlag: false, errorflag: false, errorText: '请求错误!', oneButton: [{ text: '确定' }], shareuserid: '', customerFlag: false, articleObj: {}, imgUrl: app.globalData.imgUrl, articlelogin: false, canIUseGetUserProfile: false, loadflag: false, shareobj: {}, employeeflag: false,//false是用户,true是员工 companyobj: {}, priceflag: false, designPlan: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; time = 0; if (wx.getUserProfile) { this.setData({ canIUseGetUserProfile: true }) } 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({ aid: obj.aid, shareuserid: obj.userid, customerFlag: true }) app.globalData.clientype = obj.ctp; app.globalData.shareuserid = obj.userid; } else { this.setData({ aid: options.aid, shareuserid: options.userid, customerFlag: true }) app.globalData.clientype = options.ctp; app.globalData.shareuserid = options.userid; } that.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.currentUserId = res.data.data.employee_id || ''; app.globalData.companyobj=res.data.data; 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.sharecompany(); that.setData({ shareobj: app.globalData.sharepersonobj, companyName: r.data.company }) app.globalData.personMsg = r.data.user; 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, articlelogin: true, }) app.globalData.use_id = r.data.user.id; app.globalData.userflag = false;//有个人信息 var nickname = r.data.user.nickname; var phone = r.data.user.phone; app.globalData.phone = false;//没有手机号 if (app.globalData.clientype == 'IGJFoG'){ that.setData({ articlelogin: true, loginFlag: false, }) var obj = { detail: 1 } that.artileMsg(obj); if (r.data.user.phone == '') { wx.hideLoading(); app.globalData.phone = false;//没有手机号 that.setData({ mobileflag: true, phoneFlag: true, articlelogin: false }) } else { app.globalData.phone = true;//有手机号 that.setData({ mobileflag: false, phoneFlag: false, articlelogin: true }) } }else if (r.data.user.phone == '') { that.artileMsg(); wx.hideLoading(); app.globalData.phone = false;//没有手机号 that.setData({ mobileflag: true, phoneFlag: true, articlelogin: false }) } else { app.globalData.phone = true;//有手机号 var obj = { detail: 1 } that.artileMsg(obj); that.setData({ mobileflag: false, phoneFlag: false, articlelogin: true }) } } else { if (app.globalData.clientype != 'IGJFoG') { that.artileMsg(); that.setData({ articlelogin: false, loginFlag: true, phoneFlag: false }) } else { that.setData({ articlelogin: true, loginFlag: false, }) var obj = { detail: 1 } that.artileMsg(obj); } } } } }) } } }) }, cancelGetPhone() { designTimer = setTimeout(() => { this.setData({ designPlan: true }) },4000) }, priceshowtap() { this.setData({ priceflag: true }) }, closepricetap() { this.setData({ priceflag: false }) }, closeDesigntap(e) { if (designTimer) { clearTimeout(designTimer); } if (e.detail.type == 'success') { this.setData({ designPlan: false, articlelogin: true, phoneFlag: false, }) } else { this.setData({ designPlan: false }) } }, prelookimgtap() { 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', }) }, /** * 展示地址 */ showAddressName(e) { let type = e.currentTarget.dataset.type; if (type == 'hide') { this.setData({ showAddress: false }) } else { this.setData({ showAddress: true }) } }, golastap: function () { wx.navigateBack() }, goindextap: function () { wx.reLaunch({ url: '/pages/index/index?state=1', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, artileMsg: function (type) { var that = this; wx.showLoading({ title: '加载中...', }) if (!!type && type.detail == '1') { that.setData({ articlelogin: true, phoneFlag: false, }) } utils.$post({ url: app.globalData.webUrl + 'client/article/info', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { article_id: that.data.aid }, success: function (res) { if (res.data.code == '0') { var article = ''; article = res.data.data.content; res.data.data.contentmsg = article; that.setData({ articleObj: res.data.data, loadflag: true, title: res.data.data.title }) } setTimeout(function () { wx.hideLoading(); }, 500) } }) }, callphonetap: function () { wx.makePhoneCall({ phoneNumber: app.globalData.sharepersonobj.phone }) }, lookarticlemsg() { let articleObj = this.data.articleObj; articleObj.contentmsg = articleObj.content; this.setData({ articleObj: articleObj }) }, loginfun() { 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; if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "")) { that.setData({ employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false }) app.globalData.personMsg = r.data.user; app.globalData.use_id = r.data.user.id; app.globalData.userflag = false;//有个人信息 if (r.data.user.phone == '') { designTimer = setTimeout(() => { that.setData({ designPlan: true }) },4000) } } } } }) } } }) }, getUserInfoTap: function (res) { var that = this; wx.showLoading(); if (res.detail.errMsg == 'getUserInfo:ok') { utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData: res.detail.encryptedData, iv: res.detail.iv, rawData: res.detail.rawData, signature: res.detail.signature, }, header: { 'Authorization': 'bearer ' + app.globalData.token }, success: function (r) { if (r.data.code == '0') { that.loginfun(); that.setData({ loginFlag: false, phoneFlag: false }) app.globalData.userflag = true;//有个人信息 } else { if (r.data.code == '403') { that.login(); return false } wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } }, getUserProfile: function () { var that = this; wx.getUserProfile({ lang: 'zh_CN', desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { if (res.errMsg == "getUserProfile:ok") { wx.showLoading(); utils.$post({ method: "POST",//TESTAPIURL APIURL/users/auth url: app.globalData.webUrl + 'api/users/setUserInfo', data: { encryptedData: res.encryptedData, iv: res.iv, rawData: res.rawData, signature: res.signature, }, header: { 'Authorization': 'bearer ' + app.globalData.token }, success: function (r) { setTimeout(res => { wx.hideLoading() }, 500) if (r.data.code == '0') { that.loginfun(); that.setData({ loginFlag: false, phoneFlag: false }) app.globalData.userflag = true;//有个人信息 } else { if (r.data.code == '403') { that.login(); return false } wx.showToast({ title: r.data.msg, icon: "none", duration: 2000 }); } } }) } } }) }, getPhoneNumberTap: function (res) { var that = this; // var obj={ // detail:1 // } if (res.detail.errMsg == 'getPhoneNumber:ok') { if (designTimer) { clearTimeout(designTimer); } that.lookarticlemsg(); that.setData({ articlelogin: true, phoneFlag: false, designPlan: 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({ mobileflag: false, phoneFlag: false, webUrl: app.globalData.webUrl, articlelogin: true }) } else { that.setData({ errorText: r.data.msg, errorflag: true }) } } }) } }, tapDialogButton(){ this.setData({ errorflag:false }) wx.exitMiniProgram() wx.navigateBack({ delta: 0 }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, }) timer = setInterval(function () { time = (time * 1) + 1; }, 1000) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { 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.aid, pipe_type: 'article', time: time, }, success: function (res) { } }) }, 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.aid, type: 'article' }, success: function (r) {} }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.visitimefun(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { this.sharelogtap(); return { title: this.data.title, imageUrl: this.data.articleObj.cover_img, path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + this.data.shareuserid + '&ctp=' + app.globalData.clientype } } })