index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /**
  23. * 组件的方法列表
  24. */
  25. methods: {
  26. _startReq: function(){
  27. var that = this;
  28. ctime = setInterval(function(){
  29. that.getOrderNotify();
  30. }, 3000);
  31. },
  32. getOrderNotify: function (){
  33. let that = this;
  34. app.util.request({
  35. 'url': 'entry/wxapp/index',
  36. 'data': {
  37. controller: 'goods.notify_order'
  38. },
  39. dataType: 'json',
  40. success: function (res) {
  41. if (res.data.code == 0) {
  42. let username = res.data.username;
  43. let avatar = res.data.avatar;
  44. let order_id = res.data.order_id;
  45. let userInfo = { username, avatar }
  46. if (that.data.order_id != order_id){
  47. that.setData({
  48. hide: false,
  49. userInfo,
  50. order_id
  51. })
  52. setTimeout(() => {
  53. that.setData({ hide: true });
  54. }, 5000)
  55. } else {
  56. !that.data.hide && setTimeout(() => {
  57. that.setData({ hide: true });
  58. }, 5000)
  59. }
  60. }
  61. }
  62. })
  63. }
  64. }
  65. })