index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import {
  2. ApiModel
  3. } from "../../../utils/api";
  4. const _Http = new ApiModel();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabsActive: 0, //tabs 下标
  11. msgList: [],
  12. pageNumber: 1,
  13. pageTotal: 1
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.getList()
  20. const that = this;
  21. const h = getApp().globalData.myNavBorHeight + getApp().globalData.safeAreaBottom;
  22. wx.getSystemInfo({
  23. success(res) {
  24. that.setData({
  25. scrollH: res.windowHeight - h - 7
  26. })
  27. }
  28. })
  29. },
  30. /* 阅读信息 */
  31. readMsg(e) {
  32. const {
  33. index,
  34. id,
  35. fisread
  36. } = e.currentTarget.dataset;
  37. if (fisread == 0) _Http.basic({
  38. "accesstoken": wx.getStorageSync('userData').token,
  39. "classname": "system.message.Message",
  40. "method": "readMessage",
  41. "content": {
  42. "tmessageid": id
  43. }
  44. }).then(res => {
  45. if (res.msg != '成功') return wx.showToast({
  46. title: res.data,
  47. });
  48. const name = 'msgList[' + index + '].fisread';
  49. this.setData({
  50. [name]: 1
  51. })
  52. //更新徽标
  53. this.selectComponent("#gxshuju").unReadMessageCount();
  54. setTimeout(() => {
  55. this.getTabBar().setData({
  56. 'tabbarList[3].fcount': getApp().globalData.msgFcount
  57. })
  58. }, 500)
  59. });
  60. },
  61. /* tabs切换 */
  62. tabsOnChange(e) {
  63. const {
  64. index,
  65. title
  66. } = e.detail;
  67. this.setData({
  68. tabsActive: index,
  69. pageNumber: 1,
  70. pageTotal: 1
  71. })
  72. this.getList()
  73. },
  74. /* 列表请求 */
  75. getList() {
  76. let type = "公共";
  77. switch (this.data.tabsActive) {
  78. case 1:
  79. type = "商户";
  80. break;
  81. case 2:
  82. type = "公共";
  83. break;
  84. case 3:
  85. type = "团队";
  86. break;
  87. default:
  88. break;
  89. }
  90. _Http.basic({
  91. "accesstoken": wx.getStorageSync('userData').token,
  92. "classname": "system.message.Message",
  93. "method": "queryMessage",
  94. "content": {
  95. "getdatafromdbanyway": true,
  96. "pageNumber": this.data.pageNumber,
  97. "pageSize": 20,
  98. "ftype": type
  99. }
  100. }).then(res => {
  101. if (res.msg != '成功') return wx.showToast({
  102. title: res.data,
  103. icon: 'none'
  104. });
  105. let data = res.data,
  106. date = new Date(),
  107. opt = {
  108. "Y": date.getFullYear().toString(), // 年
  109. "m": (date.getMonth() + 1).toString(), // 月
  110. "d": date.getDate().toString(), // 日
  111. "H": date.getHours().toString(), // 时
  112. "M": date.getMinutes().toString(), // 分
  113. "S": date.getSeconds().toString() // 秒
  114. };
  115. for (let i = 0; i < data.length; i++) {
  116. let arr = data[i].createdate.split(' '),
  117. YmD = arr[0].split('-'), //年月日
  118. HM = arr[1].slice(0, arr[1].lastIndexOf(':')), //小时,分钟
  119. optm = parseInt(opt.m),
  120. m = parseInt(YmD[1]),
  121. optd = parseInt(opt.d),
  122. d = parseInt(YmD[2])
  123. //同年
  124. if (parseInt(opt.Y) == parseInt(YmD[0])) {
  125. if (opt.m > 10) opt.m = "0" + opt.m;
  126. //同月
  127. if (optm == m) {
  128. if (optd == d) {
  129. data[i].time = '今天 ' + HM;
  130. } else if (optd - d == 1) {
  131. data[i].time = '昨天 ' + HM;
  132. } else if (optd - d == 2) {
  133. data[i].time = '前天 ' + HM;
  134. } else if (optd - d >= 3) {
  135. data[i].time = '三天前'
  136. } else if (optd - d >= 7) {
  137. data[i].time = '七天前'
  138. }
  139. } else {
  140. //不同月
  141. if (optm - m == 1) {
  142. data[i].time = '1月前'
  143. } else if (optm - m == 2) {
  144. data[i].time = '2月前'
  145. } else if (optm - m >= 3 && opt.m - YmD[1] < 6) {
  146. data[i].time = '3月前'
  147. } else if (optm - m >= 6) {
  148. data[i].time = '半年前'
  149. }
  150. }
  151. } else {
  152. data[i].time = YmD[0] + '年'
  153. }
  154. };
  155. this.setData({
  156. msgList: data,
  157. pageTotal: res.pageTotal
  158. })
  159. })
  160. },
  161. /* 上拉触底 加载数据 */
  162. listLoadMore() {
  163. if (this.data.pageTotal > this.data.pageNumber) {
  164. this.setData({
  165. pageNumber: this.data.pageNumber + 1
  166. })
  167. } else {
  168. return
  169. };
  170. this.getList();
  171. },
  172. /**
  173. * 生命周期函数--监听页面初次渲染完成
  174. */
  175. onReady: function () {
  176. },
  177. /**
  178. * 生命周期函数--监听页面显示
  179. */
  180. onShow: function () {
  181. this.getTabBar().init();
  182. this.selectComponent("#gxshuju").unReadMessageCount();
  183. setTimeout(() => {
  184. this.getTabBar().setData({
  185. 'tabbarList[3].fcount': getApp().globalData.msgFcount
  186. })
  187. }, 500)
  188. },
  189. /**
  190. * 生命周期函数--监听页面隐藏
  191. */
  192. onHide: function () {
  193. },
  194. /**
  195. * 生命周期函数--监听页面卸载
  196. */
  197. onUnload: function () {
  198. },
  199. /**
  200. * 页面相关事件处理函数--监听用户下拉动作
  201. */
  202. onPullDownRefresh: function () {
  203. },
  204. /**
  205. * 页面上拉触底事件的处理函数
  206. */
  207. onReachBottom: function () {
  208. },
  209. /**
  210. * 用户点击右上角分享
  211. */
  212. onShareAppMessage: function () {
  213. }
  214. })