food.vue 13 KB

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