food.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <view class="content">
  3. <u-navbar title="美食推荐" :safeAreaInsetTop="true" placeholder='true' fixed>
  4. <view class="u-nav-slot" slot="left" @click='leftClick'>
  5. <view class="iconfont applet-colors-ditu"></view>
  6. </view>
  7. </u-navbar>
  8. <mescroll-uni :up="upOption" :down="downOption" ref="mescrollRef" @init="mescrollInit"
  9. @up="upCallback" @down="downCallback" :top="150">
  10. <view class="flex content1">
  11. <view @click='placeSelect' class='address flex'>
  12. <view class='detailedAddress'>{{detailedAddress1}}</view>
  13. <view class='iconfont applet-xiala'></view>
  14. </view>
  15. <view class="search-wrap">
  16. <view class="search flex justify-space-between align-item-center flex-between" @click="search">
  17. <view class="left flex">
  18. <image class="dSLComVueTopLeftImg" style="width: 40rpx;height: 40rpx"
  19. src="@/static/image/card/search.png"></image>
  20. <text class="search-val"> {{searchVal?searchVal:'搜索美食'}}</text>
  21. </view>
  22. <view class="right">
  23. <image style='width:32rpx;height:32rpx;' v-if="searchVal" @click.stop="delSearchVal"
  24. src="@/static/image/card/searchdel.png" mode="widthFix"></image>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="tag-type head">
  30. <view v-for='item in jobs' @click="change(item)" class="item" :class="item.checked?'item-active':''">
  31. {{item.iname}}
  32. </view>
  33. </view>
  34. <scroll-view scroll-x="true" scroll-with-animation="true" class='list-type'>
  35. <view v-for='item in searchTypes' @click='changetype(item)'
  36. :class='searchType==item.value?"Semibold active":"Regular"' class="typeitem">{{item.name}}</view>
  37. </scroll-view>
  38. <view class='findItem' v-for='item in findList' @click="toShop(item)" v-if="item.foodDishesInfoList&&item.foodDishesInfoList.length!=0">
  39. <view class='flex row2'>
  40. <view class='name'>{{item.shopNames}}</view>
  41. </view>
  42. <view style='align-items: flex-start;' class='flex' >
  43. <view style='width:100vw;' class="left flex " :class='item.foodDishesInfoList.length==4?"justify-space-between":""'>
  44. <!-- @click.stop='previewImg(item1)' -->
  45. <view v-for='item1 in item.foodDishesInfoList' class="img">
  46. <u--image radius='4' :showLoading="true" :src="item1.dishImage" width="150rpx"
  47. height="150rpx" ></u--image>
  48. </view>
  49. </view>
  50. </view>
  51. <view class="tag-type1 flex">
  52. <text class="text" v-for='item1 in item.labels'> {{item1}}</text>
  53. </view>
  54. <view class='address flex justify-space-between'>
  55. <view style='width:60vw;' class='flex'>
  56. <view class='iconfont applet-dizhi'></view>
  57. <view class="detailedAddress" @click.stop="toShopDetail(item)">
  58. {{item.detailedAddress}}
  59. </view>
  60. <!-- <view>{{item.province}}{{item.city}}{{item.area}}</view> -->
  61. </view>
  62. <view style="color: #999;width:40vw;text-align:right;font-size: 28rpx;">
  63. 距离{{item.distance1>1000?item.distance:item.distance1}} {{item.distance1>1000?'km':'m'}}
  64. </view>
  65. </view>
  66. </view>
  67. </mescroll-uni>
  68. <!-- <mescroll-body ref="mescrollRef" :up="upOption" :down="downOption" @init="mescrollInit" @up="upCallback" @down="downCallback"></mescroll-body> -->
  69. <!-- <view class='group' @click='group'>
  70. <button class="tuan">团</button>
  71. </view> -->
  72. </view>
  73. </template>
  74. <script>
  75. var that;
  76. var GDMapWX = require('@/js_sdk/js-amap/amap-wx.130.js');
  77. import uniTag from '@/uni_modules/uni-tag/components/uni-tag/uni-tag.vue';
  78. import MoteLinesDivide from "@/components/text-over-flow/text-over-flow.vue"
  79. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  80. import {
  81. authorizedLocation
  82. } from '@/util/util.js'
  83. export default {
  84. components: {
  85. MoteLinesDivide,
  86. uniTag
  87. },
  88. mixins: [MescrollMixin],
  89. data() {
  90. return {
  91. place: '',
  92. searchVal: "",
  93. current: 0,
  94. mescroll: null,
  95. findList: [],
  96. inverted: true,
  97. handleList: [],
  98. labels: [],
  99. searchType: '1',
  100. label: '',
  101. longitude: '',
  102. latitude: '',
  103. curPageLen: 0,
  104. totalPage: 0,
  105. detailedAddress: '正在定位...',
  106. detailedAddress1: '',
  107. downOption: {
  108. auto: false,
  109. textColor: '#bbb'
  110. },
  111. searchTypes: [{
  112. name: '默认排序',
  113. value: '1'
  114. }, {
  115. name: '距离最近',
  116. value: '2'
  117. },
  118. // {
  119. // name: '最多点赞',
  120. // value: '3'
  121. // }, {
  122. // name: '我的收藏',
  123. // value: '4'
  124. // },
  125. ],
  126. jobs: [{
  127. id: 1,
  128. iname: '海鲜',
  129. checked: false
  130. },
  131. {
  132. id: 2,
  133. iname: '自助',
  134. checked: false
  135. }, {
  136. id: 3,
  137. iname: '烧烤',
  138. checked: false
  139. },
  140. {
  141. id: 4,
  142. iname: '火锅',
  143. checked: false
  144. },
  145. {
  146. id: 5,
  147. iname: '家常菜',
  148. checked: false
  149. },
  150. {
  151. id: 6,
  152. iname: '面食',
  153. checked: false
  154. },
  155. {
  156. id: 7,
  157. iname: '小龙虾',
  158. checked: false
  159. },
  160. {
  161. id: 8,
  162. iname: '早餐',
  163. checked: false
  164. }
  165. ],
  166. upOption: {
  167. page: {
  168. size: 10 // 每页数据的数量,默认10
  169. },
  170. auto: false,
  171. noMoreSize: 1,
  172. textNoMore: '没有更多了~',
  173. textColor: '#bbb'
  174. },
  175. };
  176. },
  177. onLoad() {
  178. that = this
  179. // this.getList()
  180. // this.getLocation()
  181. // this.mescroll.resetUpScroll();
  182. },
  183. onShow() {
  184. //判断是否有定位权限
  185. this.searchVal = uni.getStorageSync("search_food_val")
  186. if (this.detailedAddress == '正在定位...') {
  187. this.isdingwei()
  188. }
  189. },
  190. methods: {
  191. toShopDetail(val){
  192. console.log(val)
  193. uni.navigateTo({
  194. url: "/pageA/food/detailMap?val="+JSON.stringify(val)
  195. })
  196. },
  197. leftClick() {
  198. uni.navigateTo({
  199. url: "/pageA/food/fondMap"
  200. })
  201. },
  202. previewImg(item) {
  203. uni.previewImage({
  204. current: 0,
  205. urls: [item.dishImage],
  206. loop: true,
  207. })
  208. },
  209. toShop(val) {
  210. uni.navigateTo({
  211. url: "/pageA/food/menu?val=" + JSON.stringify(val)
  212. })
  213. },
  214. delSearchVal() {
  215. this.searchVal = ''
  216. uni.removetorageSync("search_food_val")
  217. that.mescroll.resetUpScroll()
  218. },
  219. isdingwei() {
  220. authorizedLocation().then(res => {
  221. let _obj = {}
  222. if (res == '取消授权') {
  223. //获取上一次,无上一次山海广场
  224. let _place = uni.getStorageSync("LocationPlace")
  225. if (_place && _place.latitude) {
  226. _obj = {
  227. latitude: _place.latitude,
  228. longitude: _place.longitude
  229. }
  230. } else {
  231. _obj = {
  232. latitude: 40.22086204872,
  233. longitude: 122.08338497727
  234. }
  235. }
  236. } else {
  237. _obj = {
  238. latitude: res.latitude,
  239. longitude: res.longitude
  240. }
  241. }
  242. this.longitude = _obj.longitude
  243. this.latitude = _obj.latitude
  244. var amapPluginInstance = new GDMapWX.AMapWX({
  245. key: '6bafe91754a563ff2b7c02542c1ef4e8'
  246. });
  247. amapPluginInstance.getRegeo({
  248. success: function(res) {
  249. console.log(res)
  250. that.detailedAddress = res[0].desc
  251. that.detailedAddress1 = that.detailedAddress.length>4 ? that.detailedAddress.slice(0,4)+'...' : that.detailedAddress
  252. that.mescroll.resetUpScroll()
  253. //成功回调
  254. },
  255. fail: function(info) {
  256. //失败回调
  257. console.log(info)
  258. }
  259. })
  260. })
  261. },
  262. search() {
  263. uni.navigateTo({
  264. url: "/pageA/food/search"
  265. })
  266. },
  267. change(item) {
  268. this.searchVal = item.iname
  269. this.mescroll.resetUpScroll()
  270. // if (this.label == item.iname) {
  271. // this.label = ''
  272. // } else {
  273. // this.label = item.iname
  274. // }
  275. // this.inverted = !this.inverted;
  276. // that.upCallback({
  277. // num: 1,
  278. // size: 10
  279. // })
  280. },
  281. changetype(item) {
  282. this.searchType = item.value
  283. that.upCallback({
  284. num: 1,
  285. size: 10
  286. })
  287. },
  288. placeSelect() {
  289. uni.chooseLocation({
  290. success: function(res) {
  291. console.log(res);
  292. that.latitude = res.latitude
  293. that.longitude = res.longitude
  294. uni.setStorageSync("findlatitude", res.latitude)
  295. uni.setStorageSync("findlongitude", res.longitude)
  296. // let _address = that.$helper.formatLocation(res.address)
  297. that.detailedAddress = res.name
  298. that.detailedAddress1 = that.detailedAddress.length>4 ? that.detailedAddress.slice(0,4)+'...' : that.detailedAddress
  299. uni.setStorageSync("detailedAddress", res.name)
  300. that.$forceUpdate()
  301. that.upCallback({
  302. num: 1,
  303. size: 10
  304. })
  305. }
  306. });
  307. },
  308. mescrollInit(mescroll) {
  309. this.mescroll = mescroll;
  310. },
  311. downCallback() {
  312. this.mescroll.resetUpScroll()
  313. // if (uni.getStorageSync("userInfo").phone) {
  314. // this.mescroll.resetUpScroll()
  315. // } else {
  316. // that.mescroll.endBySize(0, 0)
  317. // this.showAuthorizePhone = true
  318. // }
  319. },
  320. getDistance(latitude, longitude) {
  321. console.log(latitude, longitude, that.latitude, that.longitude)
  322. return new Promise((resolve, reject) => {
  323. qqmapsdk.direction({
  324. mode: 'driving', //可选值:'driving'(驾车) trucking 货车
  325. //from参数不填默认当前地址
  326. // latitude纬度 longitude 经度
  327. from: {
  328. latitude: that.latitude,
  329. longitude: that.longitude
  330. },
  331. to: {
  332. latitude: latitude,
  333. longitude: longitude
  334. },
  335. size: 4, // 车型 1: 微型车 2: 轻型车 3: 中型车 4: 重型车
  336. policy: 'LEAST_TIME', //'9', //参考实时路况,高速优先,尽量躲避拥堵
  337. height: 4,
  338. width: 2.5,
  339. length: 13,
  340. weight: 6.8,
  341. axle_weight: 34,
  342. axle_count: 6,
  343. is_trailer: 1,
  344. success: function(res1, data) {
  345. console.log(res1, data[0].distance, data)
  346. resolve(data[0])
  347. }
  348. })
  349. })
  350. },
  351. async upCallback(page) {
  352. uni.showLoading({
  353. title: '数据加载中'
  354. })
  355. await that.$request.baseRequest('admin.tourism.foodInfo', 'foodList', {
  356. page: page.num,
  357. limit: page.size,
  358. searchType: this.searchType,
  359. searchKeyWord: this.searchVal,
  360. place: this.detailedAddress,
  361. userLongitude: this.longitude,
  362. userLatitude: this.latitude,
  363. }, failres => {
  364. uni.showToast({
  365. icon: "none",
  366. title: failres.errmsg,
  367. duration: 3000
  368. });
  369. }).then(res => {
  370. uni.hideLoading()
  371. if (page.num == 1) that.findList = [], that.handleList = [];
  372. that.curPageLen = res.data.items.length;
  373. that.handleList = res.data.items
  374. that.totalPage = res.data.total;
  375. })
  376. if (that.handleList.length > 0) {
  377. for (var i = 0; i < that.handleList.length; i++) {
  378. that.handleList[i].latitude = that.handleList[i].location.split(',')[0]
  379. that.handleList[i].longitude = that.handleList[i].location.split(',')[1]
  380. // var data = await that.getDistance(that.handleList[i].latitude, that.handleList[i].longitude)
  381. that.handleList[i].distance1 = JSON.parse(JSON.stringify(that.handleList[i].distance))
  382. that.handleList[i].distance = (that.handleList[i].distance / 1000).toFixed(1)
  383. if (that.handleList[i].label) {
  384. that.handleList[i].labels = that.handleList[i].label.split(",")
  385. }
  386. if (that.handleList[i].foodDishesInfoList) {
  387. that.handleList[i].foodDishesInfoList = that.handleList[i].foodDishesInfoList.splice(0, 4)
  388. }
  389. }
  390. that.findList = that.handleList
  391. } else {
  392. uni.hideLoading()
  393. }
  394. that.$nextTick(() => {
  395. that.mescroll.endBySize(that.curPageLen, that.totalPage)
  396. });
  397. },
  398. group() {
  399. uni.navigateTo({
  400. url: '/pageA/food/groupBuying'
  401. })
  402. },
  403. }
  404. }
  405. </script>
  406. <style lang="scss" scoped>
  407. .content {}
  408. .content1 {
  409. padding: 20rpx;
  410. background-color: #fff;
  411. .search {
  412. // color: #9199af;
  413. // background: #f9d27d;
  414. border-radius: 50rpx;
  415. padding: 15rpx 0 15rpx 15rpx;
  416. box-sizing: border-box;
  417. margin-right: 20rpx;
  418. }
  419. .left {
  420. width: 80%;
  421. text {
  422. white-space: nowrap;
  423. overflow: scroll;
  424. position: relative;
  425. margin-left: 20rpx;
  426. color: #BBBBBB;
  427. display: flex;
  428. align-items: center;
  429. }
  430. }
  431. .right {
  432. // width:14%;
  433. // margin-right: 20rpx
  434. display: flex;
  435. }
  436. }
  437. .search-wrap {
  438. width: 70%;
  439. background: rgb(249, 249, 249);
  440. // border: 1px solid #f9d27d;
  441. border-radius: 50rpx;
  442. .left{
  443. align-items: center;
  444. }
  445. .search-val{
  446. color:#BBBBBB;
  447. }
  448. }
  449. .address {
  450. width: 27%;
  451. }
  452. .findItem {
  453. background: #fff;
  454. margin: 20rpx;
  455. border-radius: 20rpx;
  456. padding: 20rpx;
  457. font-size: 32rpx;
  458. .row2 {
  459. margin:0 0 20rpx 0;
  460. }
  461. .left {
  462. // background: red;
  463. }
  464. .name {
  465. color: #333;
  466. // margin-left: 10rpx;
  467. font-weight: 700;
  468. font-size: 32rpx;
  469. }
  470. .description {
  471. color: #666;
  472. margin-top: 10rpx;
  473. }
  474. .address {
  475. // margin-top: 30rpx;
  476. width: 100%;
  477. color: #393733;
  478. // margin-top: 20rpx;
  479. }
  480. .img{
  481. margin: 10rpx;
  482. }
  483. .left .img:first-child{
  484. margin-left:0;
  485. }
  486. .left .img:last-child{
  487. margin-right:0;
  488. }
  489. .detailedAddress {
  490. width: 70vw;
  491. overflow: hidden;
  492. text-overflow: ellipsis;
  493. white-space: nowrap;
  494. color:#999 ;
  495. line-height: 40rpx;
  496. text-align: left;
  497. font-size: 28rpx;
  498. }
  499. }
  500. .applet-dianpu1 {
  501. color: #393733;
  502. font-size: 50rpx;
  503. }
  504. .applet-dizhi {
  505. color: #999;
  506. font-size: 38rpx;
  507. position: relative;
  508. // top: -2rpx;
  509. }
  510. .group {
  511. position: fixed;
  512. // margin-left: 350px;
  513. bottom: 40rpx;
  514. right: 40rpx;
  515. z-index: 999;
  516. }
  517. .tuan {
  518. background: #eaad1a;
  519. border-radius: 50px;
  520. color: #fff;
  521. }
  522. .applet-colors-tianjia2 {}
  523. // .text {
  524. // font-size: 26rpx;
  525. // font-weight: 500;
  526. // color: #eaad1a;
  527. // opacity: 0.5;
  528. // margin-right: 56rpx;
  529. // }
  530. .head {
  531. white-space: nowrap;
  532. overflow-x: scroll;
  533. padding-left: 20rpx;
  534. width: calc(100vw);
  535. box-sizing: border-box;
  536. .item {
  537. display: inline-block;
  538. background: #F0F0F0;
  539. color: #999;
  540. padding: 10rpx 26rpx;
  541. margin-right: 20rpx;
  542. border-radius: 50rpx;
  543. font-size: 24rpx;
  544. }
  545. }
  546. .tag-type1 {
  547. margin: 20rpx 0;
  548. .text {
  549. border-radius: 4px;
  550. background-color: #FDF2E5;
  551. color: #E95700;
  552. margin-right: 30rpx;
  553. padding: 10rpx 26rpx;
  554. font-size: 24rpx;
  555. margin-right: 20rpx;
  556. }
  557. }
  558. .tag-type {
  559. // margin: 20rpx 0;
  560. .text {
  561. border-radius: 4px;
  562. background-color: #FDF2E5;
  563. color: #E95700;
  564. margin-right: 30rpx;
  565. padding: 10rpx 26rpx;
  566. font-size: 24rpx;
  567. margin-right: 20rpx;
  568. }
  569. }
  570. .list-type {
  571. background: #fff;
  572. width: 100vw;
  573. padding-top: 5px;
  574. height: 88rpx;
  575. overflow-x: scroll;
  576. white-space: nowrap;
  577. }
  578. .typeitem {
  579. margin: 20rpx 20rpx 0 20rpx;
  580. position: relative;
  581. display: inline-block;
  582. padding-bottom: 10px;
  583. font-size: 28rpx;
  584. color: #888;
  585. }
  586. .typeitem.active {
  587. color: #eaad1a;
  588. font-size: 32rpx;
  589. }
  590. .typeitem.active:after {
  591. content: '';
  592. display: block;
  593. position: absolute;
  594. height: 3px;
  595. bottom: 0;
  596. background: #eaad1a;
  597. width: 44rpx;
  598. left: 50%;
  599. transform: translateX(-50%);
  600. }
  601. .tag-type {
  602. background: #fff;
  603. uni-tag {
  604. margin-left: 20rpx !important;
  605. }
  606. }
  607. .applet-colors-ditu {
  608. font-size: 40rpx;
  609. }
  610. /deep/.mescroll-upwarp {
  611. padding: 30rpx 0;
  612. }
  613. .applet-xiala{
  614. margin: 0 16rpx 0 -4px;
  615. }
  616. </style>