index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const app = getApp();
  2. Page({
  3. data: {
  4. Session_list: [],
  5. now: ""
  6. },
  7. onLoad: function (options) {
  8. const {
  9. unreadCountMes,
  10. } = app.globalData;
  11. const now = Date.parse(new Date());
  12. this.setData({
  13. unreadCountMes,
  14. now,
  15. });
  16. getApp().watch('unreadCountMes', this.watchBack);
  17. app.editTabbar();
  18. },
  19. watchBack(name, value) {
  20. let data = {};
  21. data[name] = value;
  22. const now = Date.parse(new Date());
  23. this.setData({
  24. ...data,
  25. Session_list: app.globalData.Session_list,
  26. now
  27. });
  28. },
  29. onShow: function () {
  30. const token = wx.getStorageSync('token');
  31. if (token) {
  32. const {
  33. Session_list
  34. } = app.globalData;
  35. console.log(Session_list);
  36. this.setData({
  37. Session_list
  38. })
  39. } else {
  40. wx.showToast({
  41. title: '请先登录',
  42. icon: "none"
  43. })
  44. setTimeout(() => {
  45. wx.switchTab({
  46. url: '/page/tabBar/mine/index',
  47. })
  48. }, 1000)
  49. }
  50. },
  51. drawEnd: function (e) {
  52. var item = this.data.Session_list[e.currentTarget.dataset.index]
  53. if (item.left === 0) {
  54. item.left = -140
  55. this.setData({
  56. Session_list: this.data.Session_list,
  57. })
  58. }
  59. },
  60. delTap(e) {
  61. const that = this;
  62. var {
  63. index,
  64. conversationid: conversationID
  65. } = e.currentTarget.dataset;
  66. wx.showModal({
  67. title: '提示',
  68. content: '确定删除该聊天?',
  69. success: function (sm) {
  70. if (sm.confirm) {
  71. app.deleteChat(conversationID, index, that);
  72. }
  73. }
  74. })
  75. },
  76. chat(e) {
  77. const {
  78. userid: userID,
  79. showname,
  80. faceurl,
  81. index:num
  82. } = e.currentTarget.dataset;
  83. var item = this.data.Session_list[num]
  84. if (item.left === 0) {
  85. app.globalData.userID = userID;
  86. wx.navigateTo({
  87. url: `/page/message/pages/Chat/chat?userID=${userID}&showname=${showname}&faceurl=${faceurl}`,
  88. })
  89. }
  90. for (var index in this.data.Session_list) {
  91. var item = this.data.Session_list[index]
  92. item.left = 0
  93. }
  94. this.setData({
  95. Session_list: this.data.Session_list,
  96. })
  97. },
  98. })