go-search.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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()">搜索</view>
  10. </view>
  11. <view class="search-container">
  12. <view :class="'s-' + theme" v-if="isSearchHistory">
  13. <view class="header">
  14. 搜索历史
  15. <text class="iconfont icon-shanchu" @click="delhistory"></text>
  16. </view>
  17. <view class="list">
  18. <view v-for="(item,index) in serachRecordList" :key="index" @click="keywordsClick(item.searchWord)">{{item.searchWord}}</view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 删除弹窗 -->
  23. <model-alert v-if="isShowDelModal"
  24. :alertText='alertText'
  25. @btnConfirm ='confirmDetele'>
  26. </model-alert>
  27. </view>
  28. </template>
  29. <script>
  30. import modelAlert from '@/components/module/modelAlert/modelAlert.vue'
  31. import authorize from '@/common/config/authorize.js'
  32. export default{
  33. name:"go-search",
  34. components:{
  35. modelAlert
  36. },
  37. props:{
  38. isFocus:{ //是否自动获取焦点
  39. type: Boolean,
  40. default: false
  41. },
  42. theme:{ //选择块级显示还是圆形显示
  43. type: String,
  44. default: 'block'
  45. }
  46. },
  47. data() {
  48. return {
  49. searchText:'', //搜索关键词
  50. alertText:'确定删除全部历史记录?',
  51. isShowDelModal:false, //控制显示删除弹窗
  52. isShowClose:false, //是否显示清空输入框图标
  53. isSearchHistory:false, //是都显示搜索历史
  54. serachRecordList:[]
  55. };
  56. },
  57. created() {
  58. // this.initGetSerachRecord()
  59. },
  60. methods: {
  61. initGetSerachRecord(){
  62. authorize.getCode('weixin').then(wechatcode =>{
  63. // console.log(wechatcode);
  64. this.$api.get('/search/record',{organizeID:this.userOrganizeID,code:wechatcode},
  65. response =>{
  66. // console.log(response);
  67. if(response.code == '1'){
  68. this.serachRecordList = response.data
  69. if(this.serachRecordList.length>0){
  70. this.isSearchHistory = true
  71. }else{
  72. this.isSearchHistory = false
  73. }
  74. }else{
  75. this.$util.msg(response.msg,2000)
  76. }
  77. }
  78. )
  79. })
  80. },
  81. searchStart: function() { //触发搜索
  82. let _this = this;
  83. if (_this.searchText == '') {
  84. this.$util.msg('请输入商品关键词',2000);
  85. }else{
  86. _this.isSearchHistory = false
  87. _this.$emit('getSearchText', _this.searchText)
  88. }
  89. },
  90. onShowClose () { //输入框失去焦点时触发
  91. this.inputEmpty(this.searchText)
  92. },
  93. onFocus () { //输入框获取焦点时触发
  94. this.inputEmpty(this.searchText)
  95. this.initGetSerachRecord()
  96. },
  97. delInputText () { //清除输入框内容
  98. this.searchText = ''
  99. this.isShowClose = false
  100. this.$parent.isShowWrapper = false
  101. this.inputEmpty(this.searchText)
  102. this.initGetSerachRecord()
  103. },
  104. keywordsClick (item) { //关键词搜索与历史搜索
  105. this.searchText = item;
  106. this.isShowClose = true;
  107. this.searchStart();
  108. },
  109. delhistory () { //清空历史记录
  110. this.isShowDelModal = true;
  111. },
  112. confirmDetele() {
  113. this.isShowDelModal = false;
  114. authorize.getCode('weixin').then(wechatcode =>{
  115. // console.log(wechatcode);
  116. this.$api.get('/search/delete',{organizeID:this.userOrganizeID,code:wechatcode},
  117. response =>{
  118. // console.log(response);
  119. if(response.code == '1'){
  120. this.serachRecordList=[];
  121. this.isSearchHistory = false
  122. }else{
  123. this.$util.msg(response.msg,2000)
  124. }
  125. }
  126. )
  127. })
  128. },
  129. inputEmpty(val){
  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: 999;
  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>