activityInfo.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const { default: activity } = require("../../api/activity");
  2. import drawQrcode from '../../utils/weapp.qrcode.js'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. activityId:0, //活动id
  9. userMobile:'', //电话
  10. codeId:'',//code唯一码
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. console.log('接受参数');
  17. console.log(options);
  18. let _self = this;
  19. if(options.id){
  20. this.activityInfo(options.id)
  21. _self.activityId = options.id;
  22. }
  23. //用户手机
  24. if(options.mobile) {
  25. _self.userMobile = options.mobile;
  26. }
  27. if(_self.activityId!=0 && _self.userMobile!='') {
  28. //获取code
  29. _self.getCode()
  30. }
  31. },
  32. /**
  33. * 生命周期函数--监听页面初次渲染完成
  34. */
  35. onReady: function () {
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面卸载
  49. */
  50. onUnload: function () {
  51. },
  52. /**
  53. * 页面相关事件处理函数--监听用户下拉动作
  54. */
  55. onPullDownRefresh: function () {
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. onReachBottom: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. /**
  68. * 获取活动详细信息
  69. * @param {*} activityId
  70. */
  71. async activityInfo(activityId){
  72. let result = await activity.getActivityDetail(activityId);
  73. console.log('获取活动详细信息');
  74. console.log(result)
  75. var objSwitch = getApp().globalData.typeSwitchObj
  76. var couponTypeAndNumObj = {};
  77. var couponList = result.activityCouponList;
  78. for (let j = 0; j < couponList.length; j++) {
  79. var couponNum = couponList[j]['num'] ? couponList[j]['num'] : 1;
  80. var value = couponList[j]['coupon']['type'];
  81. var showText = objSwitch[couponList[j]['coupon']['type']];
  82. var nowNume = 0;
  83. if (couponTypeAndNumObj[value]) {
  84. nowNume = couponTypeAndNumObj[value]['num'];
  85. console.log(nowNume)
  86. }
  87. couponTypeAndNumObj[value] = {
  88. "typeText": showText,
  89. "num": couponNum + nowNume
  90. }
  91. }
  92. result.couponTypeAndNumObj = couponTypeAndNumObj
  93. this.setData({
  94. activityInfo:result
  95. })
  96. },
  97. /**
  98. * 获取分享码
  99. */
  100. async getCode() {
  101. let _self = this;
  102. let res = await activity.createShareActivityCode(_self.activityId,_self.userMobile);
  103. _self.codeId = res.codeId;
  104. //根据codeId 生成二维码
  105. drawQrcode({
  106. width: 200,
  107. height: 200,
  108. canvasId: 'myQrcode',
  109. // ctx: wx.createCanvasContext('myQrcode'),
  110. text: 'https://github.com/yingye',
  111. // v1.0.0+版本支持在二维码上绘制图片
  112. image: {
  113. imageResource: '../../images/logo.png',
  114. dx: 70,
  115. dy: 70,
  116. dWidth: 60,
  117. dHeight: 60
  118. }
  119. })
  120. }
  121. })