index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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: true,
  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. this.$refs.amap.ifCenter(this.carList[0]);
  187. if(!this.centerBl&&this.carList.length){
  188. this.centerBl=this.$refs.amap.setCenter(this.carList[0]);
  189. this.$refs.amap.ifCenter(this.carList[0]);
  190. //this.centerBl=true;
  191. if(this.centerBl){
  192. document.getElementById('map-route-main').scrollLeft = 0
  193. this.$nextTick(function() {
  194. const query = uni.createSelectorQuery().in(this);
  195. query.select('.map-route-car').boundingClientRect(data => {
  196. if(data){
  197. document.getElementById('map-route-main').scrollLeft = data.left-100;
  198. }
  199. //this.downBtn()
  200. }).exec();
  201. });
  202. }
  203. }
  204. //car.currentStationId=this.stationList[this.stationList.length-1].id
  205. //car.currentStationStatus="1";
  206. // this.carList=[];
  207. // this.carList.push({
  208. // currentStationId:"9e5be927-178b-4163-a34b-49bba6460eec",
  209. // currentStationStatus:"1"
  210. // })
  211. // this.carList.push({
  212. // currentStationId:"ff2251e0-26ca-41ad-a4a0-43ece7ab3471",
  213. // currentStationStatus:"2"
  214. // })
  215. for(var j in this.stationList){
  216. var station =this.stationList[j];
  217. station.currentStationStatus="1";
  218. }
  219. console.log("this.stationList")
  220. console.log(this.stationList)
  221. console.log("this.stationList")
  222. for(var j in this.stationList){
  223. var station =this.stationList[j];
  224. // station.currentStationStatus="1";
  225. for(var i in this.carList){
  226. var car =this.carList[i];
  227. if(car.currentStationId==station.id){
  228. console.log(car.licensePlateNumber+"------"+station.name)
  229. if(car.currentStationStatus==3){
  230. if(eval(j+"+"+1)!=this.stationList.length){
  231. console.log(this.stationList[eval(j+"+"+1)].id);
  232. car.currentStationId2=this.stationList[eval(j+"+"+1)].id
  233. this.stationList[eval(j+"+"+1)].currentStationStatus="2";
  234. console.log("--------this.carList----A------"+car.licensePlateNumber)
  235. }else{
  236. car.currentStationStatus=1
  237. this.stationList[j].currentStationStatus="1";
  238. console.log("--------this.carList----B------"+car.licensePlateNumber)
  239. }
  240. }else{
  241. this.stationList[j].currentStationStatus=car.currentStationStatus;
  242. console.log("--------this.carList----c------"+car.licensePlateNumber)
  243. }
  244. break;
  245. }
  246. }
  247. }
  248. console.log("--------this.carList----------")
  249. console.log(this.carList)
  250. console.log("--------this.carList----------")
  251. this.$refs.amap.setCarList(this.carList);
  252. this.vehicleStationDis();
  253. }).catch(error => {
  254. console.log(error);
  255. this.$refs.common.showLoading(false,error)
  256. })
  257. },
  258. mapopenBtn(){
  259. this.mapopen=!this.mapopen;
  260. if(this.mapopen){
  261. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  262. }else{
  263. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  264. }
  265. },
  266. downBtn(item) {
  267. this.$refs.amap.setSite(item);
  268. this.$refs.amap.setCenter(item);
  269. this.downid=item.id;
  270. this.downItem=item;
  271. this.vehicleStationDis();
  272. this.$forceUpdate()
  273. },
  274. remindAdd(){
  275. if(this.downItem.id){
  276. var obj={
  277. startStationId:this.stationList[0].id,
  278. endStationId:this.stationList[this.stationList.length-1].id,
  279. remindStationId :this.downItem.id,
  280. stopInAdvance:this.downItem.isRemind,
  281. remindType:"1",
  282. routeId:this.routeInfo.id,
  283. openId:this.carhelp.getOpenId()
  284. }
  285. API_index.saveRemind(obj).then((res) => {
  286. this.downItem.remindId=res.data.id
  287. this.$refs.common.alert( "设置成功");
  288. this.show1 = false
  289. this.$forceUpdate()
  290. }).catch(error => {
  291. this.$refs.common.alert( error);
  292. })
  293. }
  294. },
  295. drawing(point, startend) {
  296. if (this.$refs.amap) {
  297. this.$refs.amap.initMap(point, this.stationList,startend);
  298. }
  299. },
  300. carShow2(item){
  301. console.log(item)
  302. if(item.type=="car"){
  303. setTimeout(()=>{
  304. this.carShow3(item.obj)
  305. }, 100);
  306. }
  307. if(item.type=="point"){
  308. setTimeout(()=>{
  309. this.downBtn(item.obj)
  310. document.getElementById('map-route-main').scrollLeft = 0
  311. this.$nextTick(function() {
  312. const query = uni.createSelectorQuery().in(this);
  313. query.select('.map-down').boundingClientRect(data => {
  314. if(data){
  315. document.getElementById('map-route-main').scrollLeft = data.left-100;
  316. }
  317. this.$refs.common.showLoading(false);
  318. //this.downBtn()
  319. }).exec();
  320. });
  321. }, 100);
  322. }
  323. },
  324. carShow3(item){
  325. var caritem =item;
  326. this.caritem=caritem;
  327. this.caritemBl=true;
  328. },
  329. carShow(item){
  330. this.$refs.amap.setCenter(item);
  331. },
  332. reverse(){
  333. this.centerBl=false;
  334. this.stationList.reverse();
  335. this.getCar()
  336. this.passengerShiftRemindList();
  337. this.$refs.amap.setStartend(this.stationList);
  338. document.getElementById('map-route-main').scrollLeft = 0
  339. this.$nextTick(function() {
  340. const query = uni.createSelectorQuery().in(this);
  341. query.select('.map-down').boundingClientRect(data => {
  342. if(data){
  343. document.getElementById('map-route-main').scrollLeft = data.left-100;
  344. }
  345. this.$refs.common.showLoading(false);
  346. //this.downBtn()
  347. }).exec();
  348. });
  349. },
  350. setRemind(){
  351. for(var i in this.stationList){
  352. var item=this.stationList[i];
  353. item.isRemind=0;
  354. item.remindId="";
  355. for(var j in this.remindList){
  356. var obj=this.remindList[j];
  357. if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
  358. if(obj.remindStationId==item.id){
  359. item.remindId=obj.id;
  360. item.isRemind=obj.stopInAdvance;
  361. }
  362. }
  363. }
  364. }
  365. this.$forceUpdate()
  366. },
  367. passengerShiftRemindList(){
  368. this.$refs.common.showLoading()
  369. API.passengerShiftRemindList({
  370. routeId:this.id,
  371. openId:this.carhelp.getOpenId(),
  372. }).then((response) => {
  373. this.remindList=response.data;
  374. this.setRemind();
  375. this.$refs.common.showLoading(false)
  376. })
  377. },
  378. getPassengerInfo() {
  379. this.$refs.common.showLoading()
  380. API.routeDetail(this.id).then((response) => {
  381. var list=response.data.stationInfoList;
  382. if(this.upid&&list.length){
  383. if(this.upid==list[list.length-1].id){
  384. list.reverse();
  385. }
  386. this.upid="";
  387. }
  388. this.stationList=list;
  389. for(var i in list){
  390. list[i].isRemind=0;
  391. if(list[i].id==this.downid){
  392. this.downItem=list[i];
  393. }
  394. }
  395. this.passengerShiftRemindList();
  396. this.$refs.common.showLoading(false)
  397. var point = [];
  398. this.routeInfo=response.data.routeInfo;
  399. this.routeTimeTableList=response.data.routeTimeTableList;
  400. this.title=this.routeInfo.name;
  401. if(!response.data.routeInfo.mapPath){
  402. this.$refs.common.showLoading(false,"路线加载失败!")
  403. return;
  404. }
  405. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  406. var sz = item.split(",");
  407. point.push({
  408. longitude: sz[0],
  409. latitude: sz[1],
  410. })
  411. })
  412. var startend = [{
  413. longitude: this.stationList[0].longitude,
  414. latitude: this.stationList[0].latitude,
  415. name: this.stationList[0].name
  416. }, {
  417. longitude: this.stationList[this.stationList.length-1].longitude,
  418. latitude: this.stationList[this.stationList.length-1].latitude,
  419. name: this.stationList[this.stationList.length-1].name
  420. }];
  421. this.drawing(point,startend);
  422. this.$refs.common.showLoading(false)
  423. //this.getPoint()
  424. }).catch(error => {
  425. this.$refs.common.showLoading(false,error)
  426. })
  427. },
  428. mapdown(){
  429. this.getPoint();
  430. if(this.downid=="null"){
  431. this.downid="";
  432. }else{
  433. this.centerBl=true;
  434. }
  435. if(this.downid){
  436. this.downBtn(this.downItem)
  437. }
  438. },
  439. getPoint() {
  440. if (!this.info.init) {
  441. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  442. // this.$refs.common.showLoading(false)
  443. this.getLocation()
  444. });
  445. }else{
  446. this.getLocation()
  447. }
  448. this.getCar();
  449. var pages = getCurrentPages();
  450. var page = (pages[pages.length - 1]).route;
  451. if (page == "pages/route2/index") {
  452. setTimeout(this.getPoint, 10000);
  453. }
  454. },
  455. getLocation(){
  456. WxJsApi.getLocation().then((res) => {
  457. console.log("----getLocation ok-----")
  458. var latitude = parseFloat(res.latitude);
  459. var longitude = parseFloat(res.longitude);
  460. if (!this.info.init) {
  461. this.latitude = latitude;
  462. this.longitude = longitude;
  463. }
  464. this.info.init = true
  465. this.info.latitude = latitude;
  466. this.info.longitude = longitude;
  467. this.$refs.amap.setPerson(this.info,true);
  468. }).catch(error => {
  469. console.log(error)
  470. })
  471. }
  472. },
  473. onLoad(op) {
  474. this.upid=op.upid;
  475. this.id = op.id
  476. this.downid=op.downid;
  477. },
  478. onUnload() {
  479. if (this.myinterval) {
  480. clearInterval(this.myinterval)
  481. }
  482. },
  483. onReady() {
  484. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  485. // this.$refs.common.showLoading(false)
  486. this.wxinit=true;
  487. });
  488. this.getPassengerInfo()
  489. }
  490. }