food.vue 14 KB

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