cardBag.js 5.0 KB

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