index.js 6.6 KB

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