or-search.vue 7.1 KB

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