Input.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // document.activeElement.scrollIntoViewIfNeeded(true);
  54. this.borColor = false;
  55. const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
  56. this.$emit("updata",newData);
  57. },
  58. blur(){
  59. // $(".btscroll").css({'position':'fixed'})
  60. $(".foot").css({'display':'block'})
  61. if(MobileDevice.getModels().join(' or ').indexOf('6') == -1){
  62. document.activeElement.scrollIntoView({behavior: "smooth",block:'end'})
  63. }
  64. // document.activeElement.scrollIntoViewIfNeeded(true);
  65. // setTimeout(()=>{
  66. // document.activeElement.scrollIntoViewIfNeeded(true);
  67. // },300)
  68. // this.borColor = false;
  69. // const newData = Object.assign({},this.item,{value:this.val,valueP:this.val});
  70. // this.$emit("updata",newData);
  71. },
  72. focus(e){
  73. if(isIos()){
  74. // $(".btscroll").css({'position':'absolute'})
  75. $(".foot").css({'display':'none'})
  76. }
  77. }
  78. },
  79. watch:{
  80. item:{
  81. handler(newVal,oldVal){
  82. this.val = newVal.value;
  83. },
  84. deep:true
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="less" scoped>
  90. @import '../less/base.less';
  91. .inp-wrap{
  92. .bgques;
  93. padding-bottom: 0;
  94. input{
  95. width: 100%;
  96. color: #colors[theme];
  97. font-size: .3rem;
  98. border: 0 none;
  99. border-bottom: 1px solid #DFE0E4;
  100. margin-bottom: .3rem;
  101. border-radius: 0;
  102. outline-color: invert;
  103. padding-left: 0.1rem;
  104. box-sizing: border-box;
  105. // background: #fff;
  106. background: transparent;
  107. }
  108. .change{
  109. border-color: #colors[theme];
  110. }
  111. }
  112. </style>