Search.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <portal to="notification-search">
  3. <div class="searchWrap">
  4. <div class="searchTop">
  5. <div class="iptWrap">
  6. <img
  7. class="searchImg"
  8. src="../images/searchB.png"
  9. alt=""
  10. >
  11. <input
  12. type="text"
  13. autofocus
  14. placeholder="请搜索"
  15. v-model="searchVal"
  16. >
  17. </div>
  18. <span @click="search">取消</span>
  19. </div>
  20. <div class="searchList">
  21. <p
  22. class="waring"
  23. v-if="!searchVal&&!hasMore&&searchLis.length==0"
  24. >请输入搜索内容</p>
  25. <p
  26. class="waring"
  27. v-if="hasMore&&searchVal"
  28. >暂无搜索结果</p>
  29. <ul>
  30. <li
  31. v-for="(item,idx) in searchLis"
  32. :key="item.conceptId+idx"
  33. @click="showDetil(item)"
  34. :style="{'borderBottom':(idx==searchLis.length-1)?'0':'1px solid #a8a8a8'}"
  35. ><img
  36. class="searchImgLis"
  37. src="../images/search.png"
  38. alt=""
  39. >{{item.description||item.name}}{{(item.tagName&&(item.description||item.name != item.tagName))?' ('+item.tagName+')':''}}</li>
  40. </ul>
  41. </div>
  42. </div>
  43. </portal>
  44. </template>
  45. <script>
  46. import api from '@utils/api.js';
  47. export default {
  48. props: ['age', 'sexType', 'chooseSymp'],
  49. data() {
  50. return {
  51. searchVal: '',
  52. searchLis: [],
  53. tmpItem:{},
  54. hasMore:false
  55. }
  56. },
  57. watch:{
  58. searchVal(curVal, oldVal) {
  59. if (curVal.trim() == "") {
  60. this.searchVal = "";
  61. this.searchLis = [];
  62. this.hasMore = false
  63. return;
  64. }
  65. if (curVal != "" && curVal != oldVal) {
  66. this.searchList()
  67. }
  68. }
  69. },
  70. methods: {
  71. showDetil(item) {
  72. let flg = false;
  73. if(JSON.stringify(this.tmpItem)==JSON.stringify(item)){//eg:重复点击胸痛bug
  74. flg = true
  75. }
  76. this.tmpItem = item
  77. let timer = setTimeout(() => {
  78. this.$emit('showDetil',item,flg)
  79. clearTimeout(timer)
  80. }, 250);
  81. // this.$emit('search', false)
  82. },
  83. search() {
  84. this.$emit('search', false)
  85. },
  86. searchList() {
  87. let tmpArr = [], chooseSymp = this.chooseSymp;
  88. for (let i = 0; i < chooseSymp.length; i++) {
  89. tmpArr.push(chooseSymp[i].conceptId)
  90. }
  91. const param = {
  92. "age": this.age,
  93. "inputIds": tmpArr,
  94. "inputStr": this.searchVal,
  95. "sexType": this.sexType
  96. }
  97. api.getTagInfos(param).then((res) => {
  98. const result = res.data;
  99. if (result.code == 0) {
  100. this.searchLis = result.data
  101. if(result.data.length>0){
  102. this.hasMore = false
  103. }else{
  104. this.hasMore = true
  105. }
  106. }
  107. })
  108. }
  109. }
  110. }
  111. </script>
  112. <style lang="less" scoped>
  113. .searchWrap {
  114. position: fixed;
  115. height: 100%;
  116. width: 100%;
  117. top: 0;
  118. left: 0;
  119. z-index: 102;
  120. background-color: #ededed;
  121. font-size: .3rem;
  122. }
  123. .searchTop {
  124. padding: 0.15rem 0.4rem;
  125. padding-right: 1.2rem;
  126. background-color: #ededed;
  127. box-sizing: border-box;
  128. position: absolute;
  129. width: 100%;
  130. top: 0;
  131. z-index: 999;
  132. span {
  133. position: absolute;
  134. right: 0.32rem;
  135. top: 0.32rem;
  136. font-size: 0.3rem;
  137. color: #666666;
  138. }
  139. }
  140. .iptWrap {
  141. height: 0.74rem;
  142. border-radius: 0.37rem;
  143. background-color: #fff;
  144. overflow: hidden;
  145. padding: 0.16rem 0.3rem 0.16rem 0.75rem;
  146. box-sizing: border-box;
  147. width: 100%;
  148. position: relative;
  149. .searchImg {
  150. width: 0.44rem;
  151. height: 0.44rem;
  152. position: absolute;
  153. left: 0.2rem;
  154. top: 0.14rem;
  155. }
  156. input {
  157. width: 100%;
  158. height: 0.42rem;
  159. font-size: 0.3rem;
  160. line-height: 0.42rem;
  161. }
  162. }
  163. .searchList {
  164. overflow: scroll;
  165. position: absolute;
  166. -webkit-overflow-scrolling: touch;
  167. top: 0;
  168. left: 0;
  169. padding-top: 1.04rem;
  170. height: 100%;
  171. width: 100%;
  172. background-color: #ededed;
  173. .waring {
  174. padding-left: 0.5rem;
  175. margin-top: 0.2rem;
  176. }
  177. ul {
  178. padding: 0 0.4rem;
  179. box-sizing: border-box;
  180. background-color: #fff;
  181. }
  182. li {
  183. height: 1rem;
  184. line-height: 1rem;
  185. padding: 0 0.4rem;
  186. border-bottom: 1px solid #a8a8a8;
  187. box-sizing: border-box;
  188. .searchImgLis {
  189. width: 0.44rem;
  190. height: 0.44rem;
  191. float: left;
  192. margin-top: 0.26rem;
  193. margin-right: 0.15rem;
  194. }
  195. }
  196. }
  197. </style>