su-coupon.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="ui-coupon-wrap">
  3. <!-- xs: 一行三个,竖向 -->
  4. <view
  5. v-if="props.size === 'xs'"
  6. class="xs-coupon-card ss-flex ss-flex-col ss-row-between"
  7. :style="[cardStyle]"
  8. @tap="
  9. sheep.$router.go('/pages/coupon/detail', {
  10. id: couponId,
  11. })
  12. "
  13. >
  14. <view class=" ss-flex ss-flex-col ss-row-center ss-col-center">
  15. <view class="face-value-box ss-flex ss-col-bottom ss-m-t-50 ss-m-b-28">
  16. <view class="value-text ss-m-r-4">{{ props.value }}</view>
  17. <view class="value-unit">元</view>
  18. </view>
  19. <view class="title-text">{{ props.title }}</view>
  20. </view>
  21. <view class="card-bottom ss-m-b-30 ss-flex ss-row-center">
  22. <slot name="btn">
  23. <button class="ss-reset-button card-btn">{{ state.stateMap[props.state] }}</button>
  24. </slot>
  25. </view>
  26. </view>
  27. <!-- md: 一行两个,横向 -->
  28. <view
  29. v-if="props.size === 'md'"
  30. class="md-coupon-card ss-flex ss-row-between"
  31. :style="[cardStyle]"
  32. @tap="
  33. sheep.$router.go('/pages/coupon/detail', {
  34. id: couponId,
  35. })
  36. "
  37. >
  38. <view class="card-left ss-flex ss-flex-col ss-row-between ss-col-top ss-m-l-40">
  39. <view class="face-value-box ss-flex ss-col-bottom ss-m-t-28">
  40. <view class="value-unit">¥</view>
  41. <view class="value-text ss-m-r-4">{{ props.value }}</view>
  42. </view>
  43. <view class="ss-m-b-28">
  44. <view class="title-text ss-m-b-10">{{ props.title }}</view>
  45. <view class="surplus-text">仅剩:{{ props.surplus }}张</view>
  46. </view>
  47. </view>
  48. <view class="card-right ss-flex ss-row-center">
  49. <slot name="btn">
  50. <button class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center">
  51. <view class="btn-text">{{ state.stateMap[props.state] }}</view>
  52. </button>
  53. </slot>
  54. </view>
  55. </view>
  56. <!-- lg: 一行一个,横向 -->
  57. <view
  58. v-if="props.size === 'lg'"
  59. class="lg-coupon-card ss-flex ss-row-between"
  60. :style="[cardStyle]"
  61. @tap="
  62. sheep.$router.go('/pages/coupon/detail', {
  63. id: couponId,
  64. })
  65. "
  66. >
  67. <view class="card-left ss-flex ss-flex-col ss-row-between ss-col-top ss-m-l-40">
  68. <view class="face-value-box ss-flex ss-col-bottom ss-m-t-28">
  69. <view class="value-unit">¥</view>
  70. <view class="value-text ss-m-r-4">{{ props.value }}</view>
  71. </view>
  72. <view class="ss-m-b-20">
  73. <view class="title-text ss-m-b-10">{{ props.title }}</view>
  74. <view class="sellby-text">有效期:{{ props.sellBy }}</view>
  75. </view>
  76. </view>
  77. <view class="card-right ss-flex ss-flex-col ss-col-center ss-row-center">
  78. <slot name="btn">
  79. <button class="ss-reset-button card-btn ss-flex ss-row-center ss-col-center">
  80. {{ state.stateMap[props.state] }}
  81. </button>
  82. </slot>
  83. <view class="surplus-text ss-m-t-24">仅剩:{{ props.surplus }}张</view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script setup>
  89. /**
  90. * 优惠券 卡片
  91. *
  92. * @property {String} size = ['xs','md','lg'] - 类型 xs:一行三个,md:一行两个,lg:一行一个
  93. * @property {String} textColor - 文字颜色
  94. * @property {String} background - 背景
  95. * @property {String} btnBg - 按钮背景
  96. * @property {String} btnTextColor - 按钮文字颜色
  97. * @property {Number} state = [0,1] - 状态,0:未领取,1:已领取
  98. * @property {String} title - 标题
  99. * @property {String | Number} value - 面值
  100. * @property {String} sellBy - 有效期
  101. * @property {String | Number} surplus - 剩余
  102. *
  103. */
  104. import { computed, reactive } from 'vue';
  105. import sheep from '@/sheep';
  106. // 数据
  107. const state = reactive({
  108. stateMap: {
  109. 0: '立即领取',
  110. 1: '去使用',
  111. },
  112. });
  113. // 接受参数
  114. const props = defineProps({
  115. size: {
  116. type: String,
  117. default: 'lg',
  118. },
  119. textColor: {
  120. type: String,
  121. default: '#FF6000',
  122. },
  123. background: {
  124. type: String,
  125. default: '#FFC19C',
  126. },
  127. btnBg: {
  128. type: String,
  129. default: '#fff',
  130. },
  131. btnTextColor: {
  132. type: String,
  133. default: '#FF6000',
  134. },
  135. state: {
  136. type: Number,
  137. default: 0,
  138. },
  139. couponId: {
  140. type: Number,
  141. default: 0,
  142. },
  143. title: {
  144. type: String,
  145. default: '这是优惠券',
  146. },
  147. value: {
  148. type: [Number, String],
  149. default: 50,
  150. },
  151. sellBy: {
  152. type: String,
  153. default: '2019.11.25至2019.12.25',
  154. },
  155. surplus: {
  156. type: [Number, String],
  157. default: 1000,
  158. },
  159. });
  160. const cardStyle = computed(() => {
  161. return {
  162. background: props.background,
  163. };
  164. });
  165. </script>
  166. <style lang="scss" scoped>
  167. // xs
  168. .xs-coupon-card {
  169. width: 227rpx;
  170. // height: 145px;
  171. border-radius: 10rpx;
  172. overflow: hidden;
  173. .value-text {
  174. font-size: 50rpx;
  175. line-height: 50rpx;
  176. font-weight: bold;
  177. color: v-bind('props.textColor');
  178. vertical-align: text-bottom;
  179. }
  180. .value-unit {
  181. color: v-bind('props.textColor');
  182. font-size: 24rpx;
  183. line-height: 30rpx;
  184. }
  185. .title-text {
  186. color: v-bind('props.textColor');
  187. font-size: 24rpx;
  188. line-height: 30rpx;
  189. width: 150rpx;
  190. text-align: center;
  191. }
  192. .card-btn {
  193. width: 140rpx;
  194. height: 50rpx;
  195. border-radius: 25rpx;
  196. border-style: solid;
  197. border-color: v-bind('props.btnTextColor');
  198. border-width: 1px;
  199. color: v-bind('props.btnTextColor');
  200. background-color: v-bind('props.btnBg');
  201. font-size: 24rpx;
  202. line-height: 50rpx;
  203. }
  204. }
  205. // md
  206. .md-coupon-card {
  207. width: 330rpx;
  208. height: 168rpx;
  209. border-radius: 10rpx;
  210. overflow: hidden;
  211. .card-right,
  212. .card-left {
  213. height: 100%;
  214. }
  215. .value-text {
  216. font-size: 36rpx;
  217. line-height: 36rpx;
  218. font-weight: bold;
  219. color: v-bind('props.textColor');
  220. vertical-align: text-bottom;
  221. }
  222. .value-unit {
  223. color: v-bind('props.textColor');
  224. font-size: 22rpx;
  225. line-height: 22rpx;
  226. }
  227. .title-text,
  228. .surplus-text {
  229. color: v-bind('props.textColor');
  230. font-size: 22rpx;
  231. line-height: 22rpx;
  232. }
  233. .card-btn {
  234. width: 60rpx;
  235. height: 100%;
  236. .btn-text {
  237. color: v-bind('props.btnTextColor');
  238. font-size: 24rpx;
  239. text-align: center;
  240. writing-mode: vertical-lr;
  241. writing-mode: tb-lr;
  242. }
  243. }
  244. }
  245. // lg
  246. .lg-coupon-card {
  247. width: 708rpx;
  248. height: 168rpx;
  249. border-radius: 10rpx;
  250. overflow: hidden;
  251. .card-right,
  252. .card-left {
  253. height: 100%;
  254. }
  255. .value-text {
  256. font-size: 50rpx;
  257. line-height: 50rpx;
  258. font-weight: bold;
  259. color: v-bind('props.textColor');
  260. vertical-align: text-bottom;
  261. }
  262. .value-unit {
  263. color: v-bind('props.textColor');
  264. font-size: 22rpx;
  265. line-height: 22rpx;
  266. }
  267. .title-text,
  268. .sellby-text,
  269. .surplus-text {
  270. color: v-bind('props.textColor');
  271. font-size: 22rpx;
  272. line-height: 22rpx;
  273. }
  274. .card-right {
  275. width: 200rpx;
  276. .card-btn {
  277. width: 140rpx;
  278. height: 50rpx;
  279. border-radius: 25rpx;
  280. border-style: solid;
  281. border-color: v-bind('props.btnTextColor');
  282. border-width: 1px;
  283. color: v-bind('props.btnTextColor');
  284. background-color: v-bind('props.btnBg');
  285. font-size: 24rpx;
  286. line-height: 50rpx;
  287. }
  288. }
  289. }
  290. </style>