checkMap.vue 9.8 KB

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