index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import * as WxJsApi from '@/utils/wxJsApi.js'
  2. import * as API from '@/apis/index.js'
  3. import {
  4. getRemind
  5. } from '@/utils'
  6. export default {
  7. data() {
  8. return {
  9. isReady:false,
  10. rbool:false,
  11. wxinit:false,
  12. index:0,
  13. btn:{
  14. color: '#1677FF'
  15. },
  16. remindBl:false,
  17. remindInfo:null,
  18. isLoading:false,
  19. getPointBl:false,//是否定位完成
  20. longitude: '',
  21. latitude: '',
  22. optionsName:'荆州',
  23. options1:[
  24. {
  25. label: '荆州',
  26. value: '荆州',
  27. },
  28. {
  29. label: '沙市',
  30. value: '沙市',
  31. },
  32. ],
  33. list: [ ],
  34. siteList:[
  35. ],
  36. radiolist: [
  37. {
  38. name: '不提醒',
  39. isRemind: "0",
  40. },
  41. {
  42. name: '提前1站',
  43. isRemind: "1",
  44. },
  45. {
  46. name: '提前2站',
  47. isRemind: "2",
  48. }
  49. ],
  50. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  51. value: 'orange',
  52. }
  53. },
  54. onLoad(){
  55. },
  56. methods: {
  57. // 选中某个单选框时,由radio时触发
  58. radioChange(e) {
  59. // console.log(e);
  60. },
  61. // 选中任一radio时,由radio-group触发
  62. remindHD(){
  63. var item= this.remindInfo
  64. if(item.isRemind==0){
  65. if(this.remindInfo.remindId){
  66. this.del(item.remindId,item.isRemind!=0)
  67. }
  68. return
  69. }
  70. if(item.remindId){
  71. this.del(item.remindId,item.isRemind!=0)
  72. }else{
  73. this.add()
  74. }
  75. },
  76. del(id,bl){
  77. API.cancelRemind(id).then((res) => {
  78. this.remindInfo.remindId=""
  79. if(bl){
  80. this.add()
  81. }else{
  82. this.$refs.common.alert( "设置成功");
  83. }
  84. }).catch(error => {
  85. this.$refs.common.alert( error);
  86. })
  87. },
  88. add(){
  89. var item= this.remindInfo
  90. var obj={
  91. startStationId:item.startStationId,
  92. remindStationId :item.ticketDownStationId,
  93. stopInAdvance:item.isRemind,
  94. remindType:"2",
  95. vehicleShiftId:item.vehicleShiftId,
  96. openId:this.carhelp.getOpenId()
  97. }
  98. API.saveRemind(obj).then((res) => {
  99. item.remindId=res.data.id
  100. this.$refs.common.alert( "设置成功");
  101. }).catch(error => {
  102. this.$refs.common.alert( error);
  103. })
  104. },
  105. radioGroupChange(item) {
  106. this.remindHD();
  107. },
  108. getRemindInfo(){
  109. API.queryRemind(this.carhelp.getOpenId()).then((res) => {
  110. if(res.data.length){
  111. this.remindInfo=res.data[0]
  112. var obj=this.remindInfo
  113. if(obj.remindId){
  114. this.rbool=true;
  115. obj.isRemind=obj.stopInAdvance;
  116. }else{
  117. obj.isRemind="0";
  118. }
  119. }
  120. }).catch(error => {
  121. this.$refs.common.alert( error);
  122. })
  123. },
  124. getBtn(){
  125. },
  126. getNewNum(){
  127. var pages = getCurrentPages();
  128. var page = (pages[pages.length - 1]).route;
  129. if(page=="pages/index/index"||
  130. page=="pages/my/index"||
  131. page=="pages/news/index"){
  132. setTimeout(this.getNewNum,10000)
  133. }else{
  134. setTimeout(this.getNewNum,1000)
  135. return;
  136. }
  137. var data={
  138. openId:this.carhelp.getOpenId()
  139. };
  140. if(!this.carhelp.getOpenId()){
  141. return
  142. }
  143. API.passengerMessageNoReadNum(data).then((res) => {
  144. var num=res.data.num;
  145. if(num){
  146. uni.setTabBarBadge({
  147. index: 2,
  148. text: num+''
  149. })
  150. }else{
  151. uni.removeTabBarBadge({
  152. index:2
  153. })
  154. }
  155. }).catch(error => {
  156. })
  157. } ,
  158. getBanner() {
  159. API.getBannerInfo("1").then((res) => {
  160. this.list=res.data;
  161. for(var i in this.list){
  162. var obj=this.list[i]
  163. obj.url=obj.linkUrl
  164. obj.image=obj.picUrl
  165. obj.title=obj.name
  166. }
  167. this.carhelp.set("bannerList",this.list);
  168. }).catch(error => {
  169. this.$refs.common.alert( error);
  170. })
  171. },
  172. bindPickerChange: function(e) {
  173. // console.log('picker发送选择改变,携带值为', e.target.value)
  174. this.index = e.target.value
  175. },
  176. gotoQuery(){
  177. uni.navigateTo({
  178. url:'/pages/query/index?back=true'
  179. })
  180. },
  181. gotoLine(item,downid){
  182. uni.navigateTo({
  183. url:'/pages/route/index?id='+item.routeId+"&upid="+item.startStationId+"&downid="+downid
  184. })
  185. },
  186. gotoLineList(downid){
  187. uni.navigateTo({
  188. url:"/pages/index/sitePage?id="+downid+"&longitude="+this.longitude+"&latitude="+this.latitude
  189. })
  190. },
  191. getPoint() {
  192. this.$refs.common.alert("正在获取定位信息,为您查找附近的站点...");
  193. WxJsApi.getLocation().then((res) => {
  194. var latitude = parseFloat(res.latitude);
  195. var longitude = parseFloat(res.longitude);
  196. this.latitude = latitude;
  197. this.longitude = longitude;
  198. //this.$refs.common.alert("定位中...",);
  199. this.passengerNearbyStation()
  200. this.getPointBl=true
  201. this.$refs.common.showLoading(false);
  202. }).catch(error => {
  203. this.$refs.common.alert( error);
  204. })
  205. },
  206. passengerNearbyStation(){
  207. if(process.car.SIMPLE_RUN){
  208. this.latitude = '30.306452';
  209. this.longitude = '112.27642';
  210. }
  211. var form={
  212. longitude:this.longitude,
  213. latitude:this.latitude,
  214. pageIndex:1,
  215. pageSize:5
  216. }
  217. this.$refs.common.showLoading();
  218. API.passengerNearbyStation(form).then((res) => {
  219. this.siteList=res.data;
  220. this.isLoading=true;
  221. //this.$refs.common.showLoading(fa);
  222. if(this.siteList.length){
  223. this.$refs.common.alert( "已为您查询出附近的站点");
  224. }else{
  225. this.$refs.common.alert( "查询成功,附近暂无站点信息!");
  226. }
  227. }).catch(error => {
  228. this.$refs.common.alert( error);
  229. })
  230. },
  231. getScan(){
  232. this.$refs.common.showLoading()
  233. WxJsApi.scanQRCode(0,this.$refs.common).then(function(url){
  234. console.log(url)
  235. window.location.href=url;
  236. }).catch(error => {
  237. this.$refs.common.showLoading(false,error)
  238. });
  239. },
  240. clickSwiper(index){
  241. var url=this.list[index].url;
  242. if(url){
  243. if(url.indexOf("http")==0){
  244. window.location.href=url;
  245. }else if(url.indexOf("/pages/")==0){
  246. uni.navigateTo({
  247. url:this.list[index].url
  248. })
  249. }
  250. }
  251. },
  252. closeDropdown() {
  253. this.$refs.uDropdown.close();
  254. }
  255. },onReady(){
  256. WxJsApi.getWxConfig(['scanQRCode','getLocation','addEventListener']).then(()=>{
  257. this.wxinit=true;
  258. var _this=this;
  259. })
  260. //WxJsApi.requestSubscribeMessage(['Ilxy2TX264A3RHqRyDZqL_xUDxi9OuBNeJoDOBfMRHg'])
  261. var list=this.carhelp.get("bannerList");
  262. if(list){
  263. this.list=list;
  264. }
  265. //this.remindHD()
  266. this.getPoint();
  267. this.getBanner();
  268. this.getNewNum();
  269. this.getRemindInfo();
  270. this.getBtn();
  271. //清空缓存
  272. this.carhelp.set("form",{});
  273. this.isReady=true;
  274. },onShow(){
  275. if(this.isReady){
  276. this.getPoint();
  277. this.getRemindInfo();
  278. }
  279. },
  280. }