shareDialog.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. mini_code:'',
  58. share_code:'',
  59. showRCode:false
  60. },
  61. pageLifetimes: {
  62. // 组件所在页面的生命周期函数
  63. show: function () {
  64. console.log('pageLifetimes show goods_id = ', this.properties.goods_id)
  65. },
  66. hide: function () {
  67. console.log('pageLifetimes hide goods_id = ', this.properties.goods_id)
  68. },
  69. resize: function () { },
  70. },
  71. lifetimes: {
  72. attached: function () {
  73. console.log('lifetimes attached')
  74. wx.getSetting({
  75. withSubscriptions: true,
  76. success(res) {
  77. var itemSettings = res.subscriptionsSetting.itemSettings
  78. console.log('setting:', itemSettings)
  79. // if (itemSettings) {
  80. // if (itemSettings['模版id'] === 'accept') {
  81. // }
  82. // }
  83. }
  84. })
  85. },
  86. detached: function () {
  87. },
  88. },
  89. /**
  90. * 组件的方法列表
  91. */
  92. methods: {
  93. onCloseDialog() {
  94. wx.requestSubscribeMessage({
  95. tmplIds: ['zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA'],
  96. success(res) {
  97. console.log(res)
  98. }
  99. })
  100. console.log('onCloseDialog');
  101. this.triggerEvent('closeDialog', {})
  102. },
  103. onShareInfo() {
  104. console.log('onShareInfo');
  105. this.triggerEvent('onShareInfo', {})
  106. },
  107. onShareFriends() {
  108. console.log('onShareFriends');
  109. let self = this;
  110. app.writePhotosAlbum(function () {
  111. console.log('starting image ...');
  112. var imgSrc = self.data.share_code
  113. if (imgSrc == '') {
  114. return;
  115. }
  116. wx.showLoading();
  117. wx.downloadFile({
  118. url: imgSrc,
  119. success: function (res) {
  120. console.log(res);
  121. wx.saveImageToPhotosAlbum({
  122. filePath: res.tempFilePath,
  123. success: function (data) {
  124. wx.hideLoading();
  125. wx.showModal({
  126. title: '分享到朋友圈图片已经保存到相册',
  127. confirmText: "知道了",
  128. showCancel: false,
  129. success: function (res) {
  130. console.log();
  131. }
  132. })
  133. },
  134. fail: function (err) {
  135. wx.hideLoading();
  136. console.log(err);
  137. }
  138. });
  139. }
  140. });
  141. });
  142. },
  143. requestData(goods_id) {
  144. console.log('requestData goods_id=', goods_id)
  145. if (this.fGoodsRequesting) return;
  146. this.fGoodsRequesting = true
  147. getReq(app, {
  148. act: 'member_invitee',
  149. op: 'goods_share',
  150. goods_id: goods_id,
  151. }, (res) => {
  152. console.log('res:', res)
  153. if (res.code == 200) {
  154. if (res.datas) {
  155. let invitess = res.datas.invitess
  156. let policy = res.datas.policy
  157. let tip_title = res.datas.tip_title
  158. let tip_num = res.datas.tip_num
  159. let mini_code = res.datas.mini_code;
  160. let share_code = res.datas.share_code;
  161. this.setData({ tip_title, tip_num, invitess, policy, mini_code, share_code})
  162. }
  163. }
  164. this.fGoodsRequesting = false;
  165. })
  166. },
  167. onShareFace() {
  168. this.setData({ showRCode: true })
  169. },
  170. onCloseMiniDialog() {
  171. console.log('share dialog,onCloseMiniDialog')
  172. this.setData({ showRCode: false })
  173. }
  174. }
  175. })