cm-coupon-popup.vue 6.9 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. :checked="item.checked"
  48. :key="item.couponId"
  49. :couponData="item"
  50. @click="$emit('couponClick', item)"
  51. ></cm-coupon>
  52. </view>
  53. <cm-safe-area-bottom v-if="hasSafeArea"></cm-safe-area-bottom>
  54. </scroll-view>
  55. <view class="confirm-control" v-if="hasConfirm">
  56. <tui-button width="650rpx" height="88rpx" type="base" shape="circle" @click="handleClose">
  57. 确定
  58. </tui-button>
  59. <cm-safe-area-bottom v-if="hasSafeArea"></cm-safe-area-bottom>
  60. </view>
  61. </view>
  62. </view>
  63. </uni-popup>
  64. </view>
  65. </template>
  66. <script>
  67. import { mapGetters } from 'vuex'
  68. export default {
  69. name: 'cm-coupon-popup',
  70. props: {
  71. visiable: {
  72. type: Boolean,
  73. default: false
  74. },
  75. height: {
  76. type: String,
  77. default: '1000rpx'
  78. },
  79. list: {
  80. type: Array,
  81. default: () => []
  82. },
  83. couponTabs: {
  84. type: Array,
  85. default: () => []
  86. },
  87. transform: {
  88. type: String,
  89. default: '34px'
  90. },
  91. // tab切换
  92. hasTabs: {
  93. type: Boolean,
  94. default: false
  95. },
  96. // 确认按钮
  97. hasConfirm: {
  98. type: Boolean,
  99. default: false
  100. },
  101. // 是否需要安全距离
  102. hasSafeArea: {
  103. type: Boolean,
  104. default: false
  105. },
  106. checkedNone: {
  107. type: Boolean,
  108. default: false
  109. },
  110. hasCheckedNone: {
  111. type: Boolean,
  112. default: false
  113. }
  114. },
  115. data() {
  116. return {
  117. currentTab: 0
  118. }
  119. },
  120. watch: {
  121. visiable(nval) {
  122. if (nval) {
  123. this.$refs.popup.open('bottom')
  124. } else {
  125. this.$refs.popup.close()
  126. }
  127. }
  128. },
  129. computed: {
  130. ...mapGetters(['safeArea']),
  131. paddingTop() {
  132. return this.hasCheckedNone ? '168rpx' : this.hasTabs ? '188rpx' : '88rpx'
  133. },
  134. paddingBottom() {
  135. return this.hasConfirm ? '120rpx' : '0'
  136. },
  137. popupContentStyle() {
  138. return {
  139. height: this.height || '',
  140. transform: this.safeArea ? `translateY(${this.transform})` : 'translateY(0)'
  141. }
  142. },
  143. checkedClass() {
  144. return this.checkedNone ? 'icon-xuanze' : 'icon-weixuanze'
  145. }
  146. },
  147. methods: {
  148. // tab切换
  149. tabChange(e) {
  150. this.currentTab = e.index
  151. this.$emit('change', this.currentTab)
  152. },
  153. // 关闭事件
  154. handleClose() {
  155. this.$refs.popup.open('bottom')
  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>