index.js 9.2 KB

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