integral.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. },
  22. /**
  23. * 生命周期函数--监听页面初次渲染完成
  24. */
  25. onReady: function () {
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow: function () {
  31. this.getBannerList()
  32. this.getCouponList()
  33. },
  34. /**
  35. * 生命周期函数--监听页面隐藏
  36. */
  37. onHide: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. getBannerList: function() {
  60. Integralinfo.getBannerList({
  61. channelid: this.data.channelid,
  62. shopid: this.data.shopid,
  63. storeid: this.data.storeid
  64. }).then(res => {
  65. console.log(res.data)
  66. this.setData({
  67. bannerList: res.data
  68. })
  69. }).catch(err => {
  70. console.log(err)
  71. })
  72. },
  73. getCouponList: function() {
  74. Integralinfo.getList({
  75. channelid: this.data.channelid,
  76. shopid: this.data.shopid,
  77. storeid: this.data.storeid
  78. }).then(res => {
  79. this.couponListView(res.data)
  80. this.data.lock = false
  81. }).catch(_ => {
  82. console.log(_)
  83. this.data.lock = false
  84. })
  85. },
  86. couponListView: function(data) {
  87. if (!Array.isArray(data) || data.length == 0) {
  88. console.log("优惠券列表数据为空");
  89. }
  90. data.forEach((v) => {
  91. v.quantity = 0
  92. v.integral = v.price * v.ratio
  93. })
  94. if (this.mobile != '********') {
  95. let num = this.integralNum > 20000 ? 19999 : this.integralNum
  96. const arr = []
  97. for (let i = 0; i < data.length; i++) {
  98. data[i].quantity = parseInt(num / data[i].integral)
  99. if (data[i].quantity > 0) {
  100. num -= (data[i].quantity * data[i].price) * data[i].ratio
  101. this.total += (data[i].quantity * data[i].price) * data[i].ratio
  102. arr.push(data[i])
  103. data.splice(i, 1)
  104. i--
  105. }
  106. }
  107. this.setData({
  108. couponList: [...arr, ...data]
  109. })
  110. console.log(this.data.couponList)
  111. }
  112. }
  113. })