su-coupon.vue 7.9 KB

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