var businessT = require('../../tool/business-tool.js') var sysT = require('../../tool/sys-tool.js') var url = require('../../constant/url.js') import Net from '../../tool/net.js' var net = new Net() var app = getApp() Page({ /** * 页面的初始数据 */ data: { ui: { tab: [['在线客服', 'info_o_s'], ['客服热线', 'info_p'], ['留言反馈', 'info_m']] }, broadcast: { w: 0, n: 0, s: false, b:'', fa: '', sa: '', ta: '', fc: 'n', sc: 'h', tc: 'h' }, data: [], questionIndex: 0, questions: [], details: {}, scroll: true, questionDetailsView: { animation: {}, hidden: true, scroll:0 }, showContact: false, //客服需要的 isLogin: false, userInfo: { avatarUrl: '' }, params: { } }, hiddenContactListener: function(e) { businessT.debugLog('hiddenContactListener') this.setData({ scroll: true }) }, showQuestionDetails:businessT.action(function (sender) { businessT.debugLog(sender.currentTarget.id) if (!this.data.questionDetailsView.hidden) { return } var i = this.data.questionIndex + Number(sender.currentTarget.id) if (i > this.data.data.length - 1) { i = i - this.data.data.length } this.data.details = this.data.data[i] businessT.debugLog(i) this.data.questionDetailsView.hidden = false this.setData({ questionDetailsView: this.data.questionDetailsView, scroll: false, details: this.data.details }) var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) animation.bottom('0rpx').step() this.setData({ questionDetailsView: { animation: animation.export(), hidden: false } }) }), hiddenQuestionDetail:businessT.action(function (sender) { var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) animation.bottom('-800rpx').step() this.setData({ questionDetailsView: { animation: animation.export(), hidden: false } }) setTimeout(function () { this.data.questionDetailsView.hidden = true this.setData({ questionDetailsView: this.data.questionDetailsView, scroll: true }) }.bind(this), 300) }), judgeIsLogin: function () { if (app.loginStatus.key == "") { wx.navigateTo({ url: '../login/index', }) return false } return true }, tabAction: businessT.action(function (sender) { businessT.debugLog(sender.currentTarget) switch (sender.currentTarget.id) { case '0': { if (!this.judgeIsLogin()) { return } // wx.navigateTo({ // url: '../../public/pages/html/html?host=http://testwdsbh5.shanp.com/user.html&channel=h5XCX&phone=' + app.globalData.userInfo.phone + '&uid=' + app.globalData.userInfo.uid + '&t=' + new Date().getTime(), // }) break } case '1': { this.setData({ showContact: true, scroll: false }) break } case '2': { businessT.debugLog('a') if (!this.judgeIsLogin()) { return } wx.navigateTo({ url: 'pages/leave-message-list/leave-message-list', }) break } } }), broadcastAnimation: function (length) { if (length > (640 + 200) * sysT.rpxToPx()) { this.setData({ broadcast: this.data.broadcast }) this.broadcastTextAnimation(length) } businessT.debugLog(length) }, broadcastTextAnimation: function (length) { this.data.broadcast.n++ var t = length * 17.5 var y = this.data.broadcast.n % 3 businessT.debugLog(y) switch (y) { case 1: { this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.fc = 'n' this.data.broadcast.sc = 'n' this.data.broadcast.tc = 'h' if (this.data.broadcast.n == 1) { var d = 1000 setTimeout(function () { this.setData({ broadcast: this.data.broadcast }) }.bind(this), d) t = t + d } else { this.setData({ broadcast: this.data.broadcast }) } break } case 2: { this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(' + length + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 2) + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 2) + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.fc = 'h' this.data.broadcast.sc = 'n' this.data.broadcast.tc = 'n' this.setData({ broadcast: this.data.broadcast }) break } case 0: { this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(0px); transform-origin: 50% 50% 0px;' this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(0px); transform-origin: 50% 50% 0px;' this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 3) + 'px); transform-origin: 50% 50% 0px;' this.data.broadcast.fc = 'n' this.data.broadcast.sc = 'h' this.data.broadcast.tc = 'n' this.setData({ broadcast: this.data.broadcast }) break } default: break } this.broadcastTimeout = setTimeout(function () { this.broadcastTextAnimation(length) }.bind(this), t) }, judgeBroadcast: function () { if (this.data.broadcast.s) { var query = wx.createSelectorQuery(); //选择id query.select('#broadcastText').boundingClientRect() var that = this; query.exec(function (res) { //res就是 该元素的信息 数组 businessT.debugLog(res[0]) that.data.broadcast.n = 0 var singleLength = res[0].width + 200 * sysT.rpxToPx() that.data.broadcast.w = singleLength * 3 that.broadcastAnimation(singleLength) }) } }, refreshBroacast: function (b) { if (this.broadcastTimeout) { clearTimeout(this.broadcastTimeout) } var broadcast = { w: 0, n: 0, s: true, b: b, fa: '', sa: '', ta: '', fc: 'n', sc: 'h', tc: 'h' } this.setData({ broadcast: broadcast }) this.judgeBroadcast() }, deleteBroadcast: businessT.action(function (sender) { if (this.broadcastTimeout) { clearTimeout(this.broadcastTimeout) } this.data.broadcast.s = false this.setData({ broadcast: this.data.broadcast }) }), route: function (path) { var pages = getCurrentPages() wx.navigateBack({ delta: pages.length }) setTimeout(function () { wx.navigateTo({ url: path, }) }.bind(this), 500) }, changeQuestion: businessT.action(function (sender) { var l = this.data.questionIndex + 5 this.data.questions = [] for (var i = 0; i < 5; i++) { var ind = i + l if (ind > this.data.data.length - 1) { ind = ind - this.data.data.length } businessT.debugLog(ind) this.data.questions.push(this.data.data[ind].topic) } if (l > this.data.data.length - 1) { l = l - this.data.data.length } this.data.questionIndex = l this.setData({ questions: this.data.questions }) }), getQuestions: function () { net.connect({ url: url.app_host + url.getHotTopicList, data: {}, method: 'GET', success: (err, res) => { this.data.data = res.data var max = this.data.data.length > 5 ? 5 : this.data.data.length for (var i = 0; i < max; i++) { this.data.questions.push(this.data.data[i].topic) } this.setData({ questions: this.data.questions }) }, fail: (err, res) => { } }, true) }, getBroadcast: function() { net.connect({ url: url.app_host + url.getBroadcast, data: {}, method: 'GET', success: (err, res) => { if (this.data.broadcast.b == res.data) { return } this.refreshBroacast(res.data) }, fail: (err, res) => { } }, true) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getQuestions() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ redDot: app.tabRedDot, selected: 1 }) } this.judgeBroadcast() this.getBroadcast() this.data.userInfo.nickName = app.globalData.userInfo.phone this.data.params.phone = app.globalData.userInfo.phone this.data.params.userId = app.globalData.userInfo.uid this.setData({ isLogin: app.loginStatus.isLogin, userInfo: this.data.userInfo, params: this.data.params }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { if (this.broadcastTimeout) { clearTimeout(this.broadcastTimeout) } var broadcast = { w: this.data.broadcast.w, n: -100, s: this.data.broadcast.s, b: this.data.broadcast.b, fa: '', sa: '', ta: '', fc: 'n', sc: 'h', tc: 'h' } this.setData({ broadcast: broadcast }) }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return { path: '/page/home/index', imageUrl: '../../icon/public/share_img.png', title: '自助缴社保公积金,覆盖200多个城市,专业团队操作' } } })