index.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. this.$refs.common.showLoading();
  83. API.vehicleStationDis(obj).then((res) => {
  84. this.dis=res.data;
  85. this.$refs.common.showLoading(false);
  86. }).catch(error => {
  87. this.$refs.common.showLoading(false,error);
  88. })
  89. },
  90. radioGroupChange(){
  91. this.downItem.isRemind=this.popid;
  92. var item= this.downItem
  93. if(item.isRemind==0){
  94. if(this.downItem.remindId){
  95. this.del(item.remindId,item.isRemind!=0)
  96. }else{
  97. this.show1 = false
  98. this.$forceUpdate()
  99. }
  100. return
  101. }
  102. if(item.remindId){
  103. this.del(item.remindId,item.isRemind!=0)
  104. }else{
  105. this.remindAdd()
  106. }
  107. },del(id,bl){
  108. API_index.cancelRemind(id).then((res) => {
  109. this.downItem.remindId=""
  110. if(bl){
  111. this.remindAdd()
  112. }else{
  113. this.show1 = false
  114. this.$forceUpdate()
  115. this.$refs.common.alert( "设置成功");
  116. }
  117. }).catch(error => {
  118. this.$refs.common.alert( error);
  119. })
  120. },
  121. remind(){
  122. var myBtn = document.getElementById("subscribe-btn").tap();
  123. myBtn.tap();
  124. },
  125. showCar(item){
  126. for(var i in this.carList){
  127. var car= this.carList[i]
  128. if(car.currentStationId==item.id){
  129. return true;
  130. }
  131. }
  132. return false;
  133. },
  134. getCar(){
  135. if(this.stationList.length==0){
  136. return;
  137. }
  138. var obj={
  139. routeId:this.id,
  140. startStationId:this.stationList[0].id,
  141. }
  142. API.routeShiftList(obj).then((response) => {
  143. this.carList=response.data;
  144. this.$refs.amap.setCarList(response.data);
  145. }).catch(error => {
  146. this.$refs.common.showLoading(false,error)
  147. })
  148. },
  149. mapopenBtn(){
  150. this.mapopen=!this.mapopen;
  151. if(this.mapopen){
  152. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  153. }else{
  154. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  155. }
  156. },
  157. downBtn(item) {
  158. this.$refs.amap.setSite(item);
  159. this.$refs.amap.setCenter(item);
  160. this.downid=item.id;
  161. this.downItem=item;
  162. this.vehicleStationDis();
  163. this.$forceUpdate()
  164. },
  165. remindAdd(){
  166. if(this.downItem.id){
  167. var obj={
  168. startStationId:this.stationList[0].id,
  169. endStationId:this.stationList[this.stationList.length-1].id,
  170. remindStationId :this.downItem.id,
  171. stopInAdvance:this.downItem.isRemind,
  172. remindType:"1",
  173. routeId:this.routeInfo.id,
  174. openId:this.carhelp.getOpenId()
  175. }
  176. API_index.saveRemind(obj).then((res) => {
  177. this.downItem.remindId=res.data.id
  178. this.$refs.common.alert( "设置成功");
  179. this.show1 = false
  180. this.$forceUpdate()
  181. }).catch(error => {
  182. this.$refs.common.alert( error);
  183. })
  184. }
  185. },
  186. drawing(point, startend) {
  187. if (this.$refs.amap) {
  188. this.$refs.amap.initMap(point, this.stationList,startend);
  189. }
  190. },
  191. carShow(item){
  192. var caritem =null;
  193. for(var i in this.carList){
  194. var car= this.carList[i]
  195. if(car.currentStationId==item.id){
  196. var caritem=car;
  197. break
  198. }
  199. }
  200. this.caritem=caritem;
  201. this.caritemBl=true;
  202. },
  203. reverse(){
  204. this.stationList.reverse();
  205. this.getCar()
  206. this.passengerShiftRemindList();
  207. this.$refs.amap.setStartend(this.stationList);
  208. document.getElementById('map-route-main').scrollLeft = 0
  209. this.$nextTick(function() {
  210. const query = uni.createSelectorQuery().in(this);
  211. query.select('.map-down').boundingClientRect(data => {
  212. if(data){
  213. document.getElementById('map-route-main').scrollLeft = data.left-20;
  214. }
  215. this.$refs.common.showLoading(false);
  216. //this.downBtn()
  217. }).exec();
  218. });
  219. },
  220. setRemind(){
  221. for(var i in this.stationList){
  222. var item=this.stationList[i];
  223. item.isRemind=0;
  224. item.remindId="";
  225. for(var j in this.remindList){
  226. var obj=this.remindList[j];
  227. if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
  228. if(obj.remindStationId==item.id){
  229. item.remindId=obj.id;
  230. item.isRemind=obj.stopInAdvance;
  231. }
  232. }
  233. }
  234. }
  235. this.$forceUpdate()
  236. },
  237. passengerShiftRemindList(){
  238. this.$refs.common.showLoading()
  239. API.passengerShiftRemindList({
  240. routeId:this.id,
  241. openId:this.carhelp.getOpenId(),
  242. }).then((response) => {
  243. this.remindList=response.data;
  244. this.setRemind();
  245. this.$refs.common.showLoading(false)
  246. })
  247. },
  248. getPassengerInfo() {
  249. this.$refs.common.showLoading()
  250. API.routeDetail(this.id).then((response) => {
  251. var list=response.data.stationInfoList;
  252. if(this.upid&&list.length){
  253. if(this.upid==list[list.length-1].id){
  254. list.reverse();
  255. }
  256. this.upid="";
  257. }
  258. this.stationList=list;
  259. for(var i in list){
  260. list[i].isRemind=0;
  261. if(list[i].id==this.downid){
  262. this.downItem=list[i];
  263. }
  264. }
  265. this.passengerShiftRemindList();
  266. this.$refs.common.showLoading(false)
  267. var point = [];
  268. this.routeInfo=response.data.routeInfo;
  269. this.title=this.routeInfo.name;
  270. if(!response.data.routeInfo.mapPath){
  271. this.$refs.common.showLoading(false,"路线加载失败!")
  272. return;
  273. }
  274. response.data.routeInfo.mapPath.split("|").forEach((item) => {
  275. var sz = item.split(",");
  276. point.push({
  277. longitude: sz[0],
  278. latitude: sz[1],
  279. })
  280. })
  281. var startend = [{
  282. longitude: this.stationList[0].longitude,
  283. latitude: this.stationList[0].latitude,
  284. name: this.stationList[0].name
  285. }, {
  286. longitude: this.stationList[this.stationList.length-1].longitude,
  287. latitude: this.stationList[this.stationList.length-1].latitude,
  288. name: this.stationList[this.stationList.length-1].name
  289. }];
  290. this.drawing(point,startend);
  291. this.$refs.common.showLoading(false)
  292. this.getPoint()
  293. this.$nextTick(function() {
  294. const query = uni.createSelectorQuery().in(this);
  295. query.select('.map-down').boundingClientRect(data => {
  296. if(data){
  297. document.getElementById('map-route-main').scrollLeft = data.left-20;
  298. }
  299. this.$refs.common.showLoading(false);
  300. //this.downBtn()
  301. }).exec();
  302. });
  303. }).catch(error => {
  304. this.$refs.common.showLoading(false,error)
  305. })
  306. },
  307. mapdown(){
  308. if(this.downid){
  309. this.downBtn(this.downItem)
  310. }
  311. },
  312. getPoint() {
  313. if (!this.info.init) {
  314. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  315. // this.$refs.common.showLoading(false)
  316. this.getLocation()
  317. });
  318. }else{
  319. this.getLocation()
  320. }
  321. this.getCar();
  322. var pages = getCurrentPages();
  323. var page = (pages[pages.length - 1]).route;
  324. if (page == "pages/route/index") {
  325. setTimeout(this.getPoint, 10000);
  326. }
  327. },
  328. getLocation(){
  329. WxJsApi.getLocation().then((res) => {
  330. console.log("----getLocation ok-----")
  331. var latitude = parseFloat(res.latitude);
  332. var longitude = parseFloat(res.longitude);
  333. if (!this.info.init) {
  334. this.latitude = latitude;
  335. this.longitude = longitude;
  336. }
  337. this.info.init = true
  338. this.info.latitude = latitude;
  339. this.info.longitude = longitude;
  340. this.$refs.amap.setPerson(this.info);
  341. }).catch(error => {
  342. console.log(error)
  343. })
  344. }
  345. },
  346. onLoad(op) {
  347. this.upid=op.upid;
  348. this.id = op.id
  349. this.downid=op.downid;
  350. },
  351. onUnload() {
  352. if (this.myinterval) {
  353. clearInterval(this.myinterval)
  354. }
  355. },
  356. onReady() {
  357. WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
  358. // this.$refs.common.showLoading(false)
  359. this.wxinit=true;
  360. });
  361. this.getPassengerInfo()
  362. }
  363. }