activePage2.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. // pages/activePage2/activePage2.js
  2. import {
  3. get,
  4. post
  5. } from "../../utils/http";
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 分类按钮图片
  12. classifyList: [
  13. ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%2010%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%205%402x.png'],
  14. ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%204%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%206%402x.png'],
  15. ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%2013%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%207%402x.png'],
  16. ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%203%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%208%402x.png'],
  17. ['https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%402x.png', 'https://we-spa.oss-cn-shenzhen.aliyuncs.com/wxapp/20220901/%E5%B0%8F%E5%9B%BE%E6%A0%87/%E6%9C%AA%E9%80%89%E4%B8%AD%E5%A4%87%E4%BB%BD%209%402x.png']
  18. ],
  19. tabIndex: 0, //项目类别下标
  20. activityList: [], //活动界面数据列表
  21. store_id: '', //店铺id
  22. couponType: ['抵扣券', '满减券', '全额减免券', '卡券'], //优惠券类型
  23. swiperIndex: 0, //次卡活动轮播图下标
  24. goodsList: [], //美妆产品商品列表
  25. groupList:'',// 拼团列表
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. // 获取店铺id
  32. this.setData({
  33. store_id: wx.getStorageSync('store_id')
  34. })
  35. // 获取活动页面数据
  36. this.getActivityList()
  37. // 获取拼团列表
  38. this.getGroupList()
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady() {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow() {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide() {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload() {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh() {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom() {
  69. },
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage() {
  74. },
  75. // 获取商品活动轮播图下标
  76. onSlideChangeEnd() {
  77. },
  78. // 切换项目类别下标来切换图标
  79. changeTab(e) {
  80. this.setData({
  81. tabIndex: e.currentTarget.dataset.index
  82. })
  83. },
  84. // 获取活动页面数据列表
  85. getActivityList() {
  86. get('/v2/api/activity', {
  87. store_id: this.data.store_id
  88. }, res => {
  89. if (res.code == 200) {
  90. // 将商品列表商品单独加到数组里
  91. let arr = []
  92. let goodsList = res.data.goods[0].list
  93. goodsList.map(item1 => {
  94. arr.push(item1)
  95. })
  96. // 将商品两两分组
  97. let index = 0;
  98. const newArray = [];
  99. while (index < arr.length) {
  100. newArray.push(arr.slice(index, (index += 2)));
  101. }
  102. // 判断最后一个元素是否只有一个元素 是的话就将第一个元素加进去
  103. if (newArray[newArray.length - 1].length == 1) {
  104. newArray[newArray.length - 1].push(arr[0])
  105. }
  106. // 处理新人领券价格去掉00
  107. res.data.new_user.map(item => {
  108. item.price = Number(item.price)
  109. item.full_price = Number(item.full_price)
  110. })
  111. this.setData({
  112. activityList: res.data,
  113. goodsList: newArray
  114. })
  115. }
  116. })
  117. },
  118. // 商品活动轮播图改变
  119. changeGoodsList(e) {
  120. // 获取轮播图下标
  121. let index1 = e.detail.current
  122. let arr = []
  123. let goodsList = this.data.activityList.goods[index1].list
  124. goodsList.map(item1 => {
  125. arr.push(item1)
  126. })
  127. // 将商品两两分组
  128. let index = 0;
  129. const newArray = [];
  130. while (index < arr.length) {
  131. newArray.push(arr.slice(index, (index += 2)));
  132. }
  133. // 判断最后一个元素是否只有一个元素 是的话就将第一个元素加进去
  134. if (newArray[newArray.length - 1].length == 1) {
  135. newArray[newArray.length - 1].push(arr[0])
  136. }
  137. this.setData({
  138. goodsList: newArray
  139. })
  140. },
  141. // 新人活动优惠券立即使用跳转到我的优惠券
  142. useCoupon(e) {
  143. // 判断是否是新人优惠券不是的话就跳转到领券中心,是的话跳转到优惠券列表
  144. let couponName = e.currentTarget.dataset.item.name
  145. if (couponName.indexOf("新人") != -1) {
  146. wx.navigateTo({
  147. url: '/pages/coupon/coupon',
  148. })
  149. } else {
  150. wx.navigateTo({
  151. url: '/pages/couponCenter/couponCenter',
  152. })
  153. }
  154. },
  155. // 项目活动跳转到项目详情
  156. projectDetail(e) {
  157. let id = e.currentTarget.dataset.id
  158. wx.navigateTo({
  159. url: `/pages/projectDetail/projectDetail?source=project&id=${id}&store_id=${this.data.store_id}`,
  160. })
  161. },
  162. // 跳转到商品活动商品详情
  163. productDetail(e) {
  164. let id = e.currentTarget.dataset.id
  165. wx.navigateTo({
  166. url: `/pages/projectDetail/projectDetail?source=goods&id=${id}&store_id=${this.data.store_id}`,
  167. })
  168. },
  169. // 跳转到此卡活动商品详情
  170. cardDetail(e) {
  171. let id = e.currentTarget.dataset.id
  172. let index = e.currentTarget.dataset.index
  173. if(index==3){
  174. wx.navigateTo({
  175. url: '/subPackagesB/pages/groupDetail/groupDetail?id=36',
  176. })
  177. return
  178. }
  179. wx.navigateTo({
  180. url: `/pages/projectDetail/projectDetail?source=secondaryCard&id=${id}&store_id=${this.data.store_id}`,
  181. })
  182. },
  183. // 轮播图改变
  184. changeSwiper(e) {
  185. this.setData({
  186. swiperIndex: e.detail.current
  187. })
  188. },
  189. // 跳转到美妆商品列表
  190. toGoodsList() {
  191. // var app = getApp()
  192. // app.globalData.showGoods = true
  193. wx.reLaunch({
  194. url: '/pages/shoppingMall/shoppingMall',
  195. // success: function (e) {
  196. // var page = getCurrentPages().pop();
  197. // console.log("page", page)
  198. // if (page == undefined || page == null) return;
  199. // page.onPullDownRefresh();
  200. // }
  201. })
  202. },
  203. // 跳转到老送新优惠券
  204. gotoSendCoupon() {
  205. wx.navigateTo({
  206. url: '/pages/sendFriend/sendFriend',
  207. })
  208. },
  209. // 跳转到我的储值页面
  210. toStoreValue() {
  211. wx.navigateTo({
  212. url: '/pages/storedValue/index',
  213. })
  214. },
  215. // 跳转到拼团
  216. goGroup() {
  217. if(this.data.groupList.card_list.length==0&&this.data.groupList.goods_list.length==0){
  218. wx.showToast({
  219. title: '活动已结束',
  220. icon:"none"
  221. })
  222. return
  223. }else{
  224. wx.navigateTo({
  225. url: '/subPackagesB/pages/joinGroup/joinGroup',
  226. })
  227. }
  228. },
  229. // 超过时间拼团结束
  230. getGroupList() {
  231. get('v2/api/grouping/list', {
  232. store_id: this.data.store_id || wx.getStorageSync('store_id')
  233. }, (res) => {
  234. if (res.code == 200) {
  235. this.setData({
  236. groupList: res.data
  237. })
  238. }
  239. })
  240. },
  241. })