index.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import services from "../../services/index"
  2. import { queryImageConfigs, queryNotice } from "../../services/api/common/index"
  3. import { homeData } from "../../services/api/orders/index"
  4. import { loginid, loginQuery, userid } from "../../services/utils"
  5. import { hideLoading, showLoading } from "../../utils/message/index"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. /// 底部安全区域
  12. safeBottom: getApp().globalData.safeBottom,
  13. /// 窗口高度
  14. windowHeight: getApp().globalData.windowHeight,
  15. /// banner轮播图
  16. banners: [''],
  17. /// 功能菜单
  18. menus: [{id: 1, icon: 'home-zsss', title: '钻石搜索', path: '/mHome/pages/search/index'},
  19. {id: 2, icon: 'home-gpdt', title: '挂牌大厅', path: '/pages/trade/index'},
  20. {id: 3, icon: 'home-ss', title: '钻石首饰', path: '/mHome/pages/jewelry/list/index'},
  21. {id: 4, icon: 'home-cjjc', title: '出境检测', path: '/mHome/pages/inspection/list/index'},
  22. {id: 5, icon: 'home-bsfw', title: '保税服务', path: '/mHome/pages/bond/list/index'}],
  23. /// 统计
  24. statistics: [{id: 1, title: '出售中', value: 0, class: ''}],
  25. /// tabs
  26. tabs:[{id: 1, title: '公告'}, {id: 2, title: '消息'}],
  27. /// 公告消息
  28. notice: {},
  29. /// 公告系XO
  30. msgs: [{}],
  31. /// 是否为空
  32. isEmpty: true
  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. })
  50. },
  51. /**
  52. * 获取首页数据信息
  53. */
  54. homeData() {
  55. /// 获取新闻首页数据
  56. homeData({
  57. data: { userid: userid() },
  58. success:(res) => {
  59. /// 数据设置
  60. this.setData({
  61. statistics: [
  62. { id: 1, title: '出售中', value: res.data.transactionssold, class: 'transactionssold' },
  63. { id: 2, title: '求购中', value: res.data.transactioninpurchase, class: 'transactioninpurchase' },
  64. { id: 3, title: '已购买', value: res.data.purchasedtransactions, class: 'purchasedtransactions' },
  65. { id: 4, title: '已出售', value: res.data.transactionsonsale, class: 'transactionsonsale' },
  66. { id: 5, title: '今日汇率', value: loginQuery().exchangeRateConfigs[0].exchangerate, class: 'exchangerate' },
  67. ]
  68. })
  69. }
  70. })
  71. },
  72. /**
  73. * 查询通知公告消息
  74. */
  75. queryNotice(type: number){
  76. /// loading
  77. showLoading(()=>{
  78. /// 发送查询请求
  79. queryNotice({
  80. data: {
  81. loginID: loginid(),
  82. msgType: type
  83. },
  84. success:(res) => {
  85. /// 数据为空
  86. if (res.code != 200) {
  87. hideLoading(()=>{}, '请求失败,原因:'+res.msg, 'error')
  88. return
  89. }
  90. hideLoading(()=>{
  91. /// 加载成功 数据复制
  92. this.setData({
  93. notice: res.data[0],
  94. msgs: res.data,
  95. isEmpty: res.data.length === 0
  96. })
  97. })
  98. },
  99. fail: (emsg) => {
  100. /// 加载失败
  101. hideLoading(()=>{}, emsg, 'error')
  102. }
  103. })
  104. })
  105. },
  106. /**
  107. * 跳转公告消息页面方法
  108. */
  109. goToMsg() {
  110. wx.navigateTo({
  111. url: '/mHome/pages/msg/msglist/index'
  112. })
  113. },
  114. /**
  115. * 计算器跳转
  116. */
  117. goToCalculator() {
  118. wx.navigateTo({
  119. url: '/mHome/pages/calculator/index'
  120. })
  121. },
  122. /// onTabChange
  123. onTabChange(e: any) {
  124. /// 查询公告消息
  125. this.queryNotice(e.detail.index)
  126. },
  127. /**
  128. * 证书查询
  129. */
  130. goToCerserach() {
  131. wx.navigateTo({
  132. url: '/mHome/pages/cerserach/index'
  133. })
  134. },
  135. /// 进入公告消息详情页
  136. goToMsgDetail(r: any) {
  137. let jsonStr = JSON.stringify(this.data.msgs[r.currentTarget.id])
  138. wx.navigateTo({
  139. url: '/mHome/pages/msg/msgdetail/index?id='+jsonStr
  140. })
  141. },
  142. /// onGirdClick
  143. onGirdClick(e: any) {
  144. switch (e.currentTarget.id) {
  145. case "2":
  146. wx.switchTab({
  147. url: e.currentTarget.dataset.url
  148. })
  149. break;
  150. default: /// 其他页面跳转
  151. wx.navigateTo({
  152. url: e.currentTarget.dataset.url
  153. })
  154. break;
  155. }
  156. },
  157. /**
  158. * 生命周期函数--监听页面加载
  159. */
  160. onLoad() {
  161. /// 获取新闻首页数据
  162. this.homeData()
  163. /// 查询新闻资讯
  164. this.queryNotice(1)
  165. /// 查询轮播图数据
  166. this.queryImageConfigs()
  167. },
  168. /**
  169. * 生命周期函数--监听页面初次渲染完成
  170. */
  171. onReady() {
  172. },
  173. /**
  174. * 生命周期函数--监听页面显示
  175. */
  176. onShow() {
  177. this.getTabBar().init()
  178. },
  179. /**
  180. * 生命周期函数--监听页面隐藏
  181. */
  182. onHide() {
  183. },
  184. /**
  185. * 生命周期函数--监听页面卸载
  186. */
  187. onUnload() {
  188. },
  189. /**
  190. * 页面相关事件处理函数--监听用户下拉动作
  191. */
  192. onPullDownRefresh() {
  193. },
  194. /**
  195. * 页面上拉触底事件的处理函数
  196. */
  197. onReachBottom() {
  198. },
  199. /**
  200. * 用户点击右上角分享
  201. */
  202. onShareAppMessage() {
  203. }
  204. })