orderAMap.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <el-dialog v-loading='loading' element-loading-text="拼命加载中" width="80%" destroy-on-close :visible.sync="dialogTableVisible">
  3. <el-form v-if="showSearch" ref="ruleForm" class="demo-form-inline" :inline="true">
  4. <el-form-item class="search-box">
  5. <el-input @keydown.enter.native="seachEnterFun" v-model="searchKey" type="search" id="search" style="width: 219px" placeholder="请输入关键字进行搜索" />
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button type="primary" class="map-btn" @click="searchMap">搜索</el-button>
  9. </el-form-item>
  10. <div class="tip-box" id="searchTip"></div>
  11. <el-form-item label="经度" prop="lng">
  12. <el-input maxlength="11" v-model="lng" style="width: 140px" disabled></el-input>
  13. </el-form-item>
  14. <el-form-item label="纬度:" prop="lat">
  15. <el-input maxlength="10" v-model="lat" style="width: 140px" disabled></el-input>
  16. </el-form-item>
  17. <el-form-item>
  18. <el-button type="primary" class="map-btn" @click="clickSureMap">确定</el-button>
  19. </el-form-item>
  20. <div v-show="showAddressList" class="address-list">
  21. <div class="address" @click="getGeoCode(v)" v-for="(v,i) in promptList" :key="i">
  22. <span class="name">{{v.name}}</span>
  23. <span class="district">{{v.district}}{{v.address}}</span>
  24. </div>
  25. </div>
  26. </el-form>
  27. <el-amap ref="map" vid="container" :zoom="zoom" :plugins="plugin" :center="center" style="height: 600px;" class="amap-demo">
  28. <el-amap-marker v-for="(marker,index) in markers" :key="index" :position="marker.position" :icon="marker.icon"></el-amap-marker>
  29. <el-amap-text v-for="text in texts" :key="text.id" :text="text.text" :offset="text.offset" :position="text.position" :events="text.events"></el-amap-text>
  30. </el-amap>
  31. </el-dialog>
  32. </template>
  33. <script>
  34. import { getInputPrompt, getGeoCode, getMapData } from "../../api/order.js";
  35. export default {
  36. data() {
  37. return {
  38. searchKey: "",
  39. dialogTableVisible: false,
  40. order: {},
  41. markers: [],
  42. texts: [],
  43. defaultCity: "北京",
  44. zoom: 18,
  45. center: [116.39747132275389, 39.908857325556404],
  46. promptList: [],
  47. address: "",
  48. addressDetail: {},
  49. lng: "",
  50. lat: "",
  51. showAddressList: false,
  52. showSearch: false,
  53. loading: false,
  54. };
  55. },
  56. created() {},
  57. mounted() {},
  58. methods: {
  59. seachEnterFun(e) {
  60. var keyCode = window.event ? e.keyCode : e.which;
  61. if (keyCode == 13) {
  62. this.searchMap();
  63. }
  64. },
  65. getGeoCode(v) {
  66. this.showAddressList = false;
  67. let address = v.district + v.address + v.name;
  68. getGeoCode({ address }).then((res) => {
  69. if (res.code === 200) {
  70. console.log("object", res.data);
  71. this.addressDetail = res.data[0];
  72. this.addressDetail.address = address;
  73. let splitPoint = this.addressDetail.location.indexOf(",");
  74. console.log("splitPoint", splitPoint);
  75. this.lng = this.addressDetail.location.slice(0, splitPoint);
  76. this.lat = this.addressDetail.location.slice(splitPoint + 1);
  77. this.center = [this.lng, this.lat];
  78. this.markers = [
  79. {
  80. id: 1,
  81. position: this.center,
  82. icon: "/static/image/map_current.png",
  83. },
  84. ];
  85. } else {
  86. this.$message({
  87. type: "error",
  88. message: res.msg,
  89. });
  90. }
  91. });
  92. },
  93. searchMap() {
  94. if (!this.searchKey.trim()) {
  95. return this.$message({
  96. type: "error",
  97. message: "请先输入关键字后再搜索!",
  98. });
  99. }
  100. getInputPrompt({ keywords: this.searchKey }).then((res) => {
  101. if (res.code === 200) {
  102. if (res.data.length) {
  103. this.promptList = res.data;
  104. this.showAddressList = true;
  105. }
  106. } else {
  107. this.$message({
  108. type: "error",
  109. message: res.msg,
  110. });
  111. }
  112. });
  113. },
  114. init(data, mapData) {
  115. let sendM = {
  116. id: 1,
  117. position: [data.sendLng, data.sendLat],
  118. icon: "/static/image/map-fa.png",
  119. };
  120. let receiptM = {
  121. id: 2,
  122. position: [data.receiptLng, data.receiptLat],
  123. icon: "/static/image/map-shou.png",
  124. };
  125. let riderM = {
  126. id: 3,
  127. position: [mapData.shipperLng, mapData.shipperLat],
  128. icon: "/static/image/map-rider.png",
  129. };
  130. // 中心点
  131. this.center = [
  132. ((data.receiptLng * 1 + data.sendLng * 1) / 2).toFixed(6),
  133. ((data.receiptLat * 1 + data.sendLat * 1) / 2).toFixed(6),
  134. ];
  135. // marker标记
  136. this.markers = [sendM, receiptM];
  137. if (mapData.shipperLng && mapData.shipperLat) {
  138. this.markers.push(riderM);
  139. }
  140. this.$nextTick(() => {
  141. this.$refs.map.$$getInstance().setFitView();
  142. });
  143. let orderDistance =
  144. mapData.orderDistance > 1000
  145. ? (mapData.orderDistance / 1000).toFixed(1) + "公里"
  146. : mapData.orderDistance + "米";
  147. this.texts = [
  148. {
  149. id: 4,
  150. position: [data.sendLng, data.sendLat],
  151. text: `商家距离目的地${orderDistance}`,
  152. offset: [10, -50],
  153. },
  154. ];
  155. if (mapData.shipperLng && mapData.shipperLat && mapData.shipperDistance) {
  156. let distance =
  157. mapData.shipperDistance > 1000
  158. ? (mapData.shipperDistance / 1000).toFixed(1) + "公里"
  159. : mapData.shipperDistance + "米";
  160. this.texts.push({
  161. id: 5,
  162. position: [mapData.shipperLng, mapData.shipperLat],
  163. text:
  164. data.buttonStatus === 2
  165. ? `骑手距离商家${distance} | 预计${mapData.riderArriveMinute}分钟后到店`
  166. : data.buttonStatus === 3
  167. ? `骑手距离目的地${distance} | 预计${mapData.estimateArriveTime}送达`
  168. : "",
  169. offset: [15, -50],
  170. });
  171. }
  172. // 绘制折线
  173. // this.polyline.path = [
  174. // new AMap.LngLat(mapData.receiptLng, mapData.receiptLat),
  175. // new AMap.LngLat(mapData.sendLng, mapData.sendLat),
  176. // new AMap.LngLat(mapData.shipperLng, mapData.shipperLat),
  177. // ];
  178. },
  179. setDialogStatus(data) {
  180. this.dialogTableVisible = true;
  181. this.loading = true;
  182. getMapData({ orderId: data.id }).then((res) => {
  183. if (res.code === 200) {
  184. console.log(11111, res.data);
  185. this.loading = false;
  186. this.init(data, res.data);
  187. } else {
  188. this.$message({
  189. type: "error",
  190. message: res.msg,
  191. });
  192. }
  193. });
  194. },
  195. chooseLocation() {
  196. this.dialogTableVisible = true;
  197. this.showSearch = true;
  198. this.searchKey = "";
  199. this.lat = "";
  200. this.lng = "";
  201. },
  202. clickSureMap() {
  203. this.$emit("getAddressDetail", this.addressDetail, this.lng, this.lat);
  204. this.dialogTableVisible = false;
  205. },
  206. },
  207. };
  208. </script>
  209. <style lang="scss" scoped>
  210. /deep/ .amap-overlay-text-container {
  211. font-size: 12px;
  212. background: #fc7200;
  213. color: #fff;
  214. padding: 4px 8px;
  215. border: none;
  216. }
  217. /deep/ .amap-overlay-text-container:before {
  218. content: "";
  219. width: 0;
  220. height: 0;
  221. border-left: 10px solid transparent;
  222. border-right: 10px solid transparent;
  223. border-top: 10px solid #fc7200;
  224. position: absolute;
  225. bottom: -10px;
  226. left: 50%;
  227. transform: translateX(-50%);
  228. }
  229. .map-btn {
  230. background: #fc7200;
  231. border: none;
  232. }
  233. .demo-form-inline {
  234. position: relative;
  235. display: flex;
  236. align-items: center;
  237. .address-list {
  238. position: absolute;
  239. left: 0;
  240. top: 45px;
  241. border: 2px solid #3333;
  242. background: #fff;
  243. padding: 0 10px;
  244. z-index: 2;
  245. .address {
  246. line-height: 30px;
  247. cursor: pointer;
  248. .name {
  249. color: #333333;
  250. }
  251. .district {
  252. color: #999999;
  253. margin-left: 10px;
  254. }
  255. }
  256. }
  257. }
  258. /* 图标大小修改 */
  259. /deep/ .el-dialog__header {
  260. display: none !important;
  261. }
  262. #container {
  263. width: 100%;
  264. height: 400px;
  265. }
  266. /deep/ .amap-container img {
  267. width: 35px !important;
  268. height: 45px !important;
  269. }
  270. </style>