index.js 6.6 KB

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