cardBag.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // pages/cardBag/cardBag.js
  2. import {
  3. get,
  4. post
  5. } from '../../../utils/http.js'
  6. const app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. current: 1,
  13. list: [],
  14. page: 1,
  15. limit: 50,
  16. total: 0,
  17. storeId: wx.getStorageSync('store_id'),
  18. couponType: ['抵扣券', '满减券', '全额减免', '卡券'], //卡券类型 优惠券类型,1直接抵扣券,2满减券,3全额减免券,4卡券
  19. couponList: [], //优惠券列表
  20. isExplain:false,//详情开关
  21. explainIndex:0,
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. this.setData({
  28. current:options.current
  29. })
  30. // 获取卡包列表
  31. this.getList()
  32. // 获取优惠券列表
  33. this.getCoupon()
  34. },
  35. /**
  36. * 切换状态
  37. */
  38. selectTab(e) {
  39. let current = e.currentTarget.dataset.current
  40. this.setData({
  41. current,
  42. page: 1,
  43. total: 0,
  44. couponList: [],
  45. list: [],
  46. })
  47. if (current == 1) {
  48. this.getList(1)
  49. } else {
  50. this.getCoupon(1)
  51. }
  52. },
  53. // 获取卡包列表
  54. getList(_page) {
  55. let {
  56. page,
  57. limit,
  58. current,
  59. list
  60. } = this.data
  61. get('v2/api/user/card/list', {
  62. page: _page || page,
  63. limit,
  64. type: 0
  65. }, (res) => {
  66. if (_page == 1 || page == 1) {
  67. list = []
  68. this.data.page = 1
  69. }
  70. list.push(...res.data.list)
  71. this.setData({
  72. list,
  73. total: res.data.total
  74. })
  75. })
  76. },
  77. /**
  78. * 获取优惠券列表
  79. * /api/user/coupon
  80. */
  81. getCoupon(_page) {
  82. let {
  83. couponList,
  84. page
  85. } = this.data
  86. get(
  87. 'v2/api/user/coupon/list', {
  88. type: 'project',
  89. page: _page || page,
  90. limit: 10
  91. },
  92. (res) => {
  93. if (_page == 1 || page == 1) {
  94. couponList = []
  95. this.data.page = 1
  96. }
  97. couponList.push(...res.data.list)
  98. this.setData({
  99. couponList,
  100. total: res.data.total
  101. })
  102. }
  103. )
  104. },
  105. /**
  106. * 使用优惠券
  107. */
  108. goToOrderBy(e) {
  109. let coupon_range = e.currentTarget.dataset.item.coupon_range
  110. let project_id = e.currentTarget.dataset.item.project_id
  111. if (coupon_range == 3) {
  112. wx.switchTab({
  113. url: "/pages/shoppingMall/shoppingMall"
  114. })
  115. }else if(coupon_range == 1){
  116. if(project_id==0){
  117. wx.switchTab({
  118. url: '/pages/orderBy/orderBy',
  119. })
  120. }else{
  121. wx.navigateTo({
  122. url: `/pages/projectDetail/projectDetail?source=project&id=${project_id}`,
  123. })
  124. }
  125. }else{
  126. wx.switchTab({
  127. url: '/pages/orderBy/orderBy',
  128. })
  129. }
  130. wx.setStorageSync('curre', 1)
  131. },
  132. // 下拉触底触发
  133. toLower() {
  134. if (this.data.list.length < this.data.total) {
  135. // 获取卡包列表
  136. this.getList(++this.data.page)
  137. }
  138. },
  139. // 跳转到次卡详情
  140. jumpCard(e) {
  141. let id = e.currentTarget.dataset.id
  142. let status = e.currentTarget.dataset.status
  143. if(status==-1){
  144. wx.showToast({
  145. title: '次卡已过期',
  146. icon:'none'
  147. })
  148. return
  149. }
  150. if(status==0){
  151. wx.showToast({
  152. title: '次卡已使用',
  153. icon:'none'
  154. })
  155. return
  156. }
  157. if(status==-2){
  158. wx.showToast({
  159. title: '次卡已注销',
  160. icon:'none'
  161. })
  162. return
  163. }
  164. wx.navigateTo({
  165. url: `/subPackages/pages/subCardDetails/subCardDetails?source=project&id=${id}&store_id=${this.data.storeId}`,
  166. })
  167. },
  168. // 跳转到项目详情
  169. jumpProject(e) {
  170. let project_id = e.currentTarget.dataset.project_id
  171. let id = e.currentTarget.dataset.id
  172. if (project_id == 0) {
  173. wx.navigateTo({
  174. url: `/subPackages/pages/subCardDetails/subCardDetails?source=project&id=${id}&store_id=${this.data.storeId}`,
  175. })
  176. return
  177. }
  178. wx.navigateTo({
  179. url: `/pages/projectDetail/projectDetail?source=project&id=${project_id}&store_id=${this.data.storeId}`,
  180. })
  181. },
  182. // 跳转到历史记录页面
  183. jumpHis() {
  184. if (this.data.current == 1) {
  185. wx.navigateTo({
  186. url: `/subPackages/pages/couponHistory/couponHistory`,
  187. })
  188. } else {
  189. wx.navigateTo({
  190. url: `/pages/couponHistory/couponHistory`,
  191. })
  192. }
  193. },
  194. // 跳转到更多
  195. goMoreCard() {
  196. app.globalData.isCardBag = true
  197. wx.redirectTo({
  198. url: '/pages/shoppingMall/shoppingMall',
  199. })
  200. },
  201. // 打开次卡说明
  202. openExplain(e){
  203. this.setData({
  204. isExplain:!this.data.isExplain,
  205. explainIndex:e.currentTarget.dataset.index
  206. })
  207. },
  208. /**
  209. * 生命周期函数--监听页面初次渲染完成
  210. */
  211. onReady() {
  212. },
  213. /**
  214. * 生命周期函数--监听页面显示
  215. */
  216. onShow() {
  217. },
  218. /**
  219. * 生命周期函数--监听页面隐藏
  220. */
  221. onHide() {
  222. },
  223. /**
  224. * 生命周期函数--监听页面卸载
  225. */
  226. onUnload() {
  227. },
  228. /**
  229. * 页面相关事件处理函数--监听用户下拉动作
  230. */
  231. onPullDownRefresh() {
  232. },
  233. /**
  234. * 页面上拉触底事件的处理函数
  235. */
  236. onReachBottom() {
  237. if (this.data.page * 10 < this.data.total) {
  238. this.getCoupon(++this.data.page)
  239. }
  240. },
  241. /**
  242. * 用户点击右上角分享
  243. */
  244. onShareAppMessage() {
  245. }
  246. })