search.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="sld_point_search">
  3. <view class="fixed_top_status_bar"></view>
  4. <!-- 小程序头部兼容 -->
  5. <view :class="{mp_search_box:true,fixedTop:isTop}">
  6. <view class="search_con">
  7. <image :src="imgUrl+'search.png'" mode="aspectFit" class="search_img"></image>
  8. <input confirm-type="search" @confirm="search" class="ser_input" type="text" v-model="keyword" :placeholder="$L('搜索')" placeholder-class="search_input" />
  9. <image class='clear_content' v-show="keyword" @click="clearInputVal" :src="imgUrl+'input_clear.png'" />
  10. </view>
  11. <text class="search_btn" @click="backLastPage">{{$L('取消')}}</text>
  12. </view>
  13. <view class="no_data_con" v-if="recommendedList.length==0">
  14. <!-- 暂无历史记录 -->
  15. <text class="no_history" v-if="history_val.length==0&&!keyword">{{$L('暂无历史搜索记录~')}}</text>
  16. <!-- 搜索历史 start -->
  17. <view class="search-item" v-if="!keyword&&history_val && history_val.length" style="padding-bottom: 0;">
  18. <view class="search-title">
  19. <text>{{$L('搜索历史')}}</text>
  20. <view class="del" @click="clearHistory">
  21. <image :src="imgUrl+'del_search.png'" />
  22. </view>
  23. </view>
  24. <view class="search-con">
  25. <view class="item" v-for="(item,index) in history_val" :key="index" @click="btnSearch(item)">{{item}}</view>
  26. </view>
  27. </view>
  28. <!-- 搜索历史 end -->
  29. <!-- 分类空页面 -->
  30. <view class="empty_sort_page" v-if="keyword&&is_show_empty">
  31. <image :src="imgUrl+'index/empty.png'" mode="aspectFit" class="empty_img"></image>
  32. <view class="empty_text">{{$L('暂无数据')}}</view>
  33. </view>
  34. </view>
  35. <!-- 积分商城搜索列表 -->
  36. <view class="recommend_list">
  37. <recommendGoods class='recommend_pre' v-for="(recommendItem,recommendIndex) in recommendedList" :goods_info="recommendItem"></recommendGoods>
  38. </view>
  39. <recommendItemList v-if='!this.hasMore' ref='recommendList'></recommendItemList>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapState,
  45. } from 'vuex';
  46. import recommendGoods from '../components/recommend_item_v.vue'
  47. import loadingState from "../components/loading-state.vue";
  48. import recommendItemList from '../components/recommend_list.vue'
  49. export default {
  50. data() {
  51. return {
  52. imgUrl: getApp().globalData.imgUrl,
  53. keyword:'',
  54. recommendedList:[],
  55. loadingState: '',
  56. current:1,
  57. pageSize:10,
  58. hasMore:false,
  59. is_show_empty:false,
  60. labelId:'',
  61. history_val:[],
  62. isTop:false
  63. };
  64. },
  65. components: {
  66. recommendGoods,
  67. loadingState,
  68. recommendItemList
  69. },
  70. computed: {
  71. ...mapState(['hasLogin', 'userInfo', 'userCenterData'])
  72. },
  73. async mounted() {
  74. this.getHistoryList()
  75. },
  76. onReachBottom() {
  77. if(this.hasMore){
  78. this.search()
  79. }else{
  80. this.$refs.recommendList.getMoreData();
  81. }
  82. },
  83. onPageScroll(e){
  84. if(e.scrollTop>100){
  85. this.isTop = true
  86. }else{
  87. this.isTop = false
  88. }
  89. },
  90. onLoad(options) {
  91. if(options.labelId){
  92. this.labelId=options.labelId
  93. }
  94. if(options.keyword){
  95. this.keyword=options.keyword
  96. this.search()
  97. }
  98. },
  99. methods: {
  100. clearInputVal(){
  101. this.keyword=''
  102. },
  103. btnSearch(item){
  104. this.keyword=item
  105. this.search()
  106. },
  107. backLastPage(){
  108. uni.navigateBack()
  109. },
  110. search(){
  111. uni.hideKeyboard()
  112. uni.showLoading()
  113. let param = {}
  114. param.data={}
  115. param.data.keyword=this.keyword
  116. if(this.labelId){
  117. param.data.labelId=this.labelId
  118. }
  119. param.url = 'v3/integral/front/integral/mall/goodsList'
  120. param.method = 'GET'
  121. this.$request(param).then(res => {
  122. if (res.state == 200) {
  123. this.setHistoryData()
  124. this.recommendedList=res.data.list
  125. if(this.recommendedList.length==0){
  126. this.is_show_empty=true
  127. }else{
  128. this.is_show_empty=false
  129. }
  130. this.hasMore = this.$checkPaginationHasMore(res.data.pagination); //是否还有数据
  131. if (this.hasMore) {
  132. this.current++;
  133. this.loadingState = 'allow_loading_more';
  134. } else {
  135. this.loadingState = 'no_more_data';
  136. }
  137. uni.hideLoading()
  138. uni.pageScrollTo({
  139. duration:100,
  140. scrollTop:0
  141. })
  142. }else{
  143. uni.hideLoading()
  144. that.$api.msg(res.msg)
  145. }
  146. })
  147. },
  148. //设置缓存
  149. setHistoryData() {
  150. let {
  151. history_val,
  152. keyword
  153. } = this;
  154. let tmp_data = [...history_val];
  155. tmp_data.unshift(keyword);
  156. // 最多取12条,不重复且不为空的数据
  157. tmp_data = tmp_data.reduce((a, b) => {
  158. (a.length < 12 && b && a.indexOf(b) == -1) ? a.push(b): null;
  159. return a;
  160. }, [])
  161. let history_val_str = tmp_data.join('~');
  162. this.history_val = tmp_data;
  163. uni.setStorageSync("point_his_keyword", history_val_str)
  164. },
  165. //获取历史记录
  166. getHistoryList() {
  167. let history_data = uni.getStorageSync('point_his_keyword');
  168. if (history_data) {
  169. let his_array = history_data.split("~");
  170. let last_arr = [];
  171. for (var i = 0; i < his_array.length; i++) {
  172. !this.$checkSpace(his_array[i]) && last_arr.push(his_array[i]);
  173. }
  174. this.history_val = last_arr;
  175. }
  176. },
  177. //清除搜索历史
  178. clearHistory() {
  179. uni.removeStorageSync('point_his_keyword');
  180. this.history_val = [];
  181. },
  182. },
  183. }
  184. </script>
  185. <style lang="scss">
  186. .fixed_top_status_bar {
  187. position: fixed;
  188. /* #ifdef APP-PLUS */
  189. height: var(--status-bar-height);
  190. /* #endif */
  191. /* #ifndef APP-PLUS */
  192. height: 0;
  193. /* #endif */
  194. top: 0;
  195. left: 0;
  196. right: 0;
  197. z-index: 99;
  198. background: #fff;
  199. }
  200. page{
  201. background: #F5F5F5;
  202. width: 750rpx;
  203. margin: 0 auto;
  204. }
  205. .mp_search_box {
  206. display: flex;
  207. align-items: center;
  208. background-color: white;
  209. padding: 11rpx 0;
  210. transition: all 0.4s ease;
  211. /* #ifdef APP-PLUS */
  212. padding-top: calc(var(--status-bar-height) + 11rpx);
  213. /* #endif */
  214. .search_con{
  215. width: 631rpx;
  216. height: 65rpx;
  217. background: #F5F5F5;
  218. border-radius: 33rpx;
  219. padding:18rpx 22rpx;
  220. display: flex;
  221. align-items: center;
  222. margin-left: 20rpx;
  223. .ser_input{
  224. flex: 1;
  225. padding-left: 20rpx;
  226. }
  227. .search_img{
  228. width: 30rpx;
  229. height: 30rpx;
  230. }
  231. .clear_content{
  232. width: 44rpx !important;
  233. height: 44rpx !important;
  234. }
  235. .search_input{
  236. font-size: 28rpx;
  237. color: #999999;
  238. }
  239. }
  240. .search_btn{
  241. margin-left: 20rpx;
  242. font-size: 30rpx;
  243. color: #333333;
  244. }
  245. }
  246. .fixedTop{
  247. position: fixed;
  248. top: 0;
  249. z-index: 1000;
  250. width: 100%;
  251. }
  252. .no_data_con{
  253. .no_history{
  254. color: #2D2D2D;
  255. font-size: 12px;
  256. display: inline-block;
  257. width: 100%;
  258. height: 100%;
  259. text-align: center;
  260. line-height: 500rpx;
  261. }
  262. height: 514rpx;
  263. background-color: white;
  264. }
  265. .recommend_list{
  266. margin-top: 20rpx;
  267. display: flex;
  268. flex-wrap: wrap;
  269. padding: 0 20rpx;
  270. .recommend_pre{
  271. margin-right: 20rpx!important;
  272. &:nth-child(2n){
  273. margin-right: 0!important;
  274. }
  275. }
  276. }
  277. // 空页面
  278. .empty_sort_page {
  279. width: 100%;
  280. display: flex;
  281. flex-direction: column;
  282. align-items: center;
  283. padding: 100rpx;
  284. .empty_img {
  285. width: 210rpx;
  286. height: 210rpx;
  287. margin-bottom: 32rpx;
  288. }
  289. .empty_text {
  290. font-size: 26rpx;
  291. color: #999;
  292. }
  293. }
  294. .search-item {
  295. padding: 30rpx 28rpx;
  296. .search-title {
  297. display: flex;
  298. align-items: center;
  299. justify-content: space-between;
  300. height: 48rpx;
  301. color: #2D2D2D;
  302. font-size: 28rpx;
  303. font-weight: bold;
  304. image {
  305. width: 48rpx;
  306. height: 48rpx;
  307. }
  308. }
  309. .search-con {
  310. display: flex;
  311. align-items: center;
  312. flex-wrap: wrap;
  313. .item {
  314. height: 50rpx;
  315. padding: 0 18rpx;
  316. color: #2D2D2D;
  317. line-height: 50rpx;
  318. font-size: 24rpx;
  319. background-color: #F5F5F5;
  320. border-radius: 25rpx;
  321. margin-right: 20rpx;
  322. margin-top: 20rpx;
  323. max-width: 274rpx;
  324. white-space: nowrap;
  325. text-overflow: ellipsis;
  326. overflow: hidden;
  327. word-break: break-all;
  328. }
  329. }
  330. }
  331. </style>