search.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <template>
  2. <app-layout>
  3. <view class="search">
  4. <view class="search-input dir-left-nowrap cross-center main-center">
  5. <input type="text" class="input" v-model="keyword" @confirm="search">
  6. <text class="search-text" @click="search">搜索</text>
  7. <image class="delete" @click="deleteKeyword" v-if="keyword.length > 0" src="/static/image/icon/delete-yuan.png"></image>
  8. </view>
  9. <view v-if="!isSearch && historyList.length > 0" class="history">
  10. <view class="dir-left-nowrap cross-center title">
  11. <view class="box-grow-1">历史搜索</view>
  12. <image src="/static/image/icon/delete.png" class="box-grow-0" @click="deleteHistory"></image>
  13. </view>
  14. <view class="dir-left-wrap history-list">
  15. <view v-for="(item, index) in historyList"
  16. class="box-grow-0 cross-center item"
  17. @click="historyClick(item.keyword)"
  18. :key="index"
  19. >{{item.keyword}}
  20. </view>
  21. </view>
  22. </view>
  23. <view class="list">
  24. <view class="item dir-left-nowrap" v-for="(item) in list" :key="item.id" @click="navigator('/plugins/pick/detail/detail?goods_id=' + item.id)">
  25. <view v-if="item.goods_stock == 0" class="out-dialog">
  26. <image :src="appSetting.is_use_stock == '1' ? appImg.plugins_out : appSetting.sell_out_pic"></image>
  27. </view>
  28. <image class="image" :src="item.cover_pic"></image>
  29. <view class="content dir-top-nowrap main-between">
  30. <text class="name t-omit-two">{{item.name}}</text>
  31. <view class="information dir-left-nowrap main-between cross-bottom">
  32. <view class="num">
  33. <view class="value">
  34. <text class="price" :class="getTheme+ '-m-text ' + getTheme">¥{{item.price}}</text>
  35. <text class="original_price">¥{{item.original_price}}</text>
  36. </view>
  37. <text class="sales">{{item.sales}}</text>
  38. </view>
  39. <view>
  40. <view class="go-button" :class="getTheme+ '-m-back ' + getTheme">去凑单</view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view v-if="isSearch" class="goods-list">
  46. <template v-if="list.length <= 0">
  47. <view class="main-center no-result">
  48. <view class="dir-left-nowrap cross-center">
  49. <image class="box-grow-0 empty" src="/static/image/icon/empty.png"></image>
  50. <view class="box-grow-1">
  51. <view>抱歉,没有相关商品</view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. </view>
  57. </view>
  58. </view>
  59. </app-layout>
  60. </template>
  61. <script>
  62. import {mapGetters, mapState} from "vuex";
  63. export default {
  64. name: 'search',
  65. data() {
  66. return {
  67. list: [],
  68. keyword: '',
  69. activity: {},
  70. historyList: [],
  71. isSearch: false,
  72. page: 1
  73. }
  74. },
  75. onLoad() {
  76. this.historyList = this.getHistory();
  77. },
  78. computed: {
  79. ...mapState({
  80. appImg: state => state.mallConfig.__wxapp_img.mall,
  81. appSetting: state => state.mallConfig.mall.setting,
  82. }),
  83. ...mapGetters('mallConfig', {
  84. getTheme: 'getTheme',
  85. }),
  86. },
  87. onReachBottom() {
  88. this.page++;
  89. this.getList();
  90. },
  91. methods: {
  92. navigator(str) {
  93. uni.navigateTo({
  94. url: str
  95. });
  96. },
  97. search() {
  98. let keyword = this.keyword;
  99. if (keyword === '') return;
  100. this.keyword = keyword.trim();
  101. this.reset();
  102. },
  103. reset() {
  104. this.page = 1;
  105. this.getGoodsList();
  106. },
  107. async getList() {
  108. const e = await this.$request({
  109. url: this.$api.pick.goods_list,
  110. method: 'get',
  111. data: {
  112. keyword: this.keyword,
  113. page: this.page,
  114. }
  115. });
  116. if (e.code === 0) {
  117. let { list} = e.data;
  118. this.list.push(...list);
  119. }
  120. },
  121. async getGoodsList() {
  122. const e = await this.$request({
  123. url: this.$api.pick.goods_list,
  124. method: 'get',
  125. data: {
  126. keyword: this.keyword,
  127. page: this.page,
  128. }
  129. });
  130. if (e.code === 0) {
  131. let { bg_url, list, form, activity } = e.data;
  132. this.isSearch = true;
  133. this.list = list;
  134. this.background = bg_url;
  135. this.form = form;
  136. this.activity = activity;
  137. this.setHistory();
  138. }
  139. },
  140. setHistory() {
  141. let historyList = this.getHistory();
  142. let keyword = this.keyword.trim();
  143. historyList.forEach((item, index) => {
  144. if (item.keyword === keyword) historyList.splice(index, 1);
  145. });
  146. historyList.push({
  147. keyword: keyword,
  148. });
  149. if (historyList.length > 20) historyList.shift();
  150. this.historyList = historyList;
  151. uni.setStorageSync("SEARCH_HISTORY_LIST", historyList);
  152. },
  153. getHistory() {
  154. let historyList = uni.getStorageSync('SEARCH_HISTORY_LIST');
  155. if (!historyList) historyList = [];
  156. return historyList;
  157. },
  158. deleteHistory() {
  159. uni.removeStorageSync("SEARCH_HISTORY_LIST");
  160. this.historyList = [];
  161. },
  162. cancel() {
  163. this.isSearch = false;
  164. this.keyword = '';
  165. this.list = [];
  166. },
  167. historyClick(keyword) {
  168. this.keyword = keyword.trim();
  169. this.reset();
  170. },
  171. deleteKeyword() {
  172. this.keyword = '';
  173. }
  174. },
  175. watch: {
  176. keyword: {
  177. handler(v) {
  178. if (v == '') {
  179. this.cancel();
  180. }
  181. },
  182. immediate: true,
  183. }
  184. },
  185. }
  186. </script>
  187. <style scoped lang="scss">
  188. .search {
  189. position: absolute;
  190. width: 100%;
  191. height: 100%;
  192. }
  193. .search-input {
  194. width: #{750upx};
  195. height: #{105upx};
  196. background-color: #efeff4;
  197. position: fixed;
  198. top: 0;
  199. }
  200. .input {
  201. height: #{64upx};
  202. width: #{620upx};
  203. background-color: #ffffff;
  204. border-radius: #{36upx};
  205. padding: #{0 36upx};
  206. }
  207. .search-text {
  208. font-size: #{32upx};
  209. margin-left: #{20upx};
  210. }
  211. .list {
  212. padding-bottom: #{96upx};
  213. margin-top: #{105upx};
  214. }
  215. .item {
  216. padding: #{24upx};
  217. border-bottom: #{1upx} solid #eeeeee;
  218. background-color: #ffffff;
  219. position: relative;
  220. .out-dialog {
  221. width: #{220rpx};
  222. height: #{220rpx};
  223. border-radius: #{16rpx};
  224. position: absolute;
  225. top: #{24rpx};
  226. left: #{24rpx};
  227. z-index: 10;
  228. background-color: rgba(0,0,0,.5);
  229. image {
  230. width: #{220rpx};
  231. height: #{220rpx};
  232. border-radius: #{16rpx};
  233. }
  234. }
  235. }
  236. .image {
  237. width: #{220upx};
  238. height: #{220upx};
  239. border-radius: #{16upx};
  240. flex-shrink: 0;
  241. }
  242. .content {
  243. width: #{478upx};
  244. margin-left: #{24upx};
  245. height: #{228upx};
  246. }
  247. .name {
  248. font-size: #{28upx};
  249. color: #353535;
  250. }
  251. .generate {
  252. position: fixed;
  253. bottom: 0;
  254. height: #{96upx};
  255. width: #{750upx};
  256. background-color: #ffffff;
  257. border-top: #{1upx} solid #e2e2e2;
  258. }
  259. .generate-img {
  260. width: #{34upx};
  261. height: #{34upx};
  262. margin-right: #{7.5upx};
  263. }
  264. .generate-text {
  265. margin-left: #{7.5upx};
  266. font-size: #{32upx};
  267. color: #ff4d4c;
  268. }
  269. .information {
  270. margin-bottom: #{12upx};
  271. }
  272. .num {
  273. margin-bottom: #{8upx};
  274. }
  275. .sales {
  276. font-size: #{24upx};
  277. color: #999999;
  278. line-height: 1;
  279. }
  280. .value {
  281. margin-bottom: #{18upx};
  282. line-height: 1;
  283. }
  284. .price {
  285. font-size: #{32upx};
  286. line-height: 1;
  287. }
  288. .original_price {
  289. text-decoration:line-through;
  290. font-size: #{24upx};
  291. line-height: 1;
  292. color: #999999;
  293. margin-left: #{10upx};
  294. }
  295. .go-button {
  296. height: #{56upx};
  297. line-height: #{56upx};
  298. width: #{130upx};
  299. font-size: #{28upx};
  300. border-radius: #{28upx};
  301. text-align: center;
  302. color: #ffffff;
  303. }
  304. .history {
  305. padding: #{36rpx} #{24rpx};
  306. border-radius: #{16rpx} #{16rpx} 0 0;
  307. background-color: #ffffff;
  308. font-size: $uni-font-size-general-one;
  309. margin-top: #{105upx};
  310. .title {
  311. padding-bottom: #{24rpx};
  312. color: $uni-general-color-one;
  313. image {
  314. width: #{28rpx};
  315. height: #{34rpx};
  316. display: block;
  317. }
  318. }
  319. .history-list {
  320. .item {
  321. height: #{64rpx};
  322. background-color: #f7f7f7;
  323. padding: 0 #{20rpx};
  324. margin-right: #{20rpx};
  325. margin-bottom: #{16rpx};
  326. border-radius: #{32rpx};
  327. }
  328. }
  329. }
  330. .delete {
  331. width: #{32upx};
  332. height: #{32upx};
  333. position: absolute;
  334. right: #{122upx};
  335. top: #{36upx};
  336. border-radius: 50%;
  337. z-index: 1500;
  338. }
  339. .goods-list {
  340. .no-result {
  341. height: #{156rpx};
  342. padding: #{28rpx} 0;
  343. font-size: $uni-font-size-general-one;
  344. background-color: #ffffff;
  345. .empty {
  346. width: #{100rpx};
  347. height: #{100rpx};
  348. display: block;
  349. margin-right: #{40rpx};
  350. }
  351. }
  352. }
  353. </style>