OptionInp.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. :class="[{'exclu':exclu},{'cancel':item.select==0}]"
  9. v-model="txt"
  10. @click="handleCli"
  11. @blur="handleBlur"
  12. @input="changeVal">
  13. </div>
  14. <span class="suffix" v-if="msg.suffix">{{msg.suffix}}</span>
  15. </div>
  16. </template>
  17. <script type="text/javascript">
  18. import { getExpStr,scrollToV,isIos} from '@utils/tools';
  19. export default {
  20. name:'OptionInp',
  21. data(){
  22. return{
  23. msg:{},
  24. txt:this.item.value || '',
  25. select:0
  26. }
  27. },
  28. props:['item','exclu'],
  29. mounted(){
  30. const text = this.item.description || this.item.name;
  31. this.msg = getExpStr(text);
  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. document.activeElement.scrollIntoViewIfNeeded(true);
  42. // 如果该项未选中,则不存值
  43. // const select = this.item.select;
  44. // if(!select){return}
  45. const newData = Object.assign({},this.part,{value:this.txt});
  46. this.$emit("updata",newData);
  47. this.$emit('handleInp',this.txt);
  48. },
  49. preClick(e){
  50. e.stopPropagation();
  51. },
  52. handleCli(e){
  53. // const select = this.item.select;
  54. if(!this.select){//聚焦时自动选中该项
  55. this.$emit('handleSelec');
  56. }
  57. if(!isIos()){
  58. scrollToV(e)
  59. }
  60. }
  61. },
  62. watch:{
  63. item:{//清空时更新
  64. handler(newVal,oldVal){
  65. this.txt = newVal.value;
  66. this.select = newVal.select;
  67. },
  68. deep:true
  69. }
  70. },
  71. }
  72. </script>
  73. <style lang="less" scoped>
  74. .inpbox{
  75. color:#7C828E;
  76. display: inline-block;
  77. .inp{
  78. display: inline-block;
  79. vertical-align: top;
  80. // position: relative;
  81. // top:1px;
  82. input{
  83. color: #4F50FF;
  84. font-size: .28rem;
  85. border-bottom: 1px solid #DFE0E4 !important;
  86. border-radius: 0;
  87. padding-left: .05rem;
  88. }
  89. }
  90. .check{//选中
  91. color: #4F50FF;
  92. }
  93. .inp .exclu{ //互斥
  94. color:#e6e7e9 !important;
  95. }
  96. .cancel{ //取消
  97. color: #bbbbbb !important;
  98. }
  99. input:disabled, input[disabled]{
  100. background:transparent;
  101. border-bottom-color: #DEDEDE !important;
  102. }
  103. // input:disabled,input[disabled]::-webkit-input-placeholder{
  104. .exclu::-webkit-input-placeholder{
  105. color:#e6e7e9 !important;
  106. }
  107. }
  108. </style>