OptionInp.vue 4.2 KB

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