index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. shiftInfo: {
  23. },
  24. remindList:[],
  25. list: [{}, {}],
  26. carList:[],
  27. caritem:{
  28. driverInfo:{}
  29. },
  30. caritemBl:false,
  31. stationList: [],
  32. dis:'',
  33. //个人
  34. info: {
  35. obj: null,
  36. init: false,
  37. longitude: '',
  38. latitude: '',
  39. },
  40. reverseInit:false,
  41. myinterval: '',
  42. routeInfo:{},
  43. popid:0,
  44. radiolist: [
  45. {
  46. name: '不提醒',
  47. isRemind: "0",
  48. },
  49. {
  50. name: '提前1站',
  51. isRemind: "1",
  52. },
  53. {
  54. name: '提前2站',
  55. isRemind: "2",
  56. }
  57. ]
  58. }
  59. },
  60. components: {
  61. Carmap
  62. },
  63. methods: {
  64. selectBtn(i){
  65. this.popid=i;
  66. this.$forceUpdate()
  67. },
  68. makePhoneCall(tel){
  69. uni.makePhoneCall({
  70. phoneNumber: tel //仅为示例
  71. });
  72. },
  73. radioChange(e){
  74. console.log(e)
  75. },
  76. vehicleStationDis(){
  77. var obj={
  78. startStationId:this.stationList[0].id,
  79. currentStationId :this.downItem.id,
  80. routeId:this.routeInfo.id,
  81. }
  82. if(this.stationList[0].id==this.downItem.id&&this.routeInfo.interval){
  83. var nowDate =new Date();
  84. var curDay=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
  85. var startDate =new Date(curDay+" "+this.routeInfo.startTime+":00");
  86. var endDate =new Date(curDay+" "+this.routeInfo.endTime+":00");
  87. if(nowDate.getTime()>endDate.getTime()){
  88. this.dis=""
  89. }else{
  90. var d=this.routeInfo.interval - parseInt((nowDate.getTime()-startDate.getTime())/1000/60)%this.routeInfo.interval
  91. this.dis="等待发车... 大约"+d+"分钟发车"
  92. }
  93. }else{
  94. this.$refs.common.showLoading();
  95. API.vehicleStationDis(obj).then((res) => {
  96. this.dis=res.data;
  97. this.$refs.common.showLoading(false);
  98. }).catch(error => {
  99. this.$refs.common.showLoading(false,error);
  100. })
  101. }
  102. },
  103. radioGroupChange(){
  104. this.downItem.isRemind=this.popid;
  105. var item= this.downItem
  106. if(item.isRemind==0){
  107. if(this.downItem.remindId){
  108. this.del(item.remindId,item.isRemind!=0)
  109. }else{
  110. this.show1 = false
  111. this.$forceUpdate()
  112. }
  113. return
  114. }
  115. if(item.remindId){
  116. this.del(item.remindId,item.isRemind!=0)
  117. }else{
  118. this.remindAdd()
  119. }
  120. },del(id,bl){
  121. API_index.cancelRemind(id).then((res) => {
  122. this.downItem.remindId=""
  123. if(bl){
  124. this.remindAdd()
  125. }else{
  126. this.show1 = false
  127. this.$forceUpdate()
  128. this.$refs.common.alert( "设置成功");
  129. }
  130. }).catch(error => {
  131. this.$refs.common.alert( error);
  132. })
  133. },
  134. remind(){
  135. var myBtn = document.getElementById("subscribe-btn").tap();
  136. myBtn.tap();
  137. },
  138. showCar(item){
  139. for(var i in this.carList){
  140. var car= this.carList[i]
  141. if(car.currentStationId==item.id){
  142. return true;
  143. }
  144. }
  145. return false;
  146. },
  147. showname(name){
  148. if(!name){
  149. return "";
  150. }
  151. return name.substring(0,1)+'师傅';
  152. },
  153. getCar(){
  154. if(this.stationList.length==0){
  155. return;
  156. }
  157. var obj={
  158. routeId:this.id,
  159. startStationId:this.stationList[0].id,
  160. }
  161. API.routeShiftList(obj).then((response) => {
  162. this.carList=response.data;
  163. this.$refs.amap.setCarList(response.data);
  164. this.vehicleStationDis();
  165. }).catch(error => {
  166. this.$refs.common.showLoading(false,error)
  167. })
  168. },
  169. mapopenBtn(){
  170. this.mapopen=!this.mapopen;
  171. if(this.mapopen){
  172. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  173. }else{
  174. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  175. }
  176. },
  177. downBtn(item) {
  178. this.$refs.amap.setSite(item);
  179. this.$refs.amap.setCenter(item);
  180. this.downid=item.id;
  181. this.downItem=item;
  182. this.vehicleStationDis();
  183. this.$forceUpdate()
  184. },
  185. remindAdd(){
  186. if(this.downItem.id){
  187. var obj={
  188. startStationId:this.stationList[0].id,
  189. endStationId:this.stationList[this.stationList.length-1].id,
  190. remindStationId :this.downItem.id,
  191. stopInAdvance:this.downItem.isRemind,
  192. remindType:"1",
  193. routeId:this.routeInfo.id,
  194. openId:this.carhelp.getOpenId()
  195. }
  196. API_index.saveRemind(obj).then((res) => {
  197. this.downItem.remindId=res.data.id
  198. this.$refs.common.alert( "设置成功");
  199. this.show1 = false
  200. this.$forceUpdate()
  201. }).catch(error => {
  202. this.$refs.common.alert( error);
  203. })
  204. }
  205. },
  206. drawing(point, startend) {
  207. if (this.$refs.amap) {
  208. this.$refs.amap.initMap(point, this.stationList,startend);
  209. }
  210. },
  211. carShow(item){
  212. var caritem =null;
  213. for(var i in this.carList){
  214. var car= this.carList[i]
  215. if(car.currentStationId==item.id){
  216. var caritem=car;
  217. break
  218. }
  219. }
  220. this.caritem=caritem;
  221. this.caritemBl=true;
  222. },
  223. reverse(){
  224. this.stationList.reverse();
  225. this.getCar()
  226. this.passengerShiftRemindList();
  227. this.$refs.amap.setStartend(this.stationList);
  228. document.getElementById('map-route-main').scrollLeft = 0
  229. this.$nextTick(function() {
  230. const query = uni.createSelectorQuery().in(this);
  231. query.select('.map-down').boundingClientRect(data => {
  232. if(data){
  233. document.getElementById('map-route-main').scrollLeft = data.left-20;
  234. }
  235. this.$refs.common.showLoading(false);
  236. //this.downBtn()
  237. }).exec();
  238. });
  239. },
  240. setRemind(){
  241. for(var i in this.stationList){
  242. var item=this.stationList[i];
  243. item.isRemind=0;
  244. item.remindId="";
  245. for(var j in this.remindList){
  246. var obj=this.remindList[j];
  247. if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
  248. if(obj.remindStationId==item.id){
  249. item.remindId=obj.id;
  250. item.isRemind=obj.stopInAdvance;
  251. }
  252. }
  253. }
  254. }
  255. this.$forceUpdate()
  256. },
  257. passengerShiftRemindList(){
  258. this.$refs.common.showLoading()
  259. API.passengerShiftRemindList({
  260. routeId:this.id,
  261. openId:this.carhelp.getOpenId(),
  262. }).then((response) => {
  263. this.remindList=response.data;
  264. this.setRemind();
  265. this.$refs.common.showLoading(false)
  266. })
  267. },
  268. getPassengerInfo() {
  269. this.$refs.common.showLoading()
  270. API.routeDetail(this.id).then((response) => {
  271. var list=response.data.stationInfoList;
  272. if(this.upid&&list.length){
  273. if(this.upid==list[list.length-1].id){
  274. list.reverse();
  275. }
  276. this.upid="";
  277. }
  278. this.stationList=list;
  279. for(var i in list){
  280. list[i].isRemind=0;
  281. if(list[i].id==this.downid){
  282. this.downItem=list[i];
  283. }
  284. }
  285. this.passengerShiftRemindList();
  286. this.$refs.common.showLoading(false)
  287. var point = [];
  288. this.routeInfo=response.data.routeInfo;
  289. this.title=this.routeInfo.name;
  290. if(!response.data.routeInfo.mapPath){
  291. this.$refs.common.showLoading(false,"路线加载失败!")
  292. return;
  293. }
  294. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  295. var sz = item.split(",");
  296. point.push({
  297. longitude: sz[0],
  298. latitude: sz[1],
  299. })
  300. })
  301. var startend = [{
  302. longitude: this.stationList[0].longitude,
  303. latitude: this.stationList[0].latitude,
  304. name: this.stationList[0].name
  305. }, {
  306. longitude: this.stationList[this.stationList.length-1].longitude,
  307. latitude: this.stationList[this.stationList.length-1].latitude,
  308. name: this.stationList[this.stationList.length-1].name
  309. }];
  310. this.drawing(point,startend);
  311. this.$refs.common.showLoading(false)
  312. this.getPoint()
  313. this.$nextTick(function() {
  314. const query = uni.createSelectorQuery().in(this);
  315. query.select('.map-down').boundingClientRect(data => {
  316. if(data){
  317. document.getElementById('map-route-main').scrollLeft = data.left-20;
  318. }
  319. this.$refs.common.showLoading(false);
  320. //this.downBtn()
  321. }).exec();
  322. });
  323. }).catch(error => {
  324. this.$refs.common.showLoading(false,error)
  325. })
  326. },
  327. mapdown(){
  328. if(this.downid=="null"){
  329. this.downid="";
  330. }
  331. if(this.downid){
  332. this.downBtn(this.downItem)
  333. }
  334. },
  335. getPoint() {
  336. if (!this.info.init) {
  337. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  338. // this.$refs.common.showLoading(false)
  339. this.getLocation()
  340. });
  341. }else{
  342. this.getLocation()
  343. }
  344. this.getCar();
  345. var pages = getCurrentPages();
  346. var page = (pages[pages.length - 1]).route;
  347. if (page == "pages/route/index") {
  348. setTimeout(this.getPoint, 10000);
  349. }
  350. },
  351. getLocation(){
  352. WxJsApi.getLocation().then((res) => {
  353. console.log("----getLocation ok-----")
  354. var latitude = parseFloat(res.latitude);
  355. var longitude = parseFloat(res.longitude);
  356. if (!this.info.init) {
  357. this.latitude = latitude;
  358. this.longitude = longitude;
  359. }
  360. this.info.init = true
  361. this.info.latitude = latitude;
  362. this.info.longitude = longitude;
  363. this.$refs.amap.setPerson(this.info);
  364. }).catch(error => {
  365. console.log(error)
  366. })
  367. }
  368. },
  369. onLoad(op) {
  370. this.upid=op.upid;
  371. this.id = op.id
  372. this.downid=op.downid;
  373. },
  374. onUnload() {
  375. if (this.myinterval) {
  376. clearInterval(this.myinterval)
  377. }
  378. },
  379. onReady() {
  380. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  381. // this.$refs.common.showLoading(false)
  382. this.wxinit=true;
  383. });
  384. this.getPassengerInfo()
  385. }
  386. }