coupon.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div class="ns-coupon">
  3. <div class="ns-coupon-info" v-if="adList.length">
  4. <div class="ns-coupon-wrap">
  5. <div class="coupon-name">
  6. <span class="ns-text-color">优惠券中心</span>
  7. <span class="ns-text-color-gray text12">省钱更多,领券更多</span>
  8. </div>
  9. <ul class="coupon-type clear-float">
  10. <li>
  11. <i></i>
  12. <span>限时抢券</span>
  13. </li>
  14. <li>
  15. <i></i>
  16. <span>叠加使用</span>
  17. </li>
  18. <li>
  19. <i></i>
  20. <span>种类多样</span>
  21. </li>
  22. </ul>
  23. <el-button @click="myCoupon">我的优惠券</el-button>
  24. </div>
  25. <div class="ns-coupon-img" v-loading="loadingAd">
  26. <el-carousel height="406px">
  27. <el-carousel-item v-for="item in adList" :key="item.adv_id">
  28. <el-image :src="$img(item.adv_image)" fit="cover" @click="$util.pushToTab(item.adv_url.url)" />
  29. </el-carousel-item>
  30. </el-carousel>
  31. </div>
  32. </div>
  33. <el-tabs>
  34. <div v-loading="loading">
  35. <ul class="ns-coupon-list" >
  36. <li class="ns-bg-color ns-coupon-li" v-for="(item, index) in couponList" :key="index" :class="item.count == item.lead_count ? 'no-coupon' : '' ">
  37. <div class="describe">
  38. <template>
  39. <span v-if="!item.discount || item.discount == '0.00'">¥{{ item.money }}</span>
  40. <span v-else>{{ item.discount }}折</span>
  41. </template>
  42. <span>{{ activeName == 'first' ? item.coupon_name : item.platformcoupon_name }}</span>
  43. <span v-if="activeName == 'first'">{{ item.goods_type == 1 ? '全部商品可用' : '指定商品可用' }}</span>
  44. <template>
  45. <span v-if="item.at_least == '0.00'">无门槛优惠券</span>
  46. <span v-else>满{{ item.at_least }}可使用</span>
  47. </template>
  48. <template>
  49. <span class="coupon-wrap-time" v-if="item.validity_type == 0">领取之日起{{ item.fixed_term }}日内有效</span>
  50. <span class="coupon-wrap-time" v-else-if="item.validity_type == 1">有效期至{{ $timeStampTurnTime(item.end_time) }}</span>
  51. <span class="coupon-wrap-time" v-else>长期有效</span>
  52. </template>
  53. </div>
  54. <div class="receive">
  55. <!-- 如果限领数为0 或者 领取数小于最大领取数 -->
  56. <a class="ns-text-color" v-if="item.count == item.lead_count">
  57. <span>已抢完</span>
  58. </a>
  59. <a class="ns-text-color" @click="couponTap(item, index)" v-else>
  60. <span v-if="item.useState == 0">立即领取</span>
  61. <span v-else>去使用</span>
  62. </a>
  63. </div>
  64. </li>
  65. </ul>
  66. <div class="empty-wrap" v-if="couponList.length <= 0">
  67. <div class="ns-text-align">暂无优惠券</div>
  68. </div>
  69. <div class="pager">
  70. <el-pagination background :pager-count="5" :total="total" prev-text="上一页" next-text="下一页" :current-page.sync="currentPage"
  71. :page-size.sync="pageSize" @size-change="handlePageSizeChange" @current-change="handleCurrentPageChange"
  72. hide-on-single-page></el-pagination>
  73. </div>
  74. </div>
  75. </el-tabs>
  76. </div>
  77. </template>
  78. <script>
  79. import {
  80. couponList,
  81. receiveCoupon
  82. } from '@/api/coupon';
  83. import {
  84. mapGetters
  85. } from 'vuex';
  86. import {
  87. adList
  88. } from '@/api/website';
  89. export default {
  90. name: 'coupon',
  91. components: {},
  92. data: () => {
  93. return {
  94. couponList: [],
  95. total: 0,
  96. currentPage: 1,
  97. pageSize: 9,
  98. couponBtnSwitch: false,
  99. activeName: 'first',
  100. loading: true,
  101. loadingAd: true,
  102. adList: []
  103. };
  104. },
  105. created() {
  106. if (this.addonIsExit && this.addonIsExit.coupon != 1) {
  107. this.$message({
  108. message: '优惠券插件未安装',
  109. type: 'warning',
  110. duration: 2000,
  111. onClose: () => {
  112. this.$route.push('/');
  113. }
  114. });
  115. } else {
  116. this.getAdList();
  117. this.getCanReceiveCouponQuery();
  118. }
  119. },
  120. computed: {
  121. ...mapGetters(['addonIsExit'])
  122. },
  123. watch: {
  124. addonIsExit() {
  125. if (this.addonIsExit.coupon != 1) {
  126. this.$message({
  127. message: '优惠券插件未安装',
  128. type: 'warning',
  129. duration: 2000,
  130. onClose: () => {
  131. this.$route.push('/');
  132. }
  133. });
  134. }
  135. }
  136. },
  137. head() {
  138. return {
  139. title: '领券专区-' + this.$store.state.site.siteInfo.site_name,
  140. meta: [{
  141. name: 'description',
  142. content: this.$store.state.site.siteInfo.seo_description
  143. },
  144. {
  145. name: 'keyword',
  146. content: this.$store.state.site.siteInfo.seo_keywords
  147. }
  148. ]
  149. }
  150. },
  151. methods: {
  152. getAdList() {
  153. adList({
  154. keyword: 'NS_PC_COUPON'
  155. })
  156. .then(res => {
  157. this.adList = res.data.adv_list;
  158. for (let i = 0; i < this.adList.length; i++) {
  159. if (this.adList[i].adv_url) this.adList[i].adv_url = JSON.parse(this.adList[i].adv_url);
  160. }
  161. this.loadingAd = false;
  162. })
  163. .catch(err => {
  164. this.loadingAd = false;
  165. });
  166. },
  167. handleClick(tab, event) {
  168. this.loading = true;
  169. // (this.currentPage = 1), this.getCanReceiveCouponQuery();
  170. },
  171. /**
  172. * 我的优惠券
  173. */
  174. myCoupon() {
  175. this.$util.pushToTab('/member/coupon');
  176. },
  177. /**
  178. * 获取优惠券列表
  179. */
  180. getCanReceiveCouponQuery() {
  181. couponList({
  182. page: this.currentPage,
  183. page_size: this.pageSize,
  184. activeName: this.activeName
  185. })
  186. .then(res => {
  187. this.couponList = res.data.list;
  188. this.total = res.data.count;
  189. this.couponList.forEach(v => {
  190. v.useState = 0;
  191. });
  192. this.loading = false;
  193. })
  194. .catch(err => {
  195. this.loading = false;
  196. this.$message.error(err.message);
  197. });
  198. },
  199. handlePageSizeChange(size) {
  200. this.pageSize = size;
  201. this.loading = true;
  202. this.getCanReceiveCouponQuery();
  203. },
  204. handleCurrentPageChange(page) {
  205. this.currentPage = page;
  206. this.loading = true;
  207. this.getCanReceiveCouponQuery();
  208. },
  209. /**
  210. * 点击优惠券
  211. */
  212. couponTap(item, index) {
  213. if (item.useState == 0) this.receiveCoupon(item, index);
  214. else this.toGoodsList(item);
  215. },
  216. /**
  217. * 领取优惠券
  218. */
  219. receiveCoupon(item, index) {
  220. if (this.couponBtnSwitch) return;
  221. this.couponBtnSwitch = true;
  222. var data = {
  223. site_id: item.site_id,
  224. activeName: this.activeName
  225. };
  226. data.coupon_type_id = item.coupon_type_id;
  227. receiveCoupon(data)
  228. .then(res => {
  229. // console.log(res)
  230. // console.log('12312313')
  231. // return false
  232. var data = res.data;
  233. let msg = res.message;
  234. if (res.code == 0) {
  235. msg = '领取成功';
  236. this.$message({
  237. message: msg,
  238. type: 'success'
  239. });
  240. } else {
  241. this.$message({
  242. message: msg,
  243. type: 'warning'
  244. });
  245. }
  246. let list = this.couponList;
  247. if (res.data.is_exist == 1) {
  248. for (let i = 0; i < list.length; i++) {
  249. if (this.activeName == 'first') {
  250. if (list[i].coupon_type_id == item.coupon_type_id) {
  251. list[i].useState = 1;
  252. }
  253. } else {
  254. if (list[i].platformcoupon_type_id == item.platformcoupon_type_id) {
  255. list[i].useState = 1;
  256. }
  257. }
  258. }
  259. } else {
  260. for (let i = 0; i < list.length; i++) {
  261. if (this.activeName == 'first') {
  262. if (list[i].coupon_type_id == item.coupon_type_id) {
  263. list[i].useState = 2;
  264. }
  265. } else {
  266. if (list[i].platformcoupon_type_id == item.platformcoupon_type_id) {
  267. list[i].useState = 2;
  268. }
  269. }
  270. }
  271. }
  272. this.couponBtnSwitch = false;
  273. this.$forceUpdate();
  274. })
  275. .catch(err => {
  276. if( err.message == '您尚未登录,请先进行登录' ){
  277. this.$router.push('/auth/login');
  278. } else {
  279. this.$message.error(err.message)
  280. }
  281. this.couponBtnSwitch = false;
  282. });
  283. },
  284. /**
  285. * 去购买
  286. */
  287. toGoodsList(item) {
  288. if (this.activeName == 'first') {
  289. if (item.goods_type != 1) {
  290. this.$router.push({
  291. path: '/goods/list',
  292. query: {
  293. coupon: item.coupon_type_id
  294. }
  295. });
  296. } else {
  297. this.$router.push({
  298. path: '/goods/list',
  299. });
  300. }
  301. } else {
  302. this.$router.push('/goods/list');
  303. }
  304. }
  305. }
  306. };
  307. </script>
  308. <style lang="scss" scoped>
  309. .empty-wrap {
  310. margin-top: 20px;
  311. }
  312. .ns-coupon {
  313. width: $width;
  314. padding: 20px 0;
  315. margin: 0 auto;
  316. box-sizing: border-box;
  317. }
  318. .ns-coupon-info {
  319. background: url(../../assets/images/coupon-bg.png) no-repeat;
  320. background-size: cover;
  321. width: 100%;
  322. height: 450px;
  323. display: flex;
  324. .ns-coupon-wrap {
  325. width: 320px;
  326. padding: 20px;
  327. box-sizing: border-box;
  328. text-align: center;
  329. .coupon-name {
  330. margin: 45px 0 50px;
  331. span:nth-child(1) {
  332. display: block;
  333. line-height: 45px;
  334. font-size: 30px;
  335. }
  336. .ns-text-color-gray {
  337. color: #898989 !important;
  338. }
  339. .text12 {
  340. font-size: 12px;
  341. }
  342. }
  343. .coupon-type {
  344. margin-left: 20px;
  345. li {
  346. float: left;
  347. width: 80px;
  348. height: 100px;
  349. i {
  350. display: block;
  351. width: 50px;
  352. height: 50px;
  353. margin: 8px auto;
  354. }
  355. &:nth-child(1) i {
  356. background: url(../../assets/images/limited_time.png) no-repeat center;
  357. }
  358. &:nth-child(2) i {
  359. background: url(../../assets/images/superposition.png) no-repeat center;
  360. }
  361. &:nth-child(3) i {
  362. background: url(../../assets/images/coupon_type.png) no-repeat center;
  363. }
  364. }
  365. }
  366. .el-button {
  367. width: 200px;
  368. background-color: $base-color;
  369. color: #fff;
  370. margin-top: 70px;
  371. font-size: 18px;
  372. }
  373. }
  374. .ns-coupon-img {
  375. width: 850px;
  376. padding: 20px;
  377. box-sizing: border-box;
  378. img {
  379. width: 100%;
  380. height: 100%;
  381. }
  382. .el-carousel__item:nth-child(2n) {
  383. background-color: #99a9bf;
  384. }
  385. .el-carousel__item:nth-child(2n + 1) {
  386. background-color: #d3dce6;
  387. }
  388. }
  389. }
  390. .el-tabs {
  391. margin-top: 20px;
  392. }
  393. .ns-coupon-list {
  394. display: flex;
  395. flex-wrap: wrap;
  396. padding: 0 20px;
  397. .ns-coupon-li {
  398. background: url(../../assets/images/list_bj.png) no-repeat;
  399. width: 32%;
  400. height: 169px;
  401. margin-bottom: 20px;
  402. margin-right: 2%;
  403. background-size: cover;
  404. &.no-coupon {
  405. background: url(../../assets/images/no_coupon.png) no-repeat !important;
  406. background-color : #e6e6e6 !important;
  407. .describe{
  408. color : #999 !important;
  409. }
  410. .receive {
  411. .ns-text-color {
  412. color : #999 !important;
  413. }
  414. }
  415. }
  416. .describe {
  417. float: left;
  418. width: 250px;
  419. height: inherit;
  420. text-align: center;
  421. color: #fff;
  422. span {
  423. display: block;
  424. }
  425. span:nth-child(1) {
  426. font-size: 40px;
  427. margin-top: 20px;
  428. margin-bottom: 3px;
  429. line-height: 50px;
  430. }
  431. span:nth-child(3),
  432. span:nth-child(4),
  433. span:nth-child(5) {
  434. font-size: 12px;
  435. margin-left: 15px;
  436. line-height: 20px;
  437. }
  438. }
  439. .receive {
  440. float: right;
  441. width: 95px;
  442. height: inherit;
  443. text-align: center;
  444. a {
  445. display: inline-block;
  446. width: 30px;
  447. height: 120px;
  448. line-height: 120px;
  449. padding: 0 5px;
  450. margin-top: 25px;
  451. background-color: #fff;
  452. border-radius: 15px;
  453. cursor: pointer;
  454. box-sizing: border-box;
  455. span {
  456. display: inline-block;
  457. line-height: 20px;
  458. vertical-align: middle;
  459. }
  460. }
  461. }
  462. &:nth-child(3n) {
  463. margin-right: 0;
  464. }
  465. }
  466. }
  467. </style>