website.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. import wx from 'weixin-js-sdk'
  58. export default {
  59. data() {
  60. return {
  61. center_lat: '',
  62. center_lng: '',
  63. lat: '',
  64. lng: '',
  65. pageNum: 1,
  66. loadStatus: 0,
  67. dataList: [],
  68. isCloseList: false,
  69. markers: [],
  70. includePoints: []
  71. }
  72. },
  73. async onLoad() {
  74. await this.getLocation()
  75. this.getList()
  76. },
  77. methods: {
  78. // 获取位置
  79. async getLocation() {
  80. var { latitude, longitude } = await this.$getLocation()
  81. this.lat = latitude
  82. this.lng = longitude
  83. this.center_lat = latitude
  84. this.center_lng = longitude
  85. this.markers = [
  86. {
  87. id: 0,
  88. latitude: latitude,
  89. longitude: longitude,
  90. title: '我的位置',
  91. iconPath: '/static/icon/location1.png',
  92. width: 30,
  93. height: 30
  94. }
  95. ]
  96. return { latitude, longitude }
  97. },
  98. getList() {
  99. this.loadStatus = 1
  100. this.$api
  101. .get('/user/apply/websit', {
  102. lat: this.lat,
  103. lng: this.lng,
  104. examineStatus: 'OK'
  105. })
  106. .then(res => {
  107. res.data.forEach(item => {
  108. item.lat = Number(item.lat)
  109. item.lng = Number(item.lng)
  110. })
  111. this.loadStatus = 0
  112. let list = res.data
  113. this.dataList = list
  114. let markers = list.map((item, index) => {
  115. return {
  116. id: index + 1,
  117. latitude: item.lat,
  118. longitude: item.lng,
  119. title: item.name,
  120. iconPath: '/static/icon/location2.png',
  121. width: 40,
  122. height: 40
  123. }
  124. })
  125. this.markers = this.markers.concat(markers)
  126. this.includePoints = this.markers.slice(0, 1).concat(markers.slice(0, 5))
  127. })
  128. },
  129. call(item) {
  130. uni.makePhoneCall({
  131. phoneNumber: item.linkPhone
  132. })
  133. },
  134. nav(item) {
  135. uni.openLocation({
  136. latitude: item.lat,
  137. longitude: item.lng,
  138. name: item.name,
  139. address: item.address,
  140. success: res => {
  141. console.log('success')
  142. }
  143. })
  144. },
  145. setDefault(item) {
  146. this.$api
  147. .post('/user/default/websit', {
  148. websitId: item.websitId
  149. })
  150. .then(res => {
  151. this.$successToast()
  152. this.getList()
  153. })
  154. },
  155. changeCloseList() {
  156. this.isCloseList = !this.isCloseList
  157. this.center_lat = this.lat
  158. this.center_lng = this.lng
  159. },
  160. changeMapCenter(item) {
  161. this.center_lat = item.lat
  162. this.center_lng = item.lng
  163. },
  164. tapMarker(e) {
  165. // uni.createSelectorQuery().select(".item_"+e.detail.markerId).boundingClientRect((res)=>{
  166. // console.log(res)
  167. //    }).exec()
  168. },
  169. chooseWebsit(item) {
  170. this.crossPage.$emit('chooseMaterialApplyWebsit', item, 'H5')
  171. this.$navToPage(
  172. {
  173. delta: 1
  174. },
  175. 'navigateBack'
  176. )
  177. }
  178. }
  179. }
  180. </script>
  181. <style scoped lang="scss">
  182. .app-container {
  183. background: #f4f2f2;
  184. }
  185. .map-container {
  186. width: 100%;
  187. height: 45vh;
  188. &.close {
  189. height: 100vh;
  190. }
  191. }
  192. .list-container {
  193. position: fixed;
  194. bottom: 0;
  195. left: 0;
  196. z-index: 999;
  197. width: 100%;
  198. transition: all 0.5s;
  199. .switch {
  200. display: flex;
  201. justify-content: center;
  202. .icon {
  203. background: #ffffff;
  204. padding: 10rpx 40rpx 0;
  205. border-radius: 20rpx 20rpx 0 0;
  206. image {
  207. width: 14rpx;
  208. height: 28rpx;
  209. display: block;
  210. transform: rotate(90deg);
  211. }
  212. }
  213. }
  214. &.close {
  215. bottom: calc(-60vh + 40rpx);
  216. .switch {
  217. image {
  218. transform: rotate(-90deg);
  219. }
  220. }
  221. }
  222. .list {
  223. padding: 40rpx 20rpx 0;
  224. box-sizing: border-box;
  225. background: #ffffff;
  226. height: 60vh;
  227. border-radius: 40rpx 40rpx 0 0;
  228. }
  229. .scroll-view {
  230. height: 100%;
  231. }
  232. .item {
  233. padding: 20rpx;
  234. border-bottom: 1px solid #eaeaea;
  235. display: flex;
  236. justify-content: space-between;
  237. &:first-child {
  238. padding-top: 0;
  239. }
  240. .left {
  241. flex: 1;
  242. .name {
  243. color: #333333;
  244. font-size: 30rpx;
  245. font-weight: 500;
  246. margin-bottom: 8rpx;
  247. }
  248. .row {
  249. font-size: 26rpx;
  250. color: #999999;
  251. margin-top: 12rpx;
  252. }
  253. }
  254. .right {
  255. flex-shrink: 0;
  256. margin-left: 30rpx;
  257. display: flex;
  258. flex-direction: column;
  259. align-items: flex-end;
  260. ::v-deep .u-button {
  261. &:first-child {
  262. color: #f9ae3d;
  263. }
  264. &:last-child {
  265. margin-top: 20rpx;
  266. }
  267. }
  268. }
  269. }
  270. }
  271. </style>