coupon.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <div class="box">
  3. <div class="null-page" v-show="yes"></div>
  4. <el-card class="box-card member-coupon">
  5. <div slot="header" class="clearfix"><span>我的优惠券</span></div>
  6. <div>
  7. <div v-loading="loading">
  8. <el-tabs v-model="couponstatus" @tab-click="handleClickStatus">
  9. <el-tab-pane label="未使用" name="1"></el-tab-pane>
  10. <el-tab-pane label="已使用" name="2"></el-tab-pane>
  11. <el-tab-pane label="已过期" name="3"></el-tab-pane>
  12. </el-tabs>
  13. <div class="coupon-wrap">
  14. <div
  15. class="text item"
  16. :class="state == '1' ? 'coupon-not-used' : state == '2' ? 'coupon-used' : 'coupon-expire'"
  17. v-for="(item, index) in couponList"
  18. :key="index"
  19. @click="useCoupon(item)"
  20. >
  21. <template>
  22. <p class="coupon-wrap-money" v-if="item.discount == '0.00' || !item.discount">
  23. <span>{{ item.money }}</span>
  24. </p>
  25. <p class="coupon-wrap-money" v-else>
  26. <span>{{ item.discount }}</span>
  27. </p>
  28. </template>
  29. <p class="coupon-wrap-name">{{ item.platformcoupon_name }}</p>
  30. <template>
  31. <p class="coupon-wrap-least coupon-wrap-info" v-if="item.at_least > 0">满{{ item.at_least }}元可用</p>
  32. <p class="coupon-wrap-least coupon-wrap-info" v-else>无门槛优惠券</p>
  33. </template>
  34. <template>
  35. <p class="coupon-wrap-time coupon-wrap-info">{{item.end_time > 0 ? '有效期至' + $timeStampTurnTime(item.end_time) : '长期有效' }}</p>
  36. </template>
  37. </div>
  38. <div class="empty-text" v-if="couponList.length == 0">{{ text }}</div>
  39. </div>
  40. <div class="pager">
  41. <el-pagination
  42. background
  43. :pager-count="5"
  44. :total="total"
  45. prev-text="上一页"
  46. next-text="下一页"
  47. :current-page.sync="currentPage"
  48. :page-size.sync="pageSize"
  49. @size-change="handlePageSizeChange"
  50. @current-change="handleCurrentPageChange"
  51. hide-on-single-page
  52. ></el-pagination>
  53. </div>
  54. </div>
  55. </div>
  56. </el-card>
  57. </div>
  58. </template>
  59. <script>
  60. import { couponList } from '@/api/member/member';
  61. import { mapGetters } from 'vuex';
  62. export default {
  63. name: 'my_coupon',
  64. layout: "member",
  65. components: {},
  66. data: () => {
  67. return {
  68. total: 0,
  69. currentPage: 1,
  70. pageSize: 9,
  71. couponstatus: '1',
  72. couponList: [],
  73. type: '',
  74. state: 1,
  75. text: '您还没有优惠券哦',
  76. loading: true,
  77. yes: true
  78. };
  79. },
  80. created() {
  81. if (this.addonIsExit && this.addonIsExit.coupon != 1) {
  82. this.$message({
  83. message: '优惠券插件未安装',
  84. type: 'warning',
  85. duration: 2000,
  86. onClose: () => {
  87. this.$route.push('/member');
  88. }
  89. });
  90. } else {
  91. this.getListData();
  92. }
  93. },
  94. mounted() {
  95. let self = this;
  96. setTimeout(function() {
  97. self.yes = false
  98. }, 300)
  99. },
  100. computed: {
  101. ...mapGetters(['addonIsExit'])
  102. },
  103. watch: {
  104. addonIsExit() {
  105. if (this.addonIsExit.coupon != 1) {
  106. this.$message({
  107. message: '优惠券插件未安装',
  108. type: 'warning',
  109. duration: 2000,
  110. onClose: () => {
  111. this.$route.push('/member');
  112. }
  113. });
  114. }
  115. }
  116. },
  117. methods: {
  118. /**
  119. * 优惠券状态(未使用/已使用/已过期)
  120. */
  121. handleClickStatus(tab, event) {
  122. if (tab.name == '1') {
  123. this.state = 1;
  124. this.text = '您还没有优惠券哦';
  125. } else if (tab.name == '2') {
  126. this.state = 2;
  127. this.text = '您还没有使用过优惠券哦';
  128. } else {
  129. this.state = 3;
  130. this.text = '您还没有过期优惠券哦';
  131. }
  132. this.refresh();
  133. },
  134. handlePageSizeChange(size) {
  135. this.pageSize = size;
  136. this.refresh();
  137. },
  138. handleCurrentPageChange(page) {
  139. this.currentPage = page;
  140. this.refresh();
  141. },
  142. refresh() {
  143. this.loading = true;
  144. this.getListData();
  145. },
  146. // 获取优惠券列表
  147. getListData() {
  148. couponList({
  149. page: this.currentPage,
  150. page_size: this.pageSize,
  151. state: this.state,
  152. is_own: this.type,
  153. })
  154. .then(res => {
  155. if (res.code >= 0) {
  156. this.total = res.data.count;
  157. this.couponList = res.data.list;
  158. }
  159. this.loading = false;
  160. })
  161. .catch(err => {
  162. this.loading = false;
  163. this.$message.error(err.message);
  164. });
  165. },
  166. // 去使用优惠券
  167. useCoupon(item) {
  168. if (item.state == 1) {
  169. if (item.use_scenario != 1) {
  170. this.$router.push({ path: '/goods/list', query: { coupon: item.coupon_type_id } });
  171. } else {
  172. this.$router.push('/goods/list');
  173. }
  174. }
  175. }
  176. }
  177. };
  178. </script>
  179. <style lang="scss" scoped>
  180. .box {
  181. width: 100%;
  182. position: relative;
  183. }
  184. .null-page {
  185. width: 100%;
  186. height: 730px;
  187. background-color: #FFFFFF;
  188. position: absolute;
  189. top: 0;
  190. left: 0;
  191. z-index: 9;
  192. }
  193. .el-card.is-always-shadow,
  194. .el-card.is-hover-shadow:focus,
  195. .el-card.is-hover-shadow:hover {
  196. box-shadow: unset;
  197. }
  198. .el-card {
  199. border: 0;
  200. }
  201. .coupon-wrap {
  202. display: flex;
  203. align-items: center;
  204. flex-wrap: wrap;
  205. .text {
  206. width: 32%;
  207. height: 140px;
  208. margin-right: 2%;
  209. border-radius: 5px;
  210. border: 1px dashed #fff;
  211. margin-bottom: 20px;
  212. padding: 0 15px;
  213. box-sizing: border-box;
  214. color: #ffffff;
  215. .coupon-wrap-money {
  216. span {
  217. font-size: 30px;
  218. margin-right: 5px;
  219. }
  220. }
  221. .coupon-wrap-info {
  222. font-size: 12px;
  223. line-height: 18px;
  224. }
  225. }
  226. .text:nth-child(3n) {
  227. margin-right: 0;
  228. }
  229. .coupon-not-used {
  230. background-color: $base-color;
  231. cursor: pointer;
  232. }
  233. .coupon-used {
  234. background-color: hsl(360, 50%, 70%);
  235. }
  236. .coupon-expire {
  237. background-color: #d0d0d0;
  238. }
  239. .coupon-wrap-info {
  240. font-size: 12px;
  241. line-height: 20px;
  242. }
  243. .empty-text {
  244. margin: 0 auto;
  245. }
  246. }
  247. </style>
  248. <style lang="scss">
  249. .member-coupon {
  250. .el-tabs__active-bar,
  251. .el-tabs__nav-wrap::after {
  252. /* 清除tab标签底部横线 */
  253. height: 0;
  254. }
  255. }
  256. </style>