index.js 8.1 KB

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