su-coupon.vue 8.1 KB

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