index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="box adfac">
  3. <div class="box-btn l" @click="valueChange(1)">-</div>
  4. <div class="box-input">
  5. <u-input :min="min" v-model="value" @change="e=>valueChange(3,e)" @blur="valueBlur" border="none" fontSize="30rpx" color="#002846"></u-input>
  6. </div>
  7. <div class="box-btn r" @click="valueChange(2)">+</div>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props:{
  13. min:{
  14. typeof:Number,
  15. default:0
  16. },
  17. number:{
  18. typeof:Number,
  19. default:0
  20. }
  21. },
  22. data(){
  23. return {
  24. value:0
  25. }
  26. },
  27. mounted() {
  28. this.value = this.number;
  29. },
  30. methods:{
  31. valueChange(type,e){
  32. if(type===1){
  33. if(this.value<=this.min) return this.$showToast(`当前限制最小值为${this.min}`)
  34. this.value--;
  35. }
  36. else if(type===2) this.value++;
  37. else if(type===3) this.value = e;
  38. this.$emit('valChange',this.value)
  39. },
  40. valueBlur(e){
  41. if(e<=this.min){
  42. this.value = this.min;
  43. return this.$showToast(`当前限制最小值为${this.min}`)
  44. }
  45. this.value = e;
  46. this.$emit('valChange',this.value)
  47. }
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. .box{
  53. background: #FFFFFF;
  54. height: 64rpx;
  55. border-radius: 10rpx;
  56. border: 2rpx solid #E5E7EB;
  57. &-btn{
  58. width: 54rpx;
  59. height: 64rpx;
  60. background: #F5F8FA;
  61. font-family: PingFangSC, PingFang SC;
  62. font-weight: 400;
  63. font-size: 30rpx;
  64. color: #002846;
  65. line-height: 64rpx;
  66. text-align: center;
  67. &.l{
  68. border-radius: 10rpx 0rpx 0rpx 10rpx;
  69. }
  70. &.r{
  71. border-radius: 0rpx 10rpx 10rpx 0rpx;
  72. }
  73. }
  74. &-input{
  75. width: 70rpx;
  76. padding: 0 20rpx;
  77. }
  78. }
  79. </style>