search.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <template>
  2. <view>
  3. <!-- <scroll-view class="container" style="height: 100%;"> -->
  4. <view style="height: 96rpx; background: #fff; padding-top: 20rpx; position: fixed; width: 750rpx; top: 0">
  5. <view class="search-header">
  6. <view class="input-box">
  7. <!-- <van-icon name="search" /> -->
  8. <!-- placeholder="{{defaultKeyword.keyword}}" -->
  9. <image src="https://mall.zhaijieshi.cc/file/wx-dy/icon-search-grey.png" class="img" mode="aspectFit"></image>
  10. <input
  11. name="input"
  12. class="keywrod"
  13. :focus="true"
  14. :value="keyword"
  15. confirm-type="search"
  16. @input="inputChange"
  17. @focus="inputFocus"
  18. @confirm="onKeywordConfirm"
  19. placeholder="保洁、保姆、钟点工、家电清洗"
  20. placeholder-style="font-size:26rpx;color:#BEC0C5;"
  21. />
  22. <view class="devide-line"></view>
  23. <view class="search-text" @tap="onKeywordConfirmBtn">搜索</view>
  24. <!-- <van-icon class="del" wx:if="{{keyword}}" bindtap="clearKeyword" name="cross" /> -->
  25. </view>
  26. <!-- <view class="right" bindtap="closeSearch">取消</view> -->
  27. </view>
  28. </view>
  29. <view class="no-search" v-if="!searchStatus">
  30. <view class="search-keywords search-history" v-if="!keyword && historyKeyword.length">
  31. <view class="h">
  32. <text class="title">最近搜索</text>
  33. <!-- <van-icon @tap.native="clearHistory" name="delete" class="icon" /> -->
  34. </view>
  35. <view class="b history">
  36. <view class="item" @tap="onKeywordTap" :data-keyword="item.keyword" hover-class="navigator-hover" v-for="(item, index) in historyKeyword" :key="index">
  37. {{ item.keyword }}
  38. </view>
  39. </view>
  40. </view>
  41. <view class="search-keywords search-hot" v-if="!keyword && hotKeyword.length">
  42. <view class="h">
  43. <text class="title">大家都在搜</text>
  44. </view>
  45. <view class="b">
  46. <view
  47. :class="'item ' + (item.is_hot === 1 ? 'active' : '') + ' line'"
  48. hover-class="navigator-hover"
  49. @tap="onKeywordTap"
  50. :data-keyword="item.keyword"
  51. v-for="(item, index) in hotKeyword"
  52. :key="index"
  53. >
  54. <text>{{ item.keyword }}</text>
  55. <image src="https://mall.zhaijieshi.cc/file/wx-dy/icon-fire.png" class="hot" mode="aspectFit" v-if="index == 0"></image>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- <view class="shelper-list" wx:if="{{keyword}}">
  60. <view class="item" hover-class="navigator-hover" wx:for="{{helpKeyword}}" wx:key="id" bindtap="onKeywordTap" data-keyword="{{item}}">{{item}}</view>
  61. </view> -->
  62. </view>
  63. <view class="search-result" v-if="searchStatus && goodsList.length">
  64. <!-- <view class="sort">
  65. <view class="sort-box">
  66. <view class="item {{currentSortType == 'default' ? 'active' : ''}}" bindtap="openSortFilter" id="defaultSort">
  67. <text class="txt">综合</text>
  68. </view>
  69. <view class="item {{currentSortType == 'price' ? 'active' : ''}}" bindtap="openSortFilter" id="priceSort">
  70. <text class="txt">价格</text>
  71. <van-icon name="arrow-up" wx:if="{{ currentSortType == 'price' && currentSortOrder == 'asc' }}" />
  72. <van-icon name="arrow-down" wx:elif="{{ currentSortType == 'price' && currentSortOrder == 'desc'}}" />
  73. </view>
  74. <view class="item {{currentSortType == 'category' ? 'active' : ''}}" bindtap="openSortFilter" id="categoryFilter">
  75. <text class="txt">分类</text>
  76. </view>
  77. </view>
  78. <view class="sort-box-category" wx-if="{{categoryFilter}}">
  79. <view class="item {{item.checked ? 'active' : ''}}" wx:for="{{filterCategory}}" wx:key="id" data-category-index="{{index}}" bindtap="selectCategory">{{item.name}}</view>
  80. </view>
  81. </view> -->
  82. <view class="cate-item">
  83. <view class="b">
  84. <navigator
  85. :class="'item ' + ((iindex + 1) % 2 == 0 ? 'item-b' : '')"
  86. :url="'/pages/goods/goods?id=' + iitem.id"
  87. v-for="(iitem, iindex) in goodsList"
  88. :key="iindex"
  89. >
  90. <image class="img" :src="iitem.picUrl" background-size="cover"></image>
  91. <text class="name">{{ iitem.name }}</text>
  92. <view class="price">
  93. <view class="retailPrice">¥{{ iitem.retailPrice }}</view>
  94. <!-- <view class="memberPrice">¥{{iitem.memberPrice}}</view>
  95. <view class="member-price-tag">会员价</view> -->
  96. </view>
  97. <!-- <view class="price"><text>¥{{iitem.retailPrice}}</text>
  98. <text class="counterPrice sub-color">¥{{iitem.counterPrice}}</text>
  99. </view> -->
  100. </navigator>
  101. </view>
  102. </view>
  103. </view>
  104. <view class="search-result-empty" v-if="!goodsList.length && searchStatus">
  105. <text class="text">暂无数据~</text>
  106. </view>
  107. <!-- </scroll-view> -->
  108. </view>
  109. </template>
  110. <script>
  111. var util = require('../../../utils/util.js');
  112. var api = require('../../../config/api.js');
  113. var app = getApp();
  114. export default {
  115. data() {
  116. return {
  117. keyword: '',
  118. searchStatus: false,
  119. goodsList: [],
  120. helpKeyword: [],
  121. historyKeyword: [],
  122. categoryFilter: false,
  123. currentSort: 'name',
  124. currentSortType: 'default',
  125. currentSortOrder: 'desc',
  126. filterCategory: [],
  127. defaultKeyword: {},
  128. hotKeyword: [],
  129. page: 1,
  130. limit: 20,
  131. categoryId: 0,
  132. addressInfo: {},
  133. iindex: 0,
  134. iitem: {
  135. id: '',
  136. picUrl: '',
  137. name: '',
  138. retailPrice: ''
  139. }
  140. };
  141. },
  142. onLoad: function () {
  143. var addressInfo = uni.getStorageSync('addressInfo');
  144. if (addressInfo) {
  145. this.setData({
  146. addressInfo: addressInfo
  147. });
  148. }
  149. this.getSearchKeyword();
  150. },
  151. methods: {
  152. //事件处理函数
  153. closeSearch: function () {
  154. uni.navigateBack();
  155. },
  156. clearKeyword: function () {
  157. this.setData({
  158. keyword: '',
  159. searchStatus: false
  160. });
  161. },
  162. getSearchKeyword() {
  163. let that = this;
  164. util.request(api.SearchIndex).then(function (res) {
  165. if (res.errno === 0) {
  166. that.setData({
  167. historyKeyword: res.data.historyKeywordList,
  168. defaultKeyword: res.data.defaultKeyword,
  169. hotKeyword: res.data.hotKeywordList
  170. });
  171. }
  172. });
  173. },
  174. inputChange: function (e) {
  175. console.log(e);
  176. this.setData({
  177. keyword: e.detail.value,
  178. searchStatus: false
  179. });
  180. if (e.detail.value) {
  181. // this.getHelpKeyword();
  182. }
  183. },
  184. getHelpKeyword: function () {
  185. let that = this;
  186. let userInfo = uni.getStorageSync('userInfo');
  187. util.request(api.SearchHelper, {
  188. keyword: that.keyword,
  189. userId: userInfo.id
  190. }).then(function (res) {
  191. if (res.errno === 0) {
  192. that.setData({
  193. helpKeyword: res.data
  194. });
  195. }
  196. });
  197. },
  198. inputFocus: function () {
  199. this.setData({
  200. searchStatus: false,
  201. goodsList: []
  202. });
  203. if (this.keyword) {
  204. // this.getHelpKeyword();
  205. }
  206. },
  207. clearHistory: function () {
  208. this.setData({
  209. historyKeyword: []
  210. });
  211. util.request(api.SearchClearHistory, {}, 'POST').then(function (res) {
  212. console.log('清除成功');
  213. });
  214. },
  215. getGoodsList: function () {
  216. let that = this;
  217. util.request(api.GoodsList, {
  218. keyword: that.keyword,
  219. page: that.page,
  220. limit: that.limit,
  221. sort: that.currentSort,
  222. order: that.currentSortOrder,
  223. categoryId: that.categoryId,
  224. city: that.addressInfo.city,
  225. shopId: that.addressInfo.shopId
  226. }).then(function (res) {
  227. if (res.errno === 0) {
  228. that.setData({
  229. searchStatus: true,
  230. categoryFilter: false,
  231. goodsList: res.data.list,
  232. filterCategory: res.data.filterCategoryList
  233. });
  234. }
  235. //重新获取关键词
  236. that.getSearchKeyword();
  237. });
  238. },
  239. onKeywordTap: function (event) {
  240. this.getSearchResult(event.target.dataset.keyword);
  241. },
  242. getSearchResult(keyword) {
  243. this.setData({
  244. keyword: keyword,
  245. page: 1,
  246. categoryId: 0,
  247. goodsList: []
  248. });
  249. if (keyword === '') {
  250. // keyword = this.data.defaultKeyword.keyword;
  251. } else {
  252. this.getGoodsList();
  253. }
  254. },
  255. openSortFilter: function (event) {
  256. let currentId = event.currentTarget.id;
  257. switch (currentId) {
  258. case 'categoryFilter':
  259. this.setData({
  260. categoryFilter: !this.categoryFilter,
  261. currentSortType: 'category',
  262. currentSort: 'add_time',
  263. currentSortOrder: 'desc'
  264. });
  265. break;
  266. case 'priceSort':
  267. let tmpSortOrder = 'asc';
  268. if (this.currentSortOrder == 'asc') {
  269. tmpSortOrder = 'desc';
  270. }
  271. this.setData({
  272. currentSortType: 'price',
  273. currentSort: 'retail_price',
  274. currentSortOrder: tmpSortOrder,
  275. categoryFilter: false
  276. });
  277. this.getGoodsList();
  278. break;
  279. default:
  280. //综合排序
  281. this.setData({
  282. currentSortType: 'default',
  283. currentSort: 'name',
  284. currentSortOrder: 'desc',
  285. categoryFilter: false,
  286. categoryId: 0
  287. });
  288. this.getGoodsList();
  289. }
  290. },
  291. selectCategory: function (event) {
  292. let currentIndex = event.target.dataset.categoryIndex;
  293. let filterCategory = this.filterCategory;
  294. let currentCategory = null;
  295. for (let key in filterCategory) {
  296. if (key == currentIndex) {
  297. filterCategory[key].selected = true;
  298. currentCategory = filterCategory[key];
  299. } else {
  300. filterCategory[key].selected = false;
  301. }
  302. }
  303. this.setData({
  304. filterCategory: filterCategory,
  305. categoryFilter: false,
  306. categoryId: currentCategory.id,
  307. page: 1,
  308. goodsList: []
  309. });
  310. this.getGoodsList();
  311. },
  312. onKeywordConfirm(event) {
  313. this.getSearchResult(event.detail.value);
  314. this.getHelpKeyword();
  315. },
  316. onKeywordConfirmBtn() {
  317. this.setData({
  318. page: 1,
  319. categoryId: 0,
  320. goodsList: []
  321. });
  322. this.getGoodsList();
  323. this.getHelpKeyword();
  324. }
  325. }
  326. };
  327. </script>
  328. <style>
  329. page {
  330. min-height: 100%;
  331. background: #fff;
  332. /* padding-top:20rpx; */
  333. }
  334. .container {
  335. min-height: 100%;
  336. /* background-color: #f4f4f4; */
  337. }
  338. .search-header {
  339. /* position: fixed; */
  340. width: 690rpx;
  341. height: 76rpx;
  342. background: #f5f6fa;
  343. /* border-bottom: 1px solid rgba(0, 0, 0, 0.15); */
  344. margin: 0 30rpx;
  345. font-size: 28rpx;
  346. color: #333;
  347. padding: 0 40rpx;
  348. border-radius: 76rpx;
  349. }
  350. .search-header .img {
  351. width: 34rpx;
  352. height: 34rpx;
  353. }
  354. .devide-line {
  355. width: 1rpx;
  356. height: 38rpx;
  357. background: #dcdcdc;
  358. }
  359. .search-text {
  360. color: #00c0ff;
  361. font-size: 26rpx;
  362. margin-left: 30rpx;
  363. }
  364. .search-header .van-icon-search {
  365. line-height: 59rpx;
  366. }
  367. .search-header .input-box {
  368. /* position: relative;
  369. margin-top: 16rpx;
  370. float: left;
  371. width: 0; */
  372. height: 76rpx;
  373. display: flex;
  374. align-items: center;
  375. /* background: #f4f4f4; */
  376. }
  377. .search-header .icon {
  378. position: absolute;
  379. top: 14rpx;
  380. left: 20rpx;
  381. width: 31rpx;
  382. height: 31rpx;
  383. }
  384. .search-header .del {
  385. position: absolute;
  386. top: 3rpx;
  387. right: 10rpx;
  388. width: 53rpx;
  389. height: 53rpx;
  390. z-index: 10;
  391. }
  392. .search-header .keywrod {
  393. /* position: absolute;
  394. top: 0;
  395. left: 40rpx;
  396. width: 506rpx;
  397. height: 59rpx;
  398. padding-left: 30rpx; */
  399. flex: 1;
  400. height: 76rpx;
  401. line-height: 76rpx;
  402. padding: 0 20rpx;
  403. }
  404. .search-header .right {
  405. margin-top: 24rpx;
  406. margin-left: 31rpx;
  407. margin-right: 6rpx;
  408. width: 58rpx;
  409. height: 43rpx;
  410. line-height: 43rpx;
  411. float: right;
  412. }
  413. .no-search {
  414. height: auto;
  415. overflow: hidden;
  416. margin-top: 96rpx;
  417. padding-left: 70rpx;
  418. background: #fff;
  419. }
  420. .search-keywords {
  421. background: #fff;
  422. width: 750rpx;
  423. height: auto;
  424. /* overflow: hidden; */
  425. }
  426. .search-keywords .h {
  427. /* padding: 0 31.25rpx; */
  428. height: 93rpx;
  429. line-height: 93rpx;
  430. width: 100%;
  431. color: #999;
  432. font-size: 28rpx;
  433. }
  434. .search-keywords .title {
  435. /* display: block;
  436. width: 120rpx;
  437. float: left; */
  438. font-size: 24rpx;
  439. color: #666;
  440. }
  441. .search-keywords .icon {
  442. margin-top: 19rpx;
  443. float: right;
  444. display: block;
  445. margin-left: 511rpx;
  446. height: 55rpx;
  447. width: 55rpx;
  448. }
  449. .search-keywords .b {
  450. width: 750rpx;
  451. height: auto;
  452. overflow: hidden;
  453. /* padding-left: 31.25rpx; */
  454. }
  455. .search-keywords .b .item {
  456. width: 750rpx;
  457. height: 84rpx;
  458. line-height: 84rpx;
  459. /* padding: 0 15rpx; */
  460. font-size: 28rpx;
  461. color: #666;
  462. }
  463. .search-keywords .item.active {
  464. color: #b4282d;
  465. border: 1px solid #b4282d;
  466. }
  467. .shelper-list {
  468. width: 750rpx;
  469. height: auto;
  470. overflow: hidden;
  471. background: #fff;
  472. padding: 0 31.25rpx;
  473. }
  474. .shelper-list .item {
  475. height: 93rpx;
  476. width: 687.5rpx;
  477. line-height: 93rpx;
  478. font-size: 24rpx;
  479. color: #333;
  480. border-bottom: 1px solid #f4f4f4;
  481. }
  482. .sort {
  483. position: fixed;
  484. top: 91rpx;
  485. background: #fff;
  486. width: 100%;
  487. height: 78rpx;
  488. }
  489. .sort-box {
  490. background: #fff;
  491. width: 100%;
  492. height: 78rpx;
  493. overflow: hidden;
  494. padding: 0 30rpx;
  495. display: flex;
  496. border-bottom: 1px solid #d9d9d9;
  497. }
  498. .sort-box .item {
  499. height: 78rpx;
  500. line-height: 78rpx;
  501. text-align: center;
  502. flex: 1;
  503. color: #333;
  504. font-size: 30rpx;
  505. }
  506. .sort-box .item .txt {
  507. color: #333;
  508. }
  509. .sort-box .item.active .txt {
  510. color: #b4282d;
  511. }
  512. .sort-box .item .van-icon {
  513. margin-left: 6rpx;
  514. }
  515. .sort-box-category {
  516. background: #fff;
  517. width: 100%;
  518. height: auto;
  519. overflow: hidden;
  520. padding: 40rpx 40rpx 0 0;
  521. border-bottom: 1px solid #d9d9d9;
  522. }
  523. .sort-box-category .item {
  524. height: 54rpx;
  525. line-height: 54rpx;
  526. text-align: center;
  527. float: left;
  528. padding: 0 16rpx;
  529. margin: 0 0 40rpx 40rpx;
  530. border: 1px solid #666;
  531. color: #333;
  532. font-size: 24rpx;
  533. }
  534. .sort-box-category .item.active {
  535. color: #b4282d;
  536. border: 1px solid #b4282d;
  537. }
  538. .cate-item {
  539. /* margin-top: 175rpx; */
  540. margin-top: 112rpx;
  541. height: auto;
  542. overflow: hidden;
  543. }
  544. .cate-item .h {
  545. height: 145rpx;
  546. width: 750rpx;
  547. display: flex;
  548. flex-direction: column;
  549. align-items: center;
  550. justify-content: center;
  551. }
  552. .cate-item .h .name {
  553. display: block;
  554. height: 35rpx;
  555. margin-bottom: 18rpx;
  556. font-size: 30rpx;
  557. color: #333;
  558. }
  559. .cate-item .h .desc {
  560. display: block;
  561. height: 24rpx;
  562. font-size: 24rpx;
  563. color: #999;
  564. }
  565. .cate-item .b {
  566. width: 750rpx;
  567. padding: 0 6.25rpx;
  568. height: auto;
  569. overflow: hidden;
  570. }
  571. .cate-item .list-filter {
  572. height: 80rpx;
  573. width: 100%;
  574. background: #fff;
  575. margin-bottom: 6.25rpx;
  576. }
  577. .cate-item .b .item {
  578. float: left;
  579. background: #fff;
  580. width: 365rpx;
  581. margin-bottom: 6.25rpx;
  582. padding-bottom: 33.333rpx;
  583. height: auto;
  584. overflow: hidden;
  585. text-align: center;
  586. }
  587. .cate-item .b .item-b {
  588. margin-left: 6.25rpx;
  589. }
  590. .cate-item .item .img {
  591. width: 302rpx;
  592. height: 302rpx;
  593. border-radius: 10rpx;
  594. }
  595. .cate-item .item .name {
  596. display: block;
  597. width: 360rpx;
  598. height: 68rpx;
  599. line-height: 34rpx;
  600. margin: 11.5rpx 0 0rpx 0;
  601. text-align: left;
  602. overflow: hidden;
  603. padding: 0 20rpx;
  604. font-size: 28rpx;
  605. color: #333;
  606. text-overflow: ellipsis;
  607. display: -webkit-box;
  608. -webkit-box-orient: vertical;
  609. -webkit-line-clamp: 2;
  610. }
  611. .cate-item .item .price {
  612. height: 40rpx;
  613. line-height: 40rpx;
  614. text-align: center;
  615. font-size: 30rpx;
  616. color: #b4282d;
  617. }
  618. .search-result-empty {
  619. width: 100%;
  620. height: 100%;
  621. padding-top: 600rpx;
  622. }
  623. .search-result-empty .text {
  624. display: block;
  625. width: 100%;
  626. height: 40rpx;
  627. font-size: 28rpx;
  628. text-align: center;
  629. color: #999;
  630. }
  631. .cate-item .item .price {
  632. height: 40rpx;
  633. justify-content: center;
  634. display: flex;
  635. margin-top: 10rpx;
  636. align-items: flex-end;
  637. }
  638. .counterPrice {
  639. text-decoration: line-through;
  640. font-size: 24rpx;
  641. margin: 0 0 0 20rpx;
  642. }
  643. .retailPrice {
  644. font-size: 30rpx;
  645. height: 30rpx;
  646. line-height: 30rpx;
  647. }
  648. .memberPrice {
  649. font-size: 22rpx;
  650. color: #dd483e;
  651. margin: 0 10rpx 0 20rpx;
  652. }
  653. .member-price-tag {
  654. width: 88rpx;
  655. height: 26rpx;
  656. line-height: 26rpx;
  657. background: url('https://mall.zhaijieshi.cc/file/jzmall/weixin/member/member-price-bg.png') no-repeat center center;
  658. background-size: 100% 100%;
  659. color: #5e3a11;
  660. font-size: 16rpx;
  661. padding: 0 8rpx 0 0;
  662. text-align: right;
  663. margin: 0 0 6rpx 0;
  664. }
  665. .search-keywords .b.history {
  666. }
  667. .search-keywords .b.history .item {
  668. display: inline-block;
  669. height: 68rpx;
  670. line-height: 68rpx;
  671. padding: 0 15rpx;
  672. font-size: 26rpx;
  673. color: #666;
  674. margin-right: 30rpx;
  675. }
  676. .search-keywords .line {
  677. height: 84rpx;
  678. display: flex;
  679. align-items: center;
  680. }
  681. .search-keywords .line .hot {
  682. width: 24rpx;
  683. height: 24rpx;
  684. margin-left: 12rpx;
  685. }
  686. .search-keywords .b.history {
  687. display: flex;
  688. flex-wrap: wrap;
  689. }
  690. .search-keywords .b.history .item {
  691. width: auto;
  692. padding: 0;
  693. margin-right: 40rpx;
  694. }
  695. </style>