OptionInp.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!-- 带输入框选项 -->
  2. <template>
  3. <div :class="['inpbox',{'iptCheck':item.select}]">
  4. <span class="prefix" v-if="msg.prefix">{{msg.prefix}}</span>
  5. <input :type="msg.type=='number'?'number':'text'"
  6. :placeholder="msg.placeholder"
  7. :style="{'width':!msg.prefix&&!msg.suffix?'90%':'33%'}"
  8. :class="[{'cancel':item.select==0}]"
  9. v-model="txt"
  10. @click="handleCli"
  11. @input="changeVal"
  12. >
  13. <span class="suffix" v-if="msg.suffix">{{msg.suffix}}</span>
  14. </div>
  15. </template>
  16. <script type="text/javascript">
  17. import { getExpStr,isIos} from '@utils/tools';
  18. import $ from 'jquery';
  19. export default {
  20. name:'OptionInp',
  21. props:['item','inx'],
  22. data(){
  23. return{
  24. msg:{},
  25. txt:this.item.value||'',
  26. select:0,
  27. url:[require('../images/iptselect.png'),require('../images/iptdis.png')]
  28. }
  29. },
  30. mounted(){
  31. const text = this.item.description || this.item.name;
  32. this.msg = getExpStr(text);
  33. this.select = this.item.select;
  34. },
  35. methods:{
  36. changeVal(e){
  37. /*const val = e.target.value;
  38. if(!val.match(/\S/g)){ //只有空白符不算输入
  39. this.txt='';
  40. }*/
  41. if(this.msg.type=='number'){//数字键盘
  42. this.txt = e.target.value=e.target.value.replace(/^\.$/,'')
  43. }
  44. this.$emit('handleInp',this.txt,this.inx);
  45. const notNull=this.txt.match(/\S/g);
  46. if(notNull&&!this.item.select||(!notNull&&this.item.select)){
  47. this.$emit("handleSelect")
  48. }
  49. },
  50. handleBlur(){
  51. /* if(this.txt){
  52. this.$emit('handleInp',this.txt,this.inx);
  53. }*/
  54. /*setTimeout(()=>{
  55. $(".foot").css({'display':'block'})
  56. },150)*/
  57. },
  58. handleCli(e){
  59. if(this.select||!this.txt){//已选中后点击输入框不取消选中
  60. e.stopPropagation();
  61. }
  62. }
  63. },
  64. watch:{
  65. item:{//清空时更新
  66. handler(newVal,oldVal){
  67. this.txt = newVal.value;
  68. this.select = newVal.select;
  69. },
  70. deep:true
  71. }
  72. },
  73. }
  74. </script>
  75. <style lang="less" scoped>
  76. @import '../less/base.less';
  77. .inpbox{
  78. color:#colors[text];
  79. display: inline-block;
  80. width: 100%;
  81. white-space: normal;
  82. vertical-align: middle;
  83. height: .68rem;
  84. line-height: .68rem;
  85. margin-bottom:.08rem;
  86. .prefix,.suffix{
  87. display: inline-block;
  88. vertical-align: middle;
  89. }
  90. input{
  91. height: 100%;
  92. color: #colors[btn];
  93. font-size: #font[select];
  94. border-bottom: 1px solid #E6E6E6 !important;
  95. border-radius: 0;
  96. padding-left: .05rem;
  97. background-color: transparent;
  98. position: relative;
  99. top: 1px;
  100. box-sizing: border-box;
  101. &.cancel{
  102. color:#ccc ;
  103. }
  104. }
  105. }
  106. .iptCheck{
  107. span{
  108. color: #colors[btn];
  109. }
  110. }
  111. </style>