home.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. import * as WxJsApi from '@/utils/wxJsApi.js'
  2. import * as API from '@/apis/buytickets.js'
  3. import * as Pay from '@/apis/weixin.js'
  4. import {
  5. wxPayJs
  6. } from '@/utils/wxpay'
  7. import Carmap from '@/components/Carmap.vue'
  8. export default {
  9. data() {
  10. return {
  11. initBl: false,
  12. title: '乘车人',
  13. show: false,
  14. id: 0, // 使用 marker点击事件 需要填写id
  15. //地图居中后的位置
  16. longitude: 112.276527,
  17. latitude: 30.306427,
  18. shiftInfo: {
  19. },
  20. list: [{}, {}],
  21. //车的位置
  22. car: {
  23. obj: null,
  24. longitude: '',
  25. latitude: '',
  26. },
  27. stationList: [],
  28. //个人
  29. info: {
  30. obj: null,
  31. init: false,
  32. longitude: '',
  33. latitude: '',
  34. },
  35. myinterval: '',
  36. downId: '',
  37. downName: '',
  38. passengerInfo: {
  39. totalAmount: 0,
  40. id: '',
  41. list: []
  42. }
  43. }
  44. },
  45. components: {
  46. Carmap
  47. },
  48. methods: {
  49. gotoHome(){
  50. uni.switchTab({
  51. url: '/pages/index/index'
  52. });
  53. },
  54. select(op) {
  55. //passengerInfo
  56. var obj = this.carhelp.get("form");
  57. if (this.passengerInfo.id) {
  58. obj.mergeOrderId = this.passengerInfo.id;
  59. }
  60. if (op) {
  61. obj.op = op;
  62. this.carhelp.set("form", obj);
  63. uni.navigateTo({
  64. url: '/pages/buytickets/site?id=' + this.id
  65. })
  66. } else {
  67. obj.op = null;
  68. this.carhelp.set("form", obj);
  69. uni.navigateTo({
  70. url: '/pages/buytickets/index?id=' + this.id+'&back=true'
  71. })
  72. }
  73. },
  74. submit() {
  75. this.$refs.common.showLoading();
  76. console.log("Pay+"+new Date().getTime())
  77. Pay.wxpay(this.passengerInfo.id).then((response) => {
  78. if(!response.result){
  79. this.$refs.common.showLoading(false, response.message);
  80. return
  81. }
  82. var data = response.data
  83. var url = window.location.href.split("#")[0] + "/#/pages/buytickets/success";
  84. console.log("Pay+"+new Date().getTime())
  85. var obj = {
  86. ...data,
  87. url: url
  88. }
  89. wxPayJs(obj);
  90. }).catch(error => {
  91. this.$refs.common.showLoading(false, error);
  92. })
  93. },
  94. drawing(point, startend) {
  95. if (this.$refs.amap) {
  96. this.$refs.amap.initMap(point, this.stationList, startend);
  97. }
  98. },
  99. getShiftInfoResponse(response, response2) {
  100. this.$refs.common.showLoading();
  101. var res = response.data
  102. this.title = res.routeName;
  103. this.shiftInfo = res;
  104. this.car.latitude = res.latitude;
  105. this.car.longitude = res.longitude;
  106. var point = [];
  107. res.mapPath.split("|").forEach((item) => {
  108. var sz = item.split(",");
  109. point.push({
  110. longitude: sz[0],
  111. latitude: sz[1],
  112. })
  113. if (!process.car.SIMPLE_RUN) {
  114. this.longitude = sz[0]
  115. this.latitude = sz[1]
  116. }
  117. })
  118. var obj = this.carhelp.get("form")
  119. obj.getShiftInfo = response;
  120. obj.getVehicleStationInfo = response2;
  121. var list = obj.getVehicleStationInfo.data;
  122. for (var i in list) {
  123. list[i].status = 0;
  124. }
  125. this.stationList = list
  126. obj = this.carhelp.set("form", obj)
  127. var sz1 = response.data.startStationCoordinate.split("|")
  128. var sz2 = response.data.endStationCoordinate.split("|")
  129. var startend = [{
  130. longitude: sz1[0],
  131. latitude: sz1[1],
  132. name: response.data.startStation
  133. }, {
  134. longitude: sz2[0],
  135. latitude: sz2[1],
  136. name: response.data.endStation
  137. }];
  138. this.drawing(point, startend);
  139. //this.$refs.common.showLoading(false);
  140. this.getPoint()
  141. },
  142. getShiftInfo() {
  143. this.$refs.common.showLoading();
  144. var obj = this.carhelp.get("form")
  145. if (false&&obj.getShiftInfo && obj.getVehicleStationInfo) {
  146. this.stationList = obj.getVehicleStationInfo.data
  147. this.getShiftInfoResponse(obj.getShiftInfo, obj.getVehicleStationInfo);
  148. return;
  149. }
  150. API.getShiftInfo(this.id).then((response) => {
  151. if (!response.result) {
  152. this.$refs.common.goError(response.message)
  153. return
  154. }
  155. API.getVehicleStationInfo(this.id).then((response2) => {
  156. this.getShiftInfoResponse(response, response2);
  157. })
  158. }).catch(error => {
  159. this.$refs.common.showLoading(false, error);
  160. })
  161. },
  162. getPassengerInfo() {
  163. var thisform = {
  164. id: this.id,
  165. openId: this.carhelp.getOpenId()
  166. }
  167. this.$refs.common.showLoading()
  168. API.getPassengerInfo(thisform).then((response) => {
  169. if (!response.result) {
  170. this.$refs.common.goError(response.message)
  171. return
  172. }
  173. if (response.data.supply) {
  174. this.$refs.common.alert('存在需要补票的订单。')
  175. uni.switchTab({
  176. url: '/pages/news/index'
  177. });
  178. return;
  179. }
  180. this.passengerInfo = response.data
  181. var obj = this.carhelp.get("form");
  182. if(!obj){
  183. obj={}
  184. }
  185. obj.list = this.passengerInfo.list;
  186. obj.name= 'buytickets';
  187. obj.id= this.id;
  188. this.carhelp.set("form", obj);
  189. this.getShiftInfo()
  190. }).catch(error => {
  191. if (error) {
  192. this.$refs.common.goError(error)
  193. return
  194. }
  195. //this.$refs.common.showLoading(false,error)
  196. })
  197. },
  198. getPoint() {
  199. if (!this.initBl) {
  200. this.$refs.common.showLoading();
  201. }
  202. API.getVehicleInfo(this.id).then((response) => {
  203. this.car = response.data;
  204. this.$refs.amap.setCar(this.car);
  205. var bl = false;
  206. for (var i in this.stationList) {
  207. var stat = this.stationList[i];
  208. stat.status = 0
  209. if (bl) {
  210. stat.status = 2;
  211. }
  212. if (stat.id == this.car.currentStationId) {
  213. stat.status = 1;
  214. bl = true;
  215. }
  216. }
  217. if (!this.initBl) {
  218. this.initBl = true
  219. this.$nextTick(function() {
  220. const query = uni.createSelectorQuery().in(this);
  221. query.select('.map-now').boundingClientRect(data => {
  222. if (data) {
  223. document.getElementById('map-route-main').scrollLeft = data
  224. .left;
  225. }
  226. this.$refs.common.showLoading(false);
  227. }).exec();
  228. });
  229. } else {
  230. this.$refs.common.showLoading(false);
  231. }
  232. }).catch(error => {
  233. this.$refs.common.showLoading(false, error);
  234. })
  235. if (!this.info.init) {
  236. WxJsApi.getWxConfig(['getLocation']).then(() => {
  237. // this.$refs.common.showLoading(false)
  238. this.getLocation()
  239. });
  240. }else{
  241. this.getLocation()
  242. }
  243. var pages = getCurrentPages();
  244. var page = (pages[pages.length - 1]).route;
  245. if (page == "pages/buytickets/home") {
  246. setTimeout(this.getPoint, 10000);
  247. }
  248. },
  249. getLocation(){
  250. WxJsApi.getLocation().then((res) => {
  251. console.log("----getLocation ok-----")
  252. var latitude = parseFloat(res.latitude);
  253. var longitude = parseFloat(res.longitude);
  254. if (!this.info.init) {
  255. this.latitude = latitude;
  256. this.longitude = longitude;
  257. }
  258. this.info.init = true
  259. this.info.latitude = latitude;
  260. this.info.longitude = longitude;
  261. this.$refs.amap.setPerson(this.info);
  262. }).catch(error => {
  263. console.log(error)
  264. })
  265. }
  266. },
  267. onLoad(op) {
  268. this.id = op.id
  269. },
  270. onUnload() {
  271. if (this.myinterval) {
  272. clearInterval(this.myinterval)
  273. }
  274. },
  275. onReady() {
  276. if (false&&!this.carhelp.getPersonInfo()) {
  277. this.$refs.common.setFnc(this.confirmBtn)
  278. this.$refs.common.alert2('您还不是东胜掌上通勤用户,注册后再购买车票。', '前往注册', '尚未注册')
  279. } else{
  280. }
  281. this.getPassengerInfo()
  282. }
  283. }