{"ast":null,"code":"import { getAppointFun } from '@/utils/appointTime';\nimport { serverList } from '@/utils/serverMap';\nimport { getClientPhone } from '@/api/order';\nimport tabBar from \"@/components/tabBar\";\nimport BottomItem from '@/components/bottomItem';\nimport AttentionItem from '@/components/attentionItem';\nimport commonBtn from \"@/components/commonBtn\";\nimport { getLocal, getAddress } from '@/utils/map';\nimport { myMixins } from '@/utils/myMixins.js';\nexport default {\n name: \"Home\",\n mixins: [myMixins],\n data() {\n return {\n map: '',\n location: [],\n locationAddress: '',\n activeTab: 0,\n serverList: serverList,\n radio: '',\n show: false,\n // 预约时间弹框\n form: {\n startLat: '',\n startLng: '',\n startPoiAddress: '',\n endLat: '',\n endLng: '',\n endPoiAddress: '',\n isAppoint: 0,\n appointTime: '',\n positionEnvironment: ''\n },\n marker: null,\n destMarker: null,\n columns: []\n };\n },\n components: {\n BottomItem,\n tabBar,\n AttentionItem,\n commonBtn\n },\n async mounted() {\n if (this.$route.query.appCode) {\n localStorage.setItem('appCode', this.$route.query.appCode);\n }\n this.getClientHandler();\n console.log('process.env.VUE_APP_BASE_API', process.env.NODE_ENV);\n await this.initMap(); // 初始化地图\n this.columns = getAppointFun(new Date()); // 获取预约时间 picker\n await this.initData();\n if (!(this.form && this.form.startPoiAddress)) {\n await this.setLocalInfo();\n }\n this.addMarker();\n },\n async beforeDestroy() {\n await this.saveAddress();\n await this.saveDestAddress();\n await this.setOrder();\n },\n methods: {\n // 事发地 marker\n addMarker() {\n if (this.marker) {\n this.map.remove(this.marker);\n }\n let content = '
';\n this.marker = new AMap.Marker({\n position: new AMap.LngLat(this.form.startLng, this.form.startLat),\n content: content,\n offset: new AMap.Pixel(-13, -30)\n });\n this.map.add(this.marker);\n },\n // 目的地 marker\n addDestMarker() {\n if (this.destMarker) {\n this.map.remove(this.destMarker);\n }\n let content = '';\n this.marker = new AMap.Marker({\n position: new AMap.LngLat(this.form.endLng, this.form.endLat),\n content: content,\n offset: new AMap.Pixel(-13, -30)\n });\n this.map.add(this.destMarker);\n },\n async getClientHandler() {\n // 根据 appCode 获取客服电话\n let res = await getClientPhone({\n appCode: localStorage.getItem('appCode')\n });\n let client = res?.phone || '4009201995';\n localStorage.setItem('client', client);\n },\n async initData() {\n const order = this.$store.getters.order;\n console.log('order', order);\n await this.initOrderInfo();\n await this.initAddress();\n await this.initDestAddress();\n },\n // 设置 表单除地址外的信息\n initOrderInfo() {\n const orderInfo = this.$store.getters.order.orderInfo;\n this.form.isAppoint = orderInfo && orderInfo.isAppoint || 0;\n this.form.appointTime = orderInfo && orderInfo.appointTime || '';\n this.form.positionEnvironment = orderInfo && orderInfo.positionEnvironment || '';\n this.activeTab = orderInfo && orderInfo.activeTab || 0;\n },\n // 设置事发地\n initAddress() {\n const address = this.$store.getters.order.address;\n const localAddress = this.$store.getters.order.localAddress;\n this.form.startPoiAddress = address && address.startPoiAddress || localAddress && localAddress.startPoiAddress;\n this.form.startLat = address && address.startLat || localAddress && localAddress.startLat;\n this.form.startLng = address && address.startLng || localAddress && localAddress.startLng;\n },\n // 设置目的地\n initDestAddress() {\n const destAddress = this.$store.getters.order.destAddress;\n if (this.serverList[this.activeTab].serverId == 1041) {\n this.form.endPoiAddress = destAddress && destAddress.endPoiAddress || '';\n this.form.endLat = destAddress && destAddress.endLat || '';\n this.form.endLng = destAddress && destAddress.endLng || '';\n } else {\n this.form.endPoiAddress = '';\n this.form.endLat = '';\n this.form.endLng = '';\n }\n },\n // 保存事发地地址\n async saveAddress() {\n await this.$store.dispatch('order/setAddress', {\n startPoiAddress: this.form.startPoiAddress,\n startLat: this.form.startLat,\n startLng: this.form.startLng\n });\n },\n // 保存目的地地址\n async saveDestAddress() {\n if (this.serverList[this.activeTab].serverId == 1041) {\n await this.$store.dispatch('order/setDestAddress', {\n endPoiAddress: this.form.endPoiAddress,\n endLat: this.form.endLat,\n endLng: this.form.endLng\n });\n }\n },\n // 保存下单信息\n async setOrder() {\n await this.$store.dispatch('order/setOrderInfo', {\n serviceId: this.serverList[this.activeTab].serverId,\n activeTab: this.activeTab,\n appointTime: this.form.appointTime,\n isAppoint: this.form.isAppoint,\n positionEnvironment: this.form.positionEnvironment\n });\n },\n // 保存定位地址\n async saveLocalAddress(obj) {\n await this.$store.dispatch('order/setLocalAddress', obj);\n },\n // 定位地址\n async setLocalInfo() {\n this.location = await getLocal(this.map); // 获取经纬度\n this.map.setCenter(this.location); // 设置地图中心点\n let tempAddress = await getAddress(this.map, this.location); // 设置定位\n this.form.startPoiAddress = tempAddress.regeocode.formattedAddress;\n this.form.startLng = this.location.lng;\n this.form.startLat = this.location.lat;\n // 设置当前服务的城市\n // let city = '';\n // city = tempAddress.regeocode.addressComponent.province + tempAddress.regeocode.addressComponent.city\n // this.$store.dispatch('order/setServerCity', city)\n // 设置定位信息\n let localObj = {\n address: this.form.startPoiAddress,\n lat: this.form.startLat,\n lng: this.form.startLng,\n localCityCode: tempAddress.regeocode.addressComponent.adcode\n };\n // 设置 当前定位位置信息\n await this.saveLocalAddress(localObj);\n // 初始化 设置事发地\n await this.saveAddress();\n },\n initMap() {\n // 初始化地图\n this.map = new AMap.Map('mapId', {\n viewMode: '2D',\n // 默认使用 2D 模式\n zoom: 11 //初始化地图层级\n });\n },\n\n async ownClickHandler() {\n // 将事发地,目的地,服务类型,车辆位置,预约时间存入,跳转到救援页\n if (!this.form.startPoiAddress) {\n this.$toast('请先选择事发地');\n return false;\n }\n if (this.serverList[this.activeTab].serverId == 1041 && !this.form.endPoiAddress) {\n this.$toast('请选择拖车目的地');\n return false;\n }\n if (!this.form.positionEnvironment) {\n this.$toast('请选择车辆位置');\n return false;\n }\n await this.saveAddress();\n await this.saveDestAddress();\n await this.setOrder();\n await this.goPage('rescuePage');\n },\n changeTabHandler(index) {\n //切换 tab\n this.activeTab = index;\n },\n appointHandler(value, index) {\n // 设置预约时间\n if (value[1] == '尽快到') {\n this.form.appointTime = '';\n this.form.isAppoint = 0;\n } else {\n this.form.appointTime = value[0] + \" \" + value[1];\n this.form.isAppoint = 1;\n }\n this.show = false;\n // this.$toast(`当前值:${value}, 当前索引:${index}`)\n }\n }\n};","map":{"version":3,"names":["getAppointFun","serverList","getClientPhone","tabBar","BottomItem","AttentionItem","commonBtn","getLocal","getAddress","myMixins","name","mixins","data","map","location","locationAddress","activeTab","radio","show","form","startLat","startLng","startPoiAddress","endLat","endLng","endPoiAddress","isAppoint","appointTime","positionEnvironment","marker","destMarker","columns","components","mounted","$route","query","appCode","localStorage","setItem","getClientHandler","console","log","process","env","NODE_ENV","initMap","Date","initData","setLocalInfo","addMarker","beforeDestroy","saveAddress","saveDestAddress","setOrder","methods","remove","content","AMap","Marker","position","LngLat","offset","Pixel","add","addDestMarker","res","getItem","client","phone","order","$store","getters","initOrderInfo","initAddress","initDestAddress","orderInfo","address","localAddress","destAddress","serverId","dispatch","serviceId","saveLocalAddress","obj","setCenter","tempAddress","regeocode","formattedAddress","lng","lat","localObj","localCityCode","addressComponent","adcode","Map","viewMode","zoom","ownClickHandler","$toast","goPage","changeTabHandler","index","appointHandler","value"],"sources":["src/views/index/index.vue"],"sourcesContent":["\r\n