const app = getApp(); var utils = require("../../../utils/http"), page = 1; const util = require("../../../utils/util"); let time = 0, timer = null, showflag = true; Page({ /** * 页面的初始数据 */ data: { evidencetype: [], nowtype: '', evidencelist: [], leftevidencelist: [], rightevidencelist: [], datashow: false, imgUrl: app.globalData.imgUrl, loginFlag: false, phoneFlag: false, canIUseGetUserProfile: false, shareobj: {}, employeeflag: false,//false是用户,true是员工 top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, companyobj: {}, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showLoading({ title: '加载中...', }) time = 0; this.setData({ top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, }) 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]; } app.globalData.shareuserid = obj.uid; app.globalData.clientype = obj.ctp; } else { 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; 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/code2sessionmini', 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, }) util.toolfun(3); that.sharecompany(); that.praisetit(); app.globalData.companyname = r.data.company; app.globalData.official_openid = r.data.official_openid; app.globalData.agentEmployeEid = r.data.agent_employee_id; if (!!r.data.user.phone) { that.setData({ loginFlag: false, phoneFlag: false, employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false }) if (!!r.data.user.binded && r.data.user.binded.state == '在职') { app.globalData.currentUserId = r.data.user.binded.id; } app.globalData.personMsg = r.data.user; } else { that.setData({ loginFlag: false, phoneFlag: true }) wx.hideLoading(); } that.evidencelistfun(); } else { setTimeout(function () { wx.hideLoading() }, 500) } } }) } } }) }, 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链接列表 }) }, callphonetap: function () { console.log() wx.makePhoneCall({ phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码 }) }, praisetit: function () { var that = this; utils.$get({ url: app.globalData.webUrl + 'api/evidencecate', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { that.setData({ evidencetype: res.data.data }) } }) }, firsttap: function (e) { this.setData({ nowtype: e.currentTarget.dataset.text }) this.evidencelistfun(); }, evidencelistfun: function (e) { var that = this; page = 1; utils.$get({ url: app.globalData.webUrl + 'client/material/evidencelist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: 1, cate: that.data.nowtype, keyword: '' }, success: function (res) { setTimeout(function () { wx.hideLoading() }, 1000) if (res.data.code == '0') { that.setData({ evidencelist: res.data.data, leftevidencelist: [], rightevidencelist: [], datashow: true }) that.imgload(); } }, fail() { wx.hideLoading() } }) }, imgload: function () { var that = this; var leftlist = that.data.leftevidencelist; var rightlist = that.data.rightevidencelist; var indexlist = that.data.evidencelist; if (indexlist.length == 0) { return false; } if (leftlist.length == 0) { leftlist.push(indexlist[0]); indexlist.shift(); that.setData({ evidencelist: indexlist, leftevidencelist: leftlist, rightevidencelist: rightlist }) } else { var leftheight, rightheight; const query = wx.createSelectorQuery() query.select('.leftpublicpraisebox').boundingClientRect(); query.exec(function (res) { if (res[0]) { leftheight = res[0].height; const queryright = wx.createSelectorQuery() queryright.select('.rightpublicpraisebox').boundingClientRect(); queryright.exec(function (rs) { leftlist = that.data.leftevidencelist; rightlist = that.data.rightevidencelist; indexlist = that.data.evidencelist; rightheight = rs[0].height; if (leftheight <= rightheight) { leftlist.push(indexlist[0]); indexlist.shift(); } else { rightlist.push(indexlist[0]); indexlist.shift(); } that.setData({ evidencelist: indexlist, leftevidencelist: leftlist, rightevidencelist: rightlist }) }) } }) } }, publictap: function (e) { wx.navigateTo({ url: '/share/pages/publicpraisemsg/publicpraisemsg?type=3&eid=' + e.currentTarget.dataset.eid + "&uid=" + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, golastap: function () { wx.navigateBack({ delta: 1, success:function(r){ }, fail:function(r){ wx.reLaunch({ url: '/pages/index/index?state=1', }) }, }) }, goindextap: function () { if(!this.data.employeeflag){ wx.reLaunch({ url: '/pages/index/index?state=1', }) }else{ wx.reLaunch({ url: '/pages/consoledesk/consoledesk', }) } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, }) if (!showflag) { this.imgload(); } showflag = true; timer = setInterval(function () { time = time * 1 + 1; }, 1000) }, setimetap() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/visit_due_time', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.companyobj.employee_id, pipe_type: 'toolAll', time: time, }, success: function (res) { } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { showflag = false; if (timer) { clearInterval(timer) } this.setimetap(); }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { this.setimetap(); }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { var that = this; page = 1; utils.$get({ url: app.globalData.webUrl + 'client/material/evidencelist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: 1, cate: that.data.nowtype, keyword: '' }, success: function (res) { wx.stopPullDownRefresh(); if (res.data.code == '0') { that.setData({ evidencelist: res.data.data, leftevidencelist: [], rightevidencelist: [], datashow: true }) that.imgload(); } } }) }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { var that = this; page = page * 1 + 1; utils.$get({ url: app.globalData.webUrl + 'client/material/evidencelist', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { uid: app.globalData.personMsg.id, page: page, cate: that.data.nowtype, keyword: '' }, success: function (res) { wx.stopPullDownRefresh(); if (res.data.code == '0') { let evidencelist = that.data.evidencelist; var arrflag = false if (evidencelist.length != 0) { arrflag = true; } for (let i = 0; i < res.data.data.length; i++) { evidencelist.push(res.data.data[i]) } that.setData({ evidencelist: evidencelist }) if (!arrflag) { that.imgload(); } } } }) }, 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) { } }) }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { let that = this; that.addsharetap('toolAll'); return { title: "客户好评-" + this.data.companyobj.company_name, imageUrl: app.globalData.imgUrl + "xcx/praiseimg.jpg", path: '/share/pages/praiselist/praiselist?uid=' + app.globalData.shareuserid + '&cate=' + this.data.nowtype + '&ctp=' + app.globalData.clientype } } })