index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. var businessT = require('../../tool/business-tool.js')
  2. var sysT = require('../../tool/sys-tool.js')
  3. var url = require('../../constant/url.js')
  4. import Net from '../../tool/net.js'
  5. var net = new Net()
  6. var app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. ui: {
  13. tab: [['在线客服', 'info_o_s'], ['客服热线', 'info_p'], ['留言反馈', 'info_m']]
  14. },
  15. broadcast: {
  16. w: 0,
  17. n: 0,
  18. s: false,
  19. b:'',
  20. fa: '',
  21. sa: '',
  22. ta: '',
  23. fc: 'n',
  24. sc: 'h',
  25. tc: 'h'
  26. },
  27. data: [],
  28. questionIndex: 0,
  29. questions: [],
  30. details: {},
  31. scroll: true,
  32. questionDetailsView: {
  33. animation: {},
  34. hidden: true,
  35. scroll:0
  36. },
  37. showContact: false,
  38. //客服需要的
  39. isLogin: false,
  40. userInfo: {
  41. avatarUrl: ''
  42. },
  43. params: {
  44. }
  45. },
  46. hiddenContactListener: function(e) {
  47. businessT.debugLog('hiddenContactListener')
  48. this.setData({
  49. scroll: true
  50. })
  51. },
  52. showQuestionDetails:businessT.action(function (sender) {
  53. businessT.debugLog(sender.currentTarget.id)
  54. if (!this.data.questionDetailsView.hidden) {
  55. return
  56. }
  57. var i = this.data.questionIndex + Number(sender.currentTarget.id)
  58. if (i > this.data.data.length - 1) {
  59. i = i - this.data.data.length
  60. }
  61. this.data.details = this.data.data[i]
  62. businessT.debugLog(i)
  63. this.data.questionDetailsView.hidden = false
  64. this.setData({
  65. questionDetailsView: this.data.questionDetailsView,
  66. scroll: false,
  67. details: this.data.details
  68. })
  69. var animation = wx.createAnimation({
  70. duration: 300,
  71. timingFunction: 'ease',
  72. })
  73. animation.bottom('0rpx').step()
  74. this.setData({
  75. questionDetailsView: {
  76. animation: animation.export(),
  77. hidden: false
  78. }
  79. })
  80. }),
  81. hiddenQuestionDetail:businessT.action(function (sender) {
  82. var animation = wx.createAnimation({
  83. duration: 300,
  84. timingFunction: 'ease',
  85. })
  86. animation.bottom('-800rpx').step()
  87. this.setData({
  88. questionDetailsView: {
  89. animation: animation.export(),
  90. hidden: false
  91. }
  92. })
  93. setTimeout(function () {
  94. this.data.questionDetailsView.hidden = true
  95. this.setData({
  96. questionDetailsView: this.data.questionDetailsView,
  97. scroll: true
  98. })
  99. }.bind(this), 300)
  100. }),
  101. judgeIsLogin: function () {
  102. if (app.loginStatus.key == "") {
  103. wx.navigateTo({
  104. url: '../login/index',
  105. })
  106. return false
  107. }
  108. return true
  109. },
  110. tabAction: businessT.action(function (sender) {
  111. businessT.debugLog(sender.currentTarget)
  112. switch (sender.currentTarget.id) {
  113. case '0': {
  114. if (!this.judgeIsLogin()) {
  115. return
  116. }
  117. // wx.navigateTo({
  118. // 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(),
  119. // })
  120. break
  121. }
  122. case '1': {
  123. this.setData({
  124. showContact: true,
  125. scroll: false
  126. })
  127. break
  128. }
  129. case '2': {
  130. businessT.debugLog('a')
  131. if (!this.judgeIsLogin()) {
  132. return
  133. }
  134. wx.navigateTo({
  135. url: 'pages/leave-message-list/leave-message-list',
  136. })
  137. break
  138. }
  139. }
  140. }),
  141. broadcastAnimation: function (length) {
  142. if (length > (640 + 200) * sysT.rpxToPx()) {
  143. this.setData({
  144. broadcast: this.data.broadcast
  145. })
  146. this.broadcastTextAnimation(length)
  147. }
  148. businessT.debugLog(length)
  149. },
  150. broadcastTextAnimation: function (length) {
  151. this.data.broadcast.n++
  152. var t = length * 17.5
  153. var y = this.data.broadcast.n % 3
  154. businessT.debugLog(y)
  155. switch (y) {
  156. case 1: {
  157. this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;'
  158. this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;'
  159. this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + length + 'px); transform-origin: 50% 50% 0px;'
  160. this.data.broadcast.fc = 'n'
  161. this.data.broadcast.sc = 'n'
  162. this.data.broadcast.tc = 'h'
  163. if (this.data.broadcast.n == 1) {
  164. var d = 1000
  165. setTimeout(function () {
  166. this.setData({
  167. broadcast: this.data.broadcast
  168. })
  169. }.bind(this), d)
  170. t = t + d
  171. } else {
  172. this.setData({
  173. broadcast: this.data.broadcast
  174. })
  175. }
  176. break
  177. }
  178. case 2: {
  179. this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(' + length + 'px); transform-origin: 50% 50% 0px;'
  180. this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 2) + 'px); transform-origin: 50% 50% 0px;'
  181. this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 2) + 'px); transform-origin: 50% 50% 0px;'
  182. this.data.broadcast.fc = 'h'
  183. this.data.broadcast.sc = 'n'
  184. this.data.broadcast.tc = 'n'
  185. this.setData({
  186. broadcast: this.data.broadcast
  187. })
  188. break
  189. }
  190. case 0: {
  191. this.data.broadcast.fa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(0px); transform-origin: 50% 50% 0px;'
  192. this.data.broadcast.sa = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(0px); transform-origin: 50% 50% 0px;'
  193. this.data.broadcast.ta = 'transition: transform ' + t + 'ms linear 0ms; transform: translateX(-' + (length * 3) + 'px); transform-origin: 50% 50% 0px;'
  194. this.data.broadcast.fc = 'n'
  195. this.data.broadcast.sc = 'h'
  196. this.data.broadcast.tc = 'n'
  197. this.setData({
  198. broadcast: this.data.broadcast
  199. })
  200. break
  201. }
  202. default: break
  203. }
  204. this.broadcastTimeout = setTimeout(function () {
  205. this.broadcastTextAnimation(length)
  206. }.bind(this), t)
  207. },
  208. judgeBroadcast: function () {
  209. if (this.data.broadcast.s) {
  210. var query = wx.createSelectorQuery();
  211. //选择id
  212. query.select('#broadcastText').boundingClientRect()
  213. var that = this;
  214. query.exec(function (res) {
  215. //res就是 该元素的信息 数组
  216. businessT.debugLog(res[0])
  217. that.data.broadcast.n = 0
  218. var singleLength = res[0].width + 200 * sysT.rpxToPx()
  219. that.data.broadcast.w = singleLength * 3
  220. that.broadcastAnimation(singleLength)
  221. })
  222. }
  223. },
  224. refreshBroacast: function (b) {
  225. if (this.broadcastTimeout) {
  226. clearTimeout(this.broadcastTimeout)
  227. }
  228. var broadcast = {
  229. w: 0,
  230. n: 0,
  231. s: true,
  232. b: b,
  233. fa: '',
  234. sa: '',
  235. ta: '',
  236. fc: 'n',
  237. sc: 'h',
  238. tc: 'h'
  239. }
  240. this.setData({
  241. broadcast: broadcast
  242. })
  243. this.judgeBroadcast()
  244. },
  245. deleteBroadcast: businessT.action(function (sender) {
  246. if (this.broadcastTimeout) {
  247. clearTimeout(this.broadcastTimeout)
  248. }
  249. this.data.broadcast.s = false
  250. this.setData({
  251. broadcast: this.data.broadcast
  252. })
  253. }),
  254. route: function (path) {
  255. var pages = getCurrentPages()
  256. wx.navigateBack({
  257. delta: pages.length
  258. })
  259. setTimeout(function () {
  260. wx.navigateTo({
  261. url: path,
  262. })
  263. }.bind(this), 500)
  264. },
  265. changeQuestion: businessT.action(function (sender) {
  266. var l = this.data.questionIndex + 5
  267. this.data.questions = []
  268. for (var i = 0; i < 5; i++) {
  269. var ind = i + l
  270. if (ind > this.data.data.length - 1) {
  271. ind = ind - this.data.data.length
  272. }
  273. businessT.debugLog(ind)
  274. this.data.questions.push(this.data.data[ind].topic)
  275. }
  276. if (l > this.data.data.length - 1) {
  277. l = l - this.data.data.length
  278. }
  279. this.data.questionIndex = l
  280. this.setData({
  281. questions: this.data.questions
  282. })
  283. }),
  284. getQuestions: function () {
  285. net.connect({
  286. url: url.app_host + url.getHotTopicList,
  287. data: {},
  288. method: 'GET',
  289. success: (err, res) => {
  290. this.data.data = res.data
  291. var max = this.data.data.length > 5 ? 5 : this.data.data.length
  292. for (var i = 0; i < max; i++) {
  293. this.data.questions.push(this.data.data[i].topic)
  294. }
  295. this.setData({
  296. questions: this.data.questions
  297. })
  298. },
  299. fail: (err, res) => {
  300. }
  301. }, true)
  302. },
  303. getBroadcast: function() {
  304. net.connect({
  305. url: url.app_host + url.getBroadcast,
  306. data: {},
  307. method: 'GET',
  308. success: (err, res) => {
  309. if (this.data.broadcast.b == res.data) {
  310. return
  311. }
  312. this.refreshBroacast(res.data)
  313. },
  314. fail: (err, res) => {
  315. }
  316. }, true)
  317. },
  318. /**
  319. * 生命周期函数--监听页面加载
  320. */
  321. onLoad: function (options) {
  322. this.getQuestions()
  323. },
  324. /**
  325. * 生命周期函数--监听页面初次渲染完成
  326. */
  327. onReady: function () {
  328. },
  329. /**
  330. * 生命周期函数--监听页面显示
  331. */
  332. onShow: function () {
  333. if (typeof this.getTabBar === 'function' &&
  334. this.getTabBar()) {
  335. this.getTabBar().setData({
  336. redDot: app.tabRedDot,
  337. selected: 1
  338. })
  339. }
  340. this.judgeBroadcast()
  341. this.getBroadcast()
  342. this.data.userInfo.nickName = app.globalData.userInfo.phone
  343. this.data.params.phone = app.globalData.userInfo.phone
  344. this.data.params.userId = app.globalData.userInfo.uid
  345. this.setData({
  346. isLogin: app.loginStatus.isLogin,
  347. userInfo: this.data.userInfo,
  348. params: this.data.params
  349. })
  350. },
  351. /**
  352. * 生命周期函数--监听页面隐藏
  353. */
  354. onHide: function () {
  355. if (this.broadcastTimeout) {
  356. clearTimeout(this.broadcastTimeout)
  357. }
  358. var broadcast = {
  359. w: this.data.broadcast.w,
  360. n: -100,
  361. s: this.data.broadcast.s,
  362. b: this.data.broadcast.b,
  363. fa: '',
  364. sa: '',
  365. ta: '',
  366. fc: 'n',
  367. sc: 'h',
  368. tc: 'h'
  369. }
  370. this.setData({
  371. broadcast: broadcast
  372. })
  373. },
  374. /**
  375. * 生命周期函数--监听页面卸载
  376. */
  377. onUnload: function () {
  378. },
  379. /**
  380. * 页面相关事件处理函数--监听用户下拉动作
  381. */
  382. onPullDownRefresh: function () {
  383. },
  384. /**
  385. * 页面上拉触底事件的处理函数
  386. */
  387. onReachBottom: function () {
  388. },
  389. /**
  390. * 用户点击右上角分享
  391. */
  392. onShareAppMessage: function () {
  393. return {
  394. path: '/page/home/index',
  395. imageUrl: '../../icon/public/share_img.png',
  396. title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
  397. }
  398. }
  399. })