index1.vue 13 KB

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