graceNumberBox.nvue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="grace-number-box" :style="{width:width}">
  3. <text class="grace-number-box-doBtn" @tap.stop="reduce"
  4. :style="{width:btnSize, height:btnSize, fontSize:btnFontSize, lineHeight:btnSize, color:btnColr}">-</text>
  5. <input class="grace-number-box-input" type="number"
  6. :value="inputNumber" :disabled="disabled" @blur="blur"
  7. :style="{backgroundColor:inputBG, height:inputHeight, lineHeight:inputHeight, fontSize:inputFontSize, color:inputColor, padding:inputPadding, borderRadius:inputBorderRadius}"></input>
  8. <text class="grace-number-box-doBtn" @tap.stop="add"
  9. :style="{width:btnSize, height:btnSize, fontSize:btnFontSize, lineHeight:btnSize, color:btnColr}">+</text>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. name: "graceNumberBox",
  15. props: {
  16. disabled :{
  17. type : Boolean,
  18. default : false
  19. },
  20. value : {
  21. type : Number,
  22. default : 0
  23. },
  24. index : {
  25. type : Number,
  26. default : 0
  27. },
  28. maxNum:{
  29. type: Number,
  30. default: 999999
  31. },
  32. minNum: {
  33. type: Number,
  34. default: 0
  35. },
  36. datas:{
  37. type: String,
  38. default: ''
  39. },
  40. btnSize : {
  41. type : String,
  42. default : '60rpx'
  43. },
  44. btnFontSize : {
  45. type : String,
  46. default : '36rpx'
  47. },
  48. btnColr : {
  49. type : String,
  50. default : '#666666'
  51. },
  52. inputHeight : {
  53. type : String,
  54. default : '56rpx'
  55. },
  56. inputFontSize : {
  57. type : String,
  58. default : '26rpx'
  59. },
  60. inputColor : {
  61. type : String,
  62. default : '#333333'
  63. },
  64. inputBG : {
  65. type : String,
  66. default : '#F6F7F8'
  67. },
  68. inputPadding : {
  69. type : String,
  70. default : '10rpx'
  71. },
  72. inputBorderRadius : {
  73. type : String,
  74. default : '8rpx'
  75. },
  76. width:{
  77. type : String,
  78. default : '200rpx'
  79. }
  80. },
  81. data() {
  82. return {
  83. inputNumber: this.value
  84. }
  85. },
  86. watch:{
  87. value (val){
  88. this.inputNumber = val;
  89. },
  90. inputNumber (val){
  91. val = Number(val);
  92. if(val > this.maxNum){val = this.maxNum; this.inputNumber = val;}
  93. if(val < this.minNum){val = this.minNum; this.inputNumber = val;}
  94. this.$emit('change', [val, this.index, this.datas]);
  95. }
  96. },
  97. methods: {
  98. add : function(){
  99. var newVal = this.inputNumber + 1;
  100. this.inputNumber = Number(newVal);
  101. },
  102. reduce: function () {
  103. var newVal = this.inputNumber - 1;
  104. this.inputNumber = newVal;
  105. },
  106. blur : function(e){
  107. this.inputNumber = Number(e.detail.value);
  108. }
  109. }
  110. }
  111. </script>
  112. <style scoped>
  113. .grace-number-box{overflow:hidden; flex-direction:row; flex-wrap:nowrap; align-items:center;}
  114. .grace-number-box-doBtn{text-align:center; color:#666666;}
  115. .grace-number-box-input{text-align:center; width:700rpx; flex:1;}
  116. </style>