website.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="app-container">
  3. <map
  4. class="map-container"
  5. :class="isCloseList ? 'close' : ''"
  6. :latitude="center_lat"
  7. :longitude="center_lng"
  8. :markers="markers"
  9. :include-points="includePoints"
  10. @markertap="tapMarker"
  11. >
  12. </map>
  13. <view class="list-container" :class="isCloseList ? 'close' : ''">
  14. <view class="switch">
  15. <view class="icon" @tap="changeCloseList">
  16. <image src="/static/icon/right.png" mode=""></image>
  17. </view>
  18. </view>
  19. <view class="list">
  20. <scroll-view scroll-y show-scrollbar scroll-with-animation class="scroll-view">
  21. <view
  22. class="item"
  23. :class="'item_' + (index + 1)"
  24. v-for="(item, index) in dataList"
  25. :key="index"
  26. @tap="chooseWebsit(item)"
  27. >
  28. <view class="left" @tap="changeMapCenter(item)">
  29. <view class="name">{{ item.name }}</view>
  30. <view class="row">联系电话:{{ item.websitPhone || '' }}</view>
  31. <view class="row">联系地址:{{ item.address || '' }}</view>
  32. </view>
  33. <view class="right" @tap.stop>
  34. <u-button
  35. size="small"
  36. plain
  37. type="warning"
  38. :text="'距离' + (item.distance / 1000).toFixed(2) + 'km'"
  39. @click="nav(item)"
  40. ></u-button>
  41. <u-button
  42. size="small"
  43. type="primary"
  44. text="设为默认"
  45. :disabled="item.isDefaultWebsit"
  46. @click="setDefault(item)"
  47. ></u-button>
  48. </view>
  49. </view>
  50. <Loading :type="2" :loadStatus="loadStatus" :dataList="dataList" />
  51. </scroll-view>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. center_lat: '',
  61. center_lng: '',
  62. lat: '',
  63. lng: '',
  64. pageNum: 1,
  65. loadStatus: 0,
  66. dataList: [],
  67. isCloseList: false,
  68. markers: [],
  69. includePoints: []
  70. }
  71. },
  72. async onLoad() {
  73. await this.getLocation()
  74. this.getList()
  75. },
  76. methods: {
  77. // 获取位置
  78. async getLocation() {
  79. return await new Promise((resolve, reject) => {
  80. uni.getLocation({
  81. type: 'gcj02',
  82. isHighAccuracy: true,
  83. geocode: true,
  84. success: res => {
  85. console.log(res)
  86. this.lat = res.latitude
  87. this.lng = res.longitude
  88. this.center_lat = res.latitude
  89. this.center_lng = res.longitude
  90. this.markers = [
  91. {
  92. id: 0,
  93. latitude: res.latitude,
  94. longitude: res.longitude,
  95. title: '我的位置',
  96. iconPath: '/static/icon/location1.png',
  97. width: 30,
  98. height: 30
  99. }
  100. ]
  101. resolve(res)
  102. },
  103. fail: res => {
  104. reject(0)
  105. }
  106. })
  107. })
  108. },
  109. getList() {
  110. this.loadStatus = 1
  111. this.$api
  112. .get('/user/apply/websit', {
  113. lat: this.lat,
  114. lng: this.lng
  115. })
  116. .then(res => {
  117. res.data.forEach(item => {
  118. item.lat = Number(item.lat)
  119. item.lng = Number(item.lng)
  120. })
  121. this.loadStatus = 0
  122. let list = res.data
  123. this.dataList = list
  124. let markers = list.map((item, index) => {
  125. return {
  126. id: index + 1,
  127. latitude: item.lat,
  128. longitude: item.lng,
  129. title: item.name,
  130. iconPath: '/static/icon/location2.png',
  131. width: 40,
  132. height: 40
  133. }
  134. })
  135. this.markers = this.markers.concat(markers)
  136. this.includePoints = this.markers.slice(0, 1).concat(markers.slice(0, 5))
  137. })
  138. },
  139. call(item) {
  140. uni.makePhoneCall({
  141. phoneNumber: item.linkPhone
  142. })
  143. },
  144. nav(item) {
  145. uni.openLocation({
  146. latitude: item.lat,
  147. longitude: item.lng,
  148. name: item.name,
  149. address: item.address,
  150. success: res => {
  151. console.log('success')
  152. }
  153. })
  154. },
  155. setDefault(item) {
  156. this.$api
  157. .post('/user/default/websit', {
  158. websitId: item.websitId
  159. })
  160. .then(res => {
  161. this.$successToast()
  162. this.getList()
  163. })
  164. },
  165. changeCloseList() {
  166. this.isCloseList = !this.isCloseList
  167. this.center_lat = this.lat
  168. this.center_lng = this.lng
  169. },
  170. changeMapCenter(item) {
  171. this.center_lat = item.lat
  172. this.center_lng = item.lng
  173. },
  174. tapMarker(e) {
  175. // uni.createSelectorQuery().select(".item_"+e.detail.markerId).boundingClientRect((res)=>{
  176. // console.log(res)
  177. //    }).exec()
  178. },
  179. chooseWebsit(item) {
  180. this.crossPage.$emit('chooseMaterialApplyWebsit', item, 'H5')
  181. this.$navToPage(
  182. {
  183. delta: 1
  184. },
  185. 'navigateBack'
  186. )
  187. }
  188. }
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. .app-container {
  193. background: #f4f2f2;
  194. }
  195. .map-container {
  196. width: 100%;
  197. height: 45vh;
  198. &.close {
  199. height: 100vh;
  200. }
  201. }
  202. .list-container {
  203. position: fixed;
  204. bottom: 0;
  205. left: 0;
  206. z-index: 999;
  207. width: 100%;
  208. transition: all 0.5s;
  209. .switch {
  210. display: flex;
  211. justify-content: center;
  212. .icon {
  213. background: #ffffff;
  214. padding: 10rpx 40rpx 0;
  215. border-radius: 20rpx 20rpx 0 0;
  216. image {
  217. width: 14rpx;
  218. height: 28rpx;
  219. display: block;
  220. transform: rotate(90deg);
  221. }
  222. }
  223. }
  224. &.close {
  225. bottom: calc(-60vh + 40rpx);
  226. .switch {
  227. image {
  228. transform: rotate(-90deg);
  229. }
  230. }
  231. }
  232. .list {
  233. padding: 40rpx 20rpx 0;
  234. box-sizing: border-box;
  235. background: #ffffff;
  236. height: 60vh;
  237. border-radius: 40rpx 40rpx 0 0;
  238. }
  239. .scroll-view {
  240. height: 100%;
  241. }
  242. .item {
  243. padding: 20rpx;
  244. border-bottom: 1px solid #eaeaea;
  245. display: flex;
  246. justify-content: space-between;
  247. &:first-child {
  248. padding-top: 0;
  249. }
  250. .left {
  251. flex: 1;
  252. .name {
  253. color: #333333;
  254. font-size: 30rpx;
  255. font-weight: 500;
  256. margin-bottom: 8rpx;
  257. }
  258. .row {
  259. font-size: 26rpx;
  260. color: #999999;
  261. margin-top: 12rpx;
  262. }
  263. }
  264. .right {
  265. flex-shrink: 0;
  266. margin-left: 30rpx;
  267. display: flex;
  268. flex-direction: column;
  269. align-items: flex-end;
  270. ::v-deep .u-button {
  271. &:first-child {
  272. color: #f9ae3d;
  273. }
  274. &:last-child {
  275. margin-top: 20rpx;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. </style>