index.js 14 KB

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