index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. },
  54. /* tabs切换 */
  55. tabsOnChange(e) {
  56. const {
  57. index,
  58. title
  59. } = e.detail;
  60. this.setData({
  61. tabsActive: index,
  62. pageNumber: 1,
  63. pageTotal: 1
  64. })
  65. this.getList()
  66. },
  67. /* 列表请求 */
  68. getList() {
  69. let type = "公共";
  70. switch (this.data.tabsActive) {
  71. case 1:
  72. type = "商户";
  73. break;
  74. case 2:
  75. type = "公共";
  76. break;
  77. case 3:
  78. type = "团队";
  79. break;
  80. default:
  81. break;
  82. }
  83. _Http.basic({
  84. "accesstoken": wx.getStorageSync('userData').token,
  85. "classname": "system.message.Message",
  86. "method": "queryMessage",
  87. "content": {
  88. "getdatafromdbanyway": true,
  89. "pageNumber": this.data.pageNumber,
  90. "pageSize": 20,
  91. "ftype": type
  92. }
  93. }).then(res => {
  94. if (res.msg != '成功') return wx.showToast({
  95. title: res.data,
  96. icon: 'none'
  97. });
  98. let data = res.data,
  99. date = new Date(),
  100. opt = {
  101. "Y": date.getFullYear().toString(), // 年
  102. "m": (date.getMonth() + 1).toString(), // 月
  103. "d": date.getDate().toString(), // 日
  104. "H": date.getHours().toString(), // 时
  105. "M": date.getMinutes().toString(), // 分
  106. "S": date.getSeconds().toString() // 秒
  107. };
  108. for (let i = 0; i < data.length; i++) {
  109. let arr = data[i].createdate.split(' '),
  110. YmD = arr[0].split('-'), //年月日
  111. HM = arr[1].slice(0, arr[1].lastIndexOf(':')), //小时,分钟
  112. optm = parseInt(opt.m),
  113. m = parseInt(YmD[1]),
  114. optd = parseInt(opt.d),
  115. d = parseInt(YmD[2])
  116. //同年
  117. if (parseInt(opt.Y) == parseInt(YmD[0])) {
  118. if (opt.m > 10) opt.m = "0" + opt.m;
  119. //同月
  120. if (optm == m) {
  121. if (optd == d) {
  122. data[i].time = '今天 ' + HM;
  123. } else if (optd - d == 1) {
  124. data[i].time = '昨天 ' + HM;
  125. } else if (optd - d == 2) {
  126. data[i].time = '前天 ' + HM;
  127. } else if (optd - d >= 3) {
  128. data[i].time = '三天前'
  129. } else if (optd - d >= 7) {
  130. data[i].time = '七天前'
  131. }
  132. } else {
  133. //不同月
  134. if (optm - m == 1) {
  135. data[i].time = '1月前'
  136. } else if (optm - m == 2) {
  137. data[i].time = '2月前'
  138. } else if (optm - m >= 3 && opt.m - YmD[1] < 6) {
  139. data[i].time = '3月前'
  140. } else if (optm - m >= 6) {
  141. data[i].time = '半年前'
  142. }
  143. }
  144. } else {
  145. data[i].time = YmD[0] + '年'
  146. }
  147. };
  148. this.setData({
  149. msgList: data,
  150. pageTotal: res.pageTotal
  151. })
  152. })
  153. },
  154. /* 上拉触底 加载数据 */
  155. listLoadMore() {
  156. if (this.data.pageTotal > this.data.pageNumber) {
  157. this.setData({
  158. pageNumber: this.data.pageNumber + 1
  159. })
  160. } else {
  161. return
  162. };
  163. this.getList();
  164. },
  165. /**
  166. * 生命周期函数--监听页面初次渲染完成
  167. */
  168. onReady: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面显示
  172. */
  173. onShow: function () {
  174. this.getTabBar().init();
  175. },
  176. /**
  177. * 生命周期函数--监听页面隐藏
  178. */
  179. onHide: function () {
  180. },
  181. /**
  182. * 生命周期函数--监听页面卸载
  183. */
  184. onUnload: function () {
  185. },
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh: function () {
  190. },
  191. /**
  192. * 页面上拉触底事件的处理函数
  193. */
  194. onReachBottom: function () {
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage: function () {
  200. }
  201. })