or-search.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template name="or-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:"or-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. },
  98. delInputText () { //清除输入框内容
  99. this.searchText = ''
  100. this.isShowClose = false
  101. this.$parent.isShowWrapper = false
  102. this.inputEmpty(this.searchText)
  103. },
  104. keywordsClick (item) { //关键词搜索与历史搜索
  105. this.searchText = item;
  106. this.searchStart();
  107. },
  108. delhistory () { //清空历史记录
  109. this.isShowDelModal = true;
  110. },
  111. confirmDetele() {
  112. this.isShowDelModal = false;
  113. authorize.getCode('weixin').then(wechatcode =>{
  114. // console.log(wechatcode);
  115. this.$api.get('/search/delete',{organizeID:this.userOrganizeID,code:wechatcode},
  116. response =>{
  117. // console.log(response);
  118. if(response.code == '1'){
  119. this.serachRecordList=[];
  120. this.isSearchHistory = false
  121. }else{
  122. this.$util.msg(response.msg,2000)
  123. }
  124. }
  125. )
  126. })
  127. },
  128. inputEmpty(val){
  129. this.initGetSerachRecord()
  130. this.$parent.isShowWrapper = false
  131. if(val != ''){
  132. this.isShowClose = true
  133. }else{
  134. this.isShowClose = false
  135. }
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. @import "@/uni.scss";
  142. .search{
  143. width: 702rpx;
  144. height: 80rpx;
  145. padding: 12rpx 24rpx;
  146. border-bottom: 1px solid #F0F0F0;
  147. position: fixed;
  148. top: 0;
  149. left: 0;
  150. background: #FFFFFF;
  151. z-index: 1001;
  152. .search-input{
  153. width: 448rpx;
  154. height: 80rpx;
  155. padding: 0 68rpx;
  156. line-height: 80rpx;
  157. border-radius: 40rpx;
  158. position: relative;
  159. background: #F0F0F0;
  160. float: left;
  161. .icon-iconfonticonfontsousuo1{
  162. font-size: 36rpx;
  163. color: #8A8A8A;
  164. position: absolute;
  165. left: 24rpx;
  166. z-index: 10;
  167. }
  168. .icon-shanchu1{
  169. font-size: 36rpx;
  170. color: #8A8A8A;
  171. position: absolute;
  172. right: 24rpx;
  173. top: 0;
  174. padding: 0 10rpx;
  175. z-index: 10;
  176. }
  177. input{
  178. width: 448rpx;
  179. height: 80rpx;
  180. background-color: #F0F0F0;
  181. font-size: 26rpx;
  182. }
  183. }
  184. .search-btn{
  185. width: 118rpx;
  186. height: 80rpx;
  187. line-height: 80rpx;
  188. color: $color-system;
  189. font-size: 30rpx;
  190. text-align: center;
  191. float: left;
  192. }
  193. .voice-icon{
  194. width: 36rpx;
  195. height: 36rpx;
  196. padding: 16rpx 20rpx 16rpx 0;
  197. position: absolute;
  198. left: 16rpx;
  199. top: 4rpx;
  200. z-index: 10;
  201. }
  202. }
  203. .search-container{
  204. padding-top: 106rpx;
  205. }
  206. .s-block{
  207. background: #FFFFFF;
  208. .header{
  209. font-size: 32rpx;
  210. padding:40rpx 24rpx 22rpx 24rpx;
  211. line-height: 42rpx;
  212. font-size: 30rpx;
  213. font-weight: bold;
  214. position: relative;
  215. .icon-shanchu{
  216. font-size: 36rpx;
  217. color: #333333;
  218. float: right;
  219. padding: 0 10rpx;
  220. z-index: 10;
  221. font-weight: normal;
  222. }
  223. }
  224. .list{
  225. display: flex;
  226. flex-wrap: wrap;
  227. padding-bottom: 40rpx;
  228. view{
  229. color: #8A8A8A;
  230. font-size: 24rpx;
  231. box-sizing: border-box;
  232. text-align: center;
  233. height: 48rpx;
  234. line-height: 48rpx;
  235. border-radius: 24rpx;
  236. margin:12rpx;
  237. padding:.0 30rpx;
  238. overflow: hidden;
  239. white-space: nowrap;
  240. text-overflow: ellipsis;
  241. background-color: #F3F3F3;
  242. }
  243. }
  244. }
  245. .s-circle{
  246. margin-top: 30rpx;
  247. .header{
  248. font-size: 32rpx;
  249. padding: 30rpx;
  250. border-bottom: 2rpx solid #F9F9F9;
  251. position: relative;
  252. image{
  253. width: 36rpx;
  254. height: 36rpx;
  255. padding: 10rpx;
  256. position: absolute;
  257. right: 40rpx;
  258. top: 24rpx;
  259. }
  260. }
  261. .list{
  262. display: flex;
  263. flex-wrap: wrap;
  264. padding: 0 30rpx 20rpx;
  265. view{
  266. padding: 8rpx 30rpx;
  267. margin: 20rpx 30rpx 0 0;
  268. font-size: 28rpx;
  269. color: #8A8A8A;
  270. background-color: #F7F7F7;
  271. box-sizing: border-box;
  272. text-align: center;
  273. border-radius: 20rpx;
  274. }
  275. }
  276. }
  277. .wanted-block{
  278. margin-top: 30rpx;
  279. .header{
  280. font-size: 32rpx;
  281. padding: 30rpx;
  282. }
  283. .list{
  284. display: flex;
  285. flex-wrap: wrap;
  286. view{
  287. width: 50%;
  288. color: #8A8A8A;
  289. font-size: 28rpx;
  290. box-sizing: border-box;
  291. text-align: center;
  292. padding: 20rpx 0;
  293. border-top: 2rpx solid #FFF;
  294. border-left: 2rpx solid #FFF;
  295. background-color: #F7F7F7;
  296. overflow: hidden;
  297. white-space: nowrap;
  298. text-overflow: ellipsis;
  299. }
  300. }
  301. }
  302. .wanted-circle{
  303. margin-top: 30rpx;
  304. .header{
  305. font-size: 32rpx;
  306. padding: 30rpx;
  307. }
  308. .list{
  309. display: flex;
  310. flex-wrap: wrap;
  311. padding: 0 30rpx 20rpx;
  312. view{
  313. padding: 8rpx 30rpx;
  314. margin: 20rpx 30rpx 0 0;
  315. font-size: 28rpx;
  316. color: #8A8A8A;
  317. background-color: #F7F7F7;
  318. box-sizing: border-box;
  319. text-align: center;
  320. border-radius: 20rpx;
  321. }
  322. }
  323. }
  324. </style>