index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. let app = getApp();
  2. var ctime = null;
  3. Component({
  4. externalClasses: ["i-class"],
  5. properties: {
  6. stopNotify: {
  7. type: Boolean,
  8. value: true,
  9. observer: function(t){
  10. t ? (clearInterval(ctime), ctime = null) : this._startReq();
  11. }
  12. }
  13. },
  14. /**
  15. * 组件的初始数据
  16. */
  17. data: {
  18. userInfo: '',
  19. hide: false,
  20. order_id: 0
  21. },
  22. pageLifetimes: {
  23. hide: function() {
  24. console.log('notify hide')
  25. clearInterval(ctime), ctime = null;
  26. }
  27. },
  28. /**
  29. * 组件的方法列表
  30. */
  31. methods: {
  32. _startReq: function(){
  33. var that = this;
  34. ctime = setInterval(function(){
  35. that.getOrderNotify();
  36. }, 3000);
  37. },
  38. getOrderNotify: function (){
  39. let that = this;
  40. app.util.request({
  41. 'url': 'entry/wxapp/index',
  42. 'data': {
  43. controller: 'goods.notify_order'
  44. },
  45. dataType: 'json',
  46. success: function (res) {
  47. if (res.data.code == 0) {
  48. let username = res.data.username;
  49. let avatar = res.data.avatar;
  50. let order_id = res.data.order_id;
  51. let userInfo = { username, avatar }
  52. if (that.data.order_id != order_id){
  53. that.setData({
  54. hide: false,
  55. userInfo,
  56. order_id
  57. })
  58. setTimeout(() => {
  59. that.setData({ hide: true });
  60. }, 5000)
  61. } else {
  62. !that.data.hide && setTimeout(() => {
  63. that.setData({ hide: true });
  64. }, 5000)
  65. }
  66. }
  67. }
  68. })
  69. }
  70. }
  71. })