OptionInp.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!-- 带输入框选项 -->
  2. <template>
  3. <div :class="['inpbox',{'iptCheck':item.select}]">
  4. <span class="prefix" v-if="msg.prefix" @click="stopPop">{{msg.prefix}}</span>
  5. <p v-if="isXy" class="mult-inps">
  6. <input :type="msg.type=='number'?'number':'text'"
  7. :placeholder="placeholders[0]"
  8. :style="{'width':'45%'}"
  9. :class="[{'cancel':!item.select}]"
  10. v-model="ssyTxt"
  11. @click="handleCli"
  12. @input="(e)=>changeXyVal(e,'ssyTxt')"
  13. >/<input :type="msg.type=='number'?'number':'text'"
  14. :placeholder="placeholders[1]"
  15. :style="{'width':'45%'}"
  16. :class="[{'cancel':!item.select}]"
  17. v-model="szyTxt"
  18. @click="handleCli"
  19. @input="(e)=>changeXyVal(e,'szyTxt')"
  20. >
  21. </p>
  22. <input v-if="!isXy" :type="msg.type=='number'?'number':'text'"
  23. :placeholder="msg.placeholder"
  24. :style="{'width':!msg.prefix&&!msg.suffix?'90%':'33%'}"
  25. :class="[{'cancel':item.select==0}]"
  26. v-model="txt"
  27. @click="handleCli"
  28. @input="(e)=>changeVal(e)"
  29. >
  30. <span class="suffix" v-if="msg.suffix" @click="stopPop">{{msg.suffix}}</span>
  31. </div>
  32. </template>
  33. <script type="text/javascript">
  34. import { getExpStr,isIos} from '@utils/tools';
  35. import $ from 'jquery';
  36. export default {
  37. name:'OptionInp',
  38. props:['item','inx','sure'],
  39. data(){
  40. return{
  41. msg:{},
  42. txt:this.item.value||'',
  43. select:0,
  44. placeholders:[],
  45. isXy:false, //是否是血压输入框
  46. ssyTxt:'', //收缩压
  47. szyTxt:'', //舒张压
  48. url:[require('../images/iptselect.png'),require('../images/iptdis.png')]
  49. }
  50. },
  51. mounted(){
  52. const text = this.item.description || this.item.name;
  53. this.msg = getExpStr(text);
  54. const placeholder=this.msg.placeholder;
  55. if(placeholder){
  56. this.placeholders=this.msg.placeholder.split("/");
  57. this.placeholders.length>1?this.isXy=true:'';
  58. }
  59. if(this.txt.indexOf("/")!==-1){
  60. this.isXy=true;
  61. const arr = this.txt.split("/");
  62. this.ssyTxt= arr[0];
  63. this.szyTxt= arr[1];
  64. }
  65. this.select = this.item.select;
  66. },
  67. methods:{
  68. stopPop(e){
  69. e.stopPropagation();
  70. },
  71. changeXyVal(e,flag){ //血压值输入事件
  72. if(this.msg.type=='number'){//数字键盘
  73. this[flag] = e.target.value=e.target.value.replace(/^\.$/,'')
  74. }
  75. if(this.ssyTxt.match(/\S/g)&&this.szyTxt.match(/\S/g)){//2个都填
  76. this.txt = this.ssyTxt+"/"+this.szyTxt;
  77. }else{
  78. this.txt ='';
  79. }
  80. this.$emit('handleInp',this.txt,this.inx);
  81. this.$emit("handleSelect")
  82. },
  83. changeVal(e){
  84. /*const val = e.target.value;
  85. if(!val.match(/\S/g)){ //只有空白符不算输入
  86. this.txt='';
  87. }*/
  88. if(this.msg.type=='number'){//数字键盘
  89. this.txt = e.target.value=e.target.value.replace(/^\.$/,'')
  90. }
  91. this.$emit('handleInp',this.txt,this.inx);
  92. const notNull=this.txt.match(/\S/g);
  93. if(notNull&&!this.item.select||(!notNull&&this.item.select)){
  94. this.$emit("handleSelect")
  95. }
  96. },
  97. handleBlur(){
  98. /* if(this.txt){
  99. this.$emit('handleInp',this.txt,this.inx);
  100. }*/
  101. /*setTimeout(()=>{
  102. $(".foot").css({'display':'block'})
  103. },150)*/
  104. },
  105. handleCli(e){
  106. if(!this.select&&(this.txt||"").match(/\S/g)){//已选中后点击输入框不取消选中
  107. this.$emit("handleSelect")
  108. }
  109. }
  110. },
  111. watch:{
  112. item:{//清空时更新
  113. handler(newVal,oldVal){
  114. this.txt = newVal.value;
  115. this.select = newVal.select;
  116. },
  117. deep:true
  118. }
  119. },
  120. }
  121. </script>
  122. <style lang="less" scoped>
  123. @import '../less/base.less';
  124. .inpbox{
  125. color:#colors[text];
  126. display: inline-block;
  127. width: 100%;
  128. white-space: normal;
  129. vertical-align: middle;
  130. height: .68rem;
  131. line-height: .68rem;
  132. margin-bottom:.08rem;
  133. .prefix,.suffix{
  134. display: inline-block;
  135. vertical-align: middle;
  136. }
  137. input{
  138. height: 100%;
  139. color: #colors[btn];
  140. font-size: #font[select];
  141. border-bottom: 1px solid #E6E6E6 !important;
  142. border-radius: 0;
  143. padding-left: .05rem;
  144. background-color: transparent;
  145. position: relative;
  146. /*top: 1px;*/
  147. vertical-align: middle;
  148. box-sizing: border-box;
  149. &.cancel{
  150. color:#ccc ;
  151. }
  152. }
  153. .mult-inps{
  154. width:70%;
  155. display: inline-block;
  156. height:100%;
  157. /*input{
  158. width:45%;
  159. }*/
  160. }
  161. }
  162. .iptCheck{
  163. span{
  164. color: #colors[btn];
  165. }
  166. }
  167. </style>