OptionInp.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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'?'number':'text'"
  7. :placeholder="msg.placeholder"
  8. :style="{'width':!msg.prefix&&!msg.suffix?'90%':'33%'}"
  9. :disabled="exclu"
  10. :maxlength="msg.type=='number'?10:''"
  11. :class="[{'exclu':exclu},{'cancel':item.select==0}]"
  12. v-model="txt"
  13. @click="handleCli"
  14. @blur="handleBlur"
  15. @focus="focus"
  16. @input="changeVal">
  17. <!-- </div> -->
  18. <span class="suffix" v-if="msg.suffix">{{msg.suffix}}</span>
  19. </div>
  20. </template>
  21. <script type="text/javascript">
  22. import { getExpStr,isIos} from '@utils/tools';
  23. import $ from 'jquery';
  24. export default {
  25. name:'OptionInp',
  26. data(){
  27. return{
  28. msg:{},
  29. txt:this.item.value || '',
  30. select:0
  31. }
  32. },
  33. props:['item','exclu'],
  34. mounted(){
  35. const text = this.item.description || this.item.name;
  36. this.msg = getExpStr(text);
  37. this.select = this.item.select;
  38. },
  39. methods:{
  40. changeVal(e){
  41. if(this.msg.type=='number'){//数字键盘
  42. this.txt = e.target.value=e.target.value.replace(/^\.|\.$/,'')
  43. }
  44. const newData = Object.assign({},this.part,{value:this.txt});
  45. this.$emit("updata",newData);
  46. this.$emit('handleInp',this.txt);
  47. },
  48. handleBlur(){
  49. // $(".btscroll").css({'position':'fixed'})
  50. $(".foot").css({'display':'block'})
  51. document.activeElement.scrollIntoViewIfNeeded(true);
  52. setTimeout(()=>{
  53. document.activeElement.scrollIntoViewIfNeeded(true);
  54. },300)
  55. // 如果该项未选中,则不存值
  56. // const select = this.item.select;
  57. // if(!select){return}
  58. // const newData = Object.assign({},this.part,{value:this.txt});
  59. // this.$emit("updata",newData);
  60. // this.$emit('handleInp',this.txt);
  61. },
  62. focus(){
  63. if(isIos()){
  64. // $(".btscroll").css({'position':'absolute'})
  65. $(".foot").css({'display':'none'})
  66. }
  67. },
  68. preClick(e){
  69. e.stopPropagation();
  70. },
  71. handleCli(e){
  72. e.stopPropagation();
  73. // const select = this.item.select;
  74. if(!this.select){//聚焦时自动选中该项
  75. this.$emit('handleSelec');
  76. }
  77. }
  78. },
  79. watch:{
  80. item:{//清空时更新
  81. handler(newVal,oldVal){
  82. this.txt = newVal.value;
  83. this.select = newVal.select;
  84. },
  85. deep:true
  86. }
  87. },
  88. }
  89. </script>
  90. <style lang="less" scoped>
  91. @import '../less/base.less';
  92. .inpbox{
  93. color:#colors[text];
  94. display: inline-block;
  95. width: 100%;
  96. white-space: normal;
  97. vertical-align: middle;
  98. height: .42rem;
  99. line-height: .42rem;
  100. .prefix,.suffix{
  101. display: inline-block;
  102. vertical-align: middle;
  103. }
  104. input{
  105. height: .42rem;
  106. color: #4F50FF;
  107. font-size: .28rem;
  108. border-bottom: 1px solid #DFE0E4 !important;
  109. border-radius: 0;
  110. padding-left: .05rem;
  111. background-color: transparent;
  112. height: 0.38rem;
  113. line-height: 0.38rem;
  114. }
  115. .check{//选中
  116. color: #colors[theme];
  117. }
  118. // .inp .exclu{ //互斥
  119. .exclu{ //互斥
  120. color:#colors[exclu] !important;
  121. }
  122. .cancel{ //取消
  123. color: #bbbbbb !important;
  124. }
  125. input:disabled, input[disabled]{
  126. background:transparent;
  127. border-bottom-color: #DEDEDE !important;
  128. }
  129. // input:disabled,input[disabled]::-webkit-input-placeholder{
  130. .exclu::-webkit-input-placeholder{
  131. color:#e6e7e9 !important;
  132. }
  133. }
  134. </style>