coupon.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="default" v-if="isIframe && !couponList.length">
  4. <text>{{$t(`优惠券,暂无数据`)}}</text>
  5. </view>
  6. <view class="index-wrapper coupon" v-if="couponList.length&&isShow&&!isIframe">
  7. <view class='title acea-row row-between-wrapper skeleton-rect'>
  8. <view class='text'>
  9. <view class='name line1'>{{$t(`优惠券`)}}</view>
  10. <view class='line1 txt-btn'>{{$t(`领取今日好券`)}}</view>
  11. </view>
  12. <view class='more' @click="gopage('/pages/users/user_get_coupon/index')">{{$t(`更多`)}}<text
  13. class='iconfont icon-jiantou'></text>
  14. </view>
  15. </view>
  16. <!-- <view class="title acea-row row-between-wrapper">
  17. <view class="acea-row row-middle">
  18. <view class="name">优惠券</view>
  19. </view>
  20. <navigator url="/pages/users/user_get_coupon/index" hover-class="none"
  21. class="more acea-row row-center-wrapper">更多<text class="iconfont icon-xiangyou"></text></navigator>
  22. </view> -->
  23. <view class="conter skeleton-rect">
  24. <scroll-view scroll-x="true" style="white-space: nowrap; vertical-align: middle;"
  25. show-scrollbar="false">
  26. <view class="itemCon" v-for="(item, index) in couponList" :key="index">
  27. <view class="item acea-row row-between-wrapper" :class="item.is_use?'on':'no'">
  28. <view class="iconfont icon-youhuiquantoumingbeijing"></view>
  29. <view class="cir"></view>
  30. <view class="cir2"></view>
  31. <view class="text">
  32. <view class="money line1">{{$t(`¥`)}}<text class="num">{{item.coupon_price}}</text></view>
  33. <view class="man line1">{{$t(`满`)}}{{item.use_min_price}}{{$t(`可用`)}}</view>
  34. </view>
  35. <view class="bnt" v-if="item.is_use===true"><text>{{$t(`已领取`)}}</text></view>
  36. <view class="bnt" v-else-if="item.is_use===false" @click="receiveCoupon(item)">
  37. <text>{{$t(`领取`)}}</text>
  38. </view>
  39. <view class="bnt" v-else-if="item.is_use===2"><text>{{$t(`已过期`)}}</text></view>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. <view class="index-wrapper coupon" v-if="couponList.length && isIframe">
  46. <view class='title acea-row row-between-wrapper'>
  47. <view class='text'>
  48. <view class='name line1'>{{$t(`优惠券`)}}</view>
  49. <view class='line1 txt-btn'>{{$t(`领取今日好券`)}}</view>
  50. </view>
  51. <view class='more' @click="gopage('/pages/users/user_get_coupon/index')">{{$t(`更多`)}}<text
  52. class='iconfont icon-jiantou'></text>
  53. </view>
  54. </view>
  55. <view class="conter">
  56. <scroll-view scroll-x="true" style="white-space: nowrap; vertical-align: middle;"
  57. show-scrollbar="false">
  58. <view class="itemCon" v-for="(item, index) in couponList" :key="index">
  59. <view class="item acea-row row-between-wrapper" :class="item.is_use?'on':'no'">
  60. <view class="iconfont icon-youhuiquantoumingbeijing"></view>
  61. <view class="cir"></view>
  62. <view class="cir2"></view>
  63. <view class="text">
  64. <view class="money line1">{{$t(`¥`)}}<text class="num">{{item.coupon_price}}</text></view>
  65. <view class="man line1">{{$t(`满`)}}{{item.use_min_price}}{{$t(`可用`)}}</view>
  66. </view>
  67. <view class="bnt" v-if="item.is_use===true"><text>{{$t(`已领取`)}}</text></view>
  68. <view class="bnt" v-else-if="item.is_use===false" @click="receiveCoupon(item)">
  69. <text>{{$t(`领取`)}}</text>
  70. </view>
  71. <view class="bnt" v-else-if="item.is_use===2"><text>{{$t(`已过期`)}}</text></view>
  72. </view>
  73. </view>
  74. </scroll-view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. let app = getApp();
  81. import {
  82. getCouponsIndex,
  83. setCouponReceive
  84. } from '@/api/api.js';
  85. import {
  86. toLogin
  87. } from '@/libs/login.js';
  88. import {
  89. mapGetters
  90. } from 'vuex';
  91. import colors from "@/mixins/color";
  92. export default {
  93. name: 'coupon',
  94. mixins: [colors],
  95. props: {
  96. dataConfig: {
  97. type: Object,
  98. default: () => {}
  99. }
  100. },
  101. computed: {
  102. ...mapGetters(['isLogin'])
  103. },
  104. watch: {
  105. dataConfig: {
  106. immediate: true,
  107. handler(nVal, oVal) {
  108. if (nVal) {
  109. this.numberConfig = nVal.numConfig.val;
  110. this.isShow = nVal.isShow.val;
  111. this.getCoupon();
  112. }
  113. }
  114. }
  115. },
  116. data() {
  117. return {
  118. couponList: [],
  119. numberConfig: 0,
  120. name: this.$options.name, //component组件固定写法获取当前name;
  121. isIframe: app.globalData.isIframe, //判断是前台还是后台;
  122. isShow: true //判断此模块是否显示;
  123. };
  124. },
  125. created() {},
  126. mounted() {},
  127. methods: {
  128. getCoupon: function() {
  129. let that = this;
  130. let lists = [];
  131. getCouponsIndex({
  132. type: -1,
  133. num: this.numberConfig
  134. }).then(res => {
  135. res.data.forEach(function(value, key, iterable) {
  136. if (!value.used) {
  137. lists.push(value);
  138. }
  139. });
  140. that.$set(that, 'couponList', lists);
  141. }).catch(err => {
  142. return that.$util.Tips({
  143. title: err
  144. });
  145. });
  146. },
  147. receiveCoupon: function(item) {
  148. let that = this;
  149. if (!that.isLogin) {
  150. toLogin();
  151. } else {
  152. setCouponReceive(item.id)
  153. .then(function() {
  154. item.is_use = true;
  155. that.$set(that, 'couponList', that.couponList);
  156. that.$util.Tips({
  157. title: that.$t(`领取成功`)
  158. });
  159. })
  160. .catch(function(err) {
  161. that.$util.Tips({
  162. title: err
  163. });
  164. });
  165. }
  166. },
  167. gopage(url) {
  168. uni.navigateTo({
  169. url: url
  170. })
  171. }
  172. }
  173. }
  174. </script>
  175. <style lang="scss">
  176. .default {
  177. width: 690rpx;
  178. height: 300rpx;
  179. border-radius: 14rpx;
  180. margin: 26rpx auto 0 auto;
  181. background-color: #ccc;
  182. text-align: center;
  183. line-height: 300rpx;
  184. .iconfont {
  185. font-size: 50rpx;
  186. }
  187. }
  188. .title .text {
  189. display: flex;
  190. align-items: flex-end;
  191. .txt-btn {
  192. margin-bottom: 6rpx;
  193. margin-left: 6px;
  194. }
  195. }
  196. .coupon {
  197. margin: $uni-index-margin-row $uni-index-margin-col $uni-index-margin-row $uni-index-margin-col;
  198. padding: 0rpx 0 20rpx 0;
  199. background-color: #fff;
  200. border-radius: $uni-border-radius-index;
  201. .conter {
  202. margin-top: 25rpx;
  203. padding: 0 20rpx;
  204. .itemCon {
  205. background-size: 100% 100%;
  206. width: 226rpx;
  207. height: 108rpx;
  208. display: inline-block;
  209. margin-right: 24rpx;
  210. .on {
  211. // opacity: 0.6;
  212. .item {
  213. background-color: rgba(233, 51, 35, 0.1) !important;
  214. .text {
  215. // color: #CCCCCC;
  216. }
  217. }
  218. .icon-youhuiquantoumingbeijing {
  219. color: #f3f3f3 !important;
  220. }
  221. }
  222. .no {
  223. background: linear-gradient(135deg, var(--view-main-start) 0%, var(--view-main-over) 100%);
  224. .icon-youhuiquantoumingbeijing {
  225. color: rgba(255,255, 255, 0.8);
  226. }
  227. .man {
  228. background-color: var(--view-theme);
  229. }
  230. .bnt {
  231. color: var(--view-theme) !important;
  232. }
  233. }
  234. .item {
  235. width: 100%;
  236. height: 100%;
  237. position: relative;
  238. border-radius: 10rpx;
  239. background-color: #b9b9b9;
  240. .cir {
  241. position: absolute;
  242. left: -6rpx;
  243. top: -6rpx;
  244. width: 16rpx;
  245. height: 16rpx;
  246. border-radius: 50%;
  247. background: #fff;
  248. z-index: 100;
  249. }
  250. .cir2 {
  251. position: absolute;
  252. left: -6rpx;
  253. bottom: -6rpx;
  254. width: 16rpx;
  255. height: 16rpx;
  256. border-radius: 50%;
  257. background: #fff;
  258. z-index: 100;
  259. }
  260. .beijing2 {
  261. // position: absolute;
  262. // right: 0;
  263. // width: 60rpx;
  264. // height: 100%;
  265. // border-top-left-radius: 50rpx;
  266. // border-bottom-left-radius: 50rpx;
  267. // // background: var(--view-op-ten);
  268. // background-color: rgba(233, 51, 35, 0.1);
  269. // z-index: 99;
  270. }
  271. .icon-youhuiquantoumingbeijing {
  272. position: absolute;
  273. right: 0;
  274. width: 88rpx;
  275. height: 100%;
  276. font-size: 124rpx;
  277. line-height: 124rpx;
  278. height: 124rpx;
  279. // background: var(--view-op-ten);
  280. z-index: 99;
  281. }
  282. .text {
  283. padding-left: 20rpx;
  284. color: #fff;
  285. font-size: 22rpx;
  286. width: 168rpx;
  287. padding-bottom: 6rpx;
  288. z-index: 99;
  289. .money {
  290. font-size: 30rpx;
  291. font-weight: bold;
  292. .num {
  293. font-size: 44rpx;
  294. }
  295. }
  296. .man {
  297. width: max-content;
  298. border-radius: 20rpx;
  299. padding: 0 10rpx;
  300. }
  301. }
  302. .bnt {
  303. writing-mode: vertical-lr;
  304. font-size: 22rpx;
  305. margin: 0 12rpx;
  306. z-index: 99;
  307. color: #818181;
  308. }
  309. }
  310. }
  311. }
  312. }
  313. </style>