index1.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view class="content">
  3. <view class='row-between'>
  4. <view class="">运单号</view>
  5. <view class="flex align-center">
  6. <u--input placeholder="运单号" border="none" v-model="shippingNoteInfos[0].shippingNoteNumber" inputAlign='right'
  7. clearable></u--input>
  8. </view>
  9. </view>
  10. <view class='row-between'>
  11. <view class="">分单号</view>
  12. <view class="flex align-center">
  13. <u--input placeholder="分单号" border="none" v-model="shippingNoteInfos[0].serialNumber" inputAlign='right'
  14. clearable></u--input>
  15. </view>
  16. </view>
  17. <view class='row-between'>
  18. <view class="">始发地区划码</view>
  19. <view class="flex align-center">
  20. <u--input placeholder="始发地区划码" border="none" v-model="shippingNoteInfos[0].startCountrySubdivisionCode" inputAlign='right'
  21. clearable></u--input>
  22. </view>
  23. </view>
  24. <view class='row-between'>
  25. <view class="">目的地区划码</view>
  26. <view class="flex align-center">
  27. <u--input placeholder="目的地区划码" border="none" v-model="shippingNoteInfos[0].endCountrySubdivisionCode" inputAlign='right'
  28. clearable></u--input>
  29. </view>
  30. </view>
  31. <view class='row-between'>
  32. <view class="">始发地经度</view>
  33. <view class="flex align-center">
  34. <u--input placeholder="始发地经度" border="none" v-model="shippingNoteInfos[0].startLongitude" inputAlign='right'
  35. clearable></u--input>
  36. </view>
  37. </view>
  38. <view class='row-between'>
  39. <view class="">始发地纬度</view>
  40. <view class="flex align-center">
  41. <u--input placeholder="始发地纬度" border="none" v-model="shippingNoteInfos[0].startLatitude" inputAlign='right'
  42. clearable></u--input>
  43. </view>
  44. </view>
  45. <view class='row-between'>
  46. <view class="">目的地经度</view>
  47. <view class="flex align-center">
  48. <u--input placeholder="目的地经度" border="none" v-model="shippingNoteInfos[0].endLongitude" inputAlign='right'
  49. clearable></u--input>
  50. </view>
  51. </view>
  52. <view class='row-between'>
  53. <view class="">目的地纬度</view>
  54. <view class="flex align-center">
  55. <u--input placeholder="目的地纬度" border="none" v-model="shippingNoteInfos[0].endLatitude" inputAlign='right'
  56. clearable></u--input>
  57. </view>
  58. </view>
  59. <view class='row-between'>
  60. <view class="">始发地</view>
  61. <view class="flex align-center">
  62. <u--input placeholder="始发地" border="none" v-model="shippingNoteInfos[0].startLocationText" inputAlign='right'
  63. clearable></u--input>
  64. </view>
  65. </view>
  66. <view class='row-between'>
  67. <view class="">目的地</view>
  68. <view class="flex align-center">
  69. <u--input placeholder="目的地" border="none" v-model="shippingNoteInfos[0].endLocationText" inputAlign='right'
  70. clearable></u--input>
  71. </view>
  72. </view>
  73. <view class='row-between'>
  74. <view class="">车牌号</view>
  75. <view class="flex align-center">
  76. <u--input placeholder="车牌号" border="none" v-model="shippingNoteInfos[0].vehicleNumber" inputAlign='right'
  77. clearable></u--input>
  78. </view>
  79. </view>
  80. <view class='row-between'>
  81. <view class="">司机姓名</view>
  82. <view class="flex align-center">
  83. <u--input placeholder="司机姓名" border="none" v-model="shippingNoteInfos[0].driverName" inputAlign='right'
  84. clearable></u--input>
  85. </view>
  86. </view>
  87. <view class='row-between'>
  88. <view class="">时间间隔</view>
  89. <view class="flex align-center">
  90. <u--input placeholder="时间间隔" border="none" v-model="shippingNoteInfos[0].interval" inputAlign='right'
  91. clearable></u--input>
  92. </view>
  93. </view>
  94. <button type="primary" @click="auth()">授权</button>
  95. <button type="primary" @click="start()">开启定位</button>
  96. <button type="primary" @click="send()">发送定位</button>
  97. <button type="primary" @click="pause()">暂停定位</button>
  98. <button type="primary" @click="restart()">重启定位</button>
  99. <button type="primary" @click="stop()">结束定位</button>
  100. </view>
  101. </template>
  102. <script>
  103. //插件对象
  104. var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
  105. import * as config from '@/config/index.js'
  106. export default {
  107. data() {
  108. return {
  109. title: 'Hello',
  110. vehicleNumber:"辽HG6663",//车牌号
  111. driverName:"孙亚洲",//司机姓名
  112. remark:"测试",//备注
  113. appId: "", //网络货运企业APP的唯一标识
  114. appSecurity: "", //网络货运企业在省平台申请的接入安全码
  115. enterpriseSenderCode: "", //网络货运企业在省平台申请的企业发送代码
  116. environment: "debug", //环境:“debug”接入测试环境,“release”接入正式环境。
  117. shippingNoteInfos:[{
  118. shippingNoteNumber:"CY20221028860111",
  119. serialNumber:"0000",
  120. startCountrySubdivisionCode:"210804",
  121. endCountrySubdivisionCode:"210804",
  122. startLongitude: "122.17153",
  123. startLatitude:"40.266814",
  124. endLongitude:"122.146806",
  125. endLatitude: "40.261078",
  126. startLocationText:"营口市",
  127. endLocationText:"营口市",
  128. vehicleNumber:"辽HG6663",
  129. driverName:"孙亚洲",
  130. interval:"5000"
  131. }],//运单信息列表,一辆车运单数最大支持数为 10
  132. timer:""
  133. }
  134. },
  135. onLoad() {
  136. // console.log("appId-------------------",uni.getAccountInfoSync().miniProgram.appId)
  137. // let phoneType = uni.getSystemInfoSync().platform //判断手机类型
  138. // if( phoneType == "android"){
  139. // this.appId = "uni.UNIDCD13AC"
  140. // }else if(phoneType == "ios"){
  141. // this.appId = "uni.UNI9C76CB6"
  142. // }
  143. //隐私合规接口,HBuildx3.3.3及其以后的版本需要调用合规检查
  144. var isContains = true;//隐私权政策是否包含高德开平隐私权政策 true是包含
  145. var isShow = true;//隐私权政策是否弹窗展示告知用户 true是展示
  146. sdkwx.updatePrivacyShow(isContains, isShow);
  147. var isAgree = true;//隐私权政策是否取得用户同意 true是用户同意
  148. sdkwx.updatePrivacyAgree(isAgree);
  149. //检查定位权限
  150. sdkwx.checkLocationPermission(function(res){
  151. console.log(res);
  152. });
  153. },
  154. methods: {
  155. auth() {
  156. let phoneType = uni.getSystemInfoSync().platform //判断手机类型
  157. this.enterpriseSenderCode = config.def().enterpriseSenderCode
  158. this.environment = config.def().environment
  159. if (phoneType == "android") {
  160. this.appId = config.def().androidAppId
  161. this.appSecurity = config.def().androidAppSecurity
  162. } else if (phoneType == "ios") {
  163. // this.appId = "uni.UNIDCD13AC"
  164. // this.appSecurity = "b01e4805276646eeb25f0fad91de97a4f32e8c2c0e0d42e5b24cc4737e9f040f"
  165. this.appId = config.def().iosAppId
  166. this.appSecurity = config.def().iosAppSecurity
  167. }
  168. //授权
  169. // var appId = "uni.UNI9C76CB6";//网络货运企业APP的唯一标识
  170. // var appSecurity = "24c593b7037347e08857a6ab05fd231b0509f5bb7cb741078f524f506ad32db8";//网络货运企业在省平台申请的接入安全码
  171. // var enterpriseSenderCode = "23106960";//网络货运企业在省平台申请的企业发送代码
  172. // var environment = "debug";//环境:“debug”接入测试环境,“release”接入正式环境。
  173. sdkwx.auth(this.appId, this.appSecurity, this.enterpriseSenderCode, this.environment, function(res) {
  174. console.log(res);
  175. if (res.type == "onSuccess") {
  176. //成功
  177. console.log(res,"成功");
  178. } else if (res.type == "onFailure"){
  179. //失败
  180. var errorCode = res.data.errorCode;//错误码
  181. var errorMsg = res.data.errorMsg;//错误描述
  182. }
  183. uni.showModal({
  184. content:JSON.stringify(res)
  185. });
  186. });
  187. },
  188. start(){
  189. var that = this
  190. //开启定位
  191. var vehicleNumber= this.vehicleNumber;//车牌号
  192. var driverName = this.driverName;//司机姓名
  193. var remark = this.remark;//备注
  194. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  195. var startParam = uni.getStorageSync("sdkStartParam")
  196. console.log(startParam)
  197. // if(startParam){
  198. // this.$helper.sdkStart(startParam.carNo,startParam.driverName,startParam.remark,startParam.shippingNoteInfos)
  199. // }
  200. console.log("更换前",shippingNoteInfos)
  201. shippingNoteInfos = startParam.shippingNoteInfos
  202. // shippingNoteInfos[0].shippingNoteNumber = 'CY20221028860222'
  203. console.log("更换后",shippingNoteInfos)
  204. sdkwx.start(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
  205. console.log(res);
  206. if (res.type == "onSuccess") {
  207. //成功
  208. console.log("开启定位成功!!!")
  209. console.log(res)
  210. var shippingNoteInfos = res.data[0]; //运单信息列表
  211. console.log(shippingNoteInfos, "查看返回的时间")
  212. if (shippingNoteInfos) {
  213. let dateTtime = Number(shippingNoteInfos.interval + 1000)
  214. console.log("开始定时", dateTtime)
  215. // that.timer = setTimeout(() => {
  216. // console.log("定时")
  217. // that.send()
  218. // }, dateTtime);
  219. }
  220. } else if (res.type == "onFailure"){
  221. //失败
  222. var errorCode = res.data.errorCode;//错误码
  223. var errorMsg = res.data.errorMsg;//错误描述
  224. }
  225. });
  226. },
  227. send(){
  228. var that = this
  229. //发送定位
  230. var vehicleNumber= this.vehicleNumber;//车牌号
  231. var driverName = this.driverName;//司机姓名
  232. var remark = this.remark;//备注
  233. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  234. sdkwx.send(vehicleNumber, driverName, remark, shippingNoteInfos, function(res){
  235. var shippingNoteInfos = res.data[0]; //运单信息列表
  236. if (res.type == "onSuccess") {
  237. console.log("App.vue发送定位成功")
  238. console.log(res);
  239. console.log("查看返回的时间",shippingNoteInfos)
  240. if (shippingNoteInfos) {
  241. let dateTime = Number(shippingNoteInfos.interval + 1000)
  242. console.log("定时开始", dateTime)
  243. that.timer = setTimeout(() => {
  244. //TODO
  245. that.send()
  246. }, dateTime);
  247. }
  248. } else if (res.type == "onFailure") {//失败
  249. console.log("App.vue发送定位失败", res)
  250. var errorCode = res.data.errorCode; //错误码
  251. var errorMsg = res.data.errorMsg; //错误描述
  252. let dateTime1 = Number(shippingNoteInfos.interval + 1000)
  253. console.log("定时开始", dateTime1)
  254. that.timer = setTimeout(() => { //失败也需要定时上传定位(为了解决频繁调用接口问题)
  255. that.send()
  256. }, dateTime1);
  257. }
  258. });
  259. },
  260. pause(){
  261. //暂停定位
  262. var vehicleNumber= this.vehicleNumber;//车牌号
  263. var driverName = this.driverName;//司机姓名
  264. var remark = this.remark;//备注
  265. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  266. sdkwx.pause(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  267. console.log(res);
  268. if (res.type == "onSuccess") {
  269. //成功
  270. } else if (res.type == "onFailure"){
  271. //失败
  272. var errorCode = res.data.errorCode;//错误码
  273. var errorMsg = res.data.errorMsg;//错误描述
  274. }
  275. });
  276. },
  277. restart(){
  278. //重启定位
  279. var vehicleNumber= this.vehicleNumber;//车牌号
  280. var driverName = this.driverName;//司机姓名
  281. var remark = this.remark;//备注
  282. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  283. sdkwx.restart(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  284. console.log(res);
  285. if (res.type == "onSuccess") {
  286. //成功
  287. var shippingNoteInfos = res.data;//运单信息列表
  288. } else if (res.type == "onFailure"){
  289. //失败
  290. var errorCode = res.data.errorCode;//错误码
  291. var errorMsg = res.data.errorMsg;//错误描述
  292. }
  293. });
  294. },
  295. stop(){
  296. var that = this
  297. //结束定位
  298. var vehicleNumber= this.vehicleNumber;//车牌号
  299. var driverName = this.driverName;//司机姓名
  300. var remark = this.remark;//备注
  301. var shippingNoteInfos = this.shippingNoteInfos;//运单信息列表
  302. sdkwx.stop(vehicleNumber, driverName, remark, shippingNoteInfos, function(res) {
  303. console.log(res);
  304. if (res.type == "onSuccess") {
  305. clearInterval(that.timer)
  306. console.log("结束成功!!!",res)
  307. //成功
  308. } else if (res.type == "onFailure"){
  309. console.log("结束失败!!!",res)
  310. //失败
  311. var errorCode = res.data.errorCode;//错误码
  312. var errorMsg = res.data.errorMsg;//错误描述
  313. }
  314. });
  315. },
  316. }
  317. }
  318. </script>
  319. <style>
  320. .content {
  321. background: white;
  322. margin: 20rpx;
  323. border-radius: 20rpx;
  324. padding: 20rpx;
  325. .place {
  326. width: 80%;
  327. text-align: right;
  328. }
  329. }
  330. .logo {
  331. height: 200rpx;
  332. width: 200rpx;
  333. margin-top: 200rpx;
  334. margin-left: auto;
  335. margin-right: auto;
  336. margin-bottom: 50rpx;
  337. }
  338. .text-area {
  339. display: flex;
  340. justify-content: center;
  341. }
  342. .title {
  343. font-size: 36rpx;
  344. color: #8f8f94;
  345. }
  346. .row-between {
  347. margin: 20rpx 0;
  348. }
  349. </style>