App.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <style lang="scss">
  2. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  3. @import "@/uni_modules/uview-ui/index.scss";
  4. @import 'static/css/common.scss';
  5. </style>
  6. <script>
  7. import region from "@/components/region/data";
  8. import {
  9. mapMutations
  10. } from 'vuex';
  11. import * as config from '@/config'
  12. import appUpdate from 'common/appUpdate.js'
  13. import app_push from './components/APPPush/app_push.js'
  14. import permision from "@/js_sdk/wa-permission/permission.js"
  15. //插件对象
  16. var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
  17. export default {
  18. data() {
  19. return {
  20. shippingNoteInfos: [{
  21. shippingNoteNumber: '',
  22. serialNumber: "",
  23. startCountrySubdivisionCode: "",
  24. endCountrySubdivisionCode: "",
  25. startLongitude: "",
  26. startLatitude: "",
  27. endLongitude: "",
  28. endLatitude: "",
  29. startLocationText: "",
  30. endLocationText: "",
  31. vehicleNumber: "",
  32. driverName: "",
  33. interval: "",
  34. }],
  35. }},
  36. methods: {
  37. ...mapMutations(['login',"firstAuthentication"]),
  38. // vue的method里编写如下代码
  39. // async requestAndroidPermission(permisionID) {
  40. // var result = await permision.requestAndroidPermission(permisionID)
  41. // var strStatus
  42. // if (result == 1) {
  43. // strStatus = "已获得授权"
  44. // } else if (result == 0) {
  45. // strStatus = "未获得授权"
  46. // // permision.gotoAppPermissionSetting()
  47. // // 引导设置,判断是否有运输中订单,有订单,必须授权
  48. // } else {
  49. // strStatus = "被永久拒绝权限"
  50. // // permision.gotoAppPermissionSetting()
  51. // }
  52. // },
  53. send(_obj){//发送定位
  54. var remark = ""
  55. var that = this
  56. console.log("send参数",this.shippingNoteInfos)
  57. sdkwx.send(this.shippingNoteInfos[0].vehicleNumber, this.shippingNoteInfos[0].driverName,remark, this.shippingNoteInfos, function(res){
  58. console.log(res)
  59. if (res.type == "onSuccess") {
  60. console.log("App.vue发送定位成功")
  61. console.log(res);
  62. //成功
  63. var shippingNoteInfos = res.data;//运单信息列表
  64. if(shippingNoteInfos&&shippingNoteInfos.length >0 ){
  65. that.timer = setInterval(() => {
  66. //TODO
  67. that.send()
  68. }, shippingNoteInfos[0].interval+1000);
  69. }
  70. } else if (res.type == "onFailure"){
  71. console.log("App.vue发送定位失败",res)
  72. //失败
  73. var errorCode = res.data.errorCode;//错误码
  74. var errorMsg = res.data.errorMsg;//错误描述
  75. }
  76. });
  77. },
  78. },
  79. onLaunch: function() {
  80. var that = this
  81. // #ifdef APP-PLUS
  82. // this.$tabbarView.init()
  83. // uni.getNetworkType({
  84. // success: function (res) {
  85. // if(res.networkType=='none'){
  86. // let options = {
  87. // title: '提示',
  88. // info:'当前没有网络中',
  89. // okText: '连接Wifi',
  90. // cancelText:'开启流量',
  91. // infoAlignment:'center',
  92. // radius:10,
  93. // // cancelText: '否',
  94. // // showCancel:false,
  95. // okButtonColor:'#2772FB'
  96. // };
  97. // const native = uni.requireNativePlugin('AJ-Alert');
  98. // native.showAction(options, result => {
  99. // // #ifdef APP-PLUS
  100. // if (uni.getSystemInfoSync().platform == 'ios') {
  101. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  102. // } else if (uni.getSystemInfoSync().platform == 'android') {
  103. // plus.runtime.quit();
  104. // }
  105. // // #endif
  106. // // 点击是的回调, result暂时没有返回内容
  107. // }, cancel => {
  108. // // 点击否的回调
  109. // });
  110. // }
  111. // console.log(res.networkType);
  112. // }
  113. // });
  114. uni.getSystemInfo({
  115. success(res) {
  116. uni.setStorageSync('phoneType', res)
  117. }
  118. });
  119. console.log(uni.getStorageSync('userInfo'))
  120. if (uni.getStorageSync('userInfo')) {
  121. that.$request.baseRequest('get', '/driverInfo/firstAuthentication', {
  122. driverPhone: uni.getStorageSync('userInfo').phone,
  123. }).then(res => {
  124. if (res.data.authenticationStatus == '已禁用') {
  125. // this.isShowAlert = true
  126. // this.alertTitle = '账号审核中'
  127. // this.confirmText = '退出APP'
  128. // this.showCancelButton = false
  129. let options = {
  130. title: '提示',
  131. info: '账号审核中',
  132. okText: '退出程序',
  133. infoAlignment: 'center',
  134. radius: 10,
  135. // cancelText: '否',
  136. showCancel: false,
  137. okButtonColor: '#2772FB'
  138. };
  139. const native = uni.requireNativePlugin('AJ-Alert');
  140. native.showAction(options, result => {
  141. // #ifdef APP-PLUS
  142. if (uni.getSystemInfoSync().platform == 'ios') {
  143. plus.ios.import("UIApplication").sharedApplication().performSelector(
  144. "exit")
  145. } else if (uni.getSystemInfoSync().platform == 'android') {
  146. plus.runtime.quit();
  147. }
  148. // #endif
  149. // 点击是的回调, result暂时没有返回内容
  150. }, cancel => {
  151. // 点击否的回调
  152. });
  153. // uni.showModal({
  154. // title: '提示',
  155. // content: '这是一个模态弹窗',
  156. // showCancel:false,
  157. // confirmText:'退出app',
  158. // // confirmColor:'#317AFE',
  159. // confirmColor:'#F54E40',
  160. // success: function (res) {
  161. // if (res.confirm) {
  162. // // #ifdef APP-PLUS
  163. // if (uni.getSystemInfoSync().platform == 'ios') {
  164. // plus.ios.import("UIApplication").sharedApplication().performSelector("exit")
  165. // } else if (uni.getSystemInfoSync().platform == 'android') {
  166. // plus.runtime.quit();
  167. // }
  168. // // #endif
  169. // } else if (res.cancel) {
  170. // console.log('用户点击取消');
  171. // }
  172. // }
  173. // });
  174. } else {
  175. console.log(1231233212332312312213)
  176. }
  177. })
  178. }
  179. // #endif
  180. uni.setStorageSync("region", region);
  181. uni.getSystemInfo({
  182. success: function(e) {
  183. Vue.prototype.statusBar = e.statusBarHeight
  184. // #ifndef MP
  185. if (e.platform == 'android') {
  186. Vue.prototype.customBar = e.statusBarHeight + 50
  187. } else {
  188. Vue.prototype.customBar = e.statusBarHeight + 45
  189. }
  190. // #endif
  191. // #ifdef MP-WEIXIN
  192. let custom = wx.getMenuButtonBoundingClientRect()
  193. Vue.prototype.customBar = custom.bottom + custom.top - e.statusBarHeight
  194. // #endif
  195. // #ifdef MP-ALIPAY
  196. Vue.prototype.customBar = e.statusBarHeight + e.titleBarHeight
  197. // #endif
  198. }
  199. })
  200. // #ifdef APP-PLUS
  201. var that = this
  202. //判断该用户是否需要开启持续定位
  203. if(uni.getStorageSync('userInfo')){
  204. this.$request.baseRequest('get', '/orderInfo/getData', {
  205. commonId:uni.getStorageSync('userInfo').id,
  206. }).then(res1 => {
  207. console.log("/orderInfo/getData",res1.data)
  208. this.shippingNoteInfos[0].shippingNoteNumber = res1.data[0].orderNo //运单号
  209. this.shippingNoteInfos[0].serialNumber = "0000" //分单号
  210. this.shippingNoteInfos[0].startCountrySubdivisionCode = res1.data[0].sendAdCode //起点位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  211. this.shippingNoteInfos[0].endCountrySubdivisionCode = res1.data[0].unsendAdCode //到达位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  212. this.shippingNoteInfos[0].startLongitude = res1.data[0].sendLongitude //起点位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  213. this.shippingNoteInfos[0].startLatitude = res1.data[0].sendLatitude //起点位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  214. this.shippingNoteInfos[0].endLongitude = res1.data[0].unsendLongitude //到达位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  215. this.shippingNoteInfos[0].endLatitude = res1.data[0].unsendLatitude //到达位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  216. this.shippingNoteInfos[0].driverName = res1.data[0].driverName //司机姓名,SDK 回调返回, 调用 start/stop/pause/restart/ 必填,send 时非必填
  217. this.shippingNoteInfos[0].vehicleNumber = res1.data[0].carNumber //车牌号,SDK 回调返回,调 用 start/stop/pause/restart/必 填,send 时非必填
  218. this.shippingNoteInfos[0].startLocationText = res1.data[0].sendCity //起点地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  219. this.shippingNoteInfos[0].endLocationText = res1.data[0].unloadCity //到达地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  220. this.shippingNoteInfos[0].interval = "5000"
  221. // for(let i = 0; i < res1.data.length ; i++){
  222. // this.shippingNoteInfos[i].push({'shippingNoteNumber':res1.data[i].orderNo})
  223. // this.shippingNoteInfos[i].push({'serialNumber':"0000"})
  224. // this.shippingNoteInfos[i].push({'interval':'5000'})
  225. // // this.shippingNoteInfos[i].shippingNoteNumber = res1.data[i].orderNo,
  226. // // this.shippingNoteInfos[i].serialNumber = "0000", //分单号
  227. // // this.shippingNoteInfos[i].startCountrySubdivisionCode = this.detailData.publishTaskInfo.sendAdCode, //起点位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  228. // // this.shippingNoteInfos[i].endCountrySubdivisionCode = this.detailData.publishTaskInfo.unsendAdCode, //到达位置行政区划代码,调 用 start/stop/pause/restart 时 必填,调用 send 非必填
  229. // // this.shippingNoteInfos[i].startLongitude = this.detailData.loadingLatitude, //起点位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  230. // // this.shippingNoteInfos[i].startLatitude = this.detailData.loadingLatitude, //起点位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  231. // // this.shippingNoteInfos[i].endLongitude = this.detailData.publishTaskInfo.unsendLongitude, //到达位置经度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  232. // // this.shippingNoteInfos[i].endLatitude = this.detailData.publishTaskInfo.unsendLatitude, //到达位置纬度,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  233. // // this.shippingNoteInfos[i].startLocationText = res1.data.sendCity, //起点地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  234. // // this.shippingNoteInfos[i].endLocationText = res1.data.unloadCity, //到达地址文字描述,调用 start/stop/pause/restart 时必 填,调用 send 非必填
  235. // // this.shippingNoteInfos[i].vehicleNumber = res1.data.carNumber, //车牌号,SDK 回调返回,调 用 start/stop/pause/restart/必 填,send 时非必填
  236. // // this.shippingNoteInfos[i].driverName = res.data.driverName, //司机姓名,SDK 回调返回, 调用 start/stop/pause/restart/ 必填,send 时非必填
  237. // // this.shippingNoteInfos[i].interval = "5000" //请求时间间隔,SDK 回调返 回(单位 ms)
  238. // }
  239. console.log("查看参数",this.shippingNoteInfos)
  240. that.send(res1.data)
  241. if(res1.data.length>0){
  242. // if (uni.getStorageSync('userInfo')) {
  243. // this.$request.baseRequest('get', '/orderInfo/getData', {
  244. // commonId: uni.getStorageSync('userInfo').id,
  245. // }).then(res1 => {
  246. // if (res1.data.length > 0) {
  247. that.$helper.fUN_AmapLocation.start({
  248. // intervalTime: 1000 * 60,
  249. intervalTime: 5000,
  250. // locationCacheEnable:true,
  251. isReport: false
  252. // url: 'http://192.168.0.66/fun/open/test_json.do',
  253. // params: {
  254. // a: 1,
  255. // B: '测试',
  256. // c: true
  257. // },
  258. // headers: {
  259. // a: '123',
  260. // B: 'abcd'
  261. // }
  262. },
  263. res => {
  264. // console.log('====确认装车开启连续定位====');
  265. // console.log(res)
  266. let _data = {
  267. orderId: res1.data[0].id,
  268. longitude: res.longitude,
  269. latitude: res.latitude,
  270. province: res.province,
  271. city: res.city,
  272. area: res.district
  273. }
  274. this.$helper.gjList.push(_data)
  275. uni.setStorageSync('mapGJ', this.$helper.gjList);
  276. // console.log('this.$helper.gjList')
  277. // console.log(this.$helper.gjList)
  278. // console.log("条数", uni.getStorageSync('mapGJ').length)
  279. if (uni.getStorageSync('mapGJ').length > 100) {
  280. console.log(JSON.stringify(uni.getStorageSync('mapGJ')))
  281. this.$request.baseRequest('post', '/hyOrderTravelPath/api/addInfo', {
  282. orderId:"cdae6ec34c2349768c490a9fefa03fb3",
  283. longitudeLatitude:JSON.stringify(uni.getStorageSync('mapGJ'))
  284. }).then(res => {
  285. uni.removeStorageSync('mapGJ');
  286. this.$helper.gjList = []
  287. })
  288. .catch(res => {
  289. uni.$u.toast(res.message);
  290. });
  291. }
  292. //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  293. }
  294. );
  295. }
  296. })
  297. }
  298. // this.$helper.fUN_AmapLocation.stop({}, result => {
  299. // console.log('====fUN_AmapLocation定位stop====', JSON.stringify(result));
  300. // this.$helper.fUN_AmapLocation.start(
  301. // {
  302. // intervalTime: 1000*60,
  303. // isReport: true,
  304. // reportInterval: 5,
  305. // url: 'http://192.168.0.66/fun/open/test_json.do',
  306. // params: { a: 1, B: '测试', c: true },
  307. // headers: { a: '123', B: 'abcd' }
  308. // },
  309. // res => {
  310. // //见下方定位返回示例
  311. // console.log('====确认装车开启连续定位====', JSON.stringify(res));
  312. // //判断缓存数据条数,超过reportInterval时清空缓存,重新存入缓存
  313. // }
  314. // );
  315. // });
  316. // fUN_AmapLocation.permission({}, result => {
  317. // console.log('====fUN_AmapLocation定位====');
  318. // });
  319. // fUN_AmapLocation.hasLocationPermissions(function(result) {
  320. // console.log('====fUN_AmapLocation定位权限===='+ result)
  321. // });
  322. // startLocation与start均可
  323. // this.$helper.fUN_AmapLocation.start(
  324. // {
  325. // intervalTime: 1000*10,
  326. // isReport: false,
  327. // },
  328. // result => {
  329. // //见下方定位返回示例
  330. // console.log('====fUN_AmapLocation定位====', JSON.stringify(result));
  331. // }
  332. // );
  333. // let isOpenLocation= permision.checkSystemEnableLocation()
  334. // console.log("isOpenLocation",isOpenLocation)
  335. // this.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')
  336. let type = uni.getSystemInfoSync().platform
  337. console.log(type)
  338. if (type == "android") {
  339. appUpdate()
  340. }
  341. // plus.push.getClientInfoAsync((info) => {
  342. // var name = 'clientId'
  343. // var value = info.clientid
  344. // that.$store.commit('$uStore', {
  345. // name,
  346. // value
  347. // });
  348. // uni.setStorageSync("clientId", info.clientid)
  349. // console.log("info.clientid", info.clientid)
  350. // }, err => {});
  351. // 监听在线消息事件
  352. // plus.push.addEventListener("receive", function(msg) {
  353. // var title = msg.content.split(':')[0]
  354. // var content = msg.content.split(':')[1]
  355. // let params = {
  356. // inApp: true, // app内横幅提醒
  357. // voice: true, // 声音提醒
  358. // vibration: true, // 振动提醒
  359. // messageType: "",
  360. // messageTitle: title,
  361. // messageContent: content,
  362. // messageImage: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/logo.png'
  363. // }
  364. // console.log("msg", msg)
  365. // new app_push({
  366. // ...params
  367. // }).show();
  368. // var userInfo = uni.getStorageSync("userInfo")
  369. // var that = this
  370. // that.$request.baseRequest('get', '/notice/query/noticeNumber').then(res => {
  371. // if (res.data.data) {
  372. // let name = 'myTip';
  373. // let value = res.data.data.task;
  374. // that.$store.commit('$uStore', {
  375. // name,
  376. // value
  377. // });
  378. // if (value != 0 && value) {
  379. // uni.setTabBarBadge({
  380. // index: 4,
  381. // text: value + ""
  382. // })
  383. // }
  384. // name = 'taskTip';
  385. // value = res.data.data.task;
  386. // that.$store.commit('$uStore', {
  387. // name,
  388. // value
  389. // });
  390. // // name = 'contractTip';
  391. // // value = res.data.data.contractTip;
  392. // // that.$store.commit('$uStore', {
  393. // // name,
  394. // // value
  395. // // });
  396. // }
  397. // })
  398. // //其它逻辑
  399. // }, false);
  400. // //监听系统通知栏消息点击事件
  401. // plus.push.addEventListener('click', function(msg) {
  402. // //处理点击消息的业务逻辑代码
  403. // if (msg.content && msg.content.contains("任务")) {
  404. // uni.navigateTo({
  405. // url: '/pages/task/my_task'
  406. // })
  407. // } else if (msg.content && (msg.content.contains("合同") || msg.content.contains("交易"))) {
  408. // uni.navigateTo({
  409. // url: '/pageB/contract/contract'
  410. // })
  411. // }
  412. // }, false);
  413. // #endif
  414. // this.$socket.initWebIM(this.$ws, true, true)
  415. let userInfo = uni.getStorageSync('userInfo') || '';
  416. if (userInfo.id) {
  417. //更新登陆状态
  418. uni.getStorage({
  419. key: 'userInfo',
  420. success: (res) => {
  421. this.login(res.data);
  422. }
  423. });
  424. }
  425. },
  426. onShow: function() {
  427. console.log('App Show')
  428. },
  429. onHide: function() {
  430. console.log('App Hide')
  431. },
  432. }
  433. </script>
  434. <style>
  435. /*每个页面公共css */
  436. </style>