123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- import * as WxJsApi from '@/utils/wxJsApi.js'
- import * as API from '@/apis/buytickets.js'
- import * as Pay from '@/apis/weixin.js'
- import {
- wxPayJs
- } from '@/utils/wxpay'
- import Carmap from '@/components/Carmap.vue'
- export default {
- data() {
- return {
- initBl: false,
- title: '乘车人',
- show: false,
- id: 0, // 使用 marker点击事件 需要填写id
- //地图居中后的位置
- longitude: 112.276527,
- latitude: 30.306427,
- shiftInfo: {
- },
- list: [{}, {}],
- //车的位置
- car: {
- obj: null,
- longitude: '',
- latitude: '',
- },
- stationList: [],
- //个人
- info: {
- obj: null,
- init: false,
- longitude: '',
- latitude: '',
- },
- myinterval: '',
- downId: '',
- downName: '',
- passengerInfo: {
- totalAmount: 0,
- id: '',
- list: []
- }
- }
- },
- components: {
- Carmap
- },
- methods: {
- gotoHome(){
- uni.switchTab({
- url: '/pages/index/index'
- });
- },
-
-
- select(op) {
- //passengerInfo
- var obj = this.carhelp.get("form");
- if (this.passengerInfo.id) {
- obj.mergeOrderId = this.passengerInfo.id;
- }
- if (op) {
- obj.op = op;
- this.carhelp.set("form", obj);
- uni.navigateTo({
- url: '/pages/buytickets/site?id=' + this.id
- })
- } else {
- obj.op = null;
- this.carhelp.set("form", obj);
- uni.navigateTo({
- url: '/pages/buytickets/index?id=' + this.id+'&back=true'
- })
- }
- },
- submit() {
- this.$refs.common.showLoading();
-
- console.log("Pay+"+new Date().getTime())
- Pay.wxpay(this.passengerInfo.id).then((response) => {
- if(!response.result){
- this.$refs.common.showLoading(false, response.message);
- return
- }
- var data = response.data
- var url = window.location.href.split("#")[0] + "/#/pages/buytickets/success";
- console.log("Pay+"+new Date().getTime())
-
- var obj = {
- ...data,
- url: url
- }
- wxPayJs(obj);
- }).catch(error => {
- this.$refs.common.showLoading(false, error);
- })
- },
- drawing(point, startend) {
- if (this.$refs.amap) {
- this.$refs.amap.initMap(point, this.stationList, startend);
- }
- },
- getShiftInfoResponse(response, response2) {
- this.$refs.common.showLoading();
- var res = response.data
- this.title = res.routeName;
- this.shiftInfo = res;
- this.car.latitude = res.latitude;
- this.car.longitude = res.longitude;
- var point = [];
- res.mapPath.split("|").forEach((item) => {
- var sz = item.split(",");
- point.push({
- longitude: sz[0],
- latitude: sz[1],
- })
- if (!process.car.SIMPLE_RUN) {
- this.longitude = sz[0]
- this.latitude = sz[1]
- }
- })
- var obj = this.carhelp.get("form")
- obj.getShiftInfo = response;
- obj.getVehicleStationInfo = response2;
- var list = obj.getVehicleStationInfo.data;
- for (var i in list) {
- list[i].status = 0;
- }
- this.stationList = list
- obj = this.carhelp.set("form", obj)
- var sz1 = response.data.startStationCoordinate.split("|")
- var sz2 = response.data.endStationCoordinate.split("|")
- var startend = [{
- longitude: sz1[0],
- latitude: sz1[1],
- name: response.data.startStation
- }, {
- longitude: sz2[0],
- latitude: sz2[1],
- name: response.data.endStation
- }];
- this.drawing(point, startend);
- //this.$refs.common.showLoading(false);
- this.getPoint()
- },
- getShiftInfo() {
- this.$refs.common.showLoading();
- var obj = this.carhelp.get("form")
- if (false&&obj.getShiftInfo && obj.getVehicleStationInfo) {
- this.stationList = obj.getVehicleStationInfo.data
- this.getShiftInfoResponse(obj.getShiftInfo, obj.getVehicleStationInfo);
- return;
- }
- API.getShiftInfo(this.id).then((response) => {
- if (!response.result) {
- this.$refs.common.goError(response.message)
- return
- }
- API.getVehicleStationInfo(this.id).then((response2) => {
- this.getShiftInfoResponse(response, response2);
- })
- }).catch(error => {
- this.$refs.common.showLoading(false, error);
- })
- },
- getPassengerInfo() {
-
-
- var thisform = {
- id: this.id,
- openId: this.carhelp.getOpenId()
- }
- this.$refs.common.showLoading()
- API.getPassengerInfo(thisform).then((response) => {
- if (!response.result) {
- this.$refs.common.goError(response.message)
- return
- }
- if (response.data.supply) {
- this.$refs.common.alert('存在需要补票的订单。')
-
- uni.switchTab({
- url: '/pages/news/index'
- });
- return;
- }
- this.passengerInfo = response.data
-
-
- var obj = this.carhelp.get("form");
- if(!obj){
- obj={}
- }
- obj.list = this.passengerInfo.list;
- obj.name= 'buytickets';
- obj.id= this.id;
- this.carhelp.set("form", obj);
- this.getShiftInfo()
-
-
- }).catch(error => {
- if (error) {
- this.$refs.common.goError(error)
- return
- }
- //this.$refs.common.showLoading(false,error)
- })
- },
- getPoint() {
- if (!this.initBl) {
- this.$refs.common.showLoading();
- }
- API.getVehicleInfo(this.id).then((response) => {
- this.car = response.data;
- this.$refs.amap.setCar(this.car);
- var bl = false;
- for (var i in this.stationList) {
- var stat = this.stationList[i];
- stat.status = 0
- if (bl) {
- stat.status = 2;
- }
- if (stat.id == this.car.currentStationId) {
- stat.status = 1;
- bl = true;
- }
- }
- if (!this.initBl) {
- this.initBl = true
- this.$nextTick(function() {
- const query = uni.createSelectorQuery().in(this);
- query.select('.map-now').boundingClientRect(data => {
- if (data) {
- document.getElementById('map-route-main').scrollLeft = data
- .left;
- }
- this.$refs.common.showLoading(false);
- }).exec();
- });
- } else {
- this.$refs.common.showLoading(false);
- }
- }).catch(error => {
- this.$refs.common.showLoading(false, error);
- })
- if (!this.info.init) {
- WxJsApi.getWxConfig(['getLocation']).then(() => {
- // this.$refs.common.showLoading(false)
- this.getLocation()
- });
- }else{
- this.getLocation()
- }
-
-
- var pages = getCurrentPages();
- var page = (pages[pages.length - 1]).route;
- if (page == "pages/buytickets/home") {
- 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.id = op.id
- },
- onUnload() {
- if (this.myinterval) {
- clearInterval(this.myinterval)
- }
- },
- onReady() {
- if (false&&!this.carhelp.getPersonInfo()) {
- this.$refs.common.setFnc(this.confirmBtn)
- this.$refs.common.alert2('您还不是东胜掌上通勤用户,注册后再购买车票。', '前往注册', '尚未注册')
- } else{
- }
- this.getPassengerInfo()
-
-
- }
- }
|