index.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view :class="[index==0?'flex flex-column vh100 w100':'']">
  3. <view :class="[tabList.length>1?'u-flex-2':'u-flex-2','bg-white w100']" :style="'padding-top:'+height+'px;'">
  4. <view class="plr-36 flex">
  5. <view class="img-pic" @click="toMy">
  6. <image :src="token?'../../static/home-online.png':'../../static/home-offline.png'" mode=""></image>
  7. </view>
  8. <view class="img-logo">
  9. <image src="../../static/logo-title.png" mode=""></image>
  10. </view>
  11. <view class="" style="width: 76rpx;"></view>
  12. </view>
  13. <u-tabs :list="tabList" font-size="32" bg-color="#fff" height="90" active-color="#00C28E"
  14. inactive-color="#777" :is-scroll="false" :current="index" @change="change">
  15. </u-tabs>
  16. </view>
  17. <view class="u-flex-7 w100" v-show="current==0" style="height:10%">
  18. <map id="map" style="width: 100%; height: 100%;position: relative;" :latitude="latitude0"
  19. :longitude="longitude0" :markers="covers" :polyline="polyline" @regionchange="getCenterMap">
  20. <cover-image @click="toDetail" v-if="list.length>0&&list[0].status==0" class=""
  21. style="width: 100%;height: 80rpx;position: absolute;bottom: 20rpx;left: 0rpx;"
  22. src="../../static/home-1.png"></cover-image>
  23. <cover-image @click="toDetail" v-if="list.length>0&&(list[0].status==1||list[0].status==5)" class=""
  24. style="width: 100%;height: 80rpx;position: absolute;bottom: 20rpx;left: 0rpx;"
  25. src="../../static/home-2.png"></cover-image>
  26. <cover-image @click="toDetail" v-if="list.length>0&&list[0].status==4" class=""
  27. style="width: 100%;height: 80rpx;position: absolute;bottom: 20rpx;left: 0rpx;"
  28. src="../../static/home-3.png"></cover-image>
  29. <cover-image @click="toDetail" v-if="list.length>0&&list[0].status==2" class=""
  30. style="width: 100%;height: 80rpx;position: absolute;bottom: 20rpx;left: 0rpx;"
  31. src="../../static/home-4.png"></cover-image>
  32. <cover-image @click="toDetail" v-if="list.length>0&&list[0].status==3" class=""
  33. style="width: 100%;height: 80rpx;position: absolute;bottom: 20rpx;left: 0rpx;"
  34. src="../../static/home-5.png"></cover-image>
  35. <cover-view v-if="showTime" @click="showTime=false"
  36. style="width: 100%;height: 100%;background-color: rgba(0,0,0,.7);"></cover-view>
  37. <cover-image @click="goCenter" class=""
  38. style="width:100rpx;height: 100rpx;position: absolute;bottom: 120rpx;right: 10rpx;"
  39. src="../../static/now1.png"></cover-image>
  40. </map>
  41. </view>
  42. <view class="u-flex-7 w100" v-show="current==0">
  43. <indexAddress :location="longitude+','+latitude" @close="showTime=false" @showTime="showTime=true"
  44. :other="other" :showTime="showTime" :city="city"></indexAddress>
  45. </view>
  46. <sfindex v-show="current==1" class="w100"></sfindex>
  47. <hyindex v-show="current==2" :hylist="hylist" class="w100"></hyindex>
  48. </view>
  49. </template>
  50. <script>
  51. import amapFile from '../../libs/amap-wx.js'
  52. import Voice from '@/components/baidu.js';
  53. import {
  54. mapState
  55. } from 'vuex'
  56. export default {
  57. data() {
  58. return {
  59. index: 0,
  60. current: '',
  61. timer3: null,
  62. other: {},
  63. list: [],
  64. hylist: [],
  65. timer: null,
  66. showTime: false,
  67. amapPlugin: null,
  68. key: 'bb6f4ed802756f963b37c184ce4e9766',
  69. latitude: '',
  70. longitude: '',
  71. latitude1: '', //打开地图时的中心点
  72. longitude1: '', //打开地图时的中心点
  73. latitude0: "",
  74. longitude0: "",
  75. polyline: [],
  76. mapContext: null,
  77. appMap: null,
  78. scale: "16",
  79. driverCovers: {}
  80. }
  81. },
  82. computed: {
  83. ...mapState(["city","height","start","tabList","token"]),
  84. covers() {
  85. return [{
  86. id: 0,
  87. latitude: this.latitude,
  88. longitude: this.longitude,
  89. // #ifdef MP-WEIXIN
  90. iconPath: '../../static/now.png',
  91. // #endif
  92. // #ifndef MP-WEIXIN
  93. iconPath: '../../static/now2.png',
  94. // #endif
  95. title: '当前位置',
  96. width: 30,
  97. height: 45
  98. }]
  99. }
  100. },
  101. //分享
  102. onShareAppMessage(res) {
  103. if (res.from === 'button') { // 来自页面内分享按钮
  104. console.log(res.target)
  105. }
  106. return {
  107. }
  108. },
  109. onShareTimeline(res) {
  110. console.log(111111111);
  111. return {}
  112. },
  113. onReady() {
  114. this.mapContext = uni.createMapContext('map')
  115. },
  116. onLoad(option) {
  117. this.getpush()
  118. this.timer3 = setInterval(() => {
  119. if (this.tabList && this.tabList[0]) {
  120. this.current = this.tabList[0].id
  121. clearInterval(this.timer3)
  122. this.timer3 = null
  123. }
  124. }, 200)
  125. // 定位
  126. this.amapPlugin = new amapFile.AMapWX({
  127. key: this.key
  128. });
  129. uni.$on('other', (data) => {
  130. this.other = data
  131. })
  132. },
  133. onHide() {
  134. clearInterval(this.timer)
  135. this.timer = null
  136. },
  137. onUnload() {
  138. uni.$off('other')
  139. clearInterval(this.timer)
  140. this.timer = null
  141. },
  142. onShow() {
  143. this.getRegeo()
  144. this.timer = setInterval(() => {
  145. this.getList()
  146. }, 3000)
  147. },
  148. methods: {
  149. getpush: function() {
  150. },
  151. getCenterMap() {
  152. let _this = this
  153. // #ifdef MP-WEIXIN
  154. this.mapContext.getCenterLocation({
  155. success: (res) => {
  156. console.log(res);
  157. if (res.longitude != 0) {
  158. _this.longitude = res.longitude
  159. _this.latitude = res.latitude
  160. _this.mapContext.translateMarker({
  161. markerId: 0,
  162. destination: {
  163. longitude: res.longitude,
  164. latitude: res.latitude
  165. },
  166. duration: 1000,
  167. animationEnd() {
  168. //console.log(111111);
  169. }
  170. })
  171. _this.amapPlugin.getRegeo({
  172. location: res.longitude + ',' + res.latitude,
  173. success(data) {
  174. //console.log(data);
  175. let city;
  176. if (!_this.city) {
  177. if (typeof data[0].regeocodeData.addressComponent.city ==
  178. 'object') {
  179. city = data[0].regeocodeData.addressComponent.province
  180. } else {
  181. city = data[0].regeocodeData.addressComponent.city
  182. }
  183. }
  184. let start = {
  185. city: city,
  186. latitude: data[0].latitude,
  187. longitude: data[0].longitude,
  188. address: data[0].name,
  189. name: data[0].desc,
  190. flag: true
  191. }
  192. _this.$store.commit('getStart', start)
  193. }
  194. })
  195. }
  196. }
  197. })
  198. // #endif
  199. },
  200. goCenter() {
  201. this.mapContext.moveToLocation({
  202. longitude: this.longitude1,
  203. latitude: this.latitude1,
  204. longitude0: this.longitude1,
  205. latitude0: this.latitude1,
  206. success() {
  207. //console.log(11111111);
  208. }
  209. })
  210. },
  211. getList() {
  212. this.$http('/addons/ddrive/order/order_taking', {}, "POST").then(data => {
  213. this.list = data.data
  214. this.hylist = data.hy
  215. })
  216. },
  217. toDetail() {
  218. if (this.list.length == 1) {
  219. uni.navigateTo({
  220. url: '/pages/home/detail?id=' + this.list[0].id
  221. })
  222. } else {
  223. uni.navigateTo({
  224. url: '/pages/my/order/dj-order'
  225. })
  226. }
  227. },
  228. toAnquan() {
  229. uni.navigateTo({
  230. url: '/pages/home/security'
  231. })
  232. },
  233. change(index) {
  234. this.index = index;
  235. this.current = this.tabList[index].id;
  236. if (this.current == 2) {
  237. uni.$emit('price')
  238. }
  239. },
  240. toMy() {
  241. if (this.token) {
  242. uni.navigateTo({
  243. url: '/pages/my/index'
  244. })
  245. } else {
  246. uni.navigateTo({
  247. url: '/pages/login/login'
  248. })
  249. }
  250. },
  251. // 获取定位
  252. getRegeo() {
  253. let _this = this
  254. uni.showLoading({
  255. title: '获取定位信息中'
  256. });
  257. this.amapPlugin.getRegeo({
  258. success: (data) => {
  259. let city;
  260. if (!_this.city) {
  261. if (typeof data[0].regeocodeData.addressComponent.city == 'object') {
  262. city = data[0].regeocodeData.addressComponent.province
  263. } else {
  264. city = data[0].regeocodeData.addressComponent.city
  265. }
  266. _this.$store.commit('getCity', city)
  267. }
  268. _this.latitude = data[0].latitude
  269. _this.longitude = data[0].longitude
  270. _this.latitude1 = data[0].latitude
  271. _this.longitude1 = data[0].longitude
  272. _this.latitude0 = data[0].latitude
  273. _this.longitude0 = data[0].longitude
  274. if (!_this.start.name) {
  275. let start = {
  276. city: city,
  277. latitude: data[0].latitude,
  278. longitude: data[0].longitude,
  279. address: data[0].name,
  280. name: data[0].desc,
  281. flag: true
  282. }
  283. _this.$store.commit('getStart', start)
  284. }
  285. uni.hideLoading();
  286. },
  287. fail: (msg) => {
  288. uni.showToast({
  289. title: '没有开启位置权限',
  290. icon: 'none'
  291. })
  292. }
  293. });
  294. },
  295. }
  296. }
  297. </script>
  298. <style lang="scss" scoped>
  299. .img-pic {
  300. image {
  301. width: 76rpx;
  302. height: 76rpx;
  303. }
  304. }
  305. .img-logo {
  306. image {
  307. width: 168rpx;
  308. height: 42rpx;
  309. }
  310. }
  311. </style>