C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
3.7 KiB

  1. // pages/spellGroup/mySpellGroup/index.js
  2. var config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. const imgurl = require("../../../utils/imgurl");
  5. const utils = require("../../../utils/util.js")
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. teljpgUrl: imgurl.teljpg.url,
  12. wmhome: imgurl.wmhome.url,
  13. couponChannelId: '',
  14. couponId: '',
  15. data: null,
  16. spellData: null,
  17. canSpell: true,
  18. canBuyIf: true,
  19. clock: "00",
  20. day: "00",
  21. hour: "00",
  22. min: "00",
  23. sec: "00",
  24. showTime: true
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. this.setData({
  31. couponChannelId: options.couponChannelId,
  32. couponId: options.couponId
  33. })
  34. if (options && options.couponChannelId) {
  35. this.getDetail(options.couponChannelId);
  36. }
  37. },
  38. gotoIndex: function () {
  39. wx.switchTab({
  40. url: '/pages/main/index',
  41. })
  42. },
  43. /**
  44. * 拨打电话
  45. */
  46. phone: function (e) {
  47. let that = this;
  48. wx.makePhoneCall({
  49. phoneNumber: e.target.dataset.merchantlinkphone
  50. });
  51. },
  52. /**
  53. * 直接购买
  54. */
  55. gotoBuy(e) {
  56. console.log(22222)
  57. this.setData({
  58. canBuyIf: false,
  59. formId: e.detail.formId
  60. })
  61. wx.navigateTo({
  62. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + this.data.couponChannelId + '&couponId=' + this.data.couponId,
  63. })
  64. },
  65. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  66. dateformat(micro_second) {
  67. // 总秒数
  68. var second = Math.floor(micro_second / 1000);
  69. // 天数
  70. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  71. // 小时
  72. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  73. // 分钟
  74. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  75. // 秒
  76. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  77. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  78. return {
  79. a1: day,
  80. b1: hr,
  81. c1: min,
  82. d1: sec
  83. }
  84. },
  85. /**
  86. * 获取券详情信息
  87. */
  88. getDetail(couponChannelId) {
  89. let that = this;
  90. Http.get({
  91. url: config.api.couponDetail,
  92. data: {
  93. couponChannelId: couponChannelId
  94. }
  95. }).then(res => {
  96. wx.stopPullDownRefresh();
  97. let data = res.data;
  98. data.price = (data.price / 100).toFixed(2)
  99. data.salePrice = (data.salePrice / 100).toFixed(2);
  100. data.validStartDate = utils.formatTime(data.validStartDate, 'yyyy-MM-dd')
  101. data.validEndDate = utils.formatTime(data.validEndDate, 'yyyy-MM-dd')
  102. that.setData({
  103. data
  104. });
  105. });
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow: function () {
  116. this.setData({
  117. canSpell: true,
  118. canBuyIf: true,
  119. showTime: true
  120. })
  121. if (this.data.spellData != null) {
  122. this.countdown()
  123. }
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. this.setData({
  130. showTime: false
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. this.setData({
  138. showTime: false
  139. })
  140. },
  141. /**
  142. * 页面相关事件处理函数--监听用户下拉动作
  143. */
  144. onPullDownRefresh: function (e) {
  145. let that = this;
  146. that.getDetail(that.data.couponChannelId);
  147. },
  148. /**
  149. * 页面上拉触底事件的处理函数
  150. */
  151. onReachBottom: function () {
  152. }
  153. })