index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. <template>
  2. <view class="content">
  3. <view class="search-box">
  4. <!-- mSearch组件 如果使用原样式,删除组件元素-->
  5. <!-- <mSearch class="mSearch-input-box" :mode="2" button="inside" :placeholder="defaultKeyword"
  6. @search="doSearch(false)" @input="inputChange" @confirm="doSearch(false)" v-model="keyword"></mSearch> -->
  7. <!-- 原样式 如果使用原样式,恢复下方注销代码 -->
  8. <!-- <view class="input-box">
  9. <input type="text" :adjust-position="true" :placeholder="defaultKeyword" @input="inputChange" v-model="keyword" @confirm="doSearch(false)"
  10. placeholder-class="placeholder-class" confirm-type="search">
  11. </view>
  12. <view class="search-btn" @tap="doSearch(false)">搜索</view> -->
  13. <view class="margin-lr">
  14. <u-search style="width: 100%;" placeholder="请输入商家或者商品名称" :focus="true" v-model="keyword"
  15. :show-action="true" :animation="true" shape="square" action-text="取消" @custom="goBack()"
  16. @search="doSearch(false)">
  17. </u-search>
  18. </view>
  19. <!-- <u-dropdown v-show="isShowKeywordList">
  20. <u-dropdown-item v-model="value1" :title="title" :options="options1" @change="confirm">
  21. </u-dropdown-item>
  22. <u-dropdown-item v-model="value2" :title="title1" :options="options2" @change="confirm2">
  23. </u-dropdown-item>
  24. </u-dropdown> -->
  25. <view v-show="isShowKeywordList" style="width: 100%;z-index: 999;">
  26. <view class="flex justify-between align-center bg-white padding-tb padding-lr-sm">
  27. <view class="flex-sub text-center" :class="current==1?'select':''" @click="confirm(1)">综合排序</view>
  28. <view class="flex-sub text-center" :class="current==3?'select':''" @click="confirm(3)">距离优先</view>
  29. <view class="flex-sub text-center" :class="current==4?'select':''" @click="confirm(4)">销量优先</view>
  30. <view class="flex-sub text-center flex" @click="isShow = !isShow" >
  31. <view class="flex align-center" style="margin: 0 auto;">
  32. <view :class="isShow?'select':''" >筛选</view>
  33. <u-icon v-if="!isShow" name="arrow-down" size="28"></u-icon>
  34. <u-icon v-if="isShow" name="arrow-up" color="#FCD202" size="28"></u-icon>
  35. </view>
  36. </view>
  37. </view>
  38. <view v-if="isShow" style="position: absolute;top: 150rpx;width: 100%;z-index: 1000;background: rgba(0,0,0,.5);height: 100vh;" @click="isShow =false">
  39. <view class="padding-lr bg-white">
  40. <view class="flex justify-between align-center padding-tb-sm u-border-bottom" v-for="(item,index) in options4" :key='index' @click.stop="getSelect(item)" >
  41. <view class="text-df" :class="item.select?'select':''">{{item.shopTypeName}}</view>
  42. <u-icon v-if="item.select" name="checkmark" color="#FCD202" size="28"></u-icon>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 原样式 end -->
  48. <!-- 活动筛选 -->
  49. <view class="hd flex justify-center" v-if="hdlist.length>0 && isShowKeywordList">
  50. <view class="hd-box">
  51. <scroll-view scroll-x="true" class="scroll-view_H">
  52. <view class="hd-box-item" :style="currenthd==index?'background-color:#fcd202;font-weight:bold':''" @click="searchhd(index,item.activityId)" v-for="(item,index) in hdlist" :key="index">{{item.activityTitle}}</view>
  53. </scroll-view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="search-keyword">
  58. <view class="keyword-list-box" v-show="isShowKeywordList" scroll-y>
  59. <view class="padding-lr">
  60. <view class="" v-for="(item,index) in keywordList" :key='index'>
  61. <view class=" flex justify-between bg-white padding" style="margin-bottom: 20rpx;"
  62. @click="goNav('/pages/index/shop/index?shopId='+item.shopId)">
  63. <image :src="item.shopCover" class="radius" style="width: 160rpx;height: 160rpx;"></image>
  64. <view class=" margin-left-sm" style="width: 450rpx;">
  65. <view class=" flex flex-direction justify-between">
  66. <view class="text-lg text-bold text-black">{{item.shopName}}</view>
  67. <view class="flex align-center margin-top-xs" style="width: 100%;">
  68. <u-icon name="star-fill" color="#FD6416" size="28"></u-icon>
  69. <text class="text-lg" style=""> {{item.shopScore?item.shopScore:0}}</text>
  70. <text class="text-gray flex-sub margin-left-xs">销量{{item.shopSales?item.shopSales:0}}</text>
  71. <text class="text-gray margin-left-xs">{{item.errandTime}}分钟</text>
  72. <text class="text-gray margin-left-xs">{{item.distance}}</text>
  73. </view>
  74. <view class="text-gray margin-top-xs flex justify-between">
  75. <view>起送 ¥{{item.minimumDelivery}} 配送 ¥{{item.errandMoney?item.errandMoney:0}}</view>
  76. <view style="color: #FCD202;">{{item.autoSendOrder==1?'商家配送':'平台配送'}}</view>
  77. </view>
  78. <view class="text-gray margin-top-xs" v-if="item.businessHours&&item.lockHours">
  79. 营业时间:{{item.businessHours}}-{{item.lockHours}}</view>
  80. <view class="flex margin-top-xs justify-between align-start" style="width: 100%;">
  81. <view class="flex flex-wrap align-center" style="width: 100%;height: 100%;overflow: hidden;">
  82. <view class="lable flex justify-center align-center" v-if="item.exemptMinMoney">满{{item.exemptMinMoney}}免配送费</view>
  83. <view class="lable flex justify-center align-center" v-for="(ite,ind) in item.shopLable" :key='ind'
  84. v-if="item.shopLable">
  85. {{ite}}
  86. </view>
  87. <view class="lable flex justify-center align-center" v-if="item.couponList" style="border-radius: 4rpx;border: 1rpx solid red;background-color: #ffffff;color: red;box-sizing: border-box;" v-for="(it,ide) in item.couponList" :key="ide">满{{it.minMoney}}减{{it.money}}</view>
  88. </view>
  89. </view>
  90. </view>
  91. <view class="flex margin-top-xs">
  92. <view v-for="(ite,ind) in item.goodsList" :key='ind'
  93. @click.stop="goDet(ite.goodsId,item.shopId)" style="width: 33%;">
  94. <image :src="ite.goodsCover" style="width: 120rpx;height: 120rpx;"
  95. class="radius" mode=""></image>
  96. <view class="u-line-1 text-df text-bold margin-top-xs">{{ite.goodsName}}</view>
  97. <view class="text-bold margin-top-xs" style="color: #FD6416;"> <text
  98. class="text-sm">¥</text> {{ite.goodsMoney}}</view>
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </view>
  104. </view>
  105. <!-- <view v-if="keywordList.length == 0">
  106. 暂无数据
  107. </view> -->
  108. <empty v-if="keywordList.length == 0"></empty>
  109. </view>
  110. <view class="keyword-box" v-show="!isShowKeywordList" scroll-y>
  111. <view class="keyword-block" v-if="hotKeywordList.length>0">
  112. <view class="keyword-list-header">
  113. <view>热门搜索</view>
  114. <view>
  115. <image @tap="hotToggle" :src="'/static/images/index/attention'+forbid+'.png'"></image>
  116. </view>
  117. </view>
  118. <view class="keyword" v-if="forbid==''">
  119. <view v-for="(keyword,index) in hotKeywordList" @tap="doSearch(keyword)" :key="index">
  120. {{keyword}}
  121. </view>
  122. </view>
  123. <view class="hide-hot-tis" v-else>
  124. <view>当前搜热已隐藏</view>
  125. </view>
  126. </view>
  127. <view class="keyword-block" v-if="oldKeywordList.length>0">
  128. <view class="keyword-list-header">
  129. <view>历史记录</view>
  130. <view>
  131. <image @tap="oldDelete" src="/static/images/index/delete.png"></image>
  132. </view>
  133. </view>
  134. <view class="keyword">
  135. <view v-for="(keyword,index) in oldKeywordList" @tap="doSearch(keyword.message)" :key="index">
  136. {{keyword.message}}
  137. </view>
  138. </view>
  139. </view>
  140. </view>
  141. </view>
  142. </view>
  143. </template>
  144. <script>
  145. import empty from '@/components/empty.vue'
  146. export default {
  147. components: {
  148. empty
  149. },
  150. data() {
  151. return {
  152. currenthd:-1,
  153. hdlist:[],
  154. activityId:'',
  155. isShow: false,
  156. defaultKeyword: "",
  157. keyword: "",
  158. oldKeywordList: [], //历史记录
  159. hotKeywordList: [], //热搜
  160. keywordList: [], //搜索列表
  161. forbid: '',
  162. isShowKeywordList: false,
  163. limit: 10,
  164. page: 1,
  165. userId: '',
  166. isVip: false,
  167. lng: '',
  168. lat: '',
  169. value1: 1,
  170. value2: 0,
  171. options1: [{
  172. label: '综合排序',
  173. value: 1,
  174. },
  175. {
  176. label: '距离优先',
  177. value: 3,
  178. },
  179. {
  180. label: '销量优先',
  181. value: 4,
  182. }
  183. ],
  184. options2: [{
  185. value: '',
  186. label: "全部"
  187. }],
  188. options4: [{
  189. id: '',
  190. select: true,
  191. shopTypeName: "全部"
  192. }],
  193. current: 1,
  194. shopTypeId: '',
  195. title: '综合排序',
  196. title1: '筛选',
  197. totalCount: 0
  198. }
  199. },
  200. onLoad() {
  201. let that = this
  202. this.getSearchList()
  203. this.gethdlist();
  204. this.userId = uni.getStorageSync('userId') ? uni.getStorageSync('userId') : ''
  205. this.lng = uni.getStorageSync('lng')
  206. this.lat = uni.getStorageSync('lat')
  207. this.getShopType()
  208. this.isVip = uni.getStorageSync('isVIP')
  209. uni.getLocation({
  210. type: 'gcj02', //返回可以用于uni.openLocation的经纬度
  211. success: function(res) {
  212. // that.lat = res.latitude;
  213. // that.lng = res.longitude;
  214. }
  215. });
  216. },
  217. methods: {
  218. //筛选活动
  219. searchhd(index,activityId){
  220. if(index==this.currenthd){
  221. this.currenthd = -1
  222. this.activityId = '';
  223. this.doSearch(false);
  224. }else{
  225. this.currenthd = index;
  226. this.activityId=activityId;
  227. this.doSearch(false);
  228. }
  229. },
  230. //获取所有活动
  231. gethdlist(){
  232. this.$Request.get("/app/activityManage/getActivityList").then(res => {
  233. if (res.code == 0) {
  234. res.data.records.map((item,index)=>{
  235. if(item.activityId==14){
  236. res.data.records.splice(index, 1)
  237. }
  238. })
  239. this.hdlist = res.data.records
  240. }
  241. });
  242. },
  243. getSelect(e) {
  244. this.options4.forEach(res=>{
  245. if(res.id == e.id) {
  246. res.select = true
  247. this.page = 1
  248. this.shopTypeId = e.id
  249. // this.getShopList();
  250. this.doSearch(this.keyword);
  251. this.isShow = false
  252. } else {
  253. res.select = false
  254. }
  255. })
  256. },
  257. confirm(e) {
  258. console.log(e)
  259. this.page = 1
  260. this.current = e;
  261. this.doSearch(this.keyword);
  262. },
  263. confirm2(e) {
  264. console.log(e)
  265. this.page = 1
  266. this.shopTypeId = e
  267. if (e == 0) {
  268. this.title1 = '筛选'
  269. } else {
  270. this.title1 = this.options2[e].label
  271. }
  272. this.doSearch(this.keyword);
  273. },
  274. // 获取搜索历史
  275. getSearchList() {
  276. let data = {
  277. page: this.page,
  278. limit: this.limit,
  279. }
  280. this.$Request.get("/app/searchhistory/selectSearchHistory", data).then(res => {
  281. console.log(res)
  282. if (res.code == 0) {
  283. this.oldKeywordList = res.data.list
  284. }
  285. });
  286. this.$Request.getT('/app/common/type/309').then(res => { //订单状态通知
  287. if (res.code == 0) {
  288. this.hotKeywordList = res.data.value.split(',')
  289. }
  290. })
  291. },
  292. //清除历史搜索
  293. oldDelete() {
  294. uni.showModal({
  295. content: '确定清除历史搜索记录?',
  296. success: (res) => {
  297. if (res.confirm) {
  298. console.log('用户点击确定');
  299. this.$Request.get("/app/searchhistory/deleteSearchHistory").then(res => {
  300. if (res.code == 0) {
  301. this.getSearchList()
  302. }
  303. })
  304. } else if (res.cancel) {
  305. console.log('用户点击取消');
  306. }
  307. }
  308. });
  309. },
  310. //执行搜索
  311. doSearch(keyword) {
  312. this.keyword = keyword === false ? this.keyword : keyword;
  313. this.isShowKeywordList = true;
  314. if (!this.keyword) {
  315. uni.showToast({
  316. title: '请输入内容',
  317. icon: 'none',
  318. duration: 1000
  319. })
  320. return
  321. }
  322. let data = {
  323. impotr: this.keyword,
  324. screen: this.current,
  325. shopTypeId: this.shopTypeId,
  326. limit: this.limit,
  327. page: this.page,
  328. lng: this.lng,
  329. lat: this.lat,
  330. userId: this.userId,
  331. activityId:this.activityId
  332. }
  333. this.$Request.get("/app/goods/selectShop", data).then(res => {
  334. if (res.code == 0) {
  335. this.totalCount = res.data.totalCount
  336. res.data.list.forEach(ret => {
  337. if (ret.distance > 1000) {
  338. ret.distance = Number((ret.distance / 1000)).toFixed(2) + "km"
  339. } else {
  340. if (ret.distance == 0) {
  341. ret.distance = "0m";
  342. } else {
  343. ret.distance = Number(ret.distance).toFixed(1) + "m";
  344. }
  345. }
  346. ret.shopLable = ret.shopLable ? ret.shopLable.split(',') : ''
  347. ret.errandTime = Math.round(ret.errandTime)
  348. ret.shopScore = ret.shopScore.toFixed(1)
  349. })
  350. if (this.page == 1) this.keywordList = [];
  351. this.keywordList = [...this.keywordList, ...res.data.list]
  352. }
  353. });
  354. },
  355. // 商户类型
  356. getShopType() {
  357. this.$Request.getT('/app/shoptype/selectShopTypeList').then(res => {
  358. if (res.code == 0) {
  359. res.data.forEach(res => {
  360. res.select = false
  361. })
  362. this.options4 = [...this.options4, ...res.data]
  363. }
  364. })
  365. },
  366. // 点击取消返回首页
  367. goBack() {
  368. uni.navigateBack()
  369. },
  370. //热门搜索开关
  371. hotToggle() {
  372. this.forbid = this.forbid ? '' : '_forbid';
  373. },
  374. // 跳转商品详情
  375. goDet(goodsId, shopId) {
  376. uni.navigateTo({
  377. url: '/pages/index/shop/goodsDet?goodsId=' + goodsId + '&shopId=' + shopId + '&orderType=1'
  378. })
  379. },
  380. goNav(url) {
  381. console.log(url)
  382. if (this.userId) {
  383. uni.navigateTo({
  384. url
  385. })
  386. } else {
  387. uni.navigateTo({
  388. url: '/pages/public/login'
  389. })
  390. }
  391. },
  392. // 跳转订单
  393. goOrder(e) {
  394. if (this.userId) {
  395. uni.navigateTo({
  396. url: '/pages/index/game/order?id=' + e.id
  397. });
  398. } else {
  399. uni.navigateTo({
  400. url: '/pages/public/login'
  401. });
  402. }
  403. },
  404. },
  405. onReachBottom: function() {
  406. // this.page = this.page + 1;
  407. // this.doSearch(false);
  408. if(this.keywordList.length<this.totalCount) {
  409. this.page = this.page + 1;
  410. this.doSearch(false);
  411. } else {
  412. uni.showToast({
  413. title: '已经到底了',
  414. icon: 'none'
  415. })
  416. }
  417. },
  418. onPullDownRefresh: function() {
  419. this.page = 1;
  420. this.doSearch(false);
  421. },
  422. }
  423. </script>
  424. <style lang="scss">
  425. page {
  426. /* background-color: #FFFFFF; */
  427. }
  428. .hd{
  429. width: 100%;
  430. height: auto;
  431. // margin-top: 20rpx;
  432. padding-top: 20rpx;
  433. padding-bottom: 20rpx;
  434. background-color: rgb(248,248,248);
  435. .hd-box{
  436. width: 686rpx;
  437. height: 100%;
  438. .scroll-view_H{
  439. width: 100%;
  440. white-space: nowrap;
  441. }
  442. .hd-box-item{
  443. display: inline-block;
  444. padding: 10rpx 20rpx 10rpx 20rpx;
  445. background-color: #ffffff;
  446. font-size: 24rpx;
  447. border-radius: 8rpx;
  448. margin-right: 10rpx;
  449. }
  450. }
  451. }
  452. .select{
  453. color: #FCD202;
  454. }
  455. .search-box {
  456. width: 100%;
  457. /* background-color: rgb(242, 242, 242); */
  458. padding: 15upx 0 0;
  459. /* display: flex; */
  460. /* justify-content: space-between; */
  461. position: sticky;
  462. top: 0;
  463. background-color: #FFF;
  464. z-index: 99;
  465. }
  466. .search-box .mSearch-input-box {
  467. width: 100%;
  468. }
  469. .search-box .input-box {
  470. width: 85%;
  471. flex-shrink: 1;
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. }
  476. .search-box .search-btn {
  477. width: 15%;
  478. margin: 0 0 0 2%;
  479. display: flex;
  480. justify-content: center;
  481. align-items: center;
  482. flex-shrink: 0;
  483. font-size: 28upx;
  484. /* color: #fff; */
  485. background: linear-gradient(to right, #ff9801, #ff570a);
  486. border-radius: 60upx;
  487. }
  488. .search-box .input-box>input {
  489. width: 100%;
  490. height: 60upx;
  491. font-size: 32upx;
  492. border: 0;
  493. border-radius: 60upx;
  494. -webkit-appearance: none;
  495. -moz-appearance: none;
  496. appearance: none;
  497. padding: 0 3%;
  498. margin: 0;
  499. background-color: #ffffff;
  500. }
  501. .placeholder-class {
  502. color: #9e9e9e;
  503. }
  504. .search-keyword {
  505. width: 100%;
  506. /* background-color: #111224; */
  507. }
  508. .keyword-list-box {
  509. height: calc(100vh - 110upx);
  510. /* padding-top: 10upx; */
  511. /* border-radius: 20upx 20upx 0 0; */
  512. /* background-color: #fff; */
  513. }
  514. .keyword-entry-tap {
  515. background-color: #eee;
  516. }
  517. .keyword-entry {
  518. width: 94%;
  519. height: 80upx;
  520. margin: 0 3%;
  521. font-size: 30upx;
  522. color: #333;
  523. display: flex;
  524. justify-content: space-between;
  525. align-items: center;
  526. border-bottom: solid 1upx #e7e7e7;
  527. }
  528. .keyword-entry image {
  529. width: 60upx;
  530. height: 60upx;
  531. }
  532. .keyword-entry .keyword-text,
  533. .keyword-entry .keyword-img {
  534. height: 80upx;
  535. display: flex;
  536. align-items: center;
  537. }
  538. .keyword-entry .keyword-text {
  539. width: 90%;
  540. }
  541. .keyword-entry .keyword-img {
  542. width: 10%;
  543. justify-content: center;
  544. }
  545. .keyword-box {
  546. height: calc(100vh - 110upx);
  547. /* border-radius: 20upx 20upx 0 0; */
  548. /* background-color: #111224; */
  549. }
  550. .keyword-box .keyword-block {
  551. padding: 10upx 0;
  552. }
  553. .keyword-box .keyword-block .keyword-list-header {
  554. width: 94%;
  555. padding: 10upx 3%;
  556. font-size: 27upx;
  557. font-weight: 700;
  558. /* color: #FFFFFF; */
  559. display: flex;
  560. justify-content: space-between;
  561. }
  562. .keyword-box .keyword-block .keyword-list-header image {
  563. width: 40upx;
  564. height: 40upx;
  565. }
  566. .keyword-box .keyword-block .keyword {
  567. width: 94%;
  568. padding: 3px 3%;
  569. display: flex;
  570. flex-flow: wrap;
  571. justify-content: flex-start;
  572. }
  573. .keyword-box .keyword-block .hide-hot-tis {
  574. display: flex;
  575. justify-content: center;
  576. font-size: 28upx;
  577. /* color: #FFFFFF; */
  578. }
  579. .keyword-box .keyword-block .keyword>view {
  580. display: flex;
  581. justify-content: center;
  582. align-items: center;
  583. border-radius: 10upx;
  584. padding: 0 20upx;
  585. margin: 10upx 20upx 10upx 0;
  586. height: 60upx;
  587. font-size: 28upx;
  588. background-color: #eee;
  589. /* color: #FFFFFF; */
  590. }
  591. .lable {
  592. border: 1rpx solid #FFE6D9;
  593. height: 40rpx;
  594. padding: 0 14rpx;
  595. background: #FFE6D9;
  596. border-radius: 4rpx;
  597. font-weight: 500;
  598. color: #FD6416;
  599. font-size: 20rpx;
  600. margin-right: 10rpx;
  601. margin-bottom: 10rpx;
  602. }
  603. </style>