coupon-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view v-if="value" class="coupon-popup-overlay" @click="close">
  3. <view class="coupon-popup" @click.stop>
  4. <view class="coupon-popup-header">
  5. <view class="coupon-popup-title">领取优惠券</view>
  6. <view class="coupon-popup-close" @click="close">×</view>
  7. </view>
  8. <view class="coupon-popup-content">
  9. <view v-if="couponsList.length > 0" class="tui-coupon-list">
  10. <view class="tui-coupon-item tui-top20" v-for="(item, index) in couponsList" :key="index">
  11. <image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/images/bg_coupon_3x.png" class="tui-coupon-bg" mode="widthFix"></image>
  12. <view class="tui-coupon-item-left">
  13. <view class="tui-coupon-price-box" :class="{ 'tui-color-grey': item.receiveCount>0 }">
  14. <view class="tui-coupon-price-sign">¥</view>
  15. <view class="tui-coupon-price">{{ item.couponPrice }}</view>
  16. </view>
  17. <view class="tui-coupon-intro">满{{ item.useMinPrice }}元可用</view>
  18. </view>
  19. <view class="tui-coupon-item-right">
  20. <view class="tui-coupon-content">
  21. <view class="tui-coupon-title-box">
  22. <view class="tui-coupon-title">{{ item.couponName }}</view>
  23. </view>
  24. <view class="tui-coupon-rule">
  25. <view class="tui-rule-box tui-padding-btm">
  26. <view class="tui-coupon-circle"></view>
  27. <view class="tui-coupon-text">不可叠加使用</view>
  28. </view>
  29. <view class="tui-rule-box">
  30. <view class="tui-coupon-circle"></view>
  31. <view class="tui-coupon-text">{{ item.limitTime }} 到期</view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="tui-btn-box">
  37. <view
  38. class="btn receive"
  39. @click="getCouponIssueById(item)"
  40. :class="{ 'btn-received': item.receiveCount > 0 }"
  41. >
  42. {{ item.receiveCount > 0 ? '已领取' : '领取' }}
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view v-else class="no-data-box">
  48. <image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/images/no_data.png" mode="aspectFit"></image>
  49. <view class="empty-title">暂无优惠券</view>
  50. <view class="empty-desc">更多优惠敬请期待</view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. import { getCompanyCouponIssueList, receive, getCouponIssueById as apiGetCouponIssueById } from '@/api/coupon'
  58. export default {
  59. name: 'CouponPopup',
  60. props: {
  61. value: {
  62. type: Boolean,
  63. default: false
  64. }
  65. },
  66. data() {
  67. return {
  68. couponsList: [],
  69. loading: false,
  70. loadend: false,
  71. page: 1,
  72. limit: 10
  73. }
  74. },
  75. watch: {
  76. value: {
  77. immediate: true,
  78. handler(newVal) {
  79. if (newVal) {
  80. this.loadCoupons()
  81. }
  82. }
  83. }
  84. },
  85. methods: {
  86. // 关闭弹窗
  87. close() {
  88. this.$emit('input', false)
  89. },
  90. // 加载优惠券列表
  91. loadCoupons() {
  92. this.page = 1
  93. this.couponsList = []
  94. this.loadend = false
  95. this.getCouponsList()
  96. },
  97. // 获取优惠券列表
  98. getCouponsList() {
  99. if (this.loadend) return
  100. this.loading = true
  101. getCompanyCouponIssueList().then(res => {
  102. this.loading = false
  103. if (res.code == 200) {
  104. this.couponsList.push.apply(this.couponsList, res.data.list)
  105. this.loadend = res.data.list.length < this.limit
  106. this.page++
  107. }
  108. }).catch(err => {
  109. this.loading = false
  110. console.error('获取优惠券列表失败:', err)
  111. })
  112. },
  113. // 获取销售可用套餐卷
  114. getCouponIssueById(item) {
  115. console.log('获取销售可用套餐卷item:', item)
  116. if (this.loading) return
  117. if (item.receiveCount > 0) return
  118. this.loading = true
  119. // 调用接口获取优惠券信息
  120. const data = { id: item.id };
  121. console.log('API参数:', data)
  122. apiGetCouponIssueById(data).then(res => {
  123. this.loading = false
  124. console.log('获取销售可用套餐卷接口返回:', res)
  125. if (res && (res.code == 200 || res.msg == "success")) {
  126. console.log('获取销售可用套餐卷成功,准备调用领取方法')
  127. // 调用领取优惠券方法,传递完整的item对象
  128. this.receiveCoupon(item, res.code)
  129. } else {
  130. console.error('获取销售可用套餐卷失败:', res.message || '接口返回错误')
  131. uni.showToast({
  132. title: res.message || '获取优惠券信息失败',
  133. icon: 'none'
  134. })
  135. }
  136. }).catch(err => {
  137. this.loading = false
  138. console.error('获取销售可用套餐卷异常:', err)
  139. uni.showToast({
  140. title: '获取优惠券信息失败',
  141. icon: 'none'
  142. })
  143. })
  144. },
  145. // 领取优惠券
  146. receiveCoupon(item, code) {
  147. console.log('领取优惠券item:', item)
  148. console.log('领取优惠券code:', code)
  149. if (!item) {
  150. console.error('领取优惠券失败:item 参数未定义')
  151. return
  152. }
  153. if (item.receiveCount > 0) return
  154. receive({ couponIssueId: item.id, code: code }).then(res => {
  155. if (res.code == 200) {
  156. uni.showToast({
  157. title: '领取成功',
  158. icon: 'success'
  159. })
  160. // 更新优惠券状态
  161. item.receiveCount = 1
  162. } else {
  163. uni.showToast({
  164. title: res.message || '领取失败',
  165. icon: 'none'
  166. })
  167. }
  168. }).catch(err => {
  169. console.error('领取优惠券失败:', err)
  170. uni.showToast({
  171. title: '领取失败',
  172. icon: 'none'
  173. })
  174. })
  175. }
  176. }
  177. }
  178. </script>
  179. <style scoped lang="scss">
  180. /* 优惠券弹窗样式 */
  181. .coupon-popup-overlay {
  182. position: fixed;
  183. top: 0;
  184. left: 0;
  185. right: 0;
  186. bottom: 0;
  187. background: rgba(0, 0, 0, 0.5);
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. z-index: 9999;
  192. }
  193. .coupon-popup {
  194. width: 100%;
  195. max-height: 80vh;
  196. background: #fff;
  197. border-radius: 16rpx 16rpx 0 0;
  198. overflow: hidden;
  199. position: fixed;
  200. bottom: 0;
  201. }
  202. .coupon-popup-header {
  203. display: flex;
  204. justify-content: space-between;
  205. align-items: center;
  206. padding: 30rpx;
  207. border-bottom: 1rpx solid #EEEEEE;
  208. }
  209. .coupon-popup-title {
  210. font-size: 32rpx;
  211. font-weight: 500;
  212. color: #333333;
  213. }
  214. .coupon-popup-close {
  215. font-size: 40rpx;
  216. color: #999999;
  217. }
  218. .coupon-popup-content {
  219. padding: 20rpx;
  220. max-height: 60vh;
  221. overflow-y: auto;
  222. }
  223. /* 优惠券列表样式,参考 coupon.vue */
  224. .tui-coupon-list {
  225. width: 100%;
  226. padding: 0 10rpx;
  227. }
  228. .tui-coupon-item {
  229. width: 100%;
  230. height: 210rpx;
  231. position: relative;
  232. display: flex;
  233. align-items: center;
  234. padding-right: 30rpx;
  235. box-sizing: border-box;
  236. overflow: hidden;
  237. margin-top: 20rpx;
  238. }
  239. .tui-coupon-bg {
  240. width: 100%;
  241. height: 210rpx;
  242. position: absolute;
  243. left: 0;
  244. top: 0;
  245. z-index: 1;
  246. }
  247. .tui-coupon-item-left {
  248. width: 218rpx;
  249. height: 210rpx;
  250. position: relative;
  251. z-index: 2;
  252. display: flex;
  253. align-items: center;
  254. justify-content: center;
  255. flex-direction: column;
  256. flex-shrink: 0;
  257. }
  258. .tui-coupon-price-box {
  259. display: flex;
  260. color: #e41f19;
  261. align-items: flex-end;
  262. }
  263. .tui-coupon-price-sign {
  264. font-size: 30rpx;
  265. }
  266. .tui-coupon-price {
  267. font-size: 32rpx;
  268. line-height: 68rpx;
  269. font-weight: bold;
  270. }
  271. .tui-color-grey {
  272. color: #888 !important;
  273. }
  274. .tui-coupon-intro {
  275. background: #f7f7f7;
  276. padding: 8rpx 10rpx;
  277. font-size: 26rpx;
  278. line-height: 26rpx;
  279. font-weight: 400;
  280. color: #666;
  281. margin-top: 18rpx;
  282. }
  283. .tui-coupon-item-right {
  284. flex: 1;
  285. height: 210rpx;
  286. position: relative;
  287. z-index: 2;
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. padding-left: 24rpx;
  292. box-sizing: border-box;
  293. overflow: hidden;
  294. }
  295. .tui-coupon-content {
  296. width: 82%;
  297. display: flex;
  298. flex-direction: column;
  299. justify-content: center;
  300. }
  301. .tui-coupon-title-box {
  302. display: flex;
  303. align-items: center;
  304. }
  305. .tui-coupon-title {
  306. width: 100%;
  307. font-size: 26rpx;
  308. color: #333;
  309. white-space: nowrap;
  310. overflow: hidden;
  311. text-overflow: ellipsis;
  312. }
  313. .tui-coupon-rule {
  314. padding-top: 52rpx;
  315. }
  316. .tui-rule-box {
  317. display: flex;
  318. align-items: center;
  319. transform: scale(0.8);
  320. transform-origin: 0 100%;
  321. }
  322. .tui-padding-btm {
  323. padding-bottom: 6rpx;
  324. }
  325. .tui-coupon-circle {
  326. width: 8rpx;
  327. height: 8rpx;
  328. background: rgb(160, 160, 160);
  329. border-radius: 50%;
  330. }
  331. .tui-coupon-text {
  332. font-size: 28rpx;
  333. line-height: 28rpx;
  334. font-weight: 400;
  335. color: #666;
  336. padding-left: 8rpx;
  337. white-space: nowrap;
  338. }
  339. .tui-btn-box {
  340. position: absolute;
  341. right: 20rpx;
  342. bottom: 40rpx;
  343. z-index: 10;
  344. .btn {
  345. width: 155upx;
  346. height: 64upx;
  347. line-height: 64upx;
  348. font-size: 26upx;
  349. font-family: PingFang SC;
  350. font-weight: 500;
  351. text-align: center;
  352. border-radius: 32upx;
  353. margin-left: 15upx;
  354. transition: all 0.3s ease;
  355. &.receive {
  356. background: linear-gradient(135deg, #FF6B6B 0%, #FF4757 100%);
  357. color: #FFFFFF;
  358. box-shadow: 0 4rpx 12rpx rgba(255, 107, 107, 0.3);
  359. &:hover {
  360. transform: translateY(-2rpx);
  361. box-shadow: 0 6rpx 16rpx rgba(255, 107, 107, 0.4);
  362. }
  363. &:active {
  364. transform: translateY(0);
  365. box-shadow: 0 2rpx 8rpx rgba(255, 107, 107, 0.3);
  366. }
  367. }
  368. &.btn-received {
  369. background: #F5F5F5;
  370. color: #999999;
  371. border: 1rpx solid #E0E0E0;
  372. }
  373. }
  374. }
  375. .no-data-box {
  376. display: flex;
  377. flex-direction: column;
  378. align-items: center;
  379. justify-content: center;
  380. padding: 120rpx 0;
  381. background: linear-gradient(135deg, #FAFAFA 0%, #F5F5F5 100%);
  382. margin: 20rpx;
  383. border-radius: 16rpx;
  384. box-shadow: inset 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  385. }
  386. .no-data-box image {
  387. width: 200rpx;
  388. height: 200rpx;
  389. margin-bottom: 30rpx;
  390. opacity: 0.7;
  391. }
  392. .empty-title {
  393. font-size: 30rpx;
  394. color: #666666;
  395. font-weight: 500;
  396. margin-bottom: 16rpx;
  397. }
  398. .empty-desc {
  399. font-size: 24rpx;
  400. color: #999999;
  401. line-height: 36rpx;
  402. text-align: center;
  403. padding: 0 40rpx;
  404. }
  405. /* 优惠券项美化 */
  406. .tui-coupon-item {
  407. transition: all 0.3s ease;
  408. transform-origin: center;
  409. &:hover {
  410. transform: translateY(-4rpx);
  411. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.1);
  412. }
  413. }
  414. /* 价格样式优化 */
  415. .tui-coupon-price {
  416. font-size: 40rpx;
  417. line-height: 68rpx;
  418. font-weight: bold;
  419. background: linear-gradient(135deg, #FF6B6B 0%, #FF4757 100%);
  420. -webkit-background-clip: text;
  421. -webkit-text-fill-color: transparent;
  422. background-clip: text;
  423. }
  424. .tui-color-grey .tui-coupon-price {
  425. background: linear-gradient(135deg, #999999 0%, #777777 100%);
  426. -webkit-background-clip: text;
  427. -webkit-text-fill-color: transparent;
  428. background-clip: text;
  429. }
  430. /* 标题样式优化 */
  431. .tui-coupon-title {
  432. width: 100%;
  433. font-size: 28rpx;
  434. color: #333;
  435. font-weight: 500;
  436. white-space: nowrap;
  437. overflow: hidden;
  438. text-overflow: ellipsis;
  439. }
  440. /* 规则样式优化 */
  441. .tui-coupon-rule {
  442. padding-top: 40rpx;
  443. }
  444. .tui-coupon-text {
  445. font-size: 24rpx;
  446. line-height: 28rpx;
  447. font-weight: 400;
  448. color: #888;
  449. padding-left: 8rpx;
  450. white-space: nowrap;
  451. }
  452. /* 分隔线美化 */
  453. .tui-coupon-item-left::after {
  454. content: '';
  455. position: absolute;
  456. right: 0;
  457. top: 50%;
  458. transform: translateY(-50%);
  459. width: 1rpx;
  460. height: 120rpx;
  461. background: linear-gradient(180deg, transparent 0%, rgba(255, 255, 255, 0.6) 50%, transparent 100%);
  462. z-index: 1;
  463. }
  464. </style>