su-coupon.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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">仅剩:{{ 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-text ss-m-r-4">{{ type === 'reduce' ? value : Number(value) }}</view>
  70. <view class="value-unit">{{ type === 'reduce' ? '元' : '折' }}</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" v-if="props.surplus">仅剩:{{ 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: 0,
  158. },
  159. type: {
  160. type: String,
  161. default: '',
  162. },
  163. });
  164. const cardStyle = computed(() => {
  165. return {
  166. background: props.background,
  167. };
  168. });
  169. </script>
  170. <style lang="scss" scoped>
  171. // xs
  172. .xs-coupon-card {
  173. width: 227rpx;
  174. // height: 145px;
  175. border-radius: 10rpx;
  176. overflow: hidden;
  177. .value-text {
  178. font-size: 50rpx;
  179. line-height: 50rpx;
  180. font-weight: bold;
  181. color: v-bind('textColor');
  182. vertical-align: text-bottom;
  183. }
  184. .value-unit {
  185. color: v-bind('textColor');
  186. font-size: 24rpx;
  187. line-height: 38rpx;
  188. }
  189. .title-text {
  190. color: v-bind('textColor');
  191. font-size: 24rpx;
  192. line-height: 30rpx;
  193. width: 150rpx;
  194. text-align: center;
  195. }
  196. .card-btn {
  197. width: 140rpx;
  198. height: 50rpx;
  199. border-radius: 25rpx;
  200. border-style: solid;
  201. border-color: v-bind('btnTextColor');
  202. border-width: 1px;
  203. color: v-bind('btnTextColor');
  204. background-color: v-bind('btnBg');
  205. font-size: 24rpx;
  206. line-height: 50rpx;
  207. }
  208. }
  209. // md
  210. .md-coupon-card {
  211. width: 330rpx;
  212. height: 168rpx;
  213. border-radius: 10rpx;
  214. overflow: hidden;
  215. .card-right,
  216. .card-left {
  217. height: 100%;
  218. }
  219. .value-text {
  220. font-size: 36rpx;
  221. line-height: 36rpx;
  222. font-weight: bold;
  223. color: v-bind('textColor');
  224. vertical-align: text-bottom;
  225. }
  226. .value-unit {
  227. color: v-bind('textColor');
  228. font-size: 22rpx;
  229. line-height: 28rpx;
  230. }
  231. .title-text,
  232. .surplus-text {
  233. color: v-bind('textColor');
  234. font-size: 22rpx;
  235. line-height: 22rpx;
  236. }
  237. .card-btn {
  238. width: 60rpx;
  239. height: 100%;
  240. .btn-text {
  241. color: v-bind('btnTextColor');
  242. font-size: 24rpx;
  243. text-align: center;
  244. writing-mode: vertical-lr;
  245. writing-mode: tb-lr;
  246. }
  247. }
  248. }
  249. // lg
  250. .lg-coupon-card {
  251. width: 708rpx;
  252. height: 168rpx;
  253. border-radius: 10rpx;
  254. overflow: hidden;
  255. .card-right,
  256. .card-left {
  257. height: 100%;
  258. }
  259. .value-text {
  260. font-size: 50rpx;
  261. line-height: 50rpx;
  262. font-weight: bold;
  263. color: v-bind('textColor');
  264. vertical-align: text-bottom;
  265. }
  266. .value-unit {
  267. color: v-bind('textColor');
  268. font-size: 22rpx;
  269. line-height: 32rpx;
  270. }
  271. .title-text,
  272. .sellby-text,
  273. .surplus-text {
  274. color: v-bind('textColor');
  275. font-size: 22rpx;
  276. line-height: 22rpx;
  277. }
  278. .card-right {
  279. width: 200rpx;
  280. .card-btn {
  281. width: 140rpx;
  282. height: 50rpx;
  283. border-radius: 25rpx;
  284. border-style: solid;
  285. border-color: v-bind('btnTextColor');
  286. border-width: 1px;
  287. color: v-bind('btnTextColor');
  288. background-color: v-bind('btnBg');
  289. font-size: 24rpx;
  290. line-height: 50rpx;
  291. }
  292. }
  293. }
  294. </style>