Input.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <div class="inp-wrap" :style="getStyle(detail,slide)">
  3. <input :type="item.controlType==6?'text':'number'"
  4. :class="{'change':borColor}"
  5. v-model="val"
  6. @input="changeVal"
  7. @focus="focus"
  8. @blur="blur">
  9. </div>
  10. </template>
  11. <script type="text/javascript">
  12. import { isIos } from '@utils/tools';
  13. import $ from 'jquery';
  14. export default {
  15. name:'Input',
  16. props:{
  17. item:{
  18. default:''
  19. },
  20. slide:{
  21. default:false,
  22. type:Boolean
  23. },
  24. detail:{
  25. default:2,
  26. type:Number||String
  27. }
  28. },
  29. data(){
  30. return{
  31. msg:"输入框",
  32. val: this.item.value || '',
  33. borColor:false
  34. }
  35. },
  36. methods:{
  37. getStyle(detail,slide){
  38. if(detail == 1){
  39. if(slide){
  40. return {'display':'block','background-color': '#F9F9F9'}
  41. }else{
  42. return {'display':'none'}
  43. }
  44. }else{
  45. return {'display':'block'}
  46. }
  47. },
  48. changeVal(e){
  49. this.borColor = true;
  50. if(this.item.controlType==7){//数字键盘
  51. this.val = e.target.value=e.target.value.replace(/^\.$/,'').slice(0,10)
  52. }
  53. this.borColor = false;
  54. const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
  55. this.$emit("updata",newData);
  56. },
  57. blur(){
  58. setTimeout(()=>{
  59. $(".foot").css({'display':'block'})
  60. },150)
  61. // this.borColor = false;
  62. // const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
  63. // this.$emit("updata",newData);
  64. },
  65. focus(e){
  66. if(isIos()){
  67. setTimeout(() => {
  68. $(".foot").css({'display':'none'})
  69. }, 150);
  70. }
  71. }
  72. },
  73. watch:{
  74. item:{
  75. handler(newVal,oldVal){
  76. this.val = newVal.value;
  77. },
  78. deep:true
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="less" scoped>
  84. @import '../less/base.less';
  85. .inp-wrap{
  86. .bgques;
  87. padding-bottom: 0;
  88. input{
  89. width: 100%;
  90. color: #colors[theme];
  91. font-size: .3rem;
  92. border: 0 none;
  93. border-bottom: 1px solid #DFE0E4;
  94. margin-bottom: .3rem;
  95. border-radius: 0;
  96. outline-color: invert;
  97. padding-left: 0.1rem;
  98. box-sizing: border-box;
  99. // background: #fff;
  100. background: transparent;
  101. }
  102. .change{
  103. border-color: #colors[theme];
  104. }
  105. }
  106. </style>