checkMap.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="map">
  3. <view class="head">
  4. <view class="top"></view>
  5. <view class="title">
  6. <span class="cuIcon-back" @click="back"></span>
  7. <span class="text">选择检测站</span>
  8. <span class="sub" @click="submit">确定</span>
  9. </view>
  10. </view>
  11. <view class="search">
  12. <view class="left" @click="show = true">
  13. <image src="/static/index/address.png" mode=""></image>
  14. <span>{{city}}</span>
  15. <u-icon size="24" name="arrow-down-fill"></u-icon>
  16. </view>
  17. <view class="right">
  18. <u-icon size="24" name="search" style="margin-right: 10rpx;"></u-icon>
  19. <u-input v-model="searchWords" @confirm="searchFn" />
  20. </view>
  21. </view>
  22. <!-- <u-select v-model="show" mode="mutil-column-auto" :list="cityList" label-name="areaCname" value-name="id" child-name="child" @confirm="confirm"> </u-select> -->
  23. <u-select v-model="show" mode="mutil-column-auto" :list="cityList" label-name="areaCname" value-name="id"
  24. child-name="child" @confirm="confirm"></u-select>
  25. <view id="amap" class="amap" style="width: 100%; height: 40vh;" :pointList="pointList"
  26. :change:pointList="ModuleMap.setParkList">
  27. </view>
  28. <view class="list">
  29. <view class="tip" v-for="(item,index) in dataTips" :key="index" @click="select(item)">
  30. <view class="left">
  31. <span><text v-show="item.updateTime">已选</text>{{item.inspectionStationName}}</span>
  32. <span>{{item.detailedAddress}}</span>
  33. </view>
  34. <view class="right">
  35. <image src="/static/coupon/danxuan.png" mode="" v-if="item.check"></image>
  36. <image src="/static/product/round.png" mode="" v-else></image>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. var amapFile = require('@/static/map/amap-wx.130.js'); //如:..­/..­/libs/amap-wx.js
  44. // 创建地图
  45. var myAmapFun = new amapFile.AMapWX({
  46. key: '915d1d1ed40dc41450eda1d930ea1b2d'
  47. });
  48. export default {
  49. data() {
  50. return {
  51. city: '太原',
  52. searchWords: '',
  53. show: false,
  54. cityList: [],
  55. pointList: null,
  56. dataTips: [],
  57. selectList: [], //已选择监测站
  58. }
  59. },
  60. methods: {
  61. //返回
  62. back() {
  63. uni.navigateBack({
  64. delta: 1
  65. });
  66. },
  67. //城市列表
  68. getCityList() {
  69. this.$http.post("/sys/area/queryTreeSecondLevel").then(res => {
  70. if (res.data.code == 200) {
  71. this.cityList = res.data.result
  72. console.log(this.cityList)
  73. }
  74. })
  75. },
  76. confirm(e) {
  77. console.log(e)
  78. },
  79. // 根据内容进行检索
  80. searchFn() {
  81. this.getShopList()
  82. console.log("根据地址检索", this.searchWords);
  83. myAmapFun.getInputtips({
  84. keywords: this.searchWords,
  85. location: '',
  86. city:this.city || '太原' ,
  87. success: (data) => {
  88. if (data && data.tips) {
  89. console.log(data.tips)
  90. data.tips.forEach(item => {
  91. item.check = false,
  92. item.detailedAddress = item.address,
  93. item.inspectionStationName = item.name,
  94. item.locality = item.district
  95. this.dataTips.push(item);
  96. })
  97. console.log(111, this.dataTips);
  98. }
  99. },
  100. fail: data => {
  101. console.log(222, data);
  102. }
  103. })
  104. },
  105. //选中地址
  106. select(item) {
  107. console.log(item)
  108. item.check = !item.check
  109. },
  110. //保存勾选检车站
  111. submit() {
  112. let localTsMerchantLinkInspection = []
  113. this.dataTips.forEach(item => {
  114. if (item.check) {
  115. const locationParts = item.location ? item.location.split(",") : [];
  116. localTsMerchantLinkInspection.push({
  117. country: item.adcode,
  118. detailedAddress: item.detailedAddress,
  119. inspectionStationName: item.inspectionStationName,
  120. locality: item.locality,
  121. inspectionStationLongitude: item.inspectionStationLongitude || (locationParts[0] || null),
  122. inspectionStationLatitude: item.inspectionStationLatitude || (locationParts[1] || null),
  123. // inspectionStationLongitude: item.location.split(",")[0] || item.inspectionStationLongitude,
  124. // inspectionStationLatitude: item.location.split(",")[1] || item.inspectionStationLatitude,
  125. merchantId: uni.getStorageSync('login_user_info').merchantId
  126. })
  127. }
  128. })
  129. this.$http.post("/ts/localTsMerchantLinkInspection/add", localTsMerchantLinkInspection).then(res => {
  130. console.log(res)
  131. if (res.data.code == 200) {
  132. uni.showToast({
  133. icon: 'none',
  134. title: '添加成功'
  135. })
  136. this.back()
  137. }
  138. })
  139. },
  140. //获取已选择收费站
  141. getShopList() {
  142. let merchantId = uni.getStorageSync('login_user_info').merchantId
  143. this.$http.get("/ts/localTsMerchantLinkInspection/list?merchantId=" + merchantId, ).then(res => {
  144. console.log(res)
  145. if (res.data.code == 200) {
  146. res.data.result.forEach(item => {
  147. item.check = true
  148. })
  149. this.dataTips = res.data.result
  150. }
  151. })
  152. }
  153. },
  154. mounted() {
  155. this.getCityList()
  156. this.getShopList()
  157. }
  158. }
  159. </script>
  160. <script module="ModuleMap" lang="renderjs">
  161. export default {
  162. data() {
  163. return {
  164. map: null,
  165. layer: null,
  166. markers: '',
  167. isExistImplement: false,
  168. markerId: '',
  169. parkList: [],
  170. }
  171. },
  172. watch: {
  173. //监听位置数据的变化,并初始化地图(有位置数据则默认给个标点)
  174. parkList(v) {
  175. setTimeout(() => {
  176. if (window.AMap) {
  177. this.initAmap(v);
  178. } else {
  179. const script = document.createElement('script');
  180. script.src =
  181. 'https://webapi.amap.com/maps?v=1.4.15&key=6b8b0fd9f75da24fb1c13edf7b2d7daa'; //这里是自己申请的高德的key
  182. script.onload = () => {
  183. this.initAmap(v);
  184. }
  185. document.head.appendChild(script);
  186. }
  187. });
  188. }
  189. },
  190. mounted() {
  191. },
  192. methods: {
  193. initAmap(marker) {
  194. this.map = new AMap.Map('amap', {
  195. resizeEnable: true,
  196. center: [112.557429, 37.90923], //中心点坐标
  197. zoom: 10, //显示的缩放级别
  198. // zooms: [6, 30], //地图显示的缩放级别范围
  199. })
  200. //地图创建完成 标注点
  201. this.map.on("complete", () => {
  202. if (marker && marker.length) {
  203. this.markers = new AMap.Marker({
  204. // icon: new AMap.Icon({
  205. // image: 'static/img/map.png',
  206. // size: new AMap.Size(30, 34), //图标所处区域大小
  207. // imageSize: new AMap.Size(30, 34) //图标大小
  208. // }),
  209. position: [marker[0], marker[1]],
  210. offset: new AMap.Pixel(-15, -30)
  211. });
  212. this.markers.setMap(this.map);
  213. this.map.setCenter(marker)
  214. }
  215. })
  216. //点击事件
  217. this.map.on("click", (e) => {
  218. if (this.markers) {
  219. this.markers.setMap(null);
  220. this.markers = null;
  221. }
  222. if (!this.markers) {
  223. this.markers = new AMap.Marker({
  224. // icon: new AMap.Icon({
  225. // image: 'static/img/map.png',
  226. // size: new AMap.Size(30, 34), //图标所处区域大小
  227. // imageSize: new AMap.Size(30, 34) //图标大小
  228. // }),
  229. position: [e.lnglat.lng, e.lnglat.lat],
  230. offset: new AMap.Pixel(-15, -30)
  231. });
  232. this.markers.setMap(this.map);
  233. let str = e.lnglat.lng + ':' + e.lnglat.lat
  234. //地图点击事件 将位置信息传到上面的markerClick函数中
  235. this.$ownerInstance.callMethod('markerClick', str)
  236. }
  237. // this.createLabelsLayer();
  238. })
  239. },
  240. //接收传入的位置数据
  241. setParkList(newValue, oldValue, ownerInstance, instance) {
  242. this.parkList = newValue;
  243. },
  244. }
  245. }
  246. </script>
  247. <style lang="scss" scoped>
  248. .map {
  249. width: 100vw;
  250. height: 100vh;
  251. display: flex;
  252. flex-direction: column;
  253. .head {
  254. background: linear-gradient(87deg, #FFFFFF 0%, #A3CDFF 100%), linear-gradient(360deg, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%);
  255. /*#ifdef APP-PLUS*/
  256. .top {
  257. width: 100%;
  258. height: var(--status-bar-height);
  259. }
  260. /*#endif*/
  261. .title {
  262. width: 100%;
  263. height: 112rpx;
  264. padding: 20rpx;
  265. display: flex;
  266. align-items: center;
  267. justify-content: space-between;
  268. position: relative;
  269. .text {
  270. font-weight: 600;
  271. font-size: 36rpx;
  272. }
  273. .sub {
  274. display: flex;
  275. width: 104rpx;
  276. height: 49rpx;
  277. background: #2D88F4;
  278. border-radius: 8rpx;
  279. align-items: center;
  280. justify-content: center;
  281. font-size: 28rpx;
  282. color: #FFFFFF;
  283. }
  284. .cuIcon-back {
  285. font-size: 40rpx;
  286. margin-right: 40rpx;
  287. }
  288. .case {
  289. position: absolute;
  290. left: 50%;
  291. transform: translateX(-50%);
  292. font-size: 36rpx;
  293. font-weight: 600;
  294. }
  295. }
  296. }
  297. .search {
  298. width: 100%;
  299. height: 80rpx;
  300. background: #FFFFFF;
  301. border-radius: 8rpx;
  302. border: 1px solid rgba(255, 255, 255, 0.1);
  303. padding: 20rpx 24rpx;
  304. display: flex;
  305. align-items: center;
  306. .left {
  307. display: flex;
  308. align-items: center;
  309. image {
  310. width: 40rpx;
  311. height: 40rpx;
  312. }
  313. span {
  314. font-weight: 600;
  315. font-size: 28rpx;
  316. color: #181818;
  317. margin: 0 10rpx;
  318. }
  319. }
  320. .right {
  321. flex: 1;
  322. height: 58rpx;
  323. margin-left: 20rpx;
  324. background: #F6F7F9;
  325. border-radius: 33rpx;
  326. display: flex;
  327. align-items: center;
  328. padding: 12rpx 20rpx;
  329. }
  330. }
  331. .list {
  332. width: 98%;
  333. margin: 0 auto;
  334. flex: 1;
  335. overflow-y: auto;
  336. background-color: #ffffff;
  337. padding: 8rpx 20rpx;
  338. .tip {
  339. width: 100%;
  340. height: 124rpx;
  341. border-bottom: 1px solid #848484;
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-between;
  345. .left {
  346. font-weight: 500;
  347. font-size: 28rpx;
  348. display: flex;
  349. flex-direction: column;
  350. span {
  351. font-weight: 500;
  352. font-size: 24rpx;
  353. color: #666666;
  354. display: flex;
  355. align-items: center;
  356. text{
  357. display: flex;
  358. align-items: center;
  359. justify-content: center;
  360. width: 80rpx;
  361. height: 43rpx;
  362. background: rgba(253,73,18,0.05);
  363. border-radius: 4rpx ;
  364. font-size: 24rpx;
  365. color: #FD4912;
  366. margin-right: 12rpx;
  367. }
  368. }
  369. }
  370. .right {
  371. image {
  372. width: 40rpx;
  373. height: 40rpx;
  374. }
  375. }
  376. }
  377. }
  378. }
  379. </style>