cm-coupon-popup.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="coupon-popup">
  3. <uni-popup ref="popup" mask-background-color="rgba(0,0,0,0.8)" class="popup">
  4. <view class="popup-content" :style="[popupContentStyle]">
  5. <view class="close iconfont icon-iconfontguanbi" @click="handleClose"></view>
  6. <view class="header">
  7. <!-- 标题 -->
  8. <view class="title">优惠券</view>
  9. <!-- tabs选项卡 -->
  10. <tui-tabs
  11. :tabs="couponTabs"
  12. :currentTab="currentTab"
  13. selectedColor="#f83c6c"
  14. sliderBgColor="#f83c6c"
  15. badgeBgColor="#f83c6c"
  16. itemWidth="50%"
  17. @change="tabChange"
  18. v-if="hasTabs"
  19. ></tui-tabs>
  20. <!-- 不使用优惠券选项 -->
  21. <view class="choose-none" v-if="hasCheckedNone">
  22. <text>不使用优惠券</text>
  23. <view
  24. class="iconfont icon"
  25. :class="checkedClass"
  26. :data-name="controlType"
  27. @click="$emit('checkedNone')"
  28. ></view>
  29. </view>
  30. </view>
  31. <view class="coupon-list">
  32. <!-- 优惠券列表为空 -->
  33. <template v-if="list.length <= 0">
  34. <tui-no-data :imgUrl="staticUrl + 'icon-coupon-empty.png'" :imgHeight="230" :imgWidth="290">
  35. <view class="empty-tip">暂无任何优惠券~~</view>
  36. </tui-no-data>
  37. </template>
  38. <scroll-view
  39. scroll-y="true"
  40. class="scroll-box"
  41. v-else
  42. :style="{ paddingTop: paddingTop, paddingBottom: paddingBottom }"
  43. >
  44. <view class="coupon-section" v-for="item in list" :key="item.couponId">
  45. <cm-coupon
  46. :controlType="item.controlType || 'use'"
  47. :status="item.couponStatus"
  48. :checked="item.checked"
  49. :key="item.couponId"
  50. :couponData="item"
  51. @click="$emit('couponClick', item)"
  52. ></cm-coupon>
  53. </view>
  54. <cm-safe-area-bottom v-if="hasSafeArea"></cm-safe-area-bottom>
  55. </scroll-view>
  56. <view class="confirm-control" v-if="hasConfirm">
  57. <tui-button width="650rpx" height="88rpx" type="base" shape="circle" @click="handleClose">
  58. 确定
  59. </tui-button>
  60. <cm-safe-area-bottom v-if="hasSafeArea"></cm-safe-area-bottom>
  61. </view>
  62. </view>
  63. </view>
  64. </uni-popup>
  65. </view>
  66. </template>
  67. <script>
  68. import { mapGetters } from 'vuex'
  69. export default {
  70. name: 'cm-coupon-popup',
  71. props: {
  72. visiable: {
  73. type: Boolean,
  74. default: false
  75. },
  76. height: {
  77. type: String,
  78. default: '1000rpx'
  79. },
  80. list: {
  81. type: Array,
  82. default: () => []
  83. },
  84. couponTabs: {
  85. type: Array,
  86. default: () => []
  87. },
  88. transform: {
  89. type: String,
  90. default: '34px'
  91. },
  92. // tab切换
  93. hasTabs: {
  94. type: Boolean,
  95. default: false
  96. },
  97. // 确认按钮
  98. hasConfirm: {
  99. type: Boolean,
  100. default: false
  101. },
  102. // 是否需要安全距离
  103. hasSafeArea: {
  104. type: Boolean,
  105. default: false
  106. },
  107. checkedNone: {
  108. type: Boolean,
  109. default: false
  110. },
  111. hasCheckedNone: {
  112. type: Boolean,
  113. default: false
  114. }
  115. },
  116. data() {
  117. return {
  118. currentTab: 0
  119. }
  120. },
  121. watch: {
  122. visiable(nval) {
  123. if (nval) {
  124. this.$refs.popup.open('bottom')
  125. } else {
  126. this.$refs.popup.close()
  127. }
  128. }
  129. },
  130. computed: {
  131. ...mapGetters(['safeArea']),
  132. paddingTop() {
  133. return this.hasCheckedNone ? '168rpx' : this.hasTabs ? '188rpx' : '88rpx'
  134. },
  135. paddingBottom() {
  136. return this.hasConfirm ? '120rpx' : '0'
  137. },
  138. popupContentStyle() {
  139. return {
  140. height: this.height || '',
  141. transform: this.safeArea ? `translateY(${this.transform})` : 'translateY(0)'
  142. }
  143. },
  144. checkedClass() {
  145. return this.checkedNone ? 'icon-xuanze' : 'icon-weixuanze'
  146. }
  147. },
  148. methods: {
  149. // tab切换
  150. tabChange(e) {
  151. this.currentTab = e.index
  152. this.$emit('change', this.currentTab)
  153. },
  154. // 关闭事件
  155. handleClose() {
  156. this.$emit('close')
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. $title-height: 40rpx;
  163. $tab-height: 80rpx;
  164. .popup-content {
  165. position: relative;
  166. height: 100%;
  167. background-color: #fff;
  168. border-radius: 20rpx 20rpx 0 0;
  169. color: #333;
  170. .close {
  171. font-size: 30rpx;
  172. width: 40rpx;
  173. height: 40rpx;
  174. position: absolute;
  175. right: 24rpx;
  176. top: 24rpx;
  177. z-index: 100;
  178. @extend .cm-flex-center;
  179. }
  180. .title {
  181. padding-top: 24rpx;
  182. line-height: 60rpx;
  183. font-size: 30rpx;
  184. text-align: center;
  185. }
  186. .header {
  187. position: absolute;
  188. top: 0;
  189. left: 0;
  190. width: 100%;
  191. z-index: 99;
  192. }
  193. .choose-none {
  194. @extend .cm-flex-between;
  195. padding: 0 24rpx;
  196. height: 80rpx;
  197. text {
  198. font-size: 28rpx;
  199. }
  200. .icon {
  201. text-align: right;
  202. line-height: 80rpx;
  203. width: 80rpx;
  204. height: 80rpx;
  205. padding-right: 24rpx;
  206. box-sizing: border-box;
  207. }
  208. }
  209. .confirm-control {
  210. position: absolute;
  211. bottom: 0;
  212. left: 0;
  213. width: 100%;
  214. margin: 16rpx 0;
  215. background-color: #fff;
  216. @extend .cm-flex-center;
  217. align-items: center;
  218. flex-direction: column;
  219. justify-content: flex-start;
  220. }
  221. .coupon-list {
  222. height: 100%;
  223. .scroll-box {
  224. height: 100%;
  225. padding-top: 164rpx;
  226. box-sizing: border-box;
  227. .coupon-section {
  228. margin: 24rpx;
  229. &:first-child {
  230. margin-top: 0;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. </style>