or-search.vue 6.9 KB

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