index.vue 18 KB

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