index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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.currentStationId==item.id){
  157. return true;
  158. }
  159. }
  160. return false;
  161. },
  162. showname(name){
  163. if(!name){
  164. return "";
  165. }
  166. return name.substring(0,1)+'师傅';
  167. },
  168. getCar(){
  169. if(this.stationList.length==0){
  170. return;
  171. }
  172. var obj={
  173. routeId:this.id,
  174. startStationId:this.stationList[0].id,
  175. }
  176. API.routeShiftList(obj).then((response) => {
  177. this.carList=response.data;
  178. if(!this.centerBl&&this.carList.length){
  179. this.centerBl=this.$refs.amap.setCenter(this.carList[0]);
  180. //this.centerBl=true;
  181. if(this.centerBl){
  182. document.getElementById('map-route-main').scrollLeft = 0
  183. this.$nextTick(function() {
  184. const query = uni.createSelectorQuery().in(this);
  185. query.select('.map-route-car').boundingClientRect(data => {
  186. if(data){
  187. document.getElementById('map-route-main').scrollLeft = data.left-20;
  188. }
  189. //this.downBtn()
  190. }).exec();
  191. });
  192. }
  193. }
  194. this.$refs.amap.setCarList(response.data);
  195. this.vehicleStationDis();
  196. }).catch(error => {
  197. this.$refs.common.showLoading(false,error)
  198. })
  199. },
  200. mapopenBtn(){
  201. this.mapopen=!this.mapopen;
  202. if(this.mapopen){
  203. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  204. }else{
  205. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  206. }
  207. },
  208. downBtn(item) {
  209. this.$refs.amap.setSite(item);
  210. this.$refs.amap.setCenter(item);
  211. this.downid=item.id;
  212. this.downItem=item;
  213. this.vehicleStationDis();
  214. this.$forceUpdate()
  215. },
  216. remindAdd(){
  217. if(this.downItem.id){
  218. var obj={
  219. startStationId:this.stationList[0].id,
  220. endStationId:this.stationList[this.stationList.length-1].id,
  221. remindStationId :this.downItem.id,
  222. stopInAdvance:this.downItem.isRemind,
  223. remindType:"1",
  224. routeId:this.routeInfo.id,
  225. openId:this.carhelp.getOpenId()
  226. }
  227. API_index.saveRemind(obj).then((res) => {
  228. this.downItem.remindId=res.data.id
  229. this.$refs.common.alert( "设置成功");
  230. this.show1 = false
  231. this.$forceUpdate()
  232. }).catch(error => {
  233. this.$refs.common.alert( error);
  234. })
  235. }
  236. },
  237. drawing(point, startend) {
  238. if (this.$refs.amap) {
  239. this.$refs.amap.initMap(point, this.stationList,startend);
  240. }
  241. },
  242. carShow(item){
  243. var caritem =null;
  244. for(var i in this.carList){
  245. var car= this.carList[i]
  246. if(car.currentStationId==item.id){
  247. var caritem=car;
  248. break
  249. }
  250. }
  251. this.caritem=caritem;
  252. this.caritemBl=true;
  253. },
  254. reverse(){
  255. this.stationList.reverse();
  256. this.getCar()
  257. this.passengerShiftRemindList();
  258. this.$refs.amap.setStartend(this.stationList);
  259. document.getElementById('map-route-main').scrollLeft = 0
  260. this.$nextTick(function() {
  261. const query = uni.createSelectorQuery().in(this);
  262. query.select('.map-down').boundingClientRect(data => {
  263. if(data){
  264. document.getElementById('map-route-main').scrollLeft = data.left-20;
  265. }
  266. this.$refs.common.showLoading(false);
  267. //this.downBtn()
  268. }).exec();
  269. });
  270. },
  271. setRemind(){
  272. for(var i in this.stationList){
  273. var item=this.stationList[i];
  274. item.isRemind=0;
  275. item.remindId="";
  276. for(var j in this.remindList){
  277. var obj=this.remindList[j];
  278. if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
  279. if(obj.remindStationId==item.id){
  280. item.remindId=obj.id;
  281. item.isRemind=obj.stopInAdvance;
  282. }
  283. }
  284. }
  285. }
  286. this.$forceUpdate()
  287. },
  288. passengerShiftRemindList(){
  289. this.$refs.common.showLoading()
  290. API.passengerShiftRemindList({
  291. routeId:this.id,
  292. openId:this.carhelp.getOpenId(),
  293. }).then((response) => {
  294. this.remindList=response.data;
  295. this.setRemind();
  296. this.$refs.common.showLoading(false)
  297. })
  298. },
  299. getPassengerInfo() {
  300. this.$refs.common.showLoading()
  301. API.routeDetail(this.id).then((response) => {
  302. var list=response.data.stationInfoList;
  303. if(this.upid&&list.length){
  304. if(this.upid==list[list.length-1].id){
  305. list.reverse();
  306. }
  307. this.upid="";
  308. }
  309. this.stationList=list;
  310. for(var i in list){
  311. list[i].isRemind=0;
  312. if(list[i].id==this.downid){
  313. this.downItem=list[i];
  314. }
  315. }
  316. this.passengerShiftRemindList();
  317. this.$refs.common.showLoading(false)
  318. var point = [];
  319. this.routeInfo=response.data.routeInfo;
  320. this.routeTimeTableList=response.data.routeTimeTableList;
  321. this.title=this.routeInfo.name;
  322. if(!response.data.routeInfo.mapPath){
  323. this.$refs.common.showLoading(false,"路线加载失败!")
  324. return;
  325. }
  326. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  327. var sz = item.split(",");
  328. point.push({
  329. longitude: sz[0],
  330. latitude: sz[1],
  331. })
  332. })
  333. var startend = [{
  334. longitude: this.stationList[0].longitude,
  335. latitude: this.stationList[0].latitude,
  336. name: this.stationList[0].name
  337. }, {
  338. longitude: this.stationList[this.stationList.length-1].longitude,
  339. latitude: this.stationList[this.stationList.length-1].latitude,
  340. name: this.stationList[this.stationList.length-1].name
  341. }];
  342. this.drawing(point,startend);
  343. this.$refs.common.showLoading(false)
  344. this.getPoint()
  345. this.$nextTick(function() {
  346. const query = uni.createSelectorQuery().in(this);
  347. query.select('.map-down').boundingClientRect(data => {
  348. if(data){
  349. document.getElementById('map-route-main').scrollLeft = data.left-20;
  350. }
  351. this.$refs.common.showLoading(false);
  352. //this.downBtn()
  353. }).exec();
  354. });
  355. }).catch(error => {
  356. this.$refs.common.showLoading(false,error)
  357. })
  358. },
  359. mapdown(){
  360. if(this.downid=="null"){
  361. this.downid="";
  362. }else{
  363. this.centerBl=true;
  364. }
  365. if(this.downid){
  366. this.downBtn(this.downItem)
  367. }
  368. },
  369. getPoint() {
  370. if (!this.info.init) {
  371. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  372. // this.$refs.common.showLoading(false)
  373. this.getLocation()
  374. });
  375. }else{
  376. this.getLocation()
  377. }
  378. this.getCar();
  379. var pages = getCurrentPages();
  380. var page = (pages[pages.length - 1]).route;
  381. if (page == "pages/route/index") {
  382. setTimeout(this.getPoint, 10000);
  383. }
  384. },
  385. getLocation(){
  386. WxJsApi.getLocation().then((res) => {
  387. console.log("----getLocation ok-----")
  388. var latitude = parseFloat(res.latitude);
  389. var longitude = parseFloat(res.longitude);
  390. if (!this.info.init) {
  391. this.latitude = latitude;
  392. this.longitude = longitude;
  393. }
  394. this.info.init = true
  395. this.info.latitude = latitude;
  396. this.info.longitude = longitude;
  397. this.$refs.amap.setPerson(this.info,true);
  398. }).catch(error => {
  399. console.log(error)
  400. })
  401. }
  402. },
  403. onLoad(op) {
  404. this.upid=op.upid;
  405. this.id = op.id
  406. this.downid=op.downid;
  407. },
  408. onUnload() {
  409. if (this.myinterval) {
  410. clearInterval(this.myinterval)
  411. }
  412. },
  413. onReady() {
  414. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  415. // this.$refs.common.showLoading(false)
  416. this.wxinit=true;
  417. });
  418. this.getPassengerInfo()
  419. }
  420. }