count.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="countContainer">
  3. <view
  4. class="reduceBtn"
  5. :class="activeIndex === -1 ? 'active' : ''"
  6. @click="toReduce"
  7. />
  8. <view
  9. class="countNum"
  10. :class="countNum ? 'active' : ''"
  11. @click="toInputNum"
  12. >
  13. {{ countNum }}
  14. </view>
  15. <view
  16. class="plusBtn"
  17. :class="activeIndex === 1 ? 'active' : ''"
  18. @click="toPlus"
  19. />
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. countNum: {
  26. type: Number,
  27. default: 0
  28. },
  29. max: {
  30. type:Number,
  31. default: 99999
  32. },
  33. min: {
  34. type:Number,
  35. default: 0
  36. }
  37. },
  38. data(){
  39. return {
  40. activeIndex: 0
  41. }
  42. },
  43. methods: {
  44. toReduce() {
  45. this.activeIndex = -1
  46. let _v = this.countNum
  47. if(_v <= this.min) return false
  48. this.$emit('update:countNum', --_v)
  49. },
  50. toPlus() {
  51. this.activeIndex = 1
  52. let _v = this.countNum
  53. if(_v >= this.max) return false
  54. this.$emit('update:countNum', ++_v)
  55. },
  56. toInputNum() {
  57. this.$emit('update:inputCountNum')
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .countContainer {
  64. flex: 1;
  65. min-width: 0;
  66. display: flex;
  67. align-items: center;
  68. justify-content: center;
  69. .reduceBtn, .plusBtn {
  70. width: 52rpx;
  71. height: 52rpx;
  72. border: 1px solid #999999;
  73. display: flex;
  74. align-items: center;
  75. justify-content: center;
  76. border-radius: 50%;
  77. position: relative;
  78. background: #ffffff;
  79. &::after {
  80. content: "";
  81. display: block;
  82. width: 18rpx;
  83. height: 2rpx;
  84. background-color: #999999;
  85. }
  86. &.active {
  87. background: linear-gradient(to bottom, #F97C55, #F44545) !important;
  88. border: none !important;
  89. &::before, &::after {
  90. background: #ffffff !important;
  91. }
  92. }
  93. }
  94. .plusBtn {
  95. &::before {
  96. content: "";
  97. display: block;
  98. width: 2rpx;
  99. height: 18rpx;
  100. background-color: #999999;
  101. position: absolute;
  102. top: 50%;
  103. left: 50%;
  104. transform: translate(-50%, -50%);
  105. }
  106. }
  107. .countNum {
  108. color: #999999;
  109. font-size: 32rpx;
  110. line-height: 44rpx;
  111. padding: 0 10rpx;
  112. box-sizing: border-box;
  113. flex: 1;
  114. min-width: 44rpx;
  115. height: 44rpx;
  116. text-align: center;
  117. font-weight: bolder;
  118. &.active {
  119. color: #EA4A41 !important;
  120. }
  121. }
  122. }
  123. </style>