integral.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // pages/integral/integral.js
  2. import Integralinfo from '../../api/integralinfo'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. lock: false,
  9. noResult: false,
  10. noMore: false,
  11. bannerList: [],
  12. couponList: [],
  13. channelid: '',
  14. shopid: '',
  15. storeid: '',
  16. bodyHidden: true,
  17. bgStatus: false,
  18. scorePhone: false,
  19. animationData: {},
  20. integralIngo:{},
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. },
  27. /**
  28. * 生命周期函数--监听页面初次渲染完成
  29. */
  30. onReady: function () {
  31. },
  32. /**
  33. * 生命周期函数--监听页面显示
  34. */
  35. onShow: function () {
  36. this.getBannerList()
  37. this.getCouponList()
  38. },
  39. /**
  40. * 生命周期函数--监听页面隐藏
  41. */
  42. onHide: function () {
  43. },
  44. /**
  45. * 生命周期函数--监听页面卸载
  46. */
  47. onUnload: function () {
  48. },
  49. /**
  50. * 页面相关事件处理函数--监听用户下拉动作
  51. */
  52. onPullDownRefresh: function () {
  53. },
  54. /**
  55. * 页面上拉触底事件的处理函数
  56. */
  57. onReachBottom: function () {
  58. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. },
  64. getBannerList: function() {
  65. Integralinfo.getBannerList({
  66. channelid: this.data.channelid,
  67. shopid: this.data.shopid,
  68. storeid: this.data.storeid
  69. }).then(res => {
  70. console.log(res.data)
  71. this.setData({
  72. bannerList: res.data
  73. })
  74. }).catch(err => {
  75. console.log(err)
  76. })
  77. },
  78. getCouponList: function() {
  79. Integralinfo.getList({
  80. channelid: this.data.channelid,
  81. shopid: this.data.shopid,
  82. storeid: this.data.storeid
  83. }).then(res => {
  84. this.couponListView(res.data)
  85. this.data.lock = false
  86. }).catch(_ => {
  87. console.log(_)
  88. this.data.lock = false
  89. })
  90. },
  91. couponListView: function(data) {
  92. if (!Array.isArray(data) || data.length == 0) {
  93. console.log("优惠券列表数据为空");
  94. }
  95. data.forEach((v) => {
  96. v.quantity = 0
  97. v.integral = v.price * v.ratio
  98. })
  99. if (this.mobile != '********') {
  100. let num = this.integralNum > 20000 ? 19999 : this.integralNum
  101. const arr = []
  102. for (let i = 0; i < data.length; i++) {
  103. data[i].quantity = parseInt(num / data[i].integral)
  104. if (data[i].quantity > 0) {
  105. num -= (data[i].quantity * data[i].price) * data[i].ratio
  106. this.total += (data[i].quantity * data[i].price) * data[i].ratio
  107. arr.push(data[i])
  108. data.splice(i, 1)
  109. i--
  110. }
  111. }
  112. this.setData({
  113. couponList: [...arr, ...data]
  114. })
  115. console.log(this.data.couponList)
  116. }
  117. },
  118. // 点击标识点触发
  119. detailsClick(row) {
  120. this.hideModal();
  121. this.row = row.currentTarget.dataset.info
  122. console.log(this.row)
  123. if (this.row.detail_type === 0) {
  124. this.row.detailArr = this.row.detail.split('\n')
  125. } else {
  126. this.row.detailArr = row.detail
  127. }
  128. this.setData({
  129. integralIngo: this.row,
  130. })
  131. console.log(this.data.integralIngo)
  132. setTimeout(() => {
  133. this.showDodal();
  134. }, 100)
  135. },
  136. showDodal() {
  137. var that = this;
  138. // 显示遮罩层
  139. var animation = wx.createAnimation({
  140. duration: 150,
  141. timingFunction: "linear",
  142. delay: 0
  143. })
  144. this.setData({
  145. bgStatus: true,
  146. bodyHidden: false
  147. })
  148. that.animation = animation
  149. animation.translateY(-500).step()
  150. that.setData({
  151. animationData: animation.export()
  152. })
  153. },
  154. //隐藏对话框
  155. hideModal() {
  156. var that = this;
  157. console.log(that.data)
  158. // 隐藏遮罩层
  159. var animation = wx.createAnimation({
  160. duration: 150,
  161. timingFunction: "linear",
  162. delay: 0
  163. })
  164. this.setData({
  165. bodyHidden: true,
  166. bgStatus: false,
  167. scorePhone: false,
  168. })
  169. that.animation = animation
  170. animation.translateY(0).step()
  171. that.setData({
  172. animationData: animation.export()
  173. })
  174. },
  175. })