index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import * as WxJsApi from '@/utils/wxJsApi.js'
  2. import * as API from '@/apis/index.js'
  3. export default {
  4. data() {
  5. return {
  6. index:0,
  7. btn:{
  8. color: '#1677FF'
  9. },
  10. isLoading:false,
  11. getPointBl:false,//是否定位完成
  12. longitude: '',
  13. latitude: '',
  14. optionsName:'荆州',
  15. options1:[
  16. {
  17. label: '荆州',
  18. value: '荆州',
  19. },
  20. {
  21. label: '沙市',
  22. value: '沙市',
  23. },
  24. ],
  25. list: [ ],
  26. siteList:[
  27. ]
  28. }
  29. },
  30. onLoad(){
  31. },
  32. methods: {
  33. getNewNum(){
  34. var pages = getCurrentPages();
  35. var page = (pages[pages.length - 1]).route;
  36. if(page=="pages/index/index"||
  37. page=="pages/my/index"||
  38. page=="pages/news/index"){
  39. setTimeout(this.getNewNum,10000)
  40. }else{
  41. setTimeout(this.getNewNum,1000)
  42. return;
  43. }
  44. var data={
  45. openId:this.carhelp.getOpenId()
  46. };
  47. API.passengerMessageNoReadNum(data).then((res) => {
  48. var num=res.data.num;
  49. if(num){
  50. uni.setTabBarBadge({
  51. index: 1,
  52. text: num+''
  53. })
  54. }else{
  55. uni.removeTabBarBadge({
  56. index:1
  57. })
  58. }
  59. }).catch(error => {
  60. })
  61. } ,
  62. getBanner() {
  63. API.getBannerInfo("1").then((res) => {
  64. this.list=res.data;
  65. for(var i in this.list){
  66. var obj=this.list[i]
  67. obj.url=obj.linkUrl
  68. obj.image=obj.picUrl
  69. obj.title=obj.name
  70. }
  71. this.carhelp.set("bannerList",this.list);
  72. }).catch(error => {
  73. this.$refs.common.alert( error);
  74. })
  75. },
  76. bindPickerChange: function(e) {
  77. // console.log('picker发送选择改变,携带值为', e.target.value)
  78. this.index = e.target.value
  79. },
  80. gotoQuery(){
  81. uni.navigateTo({
  82. url:'/pages/query/index?back=true'
  83. })
  84. },
  85. gotoLine(item){
  86. if(item.id){
  87. this.carhelp.set("form",{});
  88. uni.navigateTo({
  89. url:'/pages/buytickets/selectSite?id='+item.id
  90. })
  91. }else{
  92. uni.navigateTo({
  93. url:'/pages/route/index?id='+item.routeId
  94. })
  95. }
  96. },
  97. getPoint() {
  98. this.$refs.common.alert("正在获取定位信息,为您查找附近的站点...");
  99. WxJsApi.getLocation().then((res) => {
  100. var latitude = parseFloat(res.latitude);
  101. var longitude = parseFloat(res.longitude);
  102. this.latitude = latitude;
  103. this.longitude = longitude;
  104. //this.$refs.common.alert("定位中...",);
  105. this.passengerNearbyStation()
  106. this.getPointBl=true
  107. this.$refs.common.showLoading(false);
  108. }).catch(error => {
  109. this.$refs.common.alert( error);
  110. })
  111. },
  112. passengerNearbyStation(){
  113. this.latitude = '30.306452';
  114. this.longitude = '112.27642';
  115. var form={
  116. longitude:this.longitude,
  117. latitude:this.latitude,
  118. pageIndex:1,
  119. pageSize:5
  120. }
  121. this.$refs.common.showLoading();
  122. API.passengerNearbyStation(form).then((res) => {
  123. this.siteList=res.data;
  124. this.isLoading=true;
  125. //this.$refs.common.showLoading(fa);
  126. if(this.siteList.length){
  127. this.$refs.common.alert( "已为您查询出附近的站点");
  128. }else{
  129. this.$refs.common.alert( "查询成功,附近暂无站点信息!");
  130. }
  131. }).catch(error => {
  132. this.$refs.common.alert( error);
  133. })
  134. },
  135. getScan(){
  136. this.$refs.common.showLoading()
  137. WxJsApi.scanQRCode(0,this.$refs.common).then(function(url){
  138. console.log(url)
  139. window.location.href=url;
  140. }).catch(error => {
  141. this.$refs.common.showLoading(false,error)
  142. });
  143. },
  144. clickSwiper(index){
  145. var url=this.list[index].url;
  146. if(url){
  147. if(url.indexOf("http")==0){
  148. window.location.href=url;
  149. }else if(url.indexOf("/pages/")==0){
  150. uni.navigateTo({
  151. url:this.list[index].url
  152. })
  153. }
  154. }
  155. },
  156. closeDropdown() {
  157. this.$refs.uDropdown.close();
  158. }
  159. },onReady(){
  160. WxJsApi.getWxConfig(['scanQRCode','getLocation']);
  161. var list=this.carhelp.get("bannerList");
  162. if(list){
  163. this.list=list;
  164. }
  165. this.getPoint();
  166. this.getBanner();
  167. this.getNewNum()
  168. //清空缓存
  169. this.carhelp.set("form",{});
  170. }
  171. }