cm-coupon-list.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="cm-coupon-list">
  3. <view class="mask" v-if="visible"></view>
  4. <view class="main-content">
  5. <uni-transition mode-class="slide-bottom" :show="visible">
  6. <view class="content">
  7. <!-- 关闭弹框按钮 -->
  8. <view class="iconfont icon-iconfontguanbi close" @click="$emit('close')"></view>
  9. <!-- 弹框标题 -->
  10. <view class="title">{{ title }}</view>
  11. <view class="other" v-if="listType !== 'receive'">
  12. <!-- 勾选不使用优惠券 -->
  13. <view class="unset" v-if="listType === 'use'">
  14. <text>不使用优惠券</text>
  15. <text
  16. class="radio-flag iconfont"
  17. :class="currentId === -1 ? 'icon-xuanze' : 'icon-weixuanze'"
  18. @click="noChoose"
  19. ></text>
  20. </view>
  21. <!-- tab切换 -->
  22. <view class="tabs" v-if="listType === 'search'">
  23. <view
  24. class="tab"
  25. :class="{ active: currentTab === index }"
  26. v-for="(tab, index) in tabs"
  27. :key="index"
  28. @click="checkedTab(index)"
  29. >
  30. <text>{{ tab.name }}</text>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="list" :class="['scroll-' + listType]">
  35. <!-- 优惠券列表 -->
  36. <template v-for="(coupon, index) in couponList">
  37. <cm-coupon
  38. :key="index"
  39. :couponData="coupon"
  40. @btnClick="couponClick"
  41. :showStatus="showStatus"
  42. :btnUseType="btnUseType"
  43. :chooseAble="chooseAble"
  44. @choose="choose"
  45. :currentId="currentId"
  46. ></cm-coupon>
  47. </template>
  48. <!-- 优惠券为空 -->
  49. <cm-empty
  50. message="暂无任何优惠券~"
  51. v-if="couponList.length <= 0"
  52. :image="baseUrl + 'icon-coupon-empty.png'"
  53. :offset="-12"
  54. ></cm-empty>
  55. </view>
  56. <!-- 使用优惠券按钮 -->
  57. <view class="btn" @click="confirm" v-if="listType === 'use'">确定</view>
  58. <!-- IPhoneX 以上版本适配 -->
  59. <view :style="{ height: isIphoneX ? '44rpx' : 0 }"></view>
  60. </view>
  61. </uni-transition>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import CmCoupon from '@/components/cm-module/cm-coupon/cm-coupon.vue'
  67. import CmEmpty from '@/components/cm-module/cm-empty/cm-empty.vue'
  68. import { mapGetters } from 'vuex'
  69. export default {
  70. name: 'cm-coupon-list',
  71. components: {
  72. CmCoupon,
  73. CmEmpty
  74. },
  75. props: {
  76. // 列表标题
  77. title: {
  78. type: String,
  79. default: '优惠券'
  80. },
  81. // 优惠券列表
  82. couponList: {
  83. type: Array,
  84. default: () => []
  85. },
  86. // 显示弹窗
  87. visible: {
  88. type: Boolean,
  89. default: false
  90. },
  91. // 列表类型 receive 领取 use 使用 search 查看
  92. listType: {
  93. type: String,
  94. default: 'receive'
  95. },
  96. btnUseType: {
  97. type: Number,
  98. default: 1
  99. },
  100. showStatus: {
  101. type: Boolean,
  102. default: false
  103. },
  104. chooseAble: {
  105. type: Boolean,
  106. default: false
  107. },
  108. currentId: {
  109. type: Number,
  110. default: -1
  111. },
  112. tabs: {
  113. type: Array,
  114. default: () => [
  115. {
  116. name: '已领取优惠券'
  117. },
  118. {
  119. name: '可领取优惠券'
  120. }
  121. ]
  122. }
  123. },
  124. data() {
  125. return {
  126. baseUrl: this.$Static,
  127. currentTab: 0
  128. }
  129. },
  130. computed: {
  131. ...mapGetters(['isIphoneX'])
  132. },
  133. methods: {
  134. // 确认需要把优惠券对象返回
  135. confirm() {
  136. this.$emit('confirm')
  137. },
  138. checkedTab(index) {
  139. this.currentTab = index
  140. this.$emit('tabClick', index)
  141. },
  142. couponClick() {
  143. this.$emit('couponClick')
  144. },
  145. choose(coupon) {
  146. this.$emit('chooseCoupon', coupon)
  147. },
  148. noChoose() {
  149. this.$emit('chooseCoupon', { couponId: -1, })
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. $grid: 24rpx;
  156. $title-top: 50rpx;
  157. $title-bottom: 28rpx;
  158. $title-line-height: 50rpx;
  159. $tabs-height: 80rpx;
  160. $unset-height: 30rpx;
  161. $main-height: 1028rpx;
  162. $base-scroll-height: $main-height - $title-top - $title-bottom - $title-line-height;
  163. $btn-height: 90rpx;
  164. .mask {
  165. position: fixed;
  166. bottom: 0;
  167. left: 0;
  168. width: 100%;
  169. height: 100%;
  170. background: rgba(0, 0, 0, 0.5);
  171. z-index: 99998;
  172. }
  173. .cm-coupon-list {
  174. .main-content {
  175. width: 750rpx;
  176. position: fixed;
  177. bottom: 0;
  178. left: 0;
  179. z-index: 99999;
  180. .content {
  181. position: relative;
  182. width: 100%;
  183. height: $main-height;
  184. border-radius: 16rpx 16rpx 0px 0px;
  185. background: #fff;
  186. .close {
  187. position: absolute;
  188. top: 26rpx;
  189. right: 26rpx;
  190. font-size: 34rpx;
  191. color: #b2b2b2;
  192. width: 60rpx;
  193. height: 60rpx;
  194. text-align: center;
  195. line-height: 60rpx;
  196. }
  197. .title {
  198. padding: $title-top 0 $title-bottom;
  199. text-align: center;
  200. font-size: 34rpx;
  201. font-weight: 500;
  202. line-height: $title-line-height;
  203. color: #333333;
  204. }
  205. .other {
  206. padding: 0 $grid $grid;
  207. .unset {
  208. display: flex;
  209. justify-content: space-between;
  210. align-items: center;
  211. padding-right: 30rpx;
  212. font-size: 30rpx;
  213. line-height: $unset-height;
  214. color: #333333;
  215. .radio-flag {
  216. color: #ff457b;
  217. }
  218. }
  219. .tabs {
  220. height: $tabs-height;
  221. line-height: $tabs-height;
  222. border-bottom: 1px solid #e1e1e1;
  223. display: flex;
  224. justify-content: space-around;
  225. align-items: center;
  226. .tab {
  227. position: relative;
  228. font-size: 30rpx;
  229. color: #333333;
  230. &::after {
  231. content: '';
  232. position: absolute;
  233. width: 100%;
  234. height: 4rpx;
  235. bottom: 0;
  236. left: 0;
  237. background-color: #fff;
  238. }
  239. &.active {
  240. color: #ff457b;
  241. &::after {
  242. background-color: #ff457b;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. .list {
  249. overflow-y: scroll;
  250. // 查看优惠券
  251. &.scroll-search {
  252. height: $base-scroll-height - $tabs-height - $grid;
  253. }
  254. // 领取优惠券
  255. &.scroll-receive {
  256. height: $base-scroll-height;
  257. }
  258. // 使用优惠券
  259. &.scroll-use {
  260. height: $base-scroll-height - $unset-height - $btn-height - 3 * $grid;
  261. }
  262. }
  263. .btn {
  264. width: 600rpx;
  265. height: $btn-height;
  266. margin: $grid auto;
  267. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  268. opacity: 1;
  269. border-radius: 45rpx;
  270. line-height: $btn-height;
  271. text-align: center;
  272. font-size: 30rpx;
  273. color: #ffffff;
  274. }
  275. }
  276. }
  277. }
  278. </style>