selectSite.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. import * as WxJsApi from '@/utils/wxJsApi.js'
  2. import * as API from '@/apis/buytickets.js'
  3. import Carmap from '@/components/Carmap.vue'
  4. export default {
  5. data() {
  6. return {
  7. caritemBl:false,
  8. show1: false,
  9. show2: false,
  10. buy:"",
  11. look:false,
  12. initBl: false,
  13. title: '乘车人',
  14. show: false,
  15. id: 0, // 使用 marker点击事件 需要填写id
  16. k:0,
  17. //地图居中后的位置
  18. longitude: 112.276527,
  19. latitude: 30.306427,
  20. upid:'',
  21. shiftInfo: {
  22. },
  23. mapopen:false,
  24. list: [{}, {}],
  25. //车的位置
  26. car: {
  27. obj: null,
  28. longitude: '',
  29. latitude: '',
  30. },
  31. stationList: [],
  32. //个人
  33. info: {
  34. obj: null,
  35. init: false,
  36. longitude: '',
  37. latitude: '',
  38. },
  39. showInfo:{
  40. driver:{}
  41. },
  42. myinterval: '',
  43. downId: '',
  44. downName: '',
  45. passengerInfo:{
  46. totalAmount:0,
  47. id:'',
  48. list:[]
  49. }
  50. }
  51. },
  52. components: {
  53. Carmap
  54. },
  55. methods: {
  56. makePhoneCall(tel){
  57. uni.makePhoneCall({
  58. phoneNumber: tel //仅为示例
  59. });
  60. },
  61. mapopenBtn(){
  62. this.mapopen=!this.mapopen;
  63. if(this.mapopen){
  64. this.$refs.amap.setMyStyle("width: 100%; height: 340px;")
  65. }else{
  66. this.$refs.amap.setMyStyle("width: 100%; height: 140px;")
  67. }
  68. },
  69. downBtn(item) {
  70. if (!this.look&&item.id==this.car.currentStationId&&this.upid!=item.id) {
  71. this.downId = item.id
  72. this.downName = item.stationName
  73. this.$refs.amap.setDown(item);
  74. }
  75. if (!this.look&&item.status != 0) {
  76. this.downId = item.id
  77. this.downName = item.stationName
  78. this.$refs.amap.setDown(item);
  79. }
  80. this.$refs.amap.setCenter(item);
  81. },
  82. selectSiteBtn(){
  83. var obj=this.carhelp.get("form");
  84. var upid='';
  85. upid=obj.oplist[0].upStationId;
  86. var downid=this.downId;
  87. this.$refs.common.showLoading();
  88. var thisform={
  89. ticketUpStationId:upid,
  90. ticketDownStationId:downid ,
  91. ticketDownStationName:this.downName,
  92. price1:0,
  93. price2:0
  94. }
  95. thisform.ticketType=1;
  96. API.ticketAmount(thisform).then((response) => {
  97. thisform.price1=response.data.price
  98. thisform.ticketType=2;
  99. API.ticketAmount(thisform).then((response2) => {
  100. thisform.price2=response2.data.price
  101. obj.ticket=thisform;
  102. if(obj.op){
  103. obj.op.ticketDownStationId=this.downId;
  104. obj.op.ticketDownStationName=this.downName;
  105. }
  106. this.carhelp.set("form",obj);
  107. //uni.navigateBack()
  108. uni.redirectTo({
  109. url: '/pages/buytickets/site?id='+this.id
  110. })
  111. })
  112. }).catch(error => {
  113. this.$refs.common.showLoading(false, error);
  114. })
  115. },
  116. drawing(point, startend) {
  117. if(this.$refs.amap){
  118. this.$refs.amap.initMap(point, this.stationList, startend);
  119. }
  120. },
  121. getShiftInfoResponse(response, response2) {
  122. this.$refs.common.showLoading();
  123. var res = response.data
  124. this.title = res.routeName;
  125. this.shiftInfo = res;
  126. this.car.latitude = res.latitude;
  127. this.car.longitude = res.longitude;
  128. var point = [];
  129. res.mapPath.split("|").forEach((item) => {
  130. var sz = item.split(",");
  131. point.push({
  132. longitude: sz[0],
  133. latitude: sz[1],
  134. })
  135. if (!process.car.SIMPLE_RUN) {
  136. this.longitude = sz[0]
  137. this.latitude = sz[1]
  138. }
  139. })
  140. var obj = this.carhelp.get("form")
  141. obj.getShiftInfo = response;
  142. obj.getVehicleStationInfo = response2;
  143. var list = obj.getVehicleStationInfo.data;
  144. for (var i in list) {
  145. list[i].status = 0;
  146. }
  147. this.stationList = list
  148. obj = this.carhelp.set("form", obj)
  149. var sz1 = response.data.startStationCoordinate.split("|")
  150. var sz2 = response.data.endStationCoordinate.split("|")
  151. var startend = [{
  152. longitude: sz1[0],
  153. latitude: sz1[1],
  154. name: response.data.startStation
  155. }, {
  156. longitude: sz2[0],
  157. latitude: sz2[1],
  158. name: response.data.endStation
  159. }];
  160. this.drawing(point, startend);
  161. //this.$refs.common.showLoading(false);
  162. this.getPoint()
  163. },
  164. showname(name){
  165. if(!name){
  166. return "";
  167. }
  168. return name.substring(0,1)+'师傅';
  169. },
  170. carShow(){
  171. this.caritemBl=true;
  172. },
  173. getShiftInfo() {
  174. this.$refs.common.showLoading();
  175. var obj = this.carhelp.get("form")
  176. if (false&&obj.getShiftInfo && obj.getVehicleStationInfo) {
  177. this.stationList = obj.getVehicleStationInfo.data
  178. this.getShiftInfoResponse(obj.getShiftInfo, obj.getVehicleStationInfo);
  179. return;
  180. }
  181. API.getShiftInfo(this.id).then((response) => {
  182. if (!response.result) {
  183. this.$refs.common.goError(response.message)
  184. return
  185. }
  186. this.showInfo={
  187. driver:response.data.driver,
  188. licensePlateNumber:response.data.licensePlateNumber
  189. }
  190. API.getVehicleStationInfo(this.id).then((response2) => {
  191. this.getShiftInfoResponse(response, response2);
  192. })
  193. }).catch(error => {
  194. this.$refs.common.showLoading(false, error);
  195. })
  196. },
  197. carShow2(item){
  198. console.log(item)
  199. if(item.type=="car"){
  200. setTimeout(()=>{
  201. this.carShow()
  202. }, 100);
  203. }
  204. if(item.type=="point"){
  205. setTimeout(()=>{
  206. this.downBtn(item.obj)
  207. document.getElementById('map-route-main').scrollLeft = 0
  208. this.$nextTick(function() {
  209. const query = uni.createSelectorQuery().in(this);
  210. query.select('.map-down').boundingClientRect(data => {
  211. if(data){
  212. document.getElementById('map-route-main').scrollLeft = data.left-100;
  213. }
  214. this.$refs.common.showLoading(false);
  215. //this.downBtn()
  216. }).exec();
  217. });
  218. }, 100);
  219. }
  220. },
  221. getPoint() {
  222. if (!this.initBl) {
  223. this.$refs.common.showLoading();
  224. }
  225. //this.k=0
  226. API.getVehicleInfo(this.id).then((response) => {
  227. this.car = response.data;
  228. //this.car.currentStationId=this.stationList[this.k].id
  229. //this.car.currentStationStatus="2"
  230. //this.car.currentStationId=this.stationList[2].id
  231. //this.car.currentStationStatus="2";
  232. this.$refs.amap.setCar(this.car);
  233. var bl = false;
  234. var bl2 = false;
  235. for (var i in this.stationList) {
  236. var stat = this.stationList[i];
  237. stat.status = 0
  238. if (bl2) {
  239. stat.status = 2;
  240. }
  241. if (bl) {
  242. stat.status = 1;
  243. bl = false;
  244. bl2 = true;
  245. }
  246. if (stat.id == this.car.currentStationId) {
  247. if(this.car.currentStationStatus=="3"){
  248. if(eval(i+"+"+1)!=this.stationList.length){
  249. this.car.currentStationId2=this.stationList[eval(i+"+"+1)].id;
  250. }
  251. }
  252. bl = true;
  253. if(i==this.stationList.length-1){
  254. stat.status = 1;
  255. }
  256. if(this.buy){
  257. this.downBtn(stat)
  258. }
  259. }
  260. }
  261. if (!this.initBl) {
  262. this.initBl = true
  263. this.$nextTick(function() {
  264. const query = uni.createSelectorQuery().in(this);
  265. query.select('#map-now').boundingClientRect(data => {
  266. if(data){
  267. document.getElementById('map-route-main').scrollLeft = data.left-100;
  268. }
  269. this.$refs.common.showLoading(false);
  270. }).exec();
  271. });
  272. }else{
  273. this.$refs.common.showLoading(false);
  274. }
  275. }).catch(error => {
  276. this.$refs.common.showLoading(false, error);
  277. })
  278. WxJsApi.getLocation().then((res) => {
  279. var latitude = parseFloat(res.latitude);
  280. var longitude = parseFloat(res.longitude);
  281. if (!this.info.init) {
  282. this.latitude = latitude;
  283. this.longitude = longitude;
  284. }
  285. this.info.init = true
  286. this.info.latitude = latitude;
  287. this.info.longitude = longitude;
  288. this.$refs.amap.setPerson(this.info);
  289. }).catch(error => {
  290. })
  291. var pages = getCurrentPages();
  292. var page = (pages[pages.length - 1]).route;
  293. if(page=="pages/buytickets/selectSite"){
  294. setTimeout(this.getPoint, 10000);
  295. }
  296. },
  297. },
  298. onLoad(op) {
  299. if(op.select){
  300. this.look=false;
  301. }else{
  302. this.look=true;// 只读界面
  303. }
  304. this.id = op.id
  305. var obj=this.carhelp.get("form");
  306. if(obj.oplist&&obj.oplist.length){
  307. this.upid=obj.oplist[0].upStationId;
  308. }
  309. },
  310. onUnload() {
  311. if (this.myinterval) {
  312. clearInterval(this.myinterval)
  313. }
  314. },onShow(){
  315. console.log("onShowonShowonShowonShow")
  316. this.$nextTick(function() {
  317. try{
  318. const query = uni.createSelectorQuery().in(this);
  319. query.select('#map-now').boundingClientRect(data => {
  320. if(data){
  321. document.getElementById('map-route-main').scrollLeft = data.left-100;
  322. }
  323. this.$refs.common.showLoading(false);
  324. }).exec();
  325. }catch(err){
  326. console.log("err")
  327. }
  328. });
  329. },
  330. onReady() {
  331. this.$refs.common.showLoading()
  332. WxJsApi.getWxConfig(['getLocation']).then(()=>{
  333. this.$refs.common.showLoading(false)
  334. });
  335. var obj = this.carhelp.get("form");
  336. this.buy=obj.buy;
  337. this.getShiftInfo()
  338. var pages = getCurrentPages();
  339. var page = (pages[pages.length - 1]).route;
  340. }
  341. }