MultiLineInput.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <div :style="{'margin-bottom':isLast?'0':'.3rem'}" :class="['multipIpt',{'border':border,'inline':inline,'check':select}]">
  3. <span class="prefix" v-if="content.prefix">{{content.prefix}}</span>
  4. <div class="sticP" :style="{paddingRight:content.suffix?'1rem':'0'}">
  5. <div class="iptWrap">
  6. <template v-for="(item,idx) in content.iptLis">
  7. <input v-if="content.iptLis.length>1"
  8. class="contentVal"
  9. :type="content.type=='number'?'number':'text'"
  10. :style="{'width':1/content.iptLis.length*100-3+'%'}"
  11. :key="item.placeholder+idx"
  12. v-model="item.value"
  13. :placeholder="item.placeholder"
  14. @input="changeVal($event,idx,content.type)"
  15. @blur="blur"
  16. @focus="focus"
  17. :maxlength="content.type=='number'?10:''"
  18. @click="handleClick">
  19. <input v-show="content.iptLis.length==1" class="contentVal"
  20. :type="content.type=='number'?'number':'text'"
  21. :placeholder="content.placeholder"
  22. v-model="item.value"
  23. @input="changeVal($event,idx,content.type)"
  24. @blur="blur"
  25. @focus="focus"
  26. :maxlength="content.type=='number'?10:''"
  27. @click="handleClick">
  28. <span v-if="idx == 0&&content.iptLis.length>1">/</span>
  29. </template>
  30. </div>
  31. </div>
  32. <span class="suffix" v-if="content.suffix">{{content.suffix}}</span>
  33. </div>
  34. </template>
  35. <script>
  36. import { getModelExpStr,isIos } from '@utils/tools';
  37. import $ from 'jquery';
  38. export default {
  39. props:{
  40. msg:{
  41. default:'',
  42. type:String
  43. },
  44. part:{
  45. type:Object,
  46. require: true
  47. },
  48. border:{//最外层边框
  49. default:true,
  50. type:Boolean
  51. },
  52. inline:{ //是否行内元素
  53. default:false,
  54. type:Boolean
  55. },
  56. select:{ //是否选中
  57. default:false,
  58. type:Boolean
  59. },
  60. isLast:{ //是否为最后一个
  61. default:false,
  62. type:Boolean
  63. },
  64. },
  65. data(){
  66. return {
  67. content:{},
  68. txt:this.part.value || '', //回读用
  69. tmpArr:[]
  70. }
  71. },
  72. mounted(){
  73. this.content = getModelExpStr(this.msg,this.txt)
  74. },
  75. methods:{
  76. changeVal(e,num,type){
  77. let tmpTxt = '',arr=this.tmpArr
  78. document.activeElement.scrollIntoViewIfNeeded(true);
  79. if(type == 'number'){
  80. e.currentTarget.value = e.currentTarget.value.replace(/^\.$/,'')
  81. }
  82. arr[num]=e.currentTarget.value
  83. tmpTxt=arr.join('/')
  84. this.txt = tmpTxt
  85. this.content = getModelExpStr(this.msg,this.txt)
  86. // this.$emit('changeMultipVal',e.currentTarget.value,num)
  87. const select = this.part.select;
  88. // if(!select){return}
  89. const newData = Object.assign({},this.part,{value:this.txt,controlType:3,valueP:this.txt});
  90. this.$emit("updata",newData);
  91. this.$emit('handleInp',this.txt);
  92. },
  93. blur(){
  94. // 如果该项未选中,则不存值
  95. // $(".btscroll").css({'position':'fixed'})
  96. $(".foot").css({'display':'block'})
  97. document.activeElement.scrollIntoView({behavior: "smooth"})
  98. document.activeElement.scrollIntoViewIfNeeded(true);
  99. setTimeout(()=>{
  100. document.activeElement.scrollIntoViewIfNeeded(true);
  101. },300)
  102. },
  103. focus(){
  104. if(isIos()){
  105. // $(".btscroll").css({'position':'absolute'})
  106. $(".foot").css({'display':'none'})
  107. }
  108. },
  109. handleClick(e){
  110. // 点击输入框时不选中该项
  111. // document.activeElement.scrollIntoViewIfNeeded(true);
  112. e.stopPropagation();
  113. }
  114. },
  115. watch:{
  116. part:{//清空时更新
  117. handler(newVal,oldVal){
  118. this.txt = newVal.value;
  119. this.content = getModelExpStr(this.msg,this.txt)
  120. },
  121. deep:true
  122. }
  123. },
  124. }
  125. </script>
  126. <style lang="less" scoped>
  127. @import '../less/base.less';
  128. .multipIpt {
  129. width: 100%;
  130. // height: .74rem /* 74/100 */;
  131. line-height: .74rem /* 74/100 */;
  132. // border: 1px solid #DFE0E4;
  133. // border-radius: .08rem /* 8/100 */;
  134. padding: 0 .12rem 0 .26rem;
  135. box-sizing: border-box;
  136. position: relative;
  137. margin-bottom: .3rem;
  138. .contentVal {
  139. font-size: .3rem /* 30/100 */;
  140. color: #colors[theme];
  141. text-align: left;
  142. border: 0 none;
  143. // border-bottom: 1px solid #b0afaf !important;
  144. border-radius: 0;
  145. // background-color: #fff;
  146. background: transparent;
  147. outline-color: invert;
  148. height: .38rem;
  149. line-height: .38rem;
  150. width: 100%;
  151. padding:0 0.1rem;
  152. box-sizing: border-box;
  153. }
  154. }
  155. .border{
  156. border: 1px solid #DFE0E4;
  157. border-radius: 2rem
  158. }
  159. .inline{
  160. display: inline-block;
  161. vertical-align: middle;
  162. color: #colors[text];
  163. padding: 0;
  164. margin:0;
  165. height: auto /* 74/100 */;
  166. line-height: .36rem /* 74/100 */;
  167. }
  168. .prefix {
  169. float: left;
  170. color: #666;
  171. line-height: .72rem;
  172. }
  173. .suffix {
  174. position: absolute;
  175. right: .1rem;
  176. top: .2rem;
  177. width: 1rem;
  178. text-align: right;
  179. text-align: left;
  180. color: #666;
  181. line-height: .36rem;
  182. }
  183. .sticP {
  184. width: 100%;
  185. padding-right: 1rem;
  186. box-sizing: border-box;
  187. .iptWrap {
  188. // width: 100%;
  189. position: relative;
  190. overflow: hidden;
  191. min-width: 1rem;
  192. span {
  193. color: #666;
  194. }
  195. }
  196. }
  197. .check{
  198. color: #colors[theme];
  199. }
  200. </style>