OptionInp.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. this.txt = e.target.value;
  38. if(this.msg.type=='number'){//数字键盘
  39. this.txt = e.target.value=e.target.value.replace(/^\.$/,'')
  40. }
  41. this.$emit('handleInp',this.txt,this.inx);
  42. if(this.txt&&!this.item.select||(!this.txt&&this.item.select)){
  43. this.$emit("handleSelect")
  44. }
  45. },
  46. handleBlur(){
  47. /* if(this.txt){
  48. this.$emit('handleInp',this.txt,this.inx);
  49. }*/
  50. /*setTimeout(()=>{
  51. $(".foot").css({'display':'block'})
  52. },150)*/
  53. },
  54. handleCli(e){
  55. if(this.select||!this.txt){//已选中后点击输入框不取消选中
  56. e.stopPropagation();
  57. }
  58. }
  59. },
  60. watch:{
  61. item:{//清空时更新
  62. handler(newVal,oldVal){
  63. this.txt = newVal.value;
  64. this.select = newVal.select;
  65. },
  66. deep:true
  67. }
  68. },
  69. }
  70. </script>
  71. <style lang="less" scoped>
  72. @import '../less/base.less';
  73. .inpbox{
  74. color:#colors[text];
  75. display: inline-block;
  76. width: 100%;
  77. white-space: normal;
  78. vertical-align: middle;
  79. height: .68rem;
  80. line-height: .68rem;
  81. margin-bottom:.08rem;
  82. .prefix,.suffix{
  83. display: inline-block;
  84. vertical-align: middle;
  85. }
  86. input{
  87. height: 100%;
  88. color: #colors[btn];
  89. font-size: .26rem;
  90. border-bottom: 1px solid #E6E6E6 !important;
  91. border-radius: 0;
  92. padding-left: .05rem;
  93. background-color: transparent;
  94. position: relative;
  95. top: 1px;
  96. box-sizing: border-box;
  97. &.cancel{
  98. color:#ccc ;
  99. }
  100. }
  101. }
  102. .iptCheck{
  103. span{
  104. color: #colors[btn];
  105. }
  106. }
  107. </style>