index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <!-- 我的有优惠券模块 -->
  3. <view :style="colorStyle">
  4. <view class="navbar acea-row row-around">
  5. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 1 }" @click="onNav(1)">未使用</view>
  6. <view class="item acea-row row-center-wrapper" :class="{ on: navOn === 2 }" @click="onNav(2)">已使用/过期</view>
  7. </view>
  8. <view class='coupon-list' v-if="couponsList.length">
  9. <view class='item acea-row row-center-wrapper' v-for='(item,index) in couponsList' :key="index"
  10. :class="{svip: item.receive_type === 4}" @click="useCoupon(item)">
  11. <view class="moneyCon acea-row row-center-wrapper">
  12. <view class='money' :class='item._type == 0 ? "moneyGray" : ""'>
  13. <view><text v-if="item.coupon_type==1">¥</text><text class='num'>{{item.coupon_type==1?item.coupon_price:parseFloat(item.coupon_price)/10}}</text><text v-if="item.coupon_type==2">折</text></view>
  14. <view class="pic-num" v-if="item.use_min_price > 0">满{{item.use_min_price}}元可用</view>
  15. <view class="pic-num" v-else>无门槛券</view>
  16. </view>
  17. </view>
  18. <view class='text'>
  19. <view class='condition'>
  20. <view class="name line2">
  21. <view class="line-title acea-row row-center-wrapper" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  22. v-if="item.applicable_type === 0">通用券</view>
  23. <view class="line-title acea-row row-center-wrapper" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  24. v-else-if="item.applicable_type === 1">品类券</view>
  25. <view class="line-title acea-row row-center-wrapper" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  26. v-else-if="item.applicable_type === 3">品牌券</view>
  27. <view class="line-title acea-row row-center-wrapper" :class="item._type === 0 ? 'bg-color-huic' : 'bg-color-check'"
  28. v-else>商品券</view>
  29. <image src="../../../static/images/fvip.png" class="pic" v-if="item.receive_type===4">
  30. </image>
  31. <text class="title">{{item.coupon_title}}</text>
  32. </view>
  33. </view>
  34. <view class='data acea-row row-between-wrapper'>
  35. <view>{{item.add_time}}-{{item.end_time}}</view>
  36. <view class='bnt gray' v-if="item._type==0">{{item._msg}}</view>
  37. <view class='bnt bg-color' v-else>{{item._msg}}</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class='noCommodity' v-if="!couponsList.length && page === 2">
  43. <view class='pictrue'>
  44. <image :src="imgHost + '/statics/images/noCoupon.png'"></image>
  45. </view>
  46. </view>
  47. <home v-if="navigation"></home>
  48. <!-- #ifdef MP -->
  49. <!-- <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize> -->
  50. <!-- #endif -->
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getUserCoupons
  56. } from '@/api/api.js';
  57. import {
  58. toLogin
  59. } from '@/libs/login.js';
  60. import {
  61. mapGetters
  62. } from "vuex";
  63. import home from '@/components/home';
  64. import colors from '@/mixins/color.js';
  65. import {HTTP_REQUEST_URL} from '@/config/app';
  66. export default {
  67. components: {
  68. home
  69. },
  70. mixins:[colors],
  71. data() {
  72. return {
  73. couponsList: [],
  74. loading: false,
  75. isAuto: false, //没有授权的不会自动授权
  76. isShowAuth: false, //是否隐藏授权
  77. navOn: 1,
  78. page: 1,
  79. limit: 15,
  80. finished: false,
  81. imgHost:HTTP_REQUEST_URL
  82. };
  83. },
  84. computed: mapGetters(['isLogin']),
  85. watch: {
  86. isLogin: {
  87. handler: function(newV, oldV) {
  88. if (newV) {
  89. this.getUseCoupons();
  90. }
  91. },
  92. deep: true
  93. }
  94. },
  95. onLoad() {
  96. if (this.isLogin) {
  97. this.getUseCoupons();
  98. } else {
  99. toLogin()
  100. }
  101. },
  102. onShow() {
  103. uni.removeStorageSync('form_type_cart');
  104. },
  105. onReachBottom() {
  106. this.getUseCoupons();
  107. },
  108. methods: {
  109. onNav: function(type) {
  110. this.navOn = type;
  111. this.couponsList = [];
  112. this.page = 1;
  113. this.finished = false;
  114. this.getUseCoupons();
  115. },
  116. useCoupon(item){
  117. let url = '';
  118. // 通用券
  119. if (item.category_id == 0 && item.product_id == '' && item.brand_id == 0) {
  120. url = '/pages/goods/goods_list/index?title=默认'
  121. }
  122. // 品类券
  123. if (item.category_id != 0) {
  124. if (item.category_type == 1) {
  125. url = '/pages/goods/goods_list/index?cid='+item.category_id+'&title='+item.category_name
  126. }else{
  127. url = '/pages/goods/goods_list/index?sid='+item.category_id+'&title='+item.category_name
  128. }
  129. }
  130. //商品券
  131. if (item.product_id != '') {
  132. let arr = item.product_id.split(',');
  133. let num = arr.length;
  134. if (num == 1) {
  135. url = '/pages/goods_details/index?id='+item.product_id
  136. } else {
  137. url = '/pages/goods/goods_list/index?productId='+item.product_id+'&title=默认'
  138. }
  139. }
  140. //品牌券
  141. if(item.brand_id != 0){
  142. url = '/pages/goods/goods_list/index?brandId='+item.brand_id+'&title=默认'
  143. }
  144. uni.navigateTo({
  145. url: url
  146. });
  147. },
  148. /**
  149. * 授权回调
  150. */
  151. onLoadFun: function() {
  152. this.getUseCoupons();
  153. this.isShowAuth = false;
  154. },
  155. // 授权关闭
  156. authColse: function(e) {
  157. this.isShowAuth = e
  158. },
  159. /**
  160. * 获取领取优惠券列表
  161. */
  162. getUseCoupons: function() {
  163. let that = this;
  164. if (that.loading || that.finished) {
  165. return;
  166. }
  167. that.loading = true;
  168. uni.showLoading({
  169. title: '正在加载…'
  170. });
  171. getUserCoupons(this.navOn, {
  172. page: this.page,
  173. limit: this.limit
  174. }).then(res => {
  175. that.loading = false;
  176. uni.hideLoading();
  177. that.couponsList = that.couponsList.concat(res.data);
  178. that.finished = res.data.length < that.limit;
  179. that.page += 1;
  180. }).catch(err => {
  181. that.loading = false;
  182. uni.showToast({
  183. title: err,
  184. icon: 'none'
  185. });
  186. });
  187. }
  188. }
  189. }
  190. </script>
  191. <style>
  192. .money {
  193. display: flex;
  194. flex-direction: column;
  195. justify-content: center;
  196. }
  197. .pic-num {
  198. color: #ffffff;
  199. font-size: 24rpx;
  200. }
  201. .coupon-list .item .text .condition {
  202. display: flex;
  203. align-items: center;
  204. }
  205. .coupon-list .item .text .condition .name {
  206. font-size: 26rpx;
  207. font-weight: 500;
  208. }
  209. .coupon-list .item .text .condition .pic {
  210. width: 30rpx;
  211. height: 30rpx;
  212. display: block;
  213. margin-right: 10rpx;
  214. display: inline-block;
  215. vertical-align: sub;
  216. }
  217. .condition .line-title {
  218. width: 70rpx;
  219. height: 32rpx !important;
  220. /* #ifndef APP */
  221. line-height: 28rpx;
  222. /* #endif */
  223. /* #ifdef APP */
  224. line-height: 30rpx;
  225. /* #endif */
  226. text-align: center;
  227. box-sizing: border-box;
  228. background: var(--view-minorColorT);
  229. border: 1px solid var(--view-theme);
  230. opacity: 1;
  231. border-radius: 20rpx;
  232. font-size: 18rpx !important;
  233. color: var(--view-theme);
  234. margin-right: 12rpx;
  235. text-align: center;
  236. display: inline-block;
  237. vertical-align: middle;
  238. }
  239. .condition .title{
  240. vertical-align: middle;
  241. }
  242. .condition .line-title.bg-color-huic {
  243. border-color: #BBB !important;
  244. color: #bbb !important;
  245. background-color: #F5F5F5 !important;
  246. }
  247. </style>
  248. <style lang="scss" scoped>
  249. .navbar {
  250. position: fixed;
  251. top: 0;
  252. left: 0;
  253. width: 100%;
  254. height: 106rpx;
  255. background-color: #FFFFFF;
  256. z-index: 9;
  257. .item {
  258. border-top: 5rpx solid transparent;
  259. border-bottom: 5rpx solid transparent;
  260. font-size: 30rpx;
  261. color: #999999;
  262. &.on {
  263. border-bottom-color: var(--view-theme);
  264. color: #282828;
  265. }
  266. }
  267. }
  268. .coupon-list {
  269. margin-top: 122rpx;
  270. }
  271. .noCommodity {
  272. margin-top: 300rpx;
  273. }
  274. </style>