go-search.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template name="go-search">
  2. <view>
  3. <view class="search">
  4. <view class="search-input">
  5. <text class="iconfont icon-iconfonticonfontsousuo1"></text>
  6. <input maxlength="20" focus type="text" value="" confirm-type="search" @focus="onFocus" @input="onShowClose" @confirm="searchStart()" placeholder="输入搜索关键词" v-model.trim="searchText"/>
  7. <text class="iconfont icon-shanchu1" v-if="isShowClose" @click="delInputText()"></text>
  8. </view>
  9. <view class="search-btn" @click="searchStart()">
  10. 搜索
  11. </view>
  12. </view>
  13. <view class="search-container">
  14. <view :class="'s-' + theme" v-if="isSearchHistory">
  15. <view class="header">
  16. 搜索历史
  17. <text class="iconfont icon-shanchu" @click="delhistory"></text>
  18. </view>
  19. <view class="list">
  20. <view v-for="(item,index) in serachRecordList" :key="index" @click="keywordsClick(item.searchWord)">{{item.searchWord}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 删除弹窗 -->
  25. <model-alert v-if="isShowDelModal"
  26. :alertText='alertText'
  27. @btnConfirm ='confirmDetele'>
  28. </model-alert>
  29. </view>
  30. </template>
  31. <script>
  32. import modelAlert from '@/components/module/modelAlert/modelAlert.vue'
  33. import authorize from '@/config/authorize.js'
  34. export default{
  35. name:"go-search",
  36. components:{
  37. modelAlert
  38. },
  39. props:{
  40. isFocus:{ //是否自动获取焦点
  41. type: Boolean,
  42. default: false
  43. },
  44. theme:{ //选择块级显示还是圆形显示
  45. type: String,
  46. default: 'block'
  47. }
  48. },
  49. data() {
  50. return {
  51. searchText:'', //搜索关键词
  52. alertText:'确定删除全部历史记录?',
  53. isShowDelModal:false, //控制显示删除弹窗
  54. isShowClose:false, //是否显示清空输入框图标
  55. isSearchHistory:false, //是都显示搜索历史
  56. serachRecordList:[]
  57. };
  58. },
  59. created() {
  60. // this.initGetSerachRecord()
  61. },
  62. methods: {
  63. initGetSerachRecord(){
  64. authorize.getCode('weixin').then(wechatcode =>{
  65. // console.log(wechatcode);
  66. this.$api.get('/search/record',{organizeID:this.userOrganizeID,code:wechatcode},
  67. response =>{
  68. // console.log(response);
  69. if(response.code == '1'){
  70. this.serachRecordList = response.data
  71. if(this.serachRecordList.length>0){
  72. this.isSearchHistory = true
  73. }else{
  74. this.isSearchHistory = false
  75. }
  76. }else{
  77. this.$util.msg(response.msg,2000)
  78. }
  79. }
  80. )
  81. })
  82. },
  83. searchStart: function() { //触发搜索
  84. let _this = this;
  85. if (_this.searchText == '') {
  86. this.$util.msg('请输入关键字',2000);
  87. }else{
  88. _this.isSearchHistory = false
  89. _this.$emit('getSearchText', _this.searchText)
  90. }
  91. },
  92. onShowClose () { //输入框失去焦点时触发
  93. this.inputEmpty(this.searchText)
  94. },
  95. onFocus () { //输入框获取焦点时触发
  96. this.inputEmpty(this.searchText)
  97. this.initGetSerachRecord()
  98. },
  99. delInputText () { //清除输入框内容
  100. this.searchText = ''
  101. this.isShowClose = false
  102. this.$parent.isShowWrapper = false
  103. this.inputEmpty(this.searchText)
  104. this.initGetSerachRecord()
  105. },
  106. keywordsClick (item) { //关键词搜索与历史搜索
  107. this.searchText = item;
  108. this.searchStart();
  109. },
  110. delhistory () { //清空历史记录
  111. this.isShowDelModal = true;
  112. },
  113. confirmDetele() {
  114. this.isShowDelModal = false;
  115. authorize.getCode('weixin').then(wechatcode =>{
  116. // console.log(wechatcode);
  117. this.$api.get('/search/delete',{organizeID:this.userOrganizeID,code:wechatcode},
  118. response =>{
  119. // console.log(response);
  120. if(response.code == '1'){
  121. this.serachRecordList=[];
  122. this.isSearchHistory = false
  123. }else{
  124. this.$util.msg(response.msg,2000)
  125. }
  126. }
  127. )
  128. })
  129. },
  130. inputEmpty(val){
  131. this.$parent.isShowWrapper = false
  132. if(val != ''){
  133. this.isShowClose = true
  134. }else{
  135. this.isShowClose = false
  136. }
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. @import "@/uni.scss";
  143. .search{
  144. width: 702rpx;
  145. height: 80rpx;
  146. padding: 12rpx 24rpx;
  147. border-bottom: 1px solid #F0F0F0;
  148. position: fixed;
  149. top: 0;
  150. left: 0;
  151. background: #FFFFFF;
  152. z-index: 999;
  153. .search-input{
  154. width: 448rpx;
  155. height: 80rpx;
  156. padding: 0 68rpx;
  157. line-height: 80rpx;
  158. border-radius: 40rpx;
  159. position: relative;
  160. background: #F0F0F0;
  161. float: left;
  162. .icon-iconfonticonfontsousuo1{
  163. font-size: 36rpx;
  164. color: #8A8A8A;
  165. position: absolute;
  166. left: 24rpx;
  167. z-index: 10;
  168. }
  169. .icon-shanchu1{
  170. font-size: 36rpx;
  171. color: #8A8A8A;
  172. position: absolute;
  173. right: 24rpx;
  174. top: 0;
  175. padding: 0 10rpx;
  176. z-index: 10;
  177. }
  178. input{
  179. width: 448rpx;
  180. height: 80rpx;
  181. background-color: #F0F0F0;
  182. font-size: 26rpx;
  183. }
  184. }
  185. .search-btn{
  186. width: 118rpx;
  187. height: 80rpx;
  188. line-height: 80rpx;
  189. color: $color-system;
  190. font-size: 30rpx;
  191. text-align: center;
  192. float: left;
  193. }
  194. .voice-icon{
  195. width: 36rpx;
  196. height: 36rpx;
  197. padding: 16rpx 20rpx 16rpx 0;
  198. position: absolute;
  199. left: 16rpx;
  200. top: 4rpx;
  201. z-index: 10;
  202. }
  203. }
  204. .search-container{
  205. padding-top: 106rpx;
  206. }
  207. .s-block{
  208. background: #FFFFFF;
  209. .header{
  210. font-size: 32rpx;
  211. padding:40rpx 24rpx 22rpx 24rpx;
  212. line-height: 42rpx;
  213. font-size: 30rpx;
  214. font-weight: bold;
  215. position: relative;
  216. .icon-shanchu{
  217. font-size: 36rpx;
  218. color: #333333;
  219. float: right;
  220. padding: 0 10rpx;
  221. z-index: 10;
  222. font-weight: normal;
  223. }
  224. }
  225. .list{
  226. display: flex;
  227. flex-wrap: wrap;
  228. padding-bottom: 40rpx;
  229. view{
  230. color: #8A8A8A;
  231. font-size: 24rpx;
  232. box-sizing: border-box;
  233. text-align: center;
  234. height: 48rpx;
  235. line-height: 48rpx;
  236. border-radius: 24rpx;
  237. margin:12rpx;
  238. padding:.0 30rpx;
  239. overflow: hidden;
  240. white-space: nowrap;
  241. text-overflow: ellipsis;
  242. background-color: #F3F3F3;
  243. }
  244. }
  245. }
  246. .s-circle{
  247. margin-top: 30rpx;
  248. .header{
  249. font-size: 32rpx;
  250. padding: 30rpx;
  251. border-bottom: 2rpx solid #F9F9F9;
  252. position: relative;
  253. image{
  254. width: 36rpx;
  255. height: 36rpx;
  256. padding: 10rpx;
  257. position: absolute;
  258. right: 40rpx;
  259. top: 24rpx;
  260. }
  261. }
  262. .list{
  263. display: flex;
  264. flex-wrap: wrap;
  265. padding: 0 30rpx 20rpx;
  266. view{
  267. padding: 8rpx 30rpx;
  268. margin: 20rpx 30rpx 0 0;
  269. font-size: 28rpx;
  270. color: #8A8A8A;
  271. background-color: #F7F7F7;
  272. box-sizing: border-box;
  273. text-align: center;
  274. border-radius: 20rpx;
  275. }
  276. }
  277. }
  278. .wanted-block{
  279. margin-top: 30rpx;
  280. .header{
  281. font-size: 32rpx;
  282. padding: 30rpx;
  283. }
  284. .list{
  285. display: flex;
  286. flex-wrap: wrap;
  287. view{
  288. width: 50%;
  289. color: #8A8A8A;
  290. font-size: 28rpx;
  291. box-sizing: border-box;
  292. text-align: center;
  293. padding: 20rpx 0;
  294. border-top: 2rpx solid #FFF;
  295. border-left: 2rpx solid #FFF;
  296. background-color: #F7F7F7;
  297. overflow: hidden;
  298. white-space: nowrap;
  299. text-overflow: ellipsis;
  300. }
  301. }
  302. }
  303. .wanted-circle{
  304. margin-top: 30rpx;
  305. .header{
  306. font-size: 32rpx;
  307. padding: 30rpx;
  308. }
  309. .list{
  310. display: flex;
  311. flex-wrap: wrap;
  312. padding: 0 30rpx 20rpx;
  313. view{
  314. padding: 8rpx 30rpx;
  315. margin: 20rpx 30rpx 0 0;
  316. font-size: 28rpx;
  317. color: #8A8A8A;
  318. background-color: #F7F7F7;
  319. box-sizing: border-box;
  320. text-align: center;
  321. border-radius: 20rpx;
  322. }
  323. }
  324. }
  325. </style>