cm-coupon-popup.vue 7.0 KB

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