OptionInp.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!-- 带输入框选项 -->
  2. <template>
  3. <div :class="['inpbox',{'check':item.select},{'exclu':exclu}]">
  4. <span class="prefix" v-if="msg.prefix">{{msg.prefix}}</span>
  5. <div class="inp" @click="preClick">
  6. <input :type="msg.type=='number'?'tel':'text'"
  7. :placeholder="msg.placeholder"
  8. :disabled="select!=1"
  9. :class="{'exclu':exclu}"
  10. v-model="txt"
  11. @click="handleCli"
  12. @blur="handleBlur"
  13. @input="changeVal">
  14. </div>
  15. <span class="suffix" v-if="msg.suffix">{{msg.suffix}}</span>
  16. </div>
  17. </template>
  18. <script type="text/javascript">
  19. import { getExpStr,scrollToV} from '@utils/tools';
  20. export default {
  21. name:'OptionInp',
  22. data(){
  23. return{
  24. msg:{},
  25. txt:this.item.value || '',
  26. select:0
  27. }
  28. },
  29. props:['item','exclu'],
  30. mounted(){
  31. this.msg = getExpStr(this.item.name);
  32. this.select = this.item.select;
  33. },
  34. methods:{
  35. changeVal(e){
  36. if(this.msg.type=='number'){//数字键盘
  37. this.txt = e.target.value=e.target.value.replace(/[^\d]/g,'')
  38. }
  39. },
  40. handleBlur(){
  41. // 如果该项未选中,则不存值
  42. // const select = this.item.select;
  43. // if(!select){return}
  44. const newData = Object.assign({},this.part,{value:this.txt});
  45. this.$emit("updata",newData);
  46. this.$emit('handleInp',this.txt);
  47. },
  48. preClick(e){
  49. e.stopPropagation();
  50. },
  51. handleCli(e){
  52. scrollToV(e)
  53. }
  54. },
  55. watch:{
  56. item:{//清空时更新
  57. handler(newVal,oldVal){
  58. this.txt = newVal.value;
  59. this.select = newVal.select;
  60. },
  61. deep:true
  62. }
  63. },
  64. }
  65. </script>
  66. <style lang="less" scoped>
  67. .inpbox{
  68. color:#7C828E;
  69. display: inline-block;
  70. .inp{
  71. display: inline-block;
  72. vertical-align: top;
  73. input{
  74. color: #4F50FF;
  75. font-size: .3rem;
  76. border-bottom: 1px solid #DFE0E4 !important;
  77. border-radius: 0;
  78. padding-left: .05rem;
  79. }
  80. }
  81. .check{
  82. color: #4F50FF;
  83. }
  84. .exclu{
  85. color:#e6e7e9 !important;
  86. }
  87. }
  88. </style>