cm-coupon-list.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. <!-- 使用优惠券按钮 -->
  56. <view class="btn" @click="confirm" v-if="listType === 'use'">确定</view>
  57. <!-- IPhoneX 以上版本适配 -->
  58. <view :style="{ height: isIphoneX ? '40rpx' : 0 }"></view>
  59. </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. $other-line-height: 40rpx;
  160. $tabs-height: 80rpx;
  161. $main-height: 1028rpx;
  162. $base-scroll-height: $main-height - $title-top - $title-bottom - $title-line-height;
  163. .mask {
  164. position: fixed;
  165. bottom: 0;
  166. left: 0;
  167. width: 100%;
  168. height: 100%;
  169. background: rgba(0, 0, 0, 0.5);
  170. z-index: 99998;
  171. }
  172. .cm-coupon-list {
  173. .main-content {
  174. width: 750rpx;
  175. position: fixed;
  176. bottom: 0;
  177. left: 0;
  178. z-index: 99999;
  179. .content {
  180. position: relative;
  181. width: 100%;
  182. height: $main-height;
  183. border-radius: 16rpx 16rpx 0px 0px;
  184. background: #fff;
  185. .close {
  186. position: absolute;
  187. top: 36rpx;
  188. right: 36rpx;
  189. font-size: 34rpx;
  190. color: #b2b2b2;
  191. }
  192. .title {
  193. padding: $title-top 0 $title-bottom;
  194. text-align: center;
  195. font-size: 34rpx;
  196. font-weight: 500;
  197. line-height: $title-line-height;
  198. color: #333333;
  199. }
  200. .other {
  201. padding: 0 $grid $grid;
  202. line-height: $other-line-height;
  203. .unset {
  204. display: flex;
  205. justify-content: space-between;
  206. align-items: center;
  207. padding-right: 30rpx;
  208. font-size: 30rpx;
  209. color: #333333;
  210. .radio-flag {
  211. color: #ff457b;
  212. }
  213. }
  214. .tabs {
  215. height: $tabs-height;
  216. line-height: $tabs-height;
  217. border-bottom: 1px solid #e1e1e1;
  218. display: flex;
  219. justify-content: space-around;
  220. align-items: center;
  221. .tab {
  222. position: relative;
  223. font-size: 30rpx;
  224. color: #333333;
  225. &::after {
  226. content: '';
  227. position: absolute;
  228. width: 100%;
  229. height: 4rpx;
  230. bottom: 0;
  231. left: 0;
  232. background-color: #fff;
  233. }
  234. &.active {
  235. color: #ff457b;
  236. &::after {
  237. background-color: #ff457b;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. .list {
  244. overflow-y: scroll;
  245. // 查看优惠券
  246. &.scroll-search {
  247. height: $base-scroll-height - $tabs-height;
  248. }
  249. // 领取优惠券
  250. &.scroll-receive {
  251. height: $base-scroll-height;
  252. }
  253. // 使用优惠券
  254. &.scroll-use {
  255. height: $base-scroll-height - $other-line-height - $grid;
  256. }
  257. .btn {
  258. width: 600rpx;
  259. height: 90rpx;
  260. margin: $grid auto;
  261. background: linear-gradient(90deg, #fc32b4 0%, #f83c6c 100%);
  262. opacity: 1;
  263. border-radius: 45rpx;
  264. line-height: 90rpx;
  265. text-align: center;
  266. font-size: 30rpx;
  267. color: #ffffff;
  268. }
  269. }
  270. }
  271. }
  272. }
  273. </style>