You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
10 KiB

4 years ago
  1. <template>
  2. <view class='app'>
  3. <!-- 当前选择地址 -->
  4. <view class="current-address row b-b">
  5. <view class="left">
  6. <view class="row">
  7. <text class="red">[当前]</text>
  8. <text class="title">{{currentAddress.title}}</text>
  9. </view>
  10. <text class="addr clamp">{{currentAddress.address}}</text>
  11. </view>
  12. <!-- 搜索图标 -->
  13. <image
  14. class="ser-icon"
  15. src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAENElEQVRoQ+2a/1XcMAzHlQkKExQmaJmAMgHtBJQJqkzQMsGpExQm6HWCHhMUJihMUJjAfd97znuucc6Sklxf4PwXjzixPtYPS/I19MJG88J4aQf83DW+0/BOw89sByY3aWbea5rmDREdhBAO0v1rmmYVQrgXkbtt7eskwMz8lojOiOgdEeHv2nggolXTNMvFYnFVmzzk+ajAbduehhA4gnrlArwQ0VcRwd+jjlGAo0YXA0FzsDW4iFyMSTwYmJk/E9GXDULdEtGSiOCnqa/uRXOHX78nolc937ghog9j+bkbGMGIiKDVjwVB7+MmLLVmGa0E7gDfL2n7REQAP2i4gCPsz0JAWoOKyKVXKmaGxmExJfDzId+GTF5gwCICp+MHtK3VaG1DmBlmjo1LTR1+PUjTZmBmRgT9lAl8ISKb/LjGV3wezRz+/zqZAOhD78aagOOuf8+kaxFKXUSKl6L7INilml6JyIni9SdT1MBx4V/ImJKvXIlIKWh5ZOl9J2p6lUG7/NkCDJPFEdSNWxHRZFGjwDMzIjhOhW64TFsFHLX7m4hwFHUDwQO7vrXBzFjvOFnQrGUtMMz2W7LQtYjkUXpycGbGmjghunEnIoeWhbXAiJSnyYePxkgCLIJ2c5kZyQeqr26YZKkCR3P+kyyAcu6fMs8juPedgi+bjkQNcG5GW4nMfRsSMzHEk26Y3EsDnEdnJPIw8f82MrN+EJF9rTAaYKR3aV679eicw+TRWkSqHN03qhMLR8G+N63TaqE2j5ndSjADW3azJrj3OTPnbqa2urkC5wUMiglVI1ADnJ/B6t30arD23tQ+7DafmuDe51MD52nlpOVgbRMKidDo5zCyqvSgvxGRo5pgUz0v1ORo56KSUo2qD+MrzIyAkHYd1EFCJYVh0pAjCctogXM/NuWvBp6NU2NaiSZEV6Y+ikhaslaX0gLnZo3iG1WK6iioSqGcUNCuOa9XAUezzrMb82JKruK0QtHwiHaTNeuzAOdahmDmjoMHuqcP7nIrNXDUcu7L+LepAHcCo1OKPnU3XNpVB61UyELHYXBzfNMmMDNaS3ln1L3JJg1HLcO00WbJbwSQkLivWHLoDdc5gxIfM3CERns27xPjEYAh0KB73bZtz0IIKBDyI8fctMs30gVcgXZfaMeuJHrfmzqilyJy7okFLh/O/BnmjWoq7SKmU5bxdxzId59cdcbffxyHEBCQAKltDrqh3RrOwEvRu08JAAeYJkO6jgGrdH3qgh4FOAlmffe6Vgt8cs9cyLLWMcNq3qMBd0QxI0L1AjNNCw4NNO6YcRlZvMIZA3p04IKPd75ZCkTd7z5w/am6pxoKPSmwRqWeOUOgZwkcY0ZezODf1WbAbIH7oGtt5FkDF6Cr/a3ZA0fodWDU5PLPAtgS+HbAlt2a49ydhueoNYvMOw1bdmuOc/8C4xLETHORTG0AAAAASUVORK5CYII="
  16. @click="navTo('search?city='+curCity)"
  17. ></image>
  18. </view>
  19. <!-- 补充详细地址 -->
  20. <view class="confirm-wrap row">
  21. <input class="input" placeholder="补充详细地址:楼号、门牌等(选填)" placeholder-class="placeholder" v-model="room" @confirm='submit'></input>
  22. <view class="btn" @click="submit">确定</view>
  23. </view>
  24. <map
  25. id="map"
  26. class="map"
  27. :scale="15"
  28. :show-location="true"
  29. :longitude="map.longitude"
  30. :latitude="map.latitude"
  31. @regionchange="onRegionchange"
  32. >
  33. <cover-image class="map-center-icon" src="https://7478-tx-cloud-mix-mall-d6944c-1302673523.tcb.qcloud.la/5bfbd58b18200d8e16f6b17a02e6ed9.png"></cover-image>
  34. </map>
  35. <!-- 结果集 -->
  36. <scroll-view scroll-y class="addr-list-scroll">
  37. <view class="addr-list">
  38. <view class="addr-item b-b row" v-for="(item, index) in list" :key="index" @click="chooseAddress(index)">
  39. <view class="left">
  40. <text class="title">{{item.title}}</text>
  41. <text class="addr">{{item.address}}</text>
  42. </view>
  43. <icon type="success" color="#ff536f" size="18" class="icon_circle" v-if='checked === index' />
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. </template>
  49. <script>
  50. import config from '@/config'
  51. const QQMapWX = require('./js/qqmap-wx-jssdk.min.js')
  52. const qqmapsdk = new QQMapWX({
  53. key: config.qqmapWxKey
  54. })
  55. let _mapCtx = null;
  56. export default {
  57. data() {
  58. return {
  59. curCity: '',
  60. mapStatus: 1,
  61. map: {
  62. longitude: 116.39742,
  63. latitude: 39.909,
  64. },
  65. room: '', //补充地址 门牌号、房间号
  66. list: [], //地址列表
  67. checked: 0, //当前选择选择地址下标
  68. tempAddress: null, //编辑或者搜索到地址时,需要手动将结果添加到poi集
  69. }
  70. },
  71. computed: {
  72. currentAddress(){
  73. if(this.list.length === 0){
  74. return {};
  75. }
  76. return this.list[this.checked];
  77. }
  78. },
  79. created() {
  80. _mapCtx = uni.createMapContext('map');
  81. },
  82. onNavigationBarButtonTap() {
  83. this.submit();
  84. },
  85. async onLoad(options) {
  86. //编辑地址时参数
  87. let optionData = options.data;
  88. let lng, lat;
  89. if(optionData){
  90. //编辑地址时
  91. this.tempAddress = JSON.parse(optionData);
  92. this.room = this.tempAddress.room;
  93. lng = this.tempAddress.location.lng;
  94. lat = this.tempAddress.location.lat;
  95. }else{
  96. //没有传坐标时获取用户当前定位
  97. const userLocation = await this.getLocation();
  98. lng = +userLocation.longitude;
  99. lat = +userLocation.latitude;
  100. }
  101. this.map = {
  102. longitude: lng,
  103. latitude: lat
  104. }
  105. this.position = {
  106. longitude: lng,
  107. latitude: lat
  108. }
  109. this.getAddressList(1)
  110. },
  111. methods: {
  112. //确定选择
  113. submit() {
  114. const {currentAddress, room} = this;
  115. const {ad_info, address, location, title} = currentAddress;
  116. /* if(!room){
  117. this.$util.msg('请补充详细地址');
  118. return;
  119. } */
  120. this.$util.prePage().setAddress(Object.assign({}, {
  121. ad_info, address, location, title,room
  122. }));
  123. uni.navigateBack();
  124. },
  125. //获取poi列表
  126. getAddressList(s = 0) {
  127. //在ios下防止搜索返回时多次加载地址列表的问题
  128. if(this.isSetTempAddress === 1){
  129. return;
  130. }
  131. qqmapsdk.reverseGeocoder({
  132. location: {
  133. latitude: this.position.latitude,
  134. longitude: this.position.longitude
  135. },
  136. get_poi: 1,
  137. poi_options: "page_size=30;page_index=1",
  138. success: res=> {
  139. //有搜索结果时,手动追加到列表顶部
  140. if(this.tempAddress){
  141. if(this.tempAddress.title != res.result.pois[0].title){
  142. res.result.pois.unshift(this.tempAddress);
  143. }
  144. this.tempAddress = null;
  145. this.isSetTempAddress = 1;
  146. setTimeout(()=>{
  147. this.isSetTempAddress = 0;
  148. }, 500)
  149. }
  150. if (s) {
  151. const ad_info = res.result.pois[0].ad_info;
  152. this.curCity = ad_info.city || '';
  153. res.result.pois[0].select = 1
  154. this.list = res.result.pois;
  155. this.checked = 0;
  156. } else {
  157. this.list = res.result.pois;
  158. }
  159. },
  160. fail: err=> {
  161. console.log(err)
  162. }
  163. })
  164. },
  165. //地图区域改变
  166. onRegionchange(e) {
  167. clearTimeout(this.timer)
  168. this.timer = setTimeout(() => {
  169. //h5 end 安卓 regionchange
  170. if (e.type === 'end' || e.type === 'regionchange') {
  171. _mapCtx.getCenterLocation({
  172. success: res => {
  173. this.position = {
  174. latitude: res.latitude,
  175. longitude: res.longitude
  176. }
  177. if (this.mapStatus == 1) { // 防止地图点击时 进行多次加载
  178. this.getAddressList(1)
  179. }
  180. },
  181. fail: err=>{
  182. console.log(err);
  183. }
  184. })
  185. }
  186. }, 200)
  187. },
  188. //地址列表点击
  189. chooseAddress(index) {
  190. let list = this.list
  191. this.map = {
  192. longitude: list[index].location.lng,
  193. latitude: list[index].location.lat
  194. }
  195. this.checked = index;
  196. this.mapStatus = 0;
  197. //防止ios下触发多次加载列表的bug
  198. clearTimeout(this.mapStatusTimer);
  199. this.mapStatusTimer = setTimeout(()=>{
  200. this.mapStatus = 1;
  201. }, 1000)
  202. },
  203. //获取用户定位
  204. getLocation (){
  205. return new Promise(resolve=> {
  206. // #ifndef H5
  207. uni.getLocation({
  208. type: 'gcj02',
  209. success: res=> {
  210. resolve({
  211. longitude: res.longitude,
  212. latitude: res.latitude
  213. })
  214. },
  215. err: err=> {
  216. console.log(err)
  217. resolve({
  218. longitude: 116.39742,
  219. latitude: 39.909,
  220. })
  221. },
  222. complete(res) {
  223. console.log(res);
  224. }
  225. })
  226. // #endif
  227. // #ifdef H5
  228. //h5的定位没有写,这里直接默认天安门,可以根据项目需求使用对应jssdk获取定位
  229. resolve({
  230. longitude: 116.39742,
  231. latitude: 39.909,
  232. })
  233. // #endif
  234. })
  235. },
  236. navTo(url){
  237. uni.navigateTo({
  238. url
  239. })
  240. }
  241. }
  242. }
  243. </script>
  244. <style>
  245. page {
  246. height: 100%;
  247. background: #F6F6F6;
  248. }
  249. </style>
  250. <style scoped lang="scss">
  251. .app{
  252. display: flex;
  253. flex-direction: column;
  254. height: 100%;
  255. overflow: hidden;
  256. }
  257. .row{
  258. display: flex;
  259. align-items: center;
  260. }
  261. .b-b{
  262. position: relative;
  263. &:after{
  264. position: absolute;
  265. z-index: 3;
  266. left: 0;
  267. top: auto;
  268. bottom: 0;
  269. right: 0;
  270. height: 0;
  271. content: '';
  272. transform: scaleY(.5);
  273. border-bottom: 1px solid #e5e5e5;
  274. }
  275. }
  276. .clamp {
  277. /* #ifdef APP-PLUS-NVUE */
  278. lines: 1;
  279. /* #endif */
  280. /* #ifndef APP-PLUS-NVUE */
  281. overflow: hidden;
  282. text-overflow: ellipsis;
  283. white-space: nowrap;
  284. display: block;
  285. /* #endif */
  286. }
  287. .current-address{
  288. height: 120rpx;
  289. padding: 0 24rpx;
  290. background-color: #fff;
  291. .left{
  292. width: 634rpx;
  293. }
  294. .red{
  295. flex-shrink: 0;
  296. margin-right: 6rpx;
  297. font-size: 28rpx;
  298. color: $base-color;
  299. line-height: 36rpx;
  300. }
  301. .title{
  302. font-size: 28rpx;
  303. color: #333;
  304. font-weight: bold;
  305. line-height: 36rpx;
  306. }
  307. .addr{
  308. width: 700rpx;
  309. margin-top: 12rpx;
  310. font-size: 24rpx;
  311. color: #909399;
  312. line-height: 1.4;
  313. }
  314. .ser-icon{
  315. flex-shrink: 0;
  316. width: 66rpx;
  317. height: 66rpx;
  318. padding: 12rpx 4rpx 12rpx 20rpx;
  319. }
  320. }
  321. .confirm-wrap{
  322. height: 88rpx;
  323. padding: 0 24rpx;
  324. background-color: #fff;
  325. .input{
  326. flex: 1;
  327. font-size: 28rpx;
  328. color: #303133;
  329. }
  330. .btn{
  331. padding: 0 24rpx;
  332. font-size: 26rpx;
  333. color: #fff;
  334. line-height: 50rpx;
  335. background-color: $base-color;
  336. border-radius: 100rpx;
  337. }
  338. }
  339. .map{
  340. width: 750rpx;
  341. height: 700rpx;
  342. .map-center-icon{
  343. position: absolute;
  344. left: 339rpx;
  345. top: 264rpx;
  346. width: 72rpx;
  347. height: 72rpx;
  348. }
  349. }
  350. .addr-list-scroll{
  351. flex: 1;
  352. overflow: hidden;
  353. .addr-list{
  354. background-color: #fff;
  355. }
  356. .addr-item{
  357. padding: 24rpx;
  358. }
  359. .left{
  360. flex: 1;
  361. display: flex;
  362. flex-direction: column;
  363. padding-right: 50rpx;
  364. }
  365. .title{
  366. font-size: 28rpx;
  367. color: #303133;
  368. }
  369. .addr{
  370. margin-top: 10rpx;
  371. font-size: 24rpx;
  372. color: #909399;
  373. line-height: 1.4;
  374. }
  375. }
  376. </style>