home.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // pages/home/home.ts
  2. import services from "../../services/index"
  3. import { queryImageConfigs, queryNotice } from "../../services/api/common/index"
  4. import { homeData } from "../../services/api/orders/index"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. /// 底部安全区域
  11. safeBottom: getApp().globalData.safeBottom,
  12. /// 窗口高度
  13. windowHeight: getApp().globalData.windowHeight,
  14. /// banner轮播图
  15. banners: [''],
  16. /// 功能菜单
  17. menus: [{id: 1, icon: '', title: '挂牌大厅', path: 'pages/trade/trade'},
  18. {id: 2, icon: '', title: '钻石首饰', path: '/mHome/pages/jewelry/jewelry'},
  19. {id: 3, icon: '', title: '出境检测', path: '/mHome/pages/inspection/inspection'},
  20. {id: 4, icon: '', title: '报税服务', path: '/mHome/pages/bond/bond'}],
  21. /// 统计
  22. statistics: [{id: 1, title: '出售中', value: 0},
  23. {id: 2, title: '求购中', value: 0},
  24. {id: 3, title: '已购买', value: 0},
  25. {id: 4, title: '已出售', value: 0},
  26. {id: 5, title: '今日汇率', value: 0}],
  27. /// 首页数据
  28. homedata: [0, 0, 0, 0, 0],
  29. /// 公告消息
  30. notice: {},
  31. /// 公告系XO
  32. msgs: [{}]
  33. },
  34. /**
  35. * 获取首页轮播图数据
  36. */
  37. queryImageConfigs() {
  38. /// 获取首页轮播图数据
  39. queryImageConfigs({
  40. data: { imageType: 1 },
  41. success:(res) => {
  42. /// 数据设置
  43. this.setData({
  44. banners: res.data.map(item => {
  45. return (services.config.openApiUrl+item.imagepath).replace('./uploadFile', '/uploadFile')
  46. })
  47. })
  48. },
  49. fail:(emsg) => {
  50. console.log('首页数据获取失败,原因:'+emsg)
  51. },
  52. complete:() => {}
  53. })
  54. },
  55. /**
  56. * 获取首页数据信息
  57. */
  58. homeData() {
  59. /// 获取新闻首页数据
  60. homeData({
  61. data: { userid: wx.getStorageSync('UserId') },
  62. success:(res) => {
  63. /// 数据设置
  64. var array = [res.data.transactionssold,
  65. res.data.transactioninpurchase,
  66. res.data.purchasedtransactions,
  67. res.data.transactionsonsale,
  68. wx.getStorageSync('LoginQuery').exchangeRateConfigs[0].exchangerate]
  69. this.setData({ homedata: array })
  70. },
  71. fail:(emsg) => {
  72. console.log('首页数据获取失败,原因:'+emsg)
  73. },
  74. complete:() => {}
  75. })
  76. },
  77. /**
  78. * 查询通知公告消息
  79. */
  80. queryNotice(){
  81. /// 发送查询请求
  82. queryNotice({
  83. data: {
  84. loginID: wx.getStorageSync('LoginID')
  85. },
  86. success:(res) => {
  87. /// 数据为空
  88. if (res.data.length == 0) {
  89. return
  90. }
  91. /// 加载成功 数据复制
  92. this.setData({
  93. notice: res.data[0],
  94. msgs: res.data
  95. })
  96. },
  97. fail: (emsg) => {
  98. /// 加载失败
  99. wx.showToast({
  100. title: '公告消息请求失败, 原因::'+emsg,
  101. icon: 'error'
  102. })
  103. },
  104. complete: () => {}
  105. })
  106. },
  107. /**
  108. * 跳转公告消息页面方法
  109. */
  110. goToMsg() {
  111. wx.navigateTo({
  112. url: '/mHome/pages/msg/msglist/msglist'
  113. })
  114. },
  115. /// 进入公告消息详情页
  116. goToMsgDetail(r: any) {
  117. console.log(r)
  118. let jsonStr = JSON.stringify(this.data.msgs[r.currentTarget.id])
  119. wx.navigateTo({
  120. url: '/mHome/pages/msg/msgdetail/msgdetail?id='+jsonStr
  121. })
  122. },
  123. /// onGirdClick
  124. onGirdClick(e: any) {
  125. switch (e.target.id) {
  126. case "挂牌大厅":
  127. wx.switchTab({
  128. url: '/pages/trade/trade'
  129. })
  130. break;
  131. default:
  132. break;
  133. }
  134. },
  135. /**
  136. * 生命周期函数--监听页面加载
  137. */
  138. onLoad() {
  139. /// 获取新闻首页数据
  140. this.homeData()
  141. /// 查询新闻资讯
  142. this.queryNotice()
  143. /// 查询轮播图数据
  144. this.queryImageConfigs()
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow() {
  155. this.getTabBar().init()
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh() {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom() {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage() {
  181. }
  182. })