red-packet-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <u-popup v-model="show" mode="bottom" border-radius="24" :safe-area-inset-bottom="true">
  3. <view class="red-packet-popup">
  4. <view class="popup-header">
  5. <text>优惠详情</text>
  6. <view class="close-btn" @click="close">
  7. <u-icon name="close" size="24" color="#666"></u-icon>
  8. </view>
  9. </view>
  10. <view class="filter-tabs" v-if="list && list.length > 0">
  11. <view class="tab" :class="{ active: currentTab === 'all' }" @click="currentTab = 'all'">全部</view>
  12. <view class="tab" :class="{ active: currentTab === 'unavailable' }" @click="currentTab = 'unavailable'">不可用</view>
  13. </view>
  14. <scroll-view scroll-y class="packet-list" v-if="list && list.length > 0">
  15. <!-- 可用红包 -->
  16. <template v-if="currentTab === 'all'">
  17. <view class="packet-item available" v-for="(item, index) in availableList" :key="index" @click="selectPacket(item)">
  18. <view class="packet-main">
  19. <view class="packet-left">
  20. <text class="currency">¥</text>
  21. <text class="amount">{{ item.faceMoney }}</text>
  22. </view>
  23. <view class="packet-right">
  24. <view class="packet-name">{{ item.couponName }}</view>
  25. <view class="packet-rule">{{ item.thresholdMoney == 0 ? '无门槛' : '满' + item.thresholdMoney + '元可用' }}</view>
  26. </view>
  27. <view class="packet-check">
  28. <u-icon name="checkmark-circle-fill" size="40"
  29. :color="selectedItem && selectedItem.userCouponId === item.userCouponId ? '#ff4500' : '#e0e0e0'"></u-icon>
  30. </view>
  31. </view>
  32. <view class="packet-time">{{ item.effectStartTime }}至{{ item.effectEndTime }}</view>
  33. </view>
  34. </template>
  35. <!-- 不可用红包 -->
  36. <template v-if="unavailableList.length > 0 && (currentTab === 'all' || currentTab === 'unavailable')">
  37. <view class="section-title" v-if="currentTab === 'all'">本单不可用红包</view>
  38. <view class="packet-item unavailable" v-for="(item, index) in unavailableList" :key="index">
  39. <view class="packet-main">
  40. <view class="packet-left">
  41. <text class="currency">¥</text>
  42. <text class="amount">{{ item.faceMoney }}</text>
  43. </view>
  44. <view class="packet-right">
  45. <view class="packet-name">{{ item.couponName }}</view>
  46. <view class="packet-rule">{{ item.thresholdMoney == 0 ? '无门槛' : '满' + item.thresholdMoney + '元可用' }}</view>
  47. </view>
  48. <view class="packet-check">
  49. <view class="disabled-radio"></view>
  50. </view>
  51. </view>
  52. <view class="packet-reason">
  53. 本单不可用原因:{{ item.unavailableReason || '不满足使用条件' }}
  54. </view>
  55. </view>
  56. </template>
  57. </scroll-view>
  58. <view class="empty-state" v-else>
  59. <image src="https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/no-data.png"
  60. style="width: 260rpx; height: 260rpx" mode="aspectFit"></image>
  61. <view class="empty-text">暂无红包</view>
  62. </view>
  63. <view class="popup-footer" v-if="list && list.length > 0">
  64. <u-button type="primary" shape="circle" @click="confirm" :custom-style="btnStyle">确定</u-button>
  65. </view>
  66. </view>
  67. </u-popup>
  68. </template>
  69. <script>
  70. export default {
  71. props: {
  72. value: {
  73. type: Boolean,
  74. default: false
  75. },
  76. list: {
  77. type: Array,
  78. default: () => []
  79. }
  80. },
  81. data() {
  82. return {
  83. show: false,
  84. currentTab: 'all',
  85. selectedItem: null,
  86. btnStyle: {
  87. background: 'linear-gradient(90deg, #ff6b00, #ff4500)',
  88. color: '#fff',
  89. border: 'none'
  90. }
  91. }
  92. },
  93. computed: {
  94. availableList() {
  95. return this.list.filter(item => item.status === 1);
  96. },
  97. unavailableList() {
  98. return this.list.filter(item => item.status === 0);
  99. }
  100. },
  101. watch: {
  102. value(val) {
  103. this.show = val;
  104. if (val) {
  105. // 重置 tab
  106. this.currentTab = 'all';
  107. }
  108. },
  109. show(val) {
  110. this.$emit('input', val);
  111. }
  112. },
  113. methods: {
  114. close() {
  115. this.show = false;
  116. },
  117. selectPacket(item) {
  118. if (this.selectedItem && this.selectedItem.userCouponId === item.userCouponId) {
  119. // 如果点击的是已选中的项,则取消选中
  120. this.selectedItem = null;
  121. } else {
  122. this.selectedItem = item;
  123. }
  124. },
  125. confirm() {
  126. this.$emit('confirm', this.selectedItem);
  127. this.close();
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .red-packet-popup {
  134. height: 100%;
  135. max-height: 80vh;
  136. display: flex;
  137. flex-direction: column;
  138. overflow: hidden;
  139. .popup-header {
  140. display: flex;
  141. justify-content: center;
  142. align-items: center;
  143. padding: 30rpx;
  144. position: relative;
  145. font-size: 32rpx;
  146. font-weight: bold;
  147. color: #333;
  148. background-color: #fff;
  149. .close-btn {
  150. position: absolute;
  151. right: 30rpx;
  152. top: 50%;
  153. transform: translateY(-50%);
  154. width: 50rpx;
  155. height: 50rpx;
  156. background-color: #f5f5f5;
  157. border-radius: 50%;
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. }
  162. }
  163. .filter-tabs {
  164. display: flex;
  165. padding: 0 30rpx;
  166. margin-bottom: 20rpx;
  167. background-color: #fff;
  168. padding-bottom: 10rpx;
  169. .tab {
  170. padding: 12rpx 30rpx;
  171. border-radius: 8rpx;
  172. font-size: 26rpx;
  173. margin-right: 20rpx;
  174. background-color: #f5f5f5;
  175. color: #333;
  176. transition: all 0.3s;
  177. &.active {
  178. background-color: #fff0e6;
  179. color: #ff4500;
  180. font-weight: bold;
  181. }
  182. }
  183. }
  184. .packet-list {
  185. flex: 1;
  186. box-sizing: border-box;
  187. height: 600rpx;
  188. overflow-y: auto;
  189. padding-top: 20rpx;
  190. padding-bottom: 40rpx;
  191. .section-title {
  192. font-size: 30rpx;
  193. color: #333;
  194. font-weight: bold;
  195. margin: 10rpx 30rpx 20rpx;
  196. }
  197. .packet-item {
  198. margin: 0 30rpx 20rpx;
  199. border-radius: 16rpx;
  200. overflow: hidden;
  201. background-color: #fffaf7;
  202. &.available {
  203. box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
  204. border: 1rpx solid #f9f9f9;
  205. .packet-left {
  206. color: #ff4500;
  207. }
  208. .packet-name {
  209. color: #333;
  210. }
  211. .packet-rule {
  212. color: #666;
  213. }
  214. .packet-time {
  215. padding: 16rpx 24rpx;
  216. font-size: 22rpx;
  217. color: #999;
  218. background-color: #fffaf7;
  219. border-top: 1rpx dashed #ffe6e6;
  220. }
  221. }
  222. &.unavailable {
  223. background-color: #fefefe;
  224. .packet-left {
  225. color: #999;
  226. }
  227. .packet-name {
  228. color: #666;
  229. }
  230. .packet-rule {
  231. color: #999;
  232. }
  233. .packet-reason {
  234. padding: 20rpx 24rpx;
  235. font-size: 24rpx;
  236. color: #999;
  237. border-top: 1rpx dashed #eee;
  238. background-color: #fafafa;
  239. }
  240. }
  241. .packet-main {
  242. display: flex;
  243. align-items: center;
  244. padding: 30rpx 24rpx;
  245. }
  246. .packet-left {
  247. width: 150rpx;
  248. display: flex;
  249. align-items: baseline;
  250. .currency {
  251. font-size: 28rpx;
  252. margin-right: 4rpx;
  253. }
  254. .amount {
  255. font-size: 48rpx;
  256. font-weight: bold;
  257. }
  258. }
  259. .packet-right {
  260. flex: 1;
  261. margin-left: 10rpx;
  262. .packet-name {
  263. font-size: 30rpx;
  264. font-weight: bold;
  265. margin-bottom: 8rpx;
  266. }
  267. .packet-rule {
  268. font-size: 24rpx;
  269. }
  270. }
  271. .packet-check {
  272. margin-left: 20rpx;
  273. .disabled-radio {
  274. width: 40rpx;
  275. height: 40rpx;
  276. border-radius: 50%;
  277. border: 2rpx solid #ddd;
  278. background-color: #eee;
  279. box-sizing: border-box;
  280. }
  281. }
  282. }
  283. }
  284. .empty-state {
  285. display: flex;
  286. flex-direction: column;
  287. align-items: center;
  288. justify-content: center;
  289. padding: 60rpx 0;
  290. .empty-text {
  291. color: #999;
  292. font-size: 28rpx;
  293. margin-top: 20rpx;
  294. }
  295. }
  296. .popup-footer {
  297. padding: 20rpx 40rpx;
  298. background-color: #fff;
  299. box-shadow: 0 -4rpx 10rpx rgba(0, 0, 0, 0.02);
  300. }
  301. }
  302. </style>