index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <view>
  3. <view class="coupon-list" v-if="couponsList.length">
  4. <view class="item-group" v-for="(item,index) in couponsList" :key="item.id">
  5. <view class="item acea-row" :class="{ disabled: item.is_use && item.used && item.used.is_fail }">
  6. <view class='money' :class="{ moneyGray: item.used && item.used.is_fail }">
  7. <view>
  8. <text v-if="item.coupon_type == 1">¥</text>
  9. <text class='num'>{{item.coupon_type == 1?item.coupon_price:parseFloat(item.coupon_price)/10}}</text>
  10. <text v-if="item.coupon_type == 2">折</text>
  11. </view>
  12. <view class="pic-num" v-if="item.use_min_price > 0">满{{ item.use_min_price | money }}元可用</view>
  13. <view class="pic-num" v-else>无门槛券</view>
  14. </view>
  15. <view class="text-wrap acea-row row-middle">
  16. <view class="text">
  17. <view class="condition">
  18. <view class="name line2">
  19. <text>{{item.coupon_title}}</text>
  20. </view>
  21. </view>
  22. <view class='data acea-row row-between-wrapper'>
  23. <view v-if="item.coupon_time">领取后{{item.coupon_time}}天内有效</view>
  24. <view v-else>{{item.start_use_time}}-{{item.end_use_time}}</view>
  25. </view>
  26. <view class="look-wrap">
  27. <view class="look" @click="openRule(index)">
  28. {{ item.applicable_type ? (item.applicable_type == 1 ? '品类' : '商品') : '通用' }}优惠券<text v-if="item.rule">丨查看用券规则</text>
  29. <text v-if="item.rule" :class="['iconfont', item.ruleShow ? 'icon-ic_uparrow' : 'icon-ic_downarrow']"></text>
  30. </view>
  31. </view>
  32. </view>
  33. <!-- is_fail:1为失效;0为可用 -->
  34. <view class="bnt" v-if="!item.is_use" @click="setCouponReceive(item.id)">立即领取</view>
  35. <view class="bnt" v-else-if="item.used && item.used.is_fail">已失效</view>
  36. <view class="bnt" v-else @click="useCoupon(item)">去使用</view>
  37. </view>
  38. </view>
  39. <view v-if="item.ruleShow" class="rules">
  40. <view v-for="(ruleItem, idx) in item.rules" :key="idx">{{ ruleItem }}</view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class='noCommodity' v-if="!couponsList.length && loading==true">
  45. <view class='pictrue'>
  46. <image :src="imgHost + '/statics/images/noCoupon.png'"></image>
  47. </view>
  48. </view>
  49. <!-- <home v-if="navigation"></home> -->
  50. <!-- #ifdef MP -->
  51. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  52. <!-- #endif -->
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. memberCouponsList
  58. } from '@/api/user.js';
  59. import {
  60. setCouponReceive
  61. } from '@/api/api.js';
  62. import {
  63. toLogin
  64. } from '@/libs/login.js';
  65. import dayjs from '@/plugin/dayjs/dayjs.min.js';
  66. import colors from '@/mixins/color.js';
  67. import {
  68. HTTP_REQUEST_URL
  69. } from '@/config/app';
  70. import {
  71. mapGetters
  72. } from "vuex";
  73. import home from '@/components/home';
  74. export default {
  75. components: {
  76. home
  77. },
  78. mixins: [colors],
  79. data() {
  80. return {
  81. couponsList: [],
  82. loading: false,
  83. isAuto: false, //没有授权的不会自动授权
  84. isShowAuth: false, //是否隐藏授权
  85. imgHost: HTTP_REQUEST_URL,
  86. page: 1,
  87. limit: 15,
  88. loadend: false,
  89. };
  90. },
  91. filters: {
  92. format(value) {
  93. if (!value) return ''
  94. return dayjs(value * 1000).format('YYYY-MM-DD');
  95. },
  96. money(value) {
  97. if (!value) return '0'
  98. return parseFloat(value);
  99. }
  100. },
  101. computed: mapGetters(['isLogin']),
  102. watch: {
  103. isLogin: {
  104. handler: function(newV, oldV) {
  105. if (newV) {
  106. // #ifndef MP
  107. this.getUseCoupons();
  108. // #endif
  109. }
  110. },
  111. deep: true
  112. }
  113. },
  114. onLoad() {
  115. if (this.isLogin) {
  116. this.getUseCoupons();
  117. }
  118. },
  119. onShow() {
  120. uni.removeStorageSync('form_type_cart');
  121. if (!this.isLogin) {
  122. toLogin()
  123. }
  124. },
  125. methods: {
  126. /**
  127. * 授权回调
  128. */
  129. onLoadFun: function() {
  130. this.getUseCoupons();
  131. this.isShowAuth = false;
  132. },
  133. // 授权关闭
  134. authColse: function(e) {
  135. this.isShowAuth = e
  136. },
  137. /**
  138. * 获取领取优惠券列表
  139. */
  140. getUseCoupons: function() {
  141. let that = this;
  142. if (this.loadend) {
  143. return;
  144. }
  145. memberCouponsList(this.page, this.limit).then(res => {
  146. that.loading = true;
  147. res.data.forEach(item => {
  148. item.ruleShow = false;
  149. item.rules = item.rule.split('\n');
  150. });
  151. this.page += 1;
  152. this.loadend = res.data.length < this.limit;
  153. this.couponsList = [...this.couponsList, ...res.data];
  154. })
  155. },
  156. // 领取优惠券
  157. setCouponReceive(id) {
  158. setCouponReceive(id).then(res => {
  159. this.$util.Tips({
  160. title: '领取成功'
  161. });
  162. for (let i = 0; i < this.couponsList.length; i++) {
  163. if (this.couponsList[i].id == id) {
  164. this.couponsList[i].is_use = true;
  165. }
  166. }
  167. }).catch(err => {
  168. this.$util.Tips({
  169. title: err
  170. });
  171. });
  172. },
  173. useCoupon(item) {
  174. let url = '';
  175. // 通用券
  176. if (item.category_id == 0 && item.product_id == '' && item.brand_id == 0) {
  177. url = '/pages/goods/goods_list/index?title=默认'
  178. }
  179. // 品类券
  180. if (item.category_id != 0) {
  181. if (item.category_type == 1) {
  182. url = '/pages/goods/goods_list/index?cid=' + item.category_id + '&title=' + item.category_name
  183. } else {
  184. url = '/pages/goods/goods_list/index?sid=' + item.category_id + '&title=' + item.category_name
  185. }
  186. }
  187. //商品券
  188. if (item.product_id != '') {
  189. let arr = item.product_id.split(',');
  190. let num = arr.length;
  191. if (num == 1) {
  192. url = '/pages/goods_details/index?id=' + item.product_id
  193. } else {
  194. url = '/pages/goods/goods_list/index?productId=' + item.product_id + '&title=默认'
  195. }
  196. }
  197. //品牌券
  198. if (item.brand_id != 0) {
  199. url = '/pages/goods/goods_list/index?brandId=' + item.brand_id + '&title=默认'
  200. }
  201. uni.navigateTo({
  202. url: url
  203. });
  204. },
  205. openRule(index) {
  206. this.couponsList[index].ruleShow = !this.couponsList[index].ruleShow
  207. },
  208. },
  209. onReachBottom() {
  210. this.getUseCoupons();
  211. }
  212. }
  213. </script>
  214. <style scoped>
  215. .coupon-list .moneyGray.item .text .data .bnt {
  216. background: #B5B5B5;
  217. }
  218. .coupon-list .moneyGray.item .money {
  219. color: #7D7D7D;
  220. }
  221. .coupon-list .moneyGray.item .text {
  222. background: linear-gradient(-90deg, #DADADA 0%, #E9E9E9 100%);
  223. }
  224. .coupon-list .moneyGray.item .text .condition {
  225. border-color: #F0F0F0;
  226. }
  227. .coupon-list .moneyGray.item .text .condition {
  228. color: #7D7D7D;
  229. }
  230. .coupon-list .moneyGray.item .text .data {
  231. color: #999999;
  232. }
  233. .moneyGray .condition .line-title {
  234. border-color: #7D7D7D;
  235. background: #EFEFEF;
  236. color: #7D7D7D;
  237. }
  238. .coupon-list .item-group {
  239. margin-bottom: 20rpx;
  240. }
  241. .coupon-list .item-group .rules {
  242. padding: 42rpx 24rpx 24rpx;
  243. border-radius: 0 0 24rpx 24rpx;
  244. margin-top: -18rpx;
  245. background: linear-gradient(180deg, #F7F7F7 0%, #FFFFFF 100%);
  246. font-size: 20rpx;
  247. line-height: 28rpx;
  248. color: #999999;
  249. }
  250. .coupon-list .item {
  251. margin-bottom: 0;
  252. }
  253. .coupon-list .item .money {
  254. position: relative;
  255. border-radius: 24rpx 0 0 24rpx;
  256. background-image: radial-gradient(circle at left, #F5F5F5 16rpx, #32302D 0, #584834 100%);
  257. font-family: Regular;
  258. }
  259. .coupon-list .item .money::after {
  260. content: "";
  261. position: absolute;
  262. top: 0;
  263. bottom: 0;
  264. right: 0;
  265. width: 6rpx;
  266. background-image: radial-gradient(circle at 6rpx, #FFFFFF 6rpx, transparent 6rpx);
  267. background-size: 6rpx 18rpx;
  268. }
  269. .coupon-list .item.disabled .money {
  270. background-image: radial-gradient(circle at left, #F5F5F5 16rpx, #CCCCCC 0);
  271. color: #FFFFFF;
  272. }
  273. .coupon-list .item.disabled .bnt {
  274. color: #FFFFFF;
  275. }
  276. .money {
  277. display: flex;
  278. flex-direction: column;
  279. justify-content: center;
  280. }
  281. .pic-num {
  282. margin-top: 8rpx;
  283. font-size: 24rpx;
  284. }
  285. .coupon-list .item {
  286. background-color: transparent;
  287. }
  288. .coupon-list .item .text-wrap {
  289. flex: 1;
  290. padding-right: 20rpx;
  291. border-radius: 0 24rpx 24rpx 0;
  292. background-color: #FFFFFF;
  293. }
  294. .coupon-list .item .text .condition {
  295. display: flex;
  296. align-items: center;
  297. }
  298. .coupon-list .item .text .condition .name {
  299. font-size: 28rpx;
  300. font-weight: 500;
  301. }
  302. .coupon-list .item .text .condition .pic {
  303. width: 30rpx;
  304. height: 30rpx;
  305. display: block;
  306. margin-right: 10rpx;
  307. display: inline-block;
  308. vertical-align: middle;
  309. }
  310. .condition .line-title {
  311. width: 70rpx;
  312. height: 32rpx !important;
  313. line-height: 30rpx;
  314. text-align: center;
  315. box-sizing: border-box;
  316. background: #FEF7EC;
  317. border: 1px solid #EEC181;
  318. opacity: 1;
  319. border-radius: 20rpx;
  320. font-size: 18rpx !important;
  321. color: #EEC181;
  322. margin-right: 12rpx;
  323. text-align: center;
  324. display: inline-block;
  325. vertical-align: middle;
  326. }
  327. .condition .line-title.bg-color-huic {
  328. border-color: #BBB;
  329. color: #bbb;
  330. background-color: #F5F5F5;
  331. }
  332. .coupon-list .item .bnt {
  333. background: linear-gradient(90deg, #584834 0%, #32302D 100%);
  334. }
  335. .coupon-list .item.disabled .bnt {
  336. background: #CCCCCC;
  337. }
  338. .look-wrap {
  339. margin-top: 20rpx;
  340. }
  341. .look-wrap .look {
  342. font-size: 20rpx;
  343. line-height: 28rpx;
  344. color: #999999;
  345. }
  346. .look-wrap .look {
  347. font-size: 20rpx;
  348. line-height: 28rpx;
  349. color: #999999;
  350. }
  351. .look-wrap .look .iconfont {
  352. margin-left: 6rpx;
  353. font-size: 20rpx;
  354. }
  355. </style>