Search.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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','setText'],
  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. if(this.chooseSymp.length == 0){
  78. item.idx = 1
  79. }
  80. let timer = setTimeout(() => {
  81. this.$emit('showDetil',item,flg)
  82. clearTimeout(timer)
  83. }, 250);
  84. // this.$emit('search', false)
  85. },
  86. search() {
  87. this.$emit('search', false)
  88. },
  89. searchList() {
  90. let tmpArr = [], chooseSymp = this.chooseSymp;
  91. for (let i = 0; i < chooseSymp.length; i++) {
  92. tmpArr.push(chooseSymp[i].conceptId)
  93. }
  94. const param = {
  95. "age": this.age,
  96. "inputIds": tmpArr,
  97. "inputStr": this.searchVal,
  98. "sexType": this.sexType
  99. }
  100. api.getTagInfos(param).then((res) => {
  101. const result = res.data;
  102. if (result.code == 0) {
  103. this.searchLis = result.data
  104. if(result.data.length>0){
  105. this.hasMore = false
  106. }else{
  107. this.hasMore = true
  108. }
  109. }
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="less" scoped>
  116. .searchWrap {
  117. position: fixed;
  118. height: 100%;
  119. width: 100%;
  120. top: 0;
  121. left: 0;
  122. z-index: 102;
  123. background-color: #ededed;
  124. font-size: .3rem;
  125. }
  126. .searchTop {
  127. padding: 0.15rem 0.4rem;
  128. padding-right: 1.2rem;
  129. background-color: #ededed;
  130. box-sizing: border-box;
  131. position: absolute;
  132. width: 100%;
  133. top: 0;
  134. z-index: 999;
  135. span {
  136. position: absolute;
  137. right: 0.32rem;
  138. top: 0.32rem;
  139. font-size: 0.3rem;
  140. color: #666666;
  141. }
  142. }
  143. .iptWrap {
  144. height: 0.74rem;
  145. border-radius: 0.37rem;
  146. background-color: #fff;
  147. overflow: hidden;
  148. padding: 0.16rem 0.3rem 0.16rem 0.75rem;
  149. box-sizing: border-box;
  150. width: 100%;
  151. position: relative;
  152. .searchImg {
  153. width: 0.44rem;
  154. height: 0.44rem;
  155. position: absolute;
  156. left: 0.2rem;
  157. top: 0.14rem;
  158. }
  159. input {
  160. width: 100%;
  161. height: 0.42rem;
  162. font-size: 0.3rem;
  163. line-height: 0.42rem;
  164. }
  165. }
  166. .searchList {
  167. overflow: scroll;
  168. position: absolute;
  169. -webkit-overflow-scrolling: touch;
  170. top: 0;
  171. left: 0;
  172. padding-top: 1.04rem;
  173. height: 100%;
  174. width: 100%;
  175. background-color: #ededed;
  176. .waring {
  177. padding-left: 0.5rem;
  178. margin-top: 0.2rem;
  179. }
  180. ul {
  181. padding: 0 0.4rem;
  182. box-sizing: border-box;
  183. background-color: #fff;
  184. }
  185. li {
  186. height: 1rem;
  187. line-height: 1rem;
  188. padding: 0 0.4rem;
  189. border-bottom: 1px solid #a8a8a8;
  190. box-sizing: border-box;
  191. .searchImgLis {
  192. width: 0.44rem;
  193. height: 0.44rem;
  194. float: left;
  195. margin-top: 0.26rem;
  196. margin-right: 0.15rem;
  197. }
  198. }
  199. }
  200. </style>