index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. var app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. info: '',
  8. list: [],
  9. showSharePopup: true,
  10. needAuth: false,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.getData();
  17. this.getInvitelist();
  18. },
  19. onPullDownRefresh() {
  20. this.getData();
  21. this.getInvitelist();
  22. },
  23. getData() {
  24. wx.showLoading();
  25. let token = wx.getStorageSync('token');
  26. app.util.ProReq('invitegift.index', {token})
  27. .then(res=>{
  28. wx.stopPullDownRefresh();
  29. this.setData({
  30. info: res.data
  31. }, ()=>{
  32. this.drawImg(res.data);
  33. });
  34. // this.onRender(res.data);
  35. })
  36. .catch(err=>{
  37. wx.stopPullDownRefresh();
  38. app.util.message(err.msg, 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  39. // if(err.code==1&&err.msg=='未登录') {
  40. // this.setData({
  41. // needAuth: true,
  42. // showAuthModal: true
  43. // })
  44. // }
  45. })
  46. },
  47. getInvitelist() {
  48. let token = wx.getStorageSync('token');
  49. app.util.ProReq('invitegift.getInvitegiftRecord', { token, page:1, type: 'invite'})
  50. .then(res=>{
  51. this.setData({
  52. list: res.data
  53. });
  54. })
  55. },
  56. goLink: function(event) {
  57. let link = event.currentTarget.dataset.link;
  58. var pages_all = getCurrentPages();
  59. if (pages_all.length > 3) {
  60. wx.redirectTo({
  61. url: link
  62. })
  63. } else {
  64. wx.navigateTo({
  65. url: link
  66. })
  67. }
  68. },
  69. checkInvitegift() {
  70. let token = wx.getStorageSync('token');
  71. wx.showLoading();
  72. app.util.ProReq('invitegift.checkInvitegift', {token})
  73. .then(res=>{
  74. wx.hideLoading();
  75. this.setData({ showSharePopup: false })
  76. }).catch(err=>{
  77. wx.hideLoading();
  78. wx.showModal({
  79. content: err.msg,
  80. showCancel: false
  81. })
  82. })
  83. },
  84. hide_share_handler: function () {
  85. this.setData({
  86. showSharePopup: !this.data.showSharePopup
  87. })
  88. },
  89. drawImg: function (info) {
  90. let {
  91. invite_poster_back_type,
  92. invite_poster_back_color,
  93. invite_poster_back_img,
  94. invite_poster_qrcode_img,
  95. invite_poster_qrcode_size,
  96. invite_poster_qrcode_top,
  97. invite_poster_qrcode_left,
  98. invite_poster_qrcode_border_status,
  99. invite_poster_qrcode_corner_type,
  100. invite_poster_qrcode_bordercolor
  101. } = info;
  102. let background = '#FFFFFF';
  103. let data = [];
  104. if(invite_poster_back_type==0) {
  105. background = invite_poster_back_color;
  106. } else {
  107. let bgImg = {
  108. type: 'image',
  109. url: invite_poster_back_img,
  110. css: {
  111. left: '0px',
  112. top: '0px',
  113. mode: 'widthFix',
  114. width: '750px',
  115. height: '1334px'
  116. }
  117. }
  118. data.push(bgImg);
  119. }
  120. let poster = {
  121. width: '750px',
  122. height: '1334px',
  123. background,
  124. views: [
  125. ...data,
  126. {
  127. type: 'image',
  128. url: invite_poster_qrcode_img,
  129. mode: 'widthFix',
  130. css: {
  131. left: invite_poster_qrcode_left + 'px',
  132. top: invite_poster_qrcode_top + 'px',
  133. width: invite_poster_qrcode_size + 'px',
  134. height: invite_poster_qrcode_size + 'px',
  135. radius: invite_poster_qrcode_corner_type==0?'10px':'0px',
  136. border: invite_poster_qrcode_border_status==1?`1px solid ${invite_poster_qrcode_bordercolor}`:'none'
  137. }
  138. }
  139. ]
  140. };
  141. console.log(poster);
  142. this.setData({
  143. template: poster
  144. });
  145. },
  146. onImgOK(e) {
  147. this.imagePath = e.detail.path;
  148. this.setData({
  149. image: this.imagePath
  150. })
  151. },
  152. saveImage() {
  153. let that = this;
  154. wx.saveImageToPhotosAlbum({
  155. filePath: this.imagePath,
  156. success(res) {
  157. that.setData({ showShareModal: false })
  158. wx.showToast({
  159. title: '保存成功!'
  160. })
  161. },
  162. fail(res) {
  163. wx.showToast({
  164. title: '保存失败,请重试!',
  165. icon: 'none'
  166. })
  167. }
  168. });
  169. },
  170. handleShareModal: function () {
  171. this.setData({
  172. showSharePopup: true,
  173. showShareModal: !this.data.showShareModal
  174. })
  175. },
  176. handleTipModal(e) {
  177. var type = e.currentTarget.dataset.type;
  178. let tip = {
  179. wait: '被邀请人的订单在售后期内,需要等待售后期结束才能获得活动奖励',
  180. invalid: '被邀请人的订单在售后期内发生退款,需要被邀请人重新下单才可获得奖励',
  181. };
  182. wx.showModal({
  183. title: '提示',
  184. content: tip[type],
  185. showCancel: false
  186. })
  187. },
  188. /**
  189. * 用户点击右上角分享
  190. */
  191. onShareAppMessage: function (options) {
  192. let { invite_share_title, invite_share_img, suid, invite_order_share_title, invite_order_share_img } = this.data.info;
  193. var community = wx.getStorageSync('community');
  194. var community_id = community.communityId;
  195. let title = invite_share_title;
  196. let imageUrl = invite_share_img;
  197. let path = "lionfish_comshop/moduleB/invite/share?community_id=" + community_id + '&share_id=' + suid;
  198. if( options && options.target && options.target.dataset.name == 'invite' ){
  199. path = "lionfish_comshop/pages/index/index?community_id=" + community_id + '&share_id=' + suid;
  200. title = invite_order_share_title;
  201. imageUrl = invite_order_share_img;
  202. }
  203. return {
  204. title,
  205. path,
  206. imageUrl,
  207. success: function() {},
  208. fail: function() {}
  209. };
  210. }
  211. })