index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. default:
  85. break;
  86. }
  87. _Http.basic({
  88. "accesstoken": wx.getStorageSync('userData').token,
  89. "classname": "system.message.Message",
  90. "method": "queryMessage",
  91. "content": {
  92. "getdatafromdbanyway": true,
  93. "pageNumber": this.data.pageNumber,
  94. "pageSize": 20,
  95. "ftype": type
  96. }
  97. }).then(res => {
  98. if (res.msg != '成功') return wx.showToast({
  99. title: res.data,
  100. icon: 'none'
  101. });
  102. let data = res.data,
  103. date = new Date(),
  104. opt = {
  105. "Y": date.getFullYear().toString(), // 年
  106. "m": (date.getMonth() + 1).toString(), // 月
  107. "d": date.getDate().toString(), // 日
  108. "H": date.getHours().toString(), // 时
  109. "M": date.getMinutes().toString(), // 分
  110. "S": date.getSeconds().toString() // 秒
  111. };
  112. for (let i = 0; i < data.length; i++) {
  113. let arr = data[i].createdate.split(' '),
  114. YmD = arr[0].split('-'), //年月日
  115. HM = arr[1].slice(0, arr[1].lastIndexOf(':')), //小时,分钟
  116. optm = parseInt(opt.m),
  117. m = parseInt(YmD[1]),
  118. optd = parseInt(opt.d),
  119. d = parseInt(YmD[2])
  120. //同年
  121. if (parseInt(opt.Y) == parseInt(YmD[0])) {
  122. if (opt.m > 10) opt.m = "0" + opt.m;
  123. //同月
  124. if (optm == m) {
  125. if (optd == d) {
  126. data[i].time = '今天 ' + HM;
  127. } else if (optd - d == 1) {
  128. data[i].time = '昨天 ' + HM;
  129. } else if (optd - d == 2) {
  130. data[i].time = '前天 ' + HM;
  131. } else if (optd - d >= 3) {
  132. data[i].time = '三天前'
  133. } else if (optd - d >= 7) {
  134. data[i].time = '七天前'
  135. }
  136. } else {
  137. //不同月
  138. if (optm - m == 1) {
  139. data[i].time = '1月前'
  140. } else if (optm - m == 2) {
  141. data[i].time = '2月前'
  142. } else if (optm - m >= 3 && opt.m - YmD[1] < 6) {
  143. data[i].time = '3月前'
  144. } else if (optm - m >= 6) {
  145. data[i].time = '半年前'
  146. }
  147. }
  148. } else {
  149. data[i].time = YmD[0] + '年'
  150. }
  151. };
  152. let msgList = data;
  153. if (this.data.pageNumber != 1) {
  154. msgList = this.data.msgList.concat(data);
  155. };
  156. this.setData({
  157. msgList,
  158. pageTotal: res.pageTotal
  159. })
  160. })
  161. },
  162. /* 上拉触底 加载数据 */
  163. listLoadMore() {
  164. if (this.data.pageTotal > this.data.pageNumber) {
  165. this.setData({
  166. pageNumber: this.data.pageNumber + 1
  167. })
  168. } else {
  169. return
  170. };
  171. this.getList();
  172. },
  173. /**
  174. * 生命周期函数--监听页面初次渲染完成
  175. */
  176. onReady: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面显示
  180. */
  181. onShow: function () {
  182. this.getTabBar().init();
  183. this.selectComponent("#gxshuju").unReadMessageCount();
  184. setTimeout(() => {
  185. this.getTabBar().setData({
  186. 'tabbarList[3].fcount': getApp().globalData.msgFcount
  187. })
  188. }, 500)
  189. },
  190. /**
  191. * 生命周期函数--监听页面隐藏
  192. */
  193. onHide: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面卸载
  197. */
  198. onUnload: function () {
  199. },
  200. /**
  201. * 页面相关事件处理函数--监听用户下拉动作
  202. */
  203. onPullDownRefresh: function () {
  204. },
  205. /**
  206. * 页面上拉触底事件的处理函数
  207. */
  208. onReachBottom: function () {
  209. },
  210. /**
  211. * 用户点击右上角分享
  212. */
  213. onShareAppMessage: function () {
  214. }
  215. })