shareDialog.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/components/shareDialog/shareDialog.js
  2. const getReq = require('../../../config').getReq;
  3. let app = getApp();
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. showDialog:{
  10. type:Boolean,
  11. value:false,
  12. observer:function(newVal,oldVal){
  13. console.log(newVal);
  14. const _self = this;
  15. const parmas = this.properties;
  16. if(newVal == true) {
  17. _self.getDataTimer = setInterval(function(){
  18. let goods_id = parmas.goods_id
  19. if(goods_id > 0) {
  20. _self.requestData(goods_id);
  21. }
  22. },5000)
  23. }
  24. else {
  25. if(_self.getDataTimer) {
  26. clearInterval(this.getDataTimer)
  27. }
  28. }
  29. }
  30. },
  31. goods_id: {
  32. type: Number,
  33. observer() {
  34. console.log('observer goods_id = ', this.properties.goods_id)
  35. let goods_id = this.properties.goods_id
  36. if(goods_id > 0) {
  37. this.requestData(goods_id);
  38. this.setData({shareModel: app.cardShareInfo()})
  39. }
  40. else {
  41. }
  42. }
  43. }
  44. },
  45. /**
  46. * 组件的初始数据
  47. */
  48. data: {
  49. current_goodsid:0,
  50. fGoodsRequesting: false,
  51. tip:'',
  52. invitess:[],
  53. policy:[],
  54. tip_title:'',
  55. tip_num:0,
  56. shareModel:{}
  57. },
  58. pageLifetimes: {
  59. // 组件所在页面的生命周期函数
  60. show: function () {
  61. console.log('pageLifetimes show goods_id = ', this.properties.goods_id)
  62. },
  63. hide: function () {
  64. console.log('pageLifetimes hide goods_id = ', this.properties.goods_id)
  65. },
  66. resize: function () { },
  67. },
  68. lifetimes: {
  69. attached: function () {
  70. console.log('lifetimes attached')
  71. wx.getSetting({
  72. withSubscriptions: true,
  73. success(res) {
  74. var itemSettings = res.subscriptionsSetting.itemSettings
  75. console.log('setting:', itemSettings)
  76. // if (itemSettings) {
  77. // if (itemSettings['模版id'] === 'accept') {
  78. // }
  79. // }
  80. }
  81. })
  82. },
  83. detached: function () {
  84. },
  85. },
  86. /**
  87. * 组件的方法列表
  88. */
  89. methods: {
  90. onCloseDialog() {
  91. wx.requestSubscribeMessage({
  92. tmplIds: ['zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA'],
  93. success(res) {
  94. console.log(res)
  95. }
  96. })
  97. console.log('onCloseDialog');
  98. this.triggerEvent('closeDialog', {})
  99. },
  100. onShareInfo(){
  101. console.log('onShareInfo');
  102. this.triggerEvent('onShareInfo', {})
  103. },
  104. requestData(goods_id)
  105. {
  106. console.log('requestData goods_id=',goods_id)
  107. if (this.fGoodsRequesting) return;
  108. this.fGoodsRequesting = true
  109. getReq(app, {
  110. act: 'member_invitee',
  111. op: 'goods_share',
  112. goods_id: goods_id,
  113. }, (res) => {
  114. console.log('res:', res)
  115. if (res.code == 200) {
  116. if (res.datas) {
  117. let invitess = res.datas.invitess
  118. let policy = res.datas.policy
  119. let tip_title = res.datas.tip_title
  120. let tip_num = res.datas.tip_num
  121. this.setData({ tip_title,tip_num,invitess, policy })
  122. }
  123. }
  124. this.fGoodsRequesting = false
  125. })
  126. }
  127. }
  128. })