dt_accumulator.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <view class="dt-accumulator">
  3. <view class="plus-btn" @tap="tapPlus(-1)">-</view>
  4. <input type="number" :value="val" @input="onInput" @blur="onBlur" class="input-box" />
  5. <view class="plus-btn" @tap="tapPlus(1)">+</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props:{
  11. isFocus:{
  12. type: Boolean,
  13. default: false
  14. },
  15. val:{
  16. type: Number,
  17. default: 1
  18. }
  19. },
  20. methods:{
  21. onBlur(e){
  22. let val = parseInt(e.detail.value)
  23. this.$emit('update:isFocus',false)
  24. this.$emit('change', val)
  25. // this.$emit('update:isFocus',false)
  26. },
  27. onInput(e){
  28. this.$emit('update:isFocus',true)
  29. },
  30. tapPlus(delta){
  31. if(this.isFocus) return
  32. let val = parseInt(this.val) + delta
  33. this.$emit('change', val)
  34. }
  35. },
  36. }
  37. </script>
  38. <style lang="scss" scoped>
  39. .dt-accumulator{
  40. display: flex;
  41. align-items: center;
  42. width: 200upx;
  43. height: 50upx;
  44. box-sizing: border-box;
  45. border:1upx solid #E5E5E5;
  46. border-radius:6upx;
  47. .plus-btn{
  48. width:60upx;
  49. height: 100%;
  50. box-sizing: border-box;
  51. text-align: center;
  52. font-size:40upx;
  53. line-height: 42rpx;
  54. }
  55. .input-box{
  56. flex:1;
  57. height:100%;
  58. padding:0 10upx;
  59. text-align: center;
  60. border-left:1upx solid #e5e5e5;
  61. border-right:1upx solid #e5e5e5;
  62. }
  63. }
  64. </style>