search.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <app-layout>
  3. <view class="layout">
  4. <view class="search dir-left-nowrap main-between cross-center">
  5. <input class="input" :focus="true" confirm-type="search" maxlength="50" type="text" v-model="keyword" @blur="setRequest">
  6. <view class="icon" v-show="keyword.length>0" @click="empyt_search"></view>
  7. <text class="search-text" @click="setRequest">搜索</text>
  8. </view>
  9. <view class="storage" v-if="strong.length > 0 && !search">
  10. <view class="operating dir-left-nowrap main-between">
  11. <text>历史搜索</text>
  12. <view class="delete-icon" @click="setClearStorage"></view>
  13. </view>
  14. <view class="history-record dir-left-wrap">
  15. <view class="item t-omit" v-for="(item, index) in strong" :key="index" @click="searchRequest(item)">
  16. {{item}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="product-list" v-if="loading && goods_list.length > 0">
  21. <app-product-list @routeGo="routeGo" :goods_list="goods_list" :theme="getTheme"></app-product-list>
  22. </view>
  23. <template v-else-if="goods_list.length === 0 && loading && search">
  24. <view class="no-empty main-center" >
  25. <app-no-goods title="暂无满减商品" ></app-no-goods>
  26. </view>
  27. </template>
  28. </view>
  29. </app-layout>
  30. </template>
  31. <script>
  32. let strong = "FULL_REDUCE_SEARCH";
  33. import appProductList from '../../../components/page-component/app-product-list/app-product-list.vue';
  34. import { mapGetters } from 'vuex';
  35. import appNoGoods from "../../../components/page-component/app-no-goods/app-no-goods.vue";
  36. export default {
  37. name: "search",
  38. data() {
  39. return {
  40. keyword: '',
  41. strong: [],
  42. page: 1,
  43. goods_list: [],
  44. search: false,
  45. is_search: 0,
  46. loading: false
  47. }
  48. },
  49. onLoad() {
  50. if (!this.$storage.getStorageSync(strong)) {
  51. this.$storage.setStorageSync(strong, []);
  52. } else {
  53. this.strong = this.$storage.getStorageSync(strong);
  54. }
  55. },
  56. methods: {
  57. async request(bool) {
  58. const res = await this.$request({
  59. url: this.$api.full_reduce.list,
  60. method: 'get',
  61. data: {
  62. page: this.page,
  63. keyword: this.keyword
  64. },
  65. });
  66. this.loading = true;
  67. if (res.code === 0) {
  68. if (bool) this.goods_list = [];
  69. this.goods_list.push(...res.data.list);
  70. this.page_count = res.data.pagination.page_count;
  71. // this.dataProcessing(res.data);
  72. }
  73. },
  74. searchRequest(data) {
  75. this.search = true;
  76. this.goods_list = [];
  77. this.page = 1;
  78. this.keyword = data;
  79. this.request(1);
  80. },
  81. setRequest() {
  82. this.keyword = this.keyword.trim();
  83. if (this.keyword.match(/^[ ]*$/)) return;
  84. this.search = true;
  85. this.goods_list = [];
  86. this.request().then(() => {
  87. let newStrong = this.$storage.getStorageSync(strong);
  88. for (let i = 0; i < newStrong.length; i++) {
  89. if (newStrong[i] === this.keyword) {
  90. return;
  91. }
  92. }
  93. newStrong.unshift(this.keyword);
  94. if (newStrong.length > 15) {
  95. newStrong = newStrong.slice(0, 15);
  96. }
  97. this.$storage.setStorageSync(strong, newStrong);
  98. });
  99. },
  100. routeGo(data) {
  101. // #ifndef MP-BAIDU
  102. if (data.video_url && this.getVideo == 1) {
  103. uni.navigateTo({
  104. url: `/pages/goods/video?goods_id=${data.id}`
  105. });
  106. } else {
  107. uni.navigateTo({
  108. url: data.page_url,
  109. });
  110. }
  111. // #endif
  112. // #ifdef MP-BAIDU
  113. uni.navigateTo({
  114. url: data.page_url,
  115. });
  116. // #endif
  117. },
  118. empyt_search() {
  119. this.goods_list = [];
  120. this.keyword = '';
  121. this.search = false;
  122. if (!this.$storage.getStorageSync(strong)) {
  123. this.$storage.setStorageSync(strong, []);
  124. } else {
  125. this.strong = this.$storage.getStorageSync(strong);
  126. }
  127. },
  128. setClearStorage() {
  129. this.$storage.removeStorageSync(strong);
  130. this.strong = [];
  131. this.$storage.setStorageSync(strong, []);
  132. }
  133. },
  134. components: {
  135. 'app-product-list': appProductList,
  136. appNoGoods
  137. },
  138. computed: {
  139. ...mapGetters('mallConfig', {
  140. getTheme: 'getTheme'
  141. }),
  142. ...mapGetters('mallConfig', {
  143. getVideo: 'getVideo'
  144. }),
  145. },
  146. // 分页请求
  147. onReachBottom() {
  148. if (this.page < this.page_count) {
  149. this.page++;
  150. this.request();
  151. }
  152. },
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .layout {
  157. position: absolute;
  158. top: 0;
  159. left: 0;
  160. width: 750upx;
  161. height: 100%;
  162. background-color: #ffffff;
  163. }
  164. .search {
  165. width: #{750upx};
  166. height: #{105upx};
  167. background-color: #efeff4;
  168. padding: #{0 24upx};
  169. position:fixed;
  170. top: 0;
  171. z-index: 1000;
  172. }
  173. .icon {
  174. width: #{32upx};
  175. height: #{32upx};
  176. border-radius: #{64upx};
  177. position: absolute;
  178. right: #{120upx};
  179. background-image: url("../../../static/image/icon/delete-yuan.png");
  180. background-repeat: no-repeat;
  181. background-size: 100% 100%;
  182. z-index: 1000;
  183. }
  184. .input {
  185. width: #{620upx};
  186. height: #{65upx};
  187. background-color: #ffffff;
  188. border-radius: #{32.5upx};
  189. padding: #{0 35upx};
  190. }
  191. .search-text {
  192. font-size: #{30upx};
  193. color: #666666;
  194. }
  195. .storage {
  196. width: #{750upx};
  197. margin-top: 115upx;
  198. padding: #{0 25upx};
  199. }
  200. .operating {
  201. margin-top: #{34upx};
  202. text {
  203. font-size: #{26upx};
  204. color: #666666;
  205. line-height: 1;
  206. }
  207. }
  208. .delete-icon {
  209. width: #{28upx};
  210. height: #{32upx};
  211. background-image: url("../../../static/image/icon/delete.png");
  212. background-repeat: no-repeat;
  213. background-size: 100% 100%;
  214. z-index: 1000;
  215. }
  216. .history-record {
  217. margin-top: #{25upx};
  218. max-height: 440upx;
  219. overflow: hidden;
  220. .item {
  221. height: #{64upx};
  222. line-height: #{64upx};
  223. font-size: #{26upx};
  224. padding: #{0 20upx};
  225. background-color: #f7f7f7;
  226. border-radius: #{32upx};
  227. margin-bottom: #{32upx};
  228. max-width: 700upx;
  229. margin-right: 24upx;
  230. }
  231. }
  232. .no-empty {
  233. width: 100%;
  234. margin-top: 280upx;
  235. }
  236. .product-list {
  237. margin-top: 115upx;
  238. }
  239. </style>