fondMap.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view>
  3. <map style="width: 100%; height: 100vh;" :show-location='true' ref="map" id="map" :latitude="latitude"
  4. :longitude="longitude" :markers="marker" :scale="scale" @callouttap='callouttap' @regionchange='regionChange'>
  5. </map>
  6. <view class="floatBtn" :style="{bottom:(currentHeight+20)+'px'}" @click="onControltap">
  7. <view class="header-avatar">
  8. <image class="cover-image" src="@/static/image/food/dw.png"></image>
  9. </view>
  10. </view>
  11. <bab-Touchbox :minHeight="0.25" :maxHeight="0.7" :touchHeight="40" @currentHeight="setScrollHeight"
  12. @maxtHeight="setScrollViewHeight">
  13. <view class="flexRow">
  14. <view class="head">
  15. <view v-for='item in jobs' @click="change(item)" class="item" :class="item.checked?'item-active':''">
  16. {{item.iname}}
  17. </view>
  18. </view>
  19. </view>
  20. <scroll-view :style="{'height':scrollViewHeight - 64 +'px'}" scroll-y="true" class="info-list">
  21. <view class="item" v-for="(item,index) in mapList" @click="toMap(item,index)">
  22. <view class="left">
  23. <image :src="item.coverImage" mode="aspectFill" class="img"></image>
  24. </view>
  25. <view class="right row1">
  26. <view class="title">
  27. {{item.shopNames}}
  28. </view>
  29. <view class="row2" v-if="item.label">
  30. <view v-for="item1 in item.label.split(',')" class="label">
  31. {{item1}}
  32. </view>
  33. </view>
  34. <view class="row3" @click.stop="toDL(item)">
  35. <view class="to-here">
  36. <image src="../../static/image/to.png" mode="widthFix" style="width: 36rpx;">
  37. </image>
  38. </view>
  39. <view class="detailedAddress">
  40. {{item.detailedAddress}}
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. <!-- <scroll-view :style="{'height':scrollViewHeight - 64 +'px'}" scroll-y="true">
  47. <view style="background-color: #4CD964;">
  48. <view><text>绿色高度(滚动区域高度) = </text><text>@maxtHeight返回值 - touchHeight值</text></view>
  49. <list>
  50. <cell v-for="(item, index) in 50" :key="index">
  51. <text>就是个地理位置{{index+1}}</text>
  52. </cell>
  53. </list>
  54. </view>
  55. </scroll-view> -->
  56. </bab-Touchbox>
  57. </view>
  58. </template>
  59. <script>
  60. var that;
  61. import {
  62. authorizedLocation
  63. } from '@/util/util.js'
  64. export default {
  65. data() {
  66. return {
  67. searchKeyWord:'',
  68. currentHeight: 0, // 滑动组件当前高度
  69. scrollViewHeight: 0, //用于计算滚动区域高度
  70. topHeight: 20,
  71. tag: false,
  72. latitude: '', //纬度
  73. longitude: '', //经度
  74. movelatitude: '', //纬度
  75. movelongitude: '', //经度
  76. scale: 14, //缩放级别
  77. current: 1,
  78. marker: [],
  79. pageSize: 10,
  80. pageNum: 1,
  81. total: 0, // 总数据量
  82. markerIdClick: [],
  83. mapList: [],
  84. jobs: [
  85. {
  86. id: 0,
  87. iname: '全部',
  88. checked: true
  89. },
  90. {
  91. id: 1,
  92. iname: '海鲜',
  93. checked: false
  94. },
  95. {
  96. id: 2,
  97. iname: '自助',
  98. checked: false
  99. }, {
  100. id: 3,
  101. iname: '烧烤',
  102. checked: false
  103. },
  104. {
  105. id: 4,
  106. iname: '火锅',
  107. checked: false
  108. },
  109. {
  110. id: 5,
  111. iname: '家常菜',
  112. checked: false
  113. },
  114. {
  115. id: 6,
  116. iname: '面食',
  117. checked: false
  118. },
  119. {
  120. id: 7,
  121. iname: '小龙虾',
  122. checked: false
  123. },
  124. {
  125. id: 8,
  126. iname: '早餐',
  127. checked: false
  128. }
  129. ],
  130. }
  131. },
  132. watch: {},
  133. onLoad(options) {
  134. that = this
  135. this.isdingwei()
  136. },
  137. computed: {
  138. windowHeight() {
  139. var systemInfo = uni.getSystemInfoSync();
  140. return systemInfo.windowHeight;
  141. },
  142. windowWidth() {
  143. return uni.getSystemInfoSync().windowWidth;
  144. }
  145. },
  146. methods: {
  147. toMap(val,index){
  148. console.log(this.marker)
  149. console.log(val)
  150. for(let i = 0;i<this.marker.length;i++){
  151. if(val.id==this.marker[i].id){
  152. this.marker[i].width = 30
  153. this.marker[i].height = 30
  154. }else{
  155. this.marker[i].width = 20
  156. this.marker[i].height = 20
  157. }
  158. }
  159. },
  160. change(val){
  161. this.searchKeyWord = val.iname
  162. if(this.searchKeyWord=='全部') this.searchKeyWord = ''
  163. for(let i = 0;i<this.jobs.length;i++){
  164. if(val.iname==this.jobs[i].iname){
  165. this.jobs[i].checked = true
  166. }else{
  167. this.jobs[i].checked = false
  168. }
  169. }
  170. this.getStationList()
  171. },
  172. async regionChange(e) {
  173. if(e.type=="end"&&e.causedBy=='drag'){
  174. console.log(e)
  175. let _centerLocation = await this.getCenterLocation()
  176. this.movelongitude = _centerLocation.longitude
  177. this.movelatitude = _centerLocation.latitude
  178. this.getStationList()
  179. }
  180. },
  181. //移动到当前位置
  182. onControltap() {
  183. uni.createMapContext("map", this).moveToLocation();
  184. },
  185. toDL(val) {
  186. console.log(val)
  187. let _latitude = val.location.split(",")[0]
  188. let _longitude = val.location.split(",")[1]
  189. uni.openLocation({
  190. latitude: Number(_latitude),
  191. longitude: Number(_longitude),
  192. success: function() {
  193. console.log('success');
  194. },
  195. fail(fail) {
  196. console.log(fail)
  197. },
  198. });
  199. },
  200. getCenterLocation() {
  201. return new Promise((resolve, reject) => {
  202. // 获取地图中心经纬度
  203. let mapObjs = uni.createMapContext("map",that)
  204. mapObjs.getCenterLocation ({
  205. success:function(res){
  206. console.log("中心经纬度",res)
  207. resolve(res)
  208. },
  209. fail:function(fail) {
  210. reject(fail)
  211. }
  212. });
  213. })
  214. },
  215. getList() {
  216. return new Promise((resolve, reject) => {
  217. uni.showLoading({
  218. mask:true,
  219. title: '加载中'
  220. })
  221. this.$request.baseRequest('admin.tourism.foodInfo', 'foodList', {
  222. page: 1,
  223. limit: 100,
  224. userLongitude: this.movelongitude,
  225. userLatitude: this.movelatitude,
  226. searchKeyWord: this.searchKeyWord,
  227. searchType:2
  228. }, failres => {
  229. uni.showToast({
  230. icon: "none",
  231. title: failres.errmsg,
  232. duration: 3000
  233. });
  234. }).then(res => {
  235. uni.hideLoading()
  236. resolve(res)
  237. })
  238. })
  239. },
  240. async getStationList() {
  241. this.mapList = []
  242. const data = await this.getList()
  243. console.log('queryStationInfos,信息列表显示总数据', data);
  244. this.total = data.total
  245. data.data.items.forEach(item => {
  246. item.latitude = item.location.split(',')[0]
  247. item.longitude = item.location.split(',')[1]
  248. this.marker.push({
  249. id: Number(item.id),
  250. iconPath: '/static/image/food/location.png', //显示的图标
  251. latitude: Number(item.latitude),
  252. longitude: Number(item.longitude),
  253. // label: {
  254. // content: item.shopNames,
  255. // textAlign: "left",
  256. // padding: -20
  257. // },
  258. width: 20,
  259. height: 20,
  260. callout: { //气泡窗口
  261. content: item.shopNames, //文本
  262. // color: '#ffffff',
  263. fontSize: 14,
  264. // borderRadius: 15,
  265. // padding: '10',
  266. bgColor: 'transparent',
  267. display: 'ALWAYS', //常显
  268. anchorX: 32,
  269. anchorY: 28
  270. }
  271. })
  272. })
  273. this.mapList = this.mapList.concat(data.data.items)
  274. console.log(this.marker);
  275. },
  276. isdingwei() {
  277. authorizedLocation().then(res => {
  278. let _obj = {}
  279. if (res == '取消授权') {
  280. //获取上一次,无上一次山海广场
  281. let _place = uni.getStorageSync("LocationPlace")
  282. if (_place && _place.latitude) {
  283. _obj = {
  284. latitude: _place.latitude,
  285. longitude: _place.longitude
  286. }
  287. } else {
  288. _obj = {
  289. latitude: 40.22086204872,
  290. longitude: 122.08338497727
  291. }
  292. }
  293. } else {
  294. _obj = {
  295. latitude: res.latitude,
  296. longitude: res.longitude
  297. }
  298. }
  299. this.longitude = _obj.longitude
  300. this.latitude = _obj.latitude
  301. this.movelongitude = _obj.longitude
  302. this.movelatitude = _obj.latitude
  303. this.getStationList()
  304. })
  305. },
  306. setScrollHeight(val) { // 实时返回的滑动组件高度
  307. this.currentHeight = val
  308. console.log(this.currentHeight)
  309. },
  310. setScrollViewHeight(val) { //最大高度
  311. this.scrollViewHeight = val
  312. },
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .header-avatar {
  318. width: 80rpx;
  319. height: 80rpx;
  320. background-color: #fff;
  321. border-radius: 100px;
  322. display: fixed;
  323. align-items: center;
  324. justify-content: center;
  325. .cover-image {
  326. width: 50rpx;
  327. height: 50rpx;
  328. position: absolute;
  329. top: 15rpx;
  330. left: 15rpx;
  331. }
  332. }
  333. .floatBtn {
  334. position: fixed;
  335. right: 40rpx;
  336. z-index: 10;
  337. }
  338. .flexRow {
  339. .head {
  340. margin: 20rpx 0;
  341. white-space: nowrap;
  342. overflow-x: scroll;
  343. width: calc(100vw - 40rpx);
  344. box-sizing: border-box;
  345. .item {
  346. display: inline-block;
  347. background: #e9eaec;
  348. color: #566068;
  349. padding: 10rpx 26rpx;
  350. margin-right: 20rpx;
  351. border-radius: 20rpx;
  352. font-size: 24rpx;
  353. }
  354. .item-active {
  355. display: inline-block;
  356. background:#f9ae3d ;
  357. color: #fff;
  358. // padding: 10rpx 26rpx;
  359. // margin-right: 20rpx;
  360. // border-radius: 20rpx;
  361. // font-size: 24rpx;
  362. }
  363. }
  364. }
  365. .info-list {
  366. // background-color: red;
  367. margin-top: 20rpx;
  368. width: calc(100vw - 40rpx);
  369. .item {
  370. background: #fff;
  371. border-radius: 20rpx;
  372. margin-bottom: 20rpx;
  373. display: flex;
  374. padding: 20rpx;
  375. box-sizing: border-box;
  376. .img {
  377. width: 160rpx;
  378. height: 160rpx;
  379. border-radius: 30rpx;
  380. }
  381. .right {
  382. margin-left: 20rpx;
  383. width: 100%;
  384. .title {
  385. font-weight: 700;
  386. }
  387. .row2 {
  388. display: flex;
  389. margin-top: 10rpx;
  390. .label {
  391. background: #fdf6ec;
  392. color: #f9ae3d;
  393. border-radius: 20rpx;
  394. padding: 6rpx 16rpx;
  395. font-size: 24rpx;
  396. margin-right: 20rpx;
  397. }
  398. }
  399. .row3 {
  400. position: relative;
  401. display: flex;
  402. width: 100%;
  403. margin-top: 10rpx;
  404. align-items: top;
  405. .detailedAddress {
  406. width: 60vw;
  407. overflow: hidden;
  408. text-overflow: ellipsis;
  409. }
  410. }
  411. }
  412. }
  413. }
  414. </style>