index.js 6.6 KB

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