123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- import * as API from '@/apis/route.js'
- import * as API_index from '@/apis/index.js'
- import * as WxJsApi from '@/utils/wxJsApi.js'
-
- import Carmap from '@/components/Carmap.vue'
- export default {
- data() {
- return {
- wxinit:false,
- mapopen:false,
- initBl: false,
- title: '乘车人',
- show: false,
- id: 0, // 使用 marker点击事件 需要填写id
- upid:'',
- downid:'',
- downItem:{},
- //地图居中后的位置
- longitude: 112.276527,
- latitude: 30.306427,
- shiftInfo: {
- },
- remindList:[],
- list: [{}, {}],
- carList:[],
- caritem:{
- driverInfo:{}
- },
- caritemBl:false,
- stationList: [],
-
- //个人
- info: {
- obj: null,
- init: false,
- longitude: '',
- latitude: '',
- },
- reverseInit:false,
- myinterval: '',
- routeInfo:{},
- radiolist: [
- {
- name: '不提醒',
- isRemind: "0",
- },
- {
- name: '提前1站',
- isRemind: "1",
- },
- {
- name: '提前2站',
- isRemind: "2",
- }
- ]
- }
- },
- components: {
- Carmap
- },
- methods: {
- radioGroupChange(){
- var item= this.downItem
-
- if(item.isRemind==0){
- if(this.downItem.remindId){
- this.del(item.remindId,item.isRemind!=0)
- }
- return
- }
- if(item.remindId){
- this.del(item.remindId,item.isRemind!=0)
- }else{
- this.remindAdd()
- }
-
- },del(id,bl){
- API_index.cancelRemind(id).then((res) => {
- this.downItem.remindId=""
- if(bl){
- this.remindAdd()
- }else{
- this.$refs.common.alert( "设置成功");
- }
- }).catch(error => {
- this.$refs.common.alert( error);
- })
- },
-
- remind(){
- var myBtn = document.getElementById("subscribe-btn").tap();
- myBtn.tap();
- },
- showCar(item){
- for(var i in this.carList){
- var car= this.carList[i]
- if(car.currentStationId==item.id){
- return true;
- }
- }
- return false;
- },
- getCar(){
- if(this.stationList.length==0){
- return;
- }
- var obj={
- routeId:this.id,
- startStationId:this.stationList[0].id,
- }
- API.routeShiftList(obj).then((response) => {
- this.carList=response.data;
- this.$refs.amap.setCarList(response.data);
-
- }).catch(error => {
- this.$refs.common.showLoading(false,error)
- })
- },
- mapopenBtn(){
- this.mapopen=!this.mapopen;
- if(this.mapopen){
- this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
- }else{
- this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
-
- }
- },
- downBtn(item) {
- this.$refs.amap.setSite(item);
- this.$refs.amap.setCenter(item);
- this.downid=item.id;
- this.downItem=item;
- this.$forceUpdate()
- },
- remindAdd(){
- if(this.downItem.id){
-
- var obj={
- startStationId:this.stationList[0].id,
- remindStationId :this.downItem.id,
- stopInAdvance:this.downItem.isRemind,
- remindType:"1",
- vehicleShiftId:this.routeInfo.id,
- openId:this.carhelp.getOpenId()
- }
- API_index.saveRemind(obj).then((res) => {
- this.downItem.remindId=res.data.id
- this.$refs.common.alert( "设置成功");
-
- }).catch(error => {
- this.$refs.common.alert( error);
- })
- }
- },
- drawing(point, startend) {
- if (this.$refs.amap) {
- this.$refs.amap.initMap(point, this.stationList,startend);
- }
- },
- carShow(item){
-
- var caritem =null;
- for(var i in this.carList){
- var car= this.carList[i]
- if(car.currentStationId==item.id){
- var caritem=car;
- break
- }
- }
- this.caritem=caritem;
- this.caritemBl=true;
-
-
- },
- reverse(){
-
- this.stationList.reverse();
- this.getCar()
- this.passengerShiftRemindList();
-
- this.$refs.amap.setStartend(this.stationList);
- document.getElementById('map-route-main').scrollLeft = 0
- this.$nextTick(function() {
- const query = uni.createSelectorQuery().in(this);
- query.select('.map-down').boundingClientRect(data => {
- if(data){
- document.getElementById('map-route-main').scrollLeft = data.left-20;
- }
- this.$refs.common.showLoading(false);
- //this.downBtn()
- }).exec();
- });
-
- },
- setRemind(){
- for(var i in this.stationList){
- var item=this.stationList[i];
- item.isRemind=0;
- item.remindId="";
- for(var j in this.remindList){
- var obj=this.remindList[j];
- if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
- if(obj.remindStationId==item.id){
- item.remindId=obj.id;
- item.isRemind=obj.stopInAdvance;
- }
- }
- }
-
- }
- this.$forceUpdate()
- },
- passengerShiftRemindList(){
- this.$refs.common.showLoading()
- API.passengerShiftRemindList({
- shiftId:this.id,
- openId:this.carhelp.getOpenId(),
- }).then((response) => {
- this.remindList=response.data;
- this.setRemind();
- this.$refs.common.showLoading(false)
- })
- },
- getPassengerInfo() {
-
- this.$refs.common.showLoading()
-
- API.routeDetail(this.id).then((response) => {
-
- var list=response.data.stationInfoList;
- if(this.upid&&list.length){
-
- if(this.upid==list[list.length-1].id){
- list.reverse();
- }
- this.upid="";
- }
- this.stationList=list;
- for(var i in list){
- list[i].isRemind=0;
- if(list[i].id==this.downid){
- this.downItem=list[i];
- }
- }
- this.passengerShiftRemindList();
-
- this.$refs.common.showLoading(false)
-
- var point = [];
- this.routeInfo=response.data.routeInfo;
- this.title=this.routeInfo.name;
- if(!response.data.routeInfo.mapPath){
- this.$refs.common.showLoading(false,"路线加载失败!")
- return;
- }
- response.data.routeInfo.mapPath.split("|").forEach((item) => {
- var sz = item.split(",");
-
- point.push({
- longitude: sz[0],
- latitude: sz[1],
- })
- })
- var startend = [{
- longitude: this.stationList[0].longitude,
- latitude: this.stationList[0].latitude,
- name: this.stationList[0].name
- }, {
- longitude: this.stationList[this.stationList.length-1].longitude,
- latitude: this.stationList[this.stationList.length-1].latitude,
- name: this.stationList[this.stationList.length-1].name
- }];
-
- this.drawing(point,startend);
- this.$refs.common.showLoading(false)
-
- this.getPoint()
-
- this.$nextTick(function() {
- const query = uni.createSelectorQuery().in(this);
- query.select('.map-down').boundingClientRect(data => {
- if(data){
- document.getElementById('map-route-main').scrollLeft = data.left-20;
- }
- this.$refs.common.showLoading(false);
- //this.downBtn()
- }).exec();
- });
-
- }).catch(error => {
- this.$refs.common.showLoading(false,error)
- })
- },
- mapdown(){
-
- if(this.downid){
- this.downBtn(this.downItem)
- }
-
- },
- getPoint() {
-
-
- if (!this.info.init) {
- WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
- // this.$refs.common.showLoading(false)
- this.getLocation()
- });
- }else{
- this.getLocation()
- }
- this.getCar();
- var pages = getCurrentPages();
- var page = (pages[pages.length - 1]).route;
- if (page == "pages/route/index") {
- setTimeout(this.getPoint, 10000);
- }
- },
- getLocation(){
- WxJsApi.getLocation().then((res) => {
- console.log("----getLocation ok-----")
- var latitude = parseFloat(res.latitude);
- var longitude = parseFloat(res.longitude);
-
- if (!this.info.init) {
- this.latitude = latitude;
- this.longitude = longitude;
- }
- this.info.init = true
- this.info.latitude = latitude;
- this.info.longitude = longitude;
-
- this.$refs.amap.setPerson(this.info);
-
- }).catch(error => {
- console.log(error)
- })
- }
- },
- onLoad(op) {
- this.upid=op.upid;
- this.id = op.id
- this.downid=op.downid;
- },
- onUnload() {
- if (this.myinterval) {
- clearInterval(this.myinterval)
- }
- },
- onReady() {
- WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
- // this.$refs.common.showLoading(false)
- this.wxinit=true;
-
-
- });
-
- this.getPassengerInfo()
-
- }
- }
|