location.nvue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view>
  3. <map :style="{width: '750rpx',height: mapHeight + 'px'}" class="map"
  4. :latitude="mapCenter.latitude"
  5. :longitude="mapCenter.longitude"
  6. :markers="markers"
  7. :polyline="polyline"></map>
  8. <view class="main">
  9. <view class="main-top">
  10. <view class="main-top-left">
  11. <view class="main-top-left-txt ">
  12. <text class="tit">骑手正在送货</text>
  13. </view>
  14. <view class="main-top-left-bottom mt8">
  15. <text class="hxicon txt14 color-dark-gray">&#xe65e;</text>
  16. <text class="txt14 ml6">预计送达</text>
  17. <text class="txt14 ml6 color-blue">19:30</text>
  18. </view>
  19. </view>
  20. <button style="width: 100px;" size="mini" class="btn" hover-class="bg-active" type="primary" @click="submit">确认收货</button>
  21. </view>
  22. <view class="main-bottom">
  23. <image class="main-bottom-row1" :src="riderInfo.avatar" mode=""></image>
  24. <view class="main-bottom-row2">
  25. <text class="main-bottom-row2-txt1">{{riderInfo.name}}</text>
  26. <text class="main-bottom-row2-txt2 mt2">满意度:{{praise}}%</text>
  27. </view>
  28. <text class="hxicon main-bottom-txt">&#xe779;</text>
  29. <text class="hxicon main-bottom-txt" @click="call">&#xe652;</text>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. // #ifdef APP-PLUS-NVUE
  36. var domModule = weex.requireModule('dom');
  37. domModule.addRule('fontFace', {
  38. 'fontFamily': "iconfont",
  39. 'src': "url('https://at.alicdn.com/t/font_1380649_u1j4yykb94h.ttf')"
  40. })
  41. // #endif
  42. var sysInfo = uni.getSystemInfoSync();
  43. export default {
  44. data() {
  45. return {
  46. orderId: null,
  47. markers: [],
  48. polyline: [],
  49. mapHeight: sysInfo.screenHeight,
  50. // 用户经纬度
  51. userAddress: {
  52. // 经度
  53. longitude: 41.173098,
  54. // 纬度
  55. latitude: 80.2632808
  56. },
  57. // 地图中心点
  58. mapCenter: {
  59. // 经度
  60. longitude: null,
  61. // 纬度
  62. latitude: null
  63. },
  64. // 骑手经纬度
  65. riderAddress: {
  66. // 经度
  67. longitude: 41.1730980,
  68. // 纬度
  69. latitude: 80.2632808
  70. },
  71. riderInfo: {
  72. id: null,
  73. name: null,
  74. praise: 30,
  75. dislike: 2,
  76. phone: null,
  77. avatar: 'https://imgs.1op.cn/i/hxshop/avatar/3.png'
  78. },
  79. praise: 100
  80. };
  81. },
  82. onLoad(option) {
  83. if(option.id){
  84. this.orderId = option.id
  85. }
  86. this.init()
  87. },
  88. mounted() {
  89. },
  90. methods:{
  91. // 获取用户收件地址
  92. init(){
  93. let that = this
  94. new Promise((resolve, reject) =>{
  95. // 你的请求逻辑
  96. // ......
  97. // 这里方便测试,我使用手机当前位置 代替 用户收件地址位置;上线则以用户填写的收件地址为准
  98. // 假如请求成功拿到用户地址
  99. uni.getLocation({
  100. type: 'gcj02',
  101. success: function (res) {
  102. resolve(res)
  103. },
  104. fail:function(res) {
  105. reject(res)
  106. }
  107. });
  108. }).then((res) => {
  109. //设置用户经纬度
  110. that.userAddress = {
  111. longitude: res.longitude,
  112. latitude: res.latitude
  113. }
  114. // 接下来去拿取骑手信息
  115. // 假如通过请求拿到骑手信息
  116. that.riderInfo = {
  117. id: 863,
  118. name: "闪电骑手",
  119. praise: 81,
  120. dislike: 3,
  121. phone: '18299989999',
  122. avatar: 'https://imgs.1op.cn/i/hxshop/avatar/3.png'
  123. },
  124. //计算好评
  125. that.praise= parseInt(that.riderInfo.praise/(that.riderInfo.praise + that.riderInfo.dislike) * 100)
  126. // 接下来去拿取骑手地址去更新地图,并且每3秒获取一次
  127. that.getRiderAddress()
  128. setInterval(()=>{
  129. that.getRiderAddress()
  130. },3000)
  131. },(err) => {
  132. console.log("获取失败")
  133. })
  134. },
  135. getRiderAddress(){
  136. let that = this
  137. // 获取骑手位置
  138. // ----------------------
  139. // 假如通过请求获取到了骑手位置
  140. // 伪造一个随机数,好像骑手在移动一样
  141. var num = Math.floor(Math.random() * 25 + 3) /10000 + 0.015;
  142. var num2 = Math.floor(Math.random() * 25 + 3) /10000 + 0.015;
  143. that.riderAddress={
  144. latitude: that.userAddress.latitude + num,
  145. longitude: that.userAddress.longitude + num2
  146. }
  147. // 地图标标记
  148. that.markers = [
  149. //用户标记
  150. {
  151. id: 1,
  152. callout: {
  153. content:'收件地址',
  154. color:'#ff9900',
  155. padding:'6',
  156. borderRadius:'50',
  157. textAlign:'left',
  158. fontSize:'14',
  159. display:'BYCLICK'
  160. },
  161. latitude: that.userAddress.latitude,
  162. longitude: that.userAddress.longitude,
  163. iconPath: '/static/img/map_home.png',
  164. width: '64',
  165. height: '64'
  166. },
  167. //骑手标记
  168. {
  169. id: 9999,
  170. callout: {
  171. content:'骑手',
  172. color:'#ff9900',
  173. padding:'6',
  174. borderRadius:'50',
  175. textAlign:'left',
  176. fontSize:'14',
  177. display:'ALWAYS'
  178. },
  179. latitude: that.riderAddress.latitude,
  180. longitude: that.riderAddress.longitude,
  181. iconPath: '/static/img/map_qs.png',
  182. width:'64',
  183. height:'64'
  184. },
  185. ];
  186. //线
  187. that.polyline = [{
  188. points: [that.userAddress,that.riderAddress],
  189. color: "#ff9900",
  190. width: 10
  191. }];
  192. that.mapCenter={
  193. latitude: that.riderAddress.latitude,
  194. longitude: that.riderAddress.longitude
  195. }
  196. },
  197. //打电话
  198. call(){
  199. if(this.riderInfo.phone){
  200. uni.makePhoneCall({
  201. phoneNumber: ''+this.riderInfo.phone,
  202. fail: (res)=>{
  203. uni.showModal({
  204. title: '提示',
  205. content: "自动拨号失败!请手动拨打电话:" + this.riderInfo.phone,
  206. showCancel: false,
  207. cancelText: '',
  208. confirmText: '确认',
  209. });
  210. }
  211. });
  212. }
  213. },
  214. //确认收货
  215. submit(){
  216. //确认收货
  217. uni.showModal({
  218. title: '提示',
  219. content: '已确认收货'+this.orderId,
  220. showCancel: false,
  221. cancelText: '',
  222. confirmText: '确认',
  223. success: res => {},
  224. fail: () => {},
  225. complete: () => {}
  226. });
  227. }
  228. }
  229. }
  230. </script>
  231. <style>
  232. .txt14{
  233. font-size: 14px;
  234. }
  235. .mt8{
  236. margin-top: 8px;
  237. }
  238. .mt2{
  239. margin-top: 2px;
  240. }
  241. .ml6{
  242. margin-left: 6px;
  243. }
  244. .color-blue{
  245. color: #2196f3;
  246. }
  247. .color-dark-gray{
  248. color: #888;
  249. }
  250. .main{
  251. position: fixed;
  252. z-index: 999;
  253. bottom: 30px;
  254. left: 15px;
  255. right: 15px;
  256. background-color: #fff;
  257. border-radius: 10px;
  258. padding: 15px 18px;
  259. box-shadow: 0px 0px 10px #b7b7b7;
  260. flex-direction: column;
  261. }
  262. .main-top{
  263. flex-direction: row;
  264. align-items: center;
  265. padding-bottom: 15px;
  266. border-bottom-width: 1px;
  267. border-bottom-style: solid;
  268. border-bottom-color: #eef1f4;
  269. }
  270. .main-top-left{
  271. flex-direction: column;
  272. flex: 1;
  273. }
  274. .main-top-left-txt{
  275. font-size: 20px;
  276. color: #333;
  277. }
  278. .main-top-left-bottom{
  279. flex-direction: row;
  280. align-items: center;
  281. }
  282. .hxicon-timefill{
  283. font-size: 14px;
  284. }
  285. .main-bottom{
  286. margin-top: 15px;
  287. flex-direction: row;
  288. align-items: center;
  289. }
  290. .main-bottom-row1{
  291. width: 44px;
  292. height: 44px;
  293. border-radius: 50%;
  294. }
  295. .main-bottom-row2{
  296. flex-direction: column;
  297. flex: 1;
  298. margin-left: 12px;
  299. }
  300. .main-bottom-row2-txt1{
  301. font-size: 18px;
  302. color: #333;
  303. }
  304. .main-bottom-row2-txt2{
  305. font-size: 14px;
  306. color: #333;
  307. }
  308. .main-bottom-txt{
  309. font-size: 26px;
  310. color: #666;
  311. padding: 5px;
  312. margin-left: 12px;
  313. }
  314. .bg-active{
  315. background-image: linear-gradient(100deg, #e8d536, #dda809);
  316. }
  317. .btn{
  318. background-image: linear-gradient(100deg, #FFEB3B, #FFC107);
  319. border-width: 0;
  320. padding: 6px 0;
  321. color: #333333;
  322. }
  323. </style>