search.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <app-layout>
  3. <view class="search" :style="{backgroundColor: search ? '#f7f7f7': '#ffffff'}">
  4. <view class="top dir-left-nowrap cross-center main-between">
  5. <input type="text" class="input" :focus="true" v-model="search_text" @blur="request">
  6. <image class="delete" v-show="search_text.length>0" @click="empyt_search" src="../image/delete.png"></image>
  7. <text style="color:#666666;font-size: 32rpx;" @click="request">搜索</text>
  8. </view>
  9. <view class="center" v-if="!search">
  10. <view class="strong dir-left-nowrap main-between cross-center" v-if="strong.length > 0">
  11. <text>历史搜索</text>
  12. <image class="delete" src="/static/image/icon/delete.png" @click="empty_strong"></image>
  13. </view>
  14. <view>
  15. <text @click="search_strong(item)" class="strong-item" v-for="(item, index) in strong" :key="index">
  16. {{item}}
  17. </text>
  18. </view>
  19. </view>
  20. <view class="bottom" v-if="search_list.length>0">
  21. <index-product-list :theme="getTheme" :product="search_list"></index-product-list>
  22. </view>
  23. <view class="order-empty" v-if="search_list.length === 0 && search">
  24. <image src="../image/product.png"></image>
  25. <text>没有任何信息哦~</text>
  26. </view>
  27. </view>
  28. </app-layout>
  29. </template>
  30. <script>
  31. import indexProductList from '../components/index-product-list.vue';
  32. import {mapGetters} from "vuex";
  33. let strong = "ADVANCE_SEARCH";
  34. export default {
  35. name: 'search',
  36. data() {
  37. return {
  38. search_text: '',
  39. search_list: [],
  40. strong: [],
  41. search: false,
  42. page: 1,
  43. over: false,
  44. interval: 0,
  45. }
  46. },
  47. onLoad() { this.$commonLoad.onload();
  48. if (!this.$storage.getStorageSync(strong)) {
  49. this.$storage.setStorageSync(strong, []);
  50. } else {
  51. this.strong = this.$storage.getStorageSync(strong);
  52. }
  53. },
  54. computed: {
  55. ...mapGetters('mallConfig', {
  56. getTheme: 'getTheme',
  57. })
  58. },
  59. onHide() {
  60. clearInterval(this.interval);
  61. },
  62. onUnload() {
  63. clearInterval(this.interval);
  64. },
  65. onReachBottom() {
  66. if (!this.over) {
  67. this.page+=1;
  68. this.$request({
  69. url: this.$api.advance.goods,
  70. method: 'get',
  71. data: {
  72. keyword: this.search_text,
  73. page: this.page,
  74. }
  75. }).then(res => {
  76. if (res.code === 0) {
  77. if (res.data.list.length > 0) {
  78. this.search_list = [...this.search_list, ...res.data.list];
  79. } else {
  80. this.over = true;
  81. }
  82. }
  83. })
  84. }
  85. },
  86. methods: {
  87. empyt_search() {
  88. this.search_text = '';
  89. this.search_list = [];
  90. this.search = false;
  91. clearInterval(this.interval);
  92. },
  93. async request() {
  94. this.search = true;
  95. this.page = 1;
  96. let getStrong = this.$storage.getStorageSync(strong);
  97. if (this.search_text.match(/^[ ]*$/)) return;
  98. let newStrong = [...getStrong, this.search_text];
  99. const res = await this.$request({
  100. url: this.$api.advance.goods,
  101. method: 'get',
  102. data: {
  103. keyword: this.search_text,
  104. page: this.page,
  105. }
  106. });
  107. if (res.code === 0) {
  108. this.search_list = res.data.list;
  109. this.set_interval();
  110. this.$storage.setStorageSync(strong, newStrong);
  111. }
  112. },
  113. empty_strong() {
  114. this.$storage.removeStorageSync(strong);
  115. this.strong = [];
  116. },
  117. search_strong(data) {
  118. this.search_text = data;
  119. this.request();
  120. },
  121. set_interval() {
  122. clearInterval(this.interval);
  123. this.interval = setInterval(() => {
  124. let now = new Date().getTime();
  125. if (this.search_list.length === 0) clearInterval(this.interval);
  126. for (let i = 0; i < this.search_list.length; i++) {
  127. let timelog = new Date(this.search_list[i].advanceGoods.end_prepayment_at.replace(/-/g, '/')).getTime();
  128. let time = timelog - now;
  129. if (time > 0) {
  130. let day = parseInt((time/1000/60/60/24)%30);
  131. let hou = parseInt((time/1000/60/60)%24);
  132. let min = parseInt((time/1000/60)%60);
  133. let sec = parseInt((time/1000)%60);
  134. if (day > 0) {
  135. this.$set(this.search_list[i], 'html', day+"天"+hou+":"+(min<10?"0"+min:min) + ":"+(sec<10?"0"+sec:sec));
  136. } else {
  137. this.$set(this.search_list[i], 'html', hou+":"+(min<10?"0"+min:min) + ":"+(sec<10?"0"+sec:sec));
  138. }
  139. } else {
  140. this.$delete(this.search_list, i);
  141. if (this.search_list.length < 10 && this.page_count > 1) {
  142. this.$request({
  143. url: this.$api.advance.goods,
  144. method: 'get'
  145. }).then(res => {
  146. if (res.code === 0) {
  147. this.search_list = res.data.list;
  148. this.set_interval();
  149. }
  150. });
  151. }
  152. }
  153. }
  154. }, 1000);
  155. }
  156. },
  157. components: {
  158. 'index-product-list': indexProductList,
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .search {
  164. position: absolute;
  165. width: #{750rpx};
  166. height: 100%;
  167. background-color: #ffffff;
  168. .top {
  169. height: #{104rpx};
  170. width: 100%;
  171. background-color: #efeff4;
  172. padding: #{20rpx 24rpx};
  173. position: relative;
  174. overflow: hidden;
  175. .delete {
  176. width: #{32rpx};
  177. height: #{32rpx};
  178. }
  179. .input {
  180. height: #{64rpx};
  181. width: #{620rpx};
  182. border-radius: #{50rpx};
  183. background-color: #ffffff;
  184. padding-left: #{32rpx};
  185. font-size: #{28rpx};
  186. color: #353535;
  187. }
  188. .delete {
  189. position: absolute;
  190. right: #{125rpx};
  191. z-index: 1600;
  192. }
  193. }
  194. .center {
  195. font-size: #{28rpx};
  196. padding: #{32rpx 24rpx 0 24rpx};
  197. .strong {
  198. color: #666666;
  199. padding-bottom: #{24rpx};
  200. text {
  201. margin-top: #{4rpx};
  202. }
  203. .delete {
  204. width: #{44rpx};
  205. height: #{32rpx};
  206. padding: 0 #{6rpx};
  207. }
  208. }
  209. .strong-item {
  210. display: inline-block;
  211. height: #{64rpx};
  212. line-height: #{64rpx};
  213. padding: 0 #{20rpx};
  214. margin: #{0 20rpx 16rpx 0};
  215. color: #353535;
  216. font-size: #{28rpx};
  217. border-radius: #{32rpx};
  218. background-color: #f7f7f7;
  219. }
  220. }
  221. }
  222. .order-empty {
  223. position: absolute;
  224. top: #{555rpx};
  225. left: 50%;
  226. transform: translate(-50%, -50%);
  227. width: #{240rpx};
  228. text-align: center;
  229. >image {
  230. height: #{240rpx};
  231. width: #{240rpx};
  232. }
  233. >text {
  234. font-size: #{24rpx};
  235. color: #666666;
  236. }
  237. }
  238. </style>