index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. import * as API from '@/apis/route.js'
  2. import * as API_index from '@/apis/index.js'
  3. import * as WxJsApi from '@/utils/wxJsApi.js'
  4. import Carmap from '@/components/Carmap.vue'
  5. export default {
  6. data() {
  7. return {
  8. wxinit:false,
  9. mapopen:false,
  10. initBl: false,
  11. title: '乘车人',
  12. show: false,
  13. id: 0, // 使用 marker点击事件 需要填写id
  14. upid:'',
  15. downid:'',
  16. downItem:{},
  17. //地图居中后的位置
  18. longitude: 112.276527,
  19. latitude: 30.306427,
  20. show1: false,
  21. show2: false,
  22. centerBl:false,
  23. shiftInfo: {
  24. },
  25. remindList:[],
  26. list: [{}, {}],
  27. carList:[],
  28. caritem:{
  29. driverInfo:{}
  30. },
  31. caritemBl:false,
  32. stationList: [],
  33. routeTimeTableList:[],
  34. dis:'',
  35. //个人
  36. info: {
  37. obj: null,
  38. init: false,
  39. longitude: '',
  40. latitude: '',
  41. },
  42. reverseInit:false,
  43. myinterval: '',
  44. routeInfo:{},
  45. popid:0,
  46. radiolist: [
  47. {
  48. name: '不提醒',
  49. isRemind: "0",
  50. },
  51. {
  52. name: '提前1站',
  53. isRemind: "1",
  54. },
  55. {
  56. name: '提前2站',
  57. isRemind: "2",
  58. }
  59. ]
  60. }
  61. },
  62. components: {
  63. Carmap
  64. },
  65. methods: {
  66. selectBtn(i){
  67. this.popid=i;
  68. this.$forceUpdate()
  69. },
  70. makePhoneCall(tel){
  71. uni.makePhoneCall({
  72. phoneNumber: tel //仅为示例
  73. });
  74. },
  75. radioChange(e){
  76. console.log(e)
  77. },
  78. vehicleStationDis(){
  79. if(this.stationList[0].id==this.downItem.id&&this.routeTimeTableList&&this.routeTimeTableList.length){
  80. var nowDate =new Date();
  81. var curDay=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
  82. var startDate =null;
  83. for(var i in this.routeTimeTableList){
  84. var obj=this.routeTimeTableList[i]
  85. var objDate =new Date(curDay+" "+obj.startTime+":00");
  86. if(nowDate.getTime()<objDate.getTime()){
  87. if(startDate==null){
  88. startDate=objDate;
  89. }
  90. if(objDate<startDate){
  91. startDate=objDate;
  92. }
  93. }
  94. }
  95. if(startDate==null){
  96. this.dis="今日发车已经结束,明日发车时间"+this.routeInfo.startTime
  97. }else{
  98. console.log(startDate)
  99. console.log(nowDate)
  100. var d= parseInt((startDate.getTime()-nowDate.getTime())/1000/60)
  101. this.dis="等待发车... 大约"+d+"分钟发车"
  102. }
  103. }else{
  104. var obj={
  105. startStationId:this.stationList[0].id,
  106. currentStationId :this.downItem.id,
  107. routeId:this.routeInfo.id,
  108. }
  109. //this.$refs.common.showLoading();
  110. API.vehicleStationDis(obj).then((res) => {
  111. this.dis=res.data;
  112. //this.$refs.common.showLoading(false);
  113. }).catch(error => {
  114. this.$refs.common.showLoading(false,error);
  115. })
  116. }
  117. },
  118. radioGroupChange(){
  119. this.downItem.isRemind=this.popid;
  120. var item= this.downItem
  121. if(item.isRemind==0){
  122. if(this.downItem.remindId){
  123. this.del(item.remindId,item.isRemind!=0)
  124. }else{
  125. this.show1 = false
  126. this.$forceUpdate()
  127. }
  128. return
  129. }
  130. if(item.remindId){
  131. this.del(item.remindId,item.isRemind!=0)
  132. }else{
  133. this.remindAdd()
  134. }
  135. },del(id,bl){
  136. API_index.cancelRemind(id).then((res) => {
  137. this.downItem.remindId=""
  138. if(bl){
  139. this.remindAdd()
  140. }else{
  141. this.show1 = false
  142. this.$forceUpdate()
  143. this.$refs.common.alert( "设置成功");
  144. }
  145. }).catch(error => {
  146. this.$refs.common.alert( error);
  147. })
  148. },
  149. remind(){
  150. var myBtn = document.getElementById("subscribe-btn").tap();
  151. myBtn.tap();
  152. },
  153. showCar(item){
  154. for(var i in this.carList){
  155. var car= this.carList[i]
  156. if(car.currentStationStatus=="3"){
  157. if(car.currentStationId==this.stationList[this.stationList.length-1].id&&car.currentStationId==item.id){
  158. return true;
  159. }else if(car.currentStationId2==item.id){
  160. return true;
  161. }
  162. }else{
  163. if(car.currentStationId==item.id){
  164. return true;
  165. }
  166. }
  167. }
  168. return false;
  169. },
  170. showname(name){
  171. if(!name){
  172. return "";
  173. }
  174. return name.substring(0,1)+'师傅';
  175. },
  176. getCar(){
  177. if(this.stationList.length==0){
  178. return;
  179. }
  180. var obj={
  181. routeId:this.id,
  182. startStationId:this.stationList[0].id,
  183. }
  184. API.routeShiftList(obj).then((response) => {
  185. this.carList=response.data;
  186. if(!this.centerBl&&this.carList.length){
  187. this.centerBl=this.$refs.amap.setCenter(this.carList[0]);
  188. //this.centerBl=true;
  189. if(this.centerBl){
  190. document.getElementById('map-route-main').scrollLeft = 0
  191. this.$nextTick(function() {
  192. const query = uni.createSelectorQuery().in(this);
  193. query.select('.map-route-car').boundingClientRect(data => {
  194. if(data){
  195. document.getElementById('map-route-main').scrollLeft = data.left-100;
  196. }
  197. //this.downBtn()
  198. }).exec();
  199. });
  200. }
  201. }
  202. //car.currentStationId=this.stationList[this.stationList.length-1].id
  203. //car.currentStationStatus="1";
  204. // this.carList=[];
  205. // this.carList.push({
  206. // currentStationId:"9e5be927-178b-4163-a34b-49bba6460eec",
  207. // currentStationStatus:"1"
  208. // })
  209. // this.carList.push({
  210. // currentStationId:"ff2251e0-26ca-41ad-a4a0-43ece7ab3471",
  211. // currentStationStatus:"2"
  212. // })
  213. for(var j in this.stationList){
  214. var station =this.stationList[j];
  215. station.currentStationStatus="1";
  216. }
  217. console.log("this.stationList")
  218. console.log(this.stationList)
  219. console.log("this.stationList")
  220. for(var j in this.stationList){
  221. var station =this.stationList[j];
  222. // station.currentStationStatus="1";
  223. for(var i in this.carList){
  224. var car =this.carList[i];
  225. if(car.currentStationId==station.id){
  226. console.log(car.licensePlateNumber+"------"+station.name)
  227. if(car.currentStationStatus==3){
  228. if(eval(j+"+"+1)!=this.stationList.length){
  229. console.log(this.stationList[eval(j+"+"+1)].id);
  230. car.currentStationId2=this.stationList[eval(j+"+"+1)].id
  231. this.stationList[eval(j+"+"+1)].currentStationStatus="2";
  232. console.log("--------this.carList----A------"+car.licensePlateNumber)
  233. }else{
  234. car.currentStationStatus=1
  235. this.stationList[j].currentStationStatus="1";
  236. console.log("--------this.carList----B------"+car.licensePlateNumber)
  237. }
  238. }else{
  239. this.stationList[j].currentStationStatus=car.currentStationStatus;
  240. console.log("--------this.carList----c------"+car.licensePlateNumber)
  241. }
  242. break;
  243. }
  244. }
  245. }
  246. console.log("--------this.carList----------")
  247. console.log(this.carList)
  248. console.log("--------this.carList----------")
  249. this.$refs.amap.setCarList(this.carList);
  250. this.vehicleStationDis();
  251. }).catch(error => {
  252. console.log(error);
  253. this.$refs.common.showLoading(false,error)
  254. })
  255. },
  256. mapopenBtn(){
  257. this.mapopen=!this.mapopen;
  258. if(this.mapopen){
  259. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  260. }else{
  261. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  262. }
  263. },
  264. downBtn(item) {
  265. this.$refs.amap.setSite(item);
  266. this.$refs.amap.setCenter(item);
  267. this.downid=item.id;
  268. this.downItem=item;
  269. this.vehicleStationDis();
  270. this.$forceUpdate()
  271. },
  272. remindAdd(){
  273. if(this.downItem.id){
  274. var obj={
  275. startStationId:this.stationList[0].id,
  276. endStationId:this.stationList[this.stationList.length-1].id,
  277. remindStationId :this.downItem.id,
  278. stopInAdvance:this.downItem.isRemind,
  279. remindType:"1",
  280. routeId:this.routeInfo.id,
  281. openId:this.carhelp.getOpenId()
  282. }
  283. API_index.saveRemind(obj).then((res) => {
  284. this.downItem.remindId=res.data.id
  285. this.$refs.common.alert( "设置成功");
  286. this.show1 = false
  287. this.$forceUpdate()
  288. }).catch(error => {
  289. this.$refs.common.alert( error);
  290. })
  291. }
  292. },
  293. drawing(point, startend) {
  294. if (this.$refs.amap) {
  295. this.$refs.amap.initMap(point, this.stationList,startend);
  296. }
  297. },
  298. carShow2(item){
  299. console.log(item)
  300. if(item.type=="car"){
  301. setTimeout(()=>{
  302. this.carShow3(item.obj)
  303. }, 100);
  304. }
  305. if(item.type=="point"){
  306. setTimeout(()=>{
  307. this.downBtn(item.obj)
  308. document.getElementById('map-route-main').scrollLeft = 0
  309. this.$nextTick(function() {
  310. const query = uni.createSelectorQuery().in(this);
  311. query.select('.map-down').boundingClientRect(data => {
  312. if(data){
  313. document.getElementById('map-route-main').scrollLeft = data.left-100;
  314. }
  315. this.$refs.common.showLoading(false);
  316. //this.downBtn()
  317. }).exec();
  318. });
  319. }, 100);
  320. }
  321. },
  322. carShow3(item){
  323. var caritem =item;
  324. this.caritem=caritem;
  325. this.caritemBl=true;
  326. },
  327. carShow(item){
  328. var caritem =null;
  329. for(var i in this.carList){
  330. var car= this.carList[i]
  331. if(car.currentStationId==this.stationList[this.stationList.length-1].id&&car.currentStationStatus==3 ){
  332. if(car.currentStationId==item.id){
  333. var caritem=car;
  334. break
  335. }
  336. }else if(car.currentStationStatus==3){
  337. if(car.currentStationId2==item.id){
  338. var caritem=car;
  339. break
  340. }
  341. }else{
  342. if(car.currentStationId==item.id){
  343. var caritem=car;
  344. break
  345. }
  346. }
  347. }
  348. this.caritem=caritem;
  349. this.caritemBl=true;
  350. },
  351. reverse(){
  352. this.centerBl=false;
  353. this.stationList.reverse();
  354. this.getCar()
  355. this.passengerShiftRemindList();
  356. this.$refs.amap.setStartend(this.stationList);
  357. document.getElementById('map-route-main').scrollLeft = 0
  358. this.$nextTick(function() {
  359. const query = uni.createSelectorQuery().in(this);
  360. query.select('.map-down').boundingClientRect(data => {
  361. if(data){
  362. document.getElementById('map-route-main').scrollLeft = data.left-100;
  363. }
  364. this.$refs.common.showLoading(false);
  365. //this.downBtn()
  366. }).exec();
  367. });
  368. },
  369. setRemind(){
  370. for(var i in this.stationList){
  371. var item=this.stationList[i];
  372. item.isRemind=0;
  373. item.remindId="";
  374. for(var j in this.remindList){
  375. var obj=this.remindList[j];
  376. if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
  377. if(obj.remindStationId==item.id){
  378. item.remindId=obj.id;
  379. item.isRemind=obj.stopInAdvance;
  380. }
  381. }
  382. }
  383. }
  384. this.$forceUpdate()
  385. },
  386. passengerShiftRemindList(){
  387. this.$refs.common.showLoading()
  388. API.passengerShiftRemindList({
  389. routeId:this.id,
  390. openId:this.carhelp.getOpenId(),
  391. }).then((response) => {
  392. this.remindList=response.data;
  393. this.setRemind();
  394. this.$refs.common.showLoading(false)
  395. })
  396. },
  397. getPassengerInfo() {
  398. this.$refs.common.showLoading()
  399. API.routeDetail(this.id).then((response) => {
  400. var list=response.data.stationInfoList;
  401. if(this.upid&&list.length){
  402. if(this.upid==list[list.length-1].id){
  403. list.reverse();
  404. }
  405. this.upid="";
  406. }
  407. this.stationList=list;
  408. for(var i in list){
  409. list[i].isRemind=0;
  410. if(list[i].id==this.downid){
  411. this.downItem=list[i];
  412. }
  413. }
  414. this.passengerShiftRemindList();
  415. this.$refs.common.showLoading(false)
  416. var point = [];
  417. this.routeInfo=response.data.routeInfo;
  418. this.routeTimeTableList=response.data.routeTimeTableList;
  419. this.title=this.routeInfo.name;
  420. if(!response.data.routeInfo.mapPath){
  421. this.$refs.common.showLoading(false,"路线加载失败!")
  422. return;
  423. }
  424. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  425. var sz = item.split(",");
  426. point.push({
  427. longitude: sz[0],
  428. latitude: sz[1],
  429. })
  430. })
  431. var startend = [{
  432. longitude: this.stationList[0].longitude,
  433. latitude: this.stationList[0].latitude,
  434. name: this.stationList[0].name
  435. }, {
  436. longitude: this.stationList[this.stationList.length-1].longitude,
  437. latitude: this.stationList[this.stationList.length-1].latitude,
  438. name: this.stationList[this.stationList.length-1].name
  439. }];
  440. this.drawing(point,startend);
  441. this.$refs.common.showLoading(false)
  442. //this.getPoint()
  443. }).catch(error => {
  444. this.$refs.common.showLoading(false,error)
  445. })
  446. },
  447. mapdown(){
  448. this.getPoint();
  449. if(this.downid=="null"){
  450. this.downid="";
  451. }else{
  452. this.centerBl=true;
  453. }
  454. if(this.downid){
  455. this.downBtn(this.downItem)
  456. }
  457. },
  458. getPoint() {
  459. if (!this.info.init) {
  460. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  461. // this.$refs.common.showLoading(false)
  462. this.getLocation()
  463. });
  464. }else{
  465. this.getLocation()
  466. }
  467. this.getCar();
  468. var pages = getCurrentPages();
  469. var page = (pages[pages.length - 1]).route;
  470. if (page == "pages/route/index") {
  471. setTimeout(this.getPoint, 10000);
  472. }
  473. },
  474. getLocation(){
  475. WxJsApi.getLocation().then((res) => {
  476. console.log("----getLocation ok-----")
  477. var latitude = parseFloat(res.latitude);
  478. var longitude = parseFloat(res.longitude);
  479. if (!this.info.init) {
  480. this.latitude = latitude;
  481. this.longitude = longitude;
  482. }
  483. this.info.init = true
  484. this.info.latitude = latitude;
  485. this.info.longitude = longitude;
  486. this.$refs.amap.setPerson(this.info,true);
  487. }).catch(error => {
  488. console.log(error)
  489. })
  490. }
  491. },
  492. onLoad(op) {
  493. this.upid=op.upid;
  494. this.id = op.id
  495. this.downid=op.downid;
  496. },
  497. onUnload() {
  498. if (this.myinterval) {
  499. clearInterval(this.myinterval)
  500. }
  501. },
  502. onReady() {
  503. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  504. // this.$refs.common.showLoading(false)
  505. this.wxinit=true;
  506. });
  507. this.getPassengerInfo()
  508. }
  509. }