index.js 14 KB

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