position.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <view class="">
  3. <view class="header">
  4. <view class="city Medium">
  5. <text class="select-city" @click="loadCity">{{city}}</text>
  6. <u-icon name="arrow-down"></u-icon>
  7. </view>
  8. <u-search input-align="left" :disabled="true" @click="searchAddress" :show-action="false" height="70"
  9. placeholder="请输入位置信息" v-model="addressName"></u-search>
  10. </view>
  11. <view class="header2">
  12. <view class="header2-tip Regular">
  13. 当前定位
  14. </view>
  15. <view class="header2-content">
  16. <view class="left Medium">
  17. <u-icon name="arrow-down"></u-icon>
  18. <view class="">{{address}}</view>
  19. <view class="" v-if="isposition">{{text}}</view>
  20. </view>
  21. <view class="reposition Regular" @click="reloadPosition">{{po_tips}}</view>
  22. </view>
  23. </view>
  24. <view class="position-list Regular">
  25. <view class="search">
  26. <view>最近搜索</view>
  27. <u-icon name="trash-fill" color="#AFB3BF" size="28" @click="delList"></u-icon>
  28. </view>
  29. <view class="search-list">
  30. <view v-for="(item,index) in list" class="search-list-item" @click="toHome(item)">
  31. {{item}}
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import permision from "@/js_sdk/wa-permission/permission.js"
  39. import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
  40. export default {
  41. components: {
  42. uniSegmentedControl
  43. },
  44. data() {
  45. return {
  46. addressName: "",
  47. isposition: false,
  48. isIos: true,
  49. address: "定位失败,请点击重新定位",
  50. city: '营口市',
  51. list: [],
  52. position: '',
  53. addressObj: {},
  54. seconds: 3,
  55. po_tips: '重新定位',
  56. }
  57. },
  58. onLoad(e) {
  59. debugger
  60. if (e.city) {
  61. this.city = e.city
  62. }
  63. let that = this
  64. uni.getStorage({
  65. key: 'SearchList_key',
  66. success: function(res) {
  67. debugger
  68. that.list = res.data
  69. }
  70. });
  71. this.getLocation()
  72. // 获取定位
  73. // this.utils.getLocation().then(function(res) {
  74. // debugger
  75. // console.log("定位信息",res)
  76. // this.city = res.address.city
  77. // this.address = res.address.poiName
  78. // console.log('city',this.city)
  79. // console.log('poiName',this.address)
  80. // if (res.errMsg != "getLocation:ok") {
  81. // // 定位权限未开启,引导设置
  82. // uni.showModal({
  83. // title: '温馨提示',
  84. // content: '您已拒绝定位,请开启',
  85. // confirmText: '去设置',
  86. // success(res) {
  87. // if (res.confirm) {
  88. // //打开授权设置
  89. // this.utils.openSetting()
  90. // }
  91. // }
  92. // })
  93. // }
  94. // })
  95. },
  96. methods: {
  97. // 删除最近搜索
  98. delList() {
  99. uni.setStorage({
  100. key: 'SearchList_key',
  101. data: []
  102. });
  103. },
  104. getLocation() {
  105. let that = this;
  106. uni.getLocation({
  107. type: 'gcj02',
  108. geocode: true,
  109. success: function(res) {
  110. console.log('获取位置数据:', res);
  111. console.log('当前位置的经度:' + res.longitude);
  112. console.log('当前位置的纬度:' + res.latitude);
  113. //拼接当前定位回显地址
  114. // #ifdef APP-PLUS
  115. let _address = res.address
  116. that.city = _address.city
  117. that.address = _address.province + _address.city + _address.district + _address.poiName
  118. console.log(that.address)
  119. // #endif
  120. }
  121. });
  122. },
  123. // 重新定位
  124. reloadPosition() {
  125. var that = this
  126. that.po_tips = '定位中...'
  127. let countdown = setInterval(() => {
  128. that.seconds--;
  129. uni.getLocation({
  130. type: 'gcj02',
  131. success: function(res) {
  132. console.log('当前位置的经度:' + res.longitude);
  133. console.log('当前位置的纬度:' + res.latitude);
  134. // #ifdef APP-PLUS
  135. let _address = res.address
  136. that.city = _address.city
  137. that.longitude = res.longitude
  138. that.latitude = res.latitude
  139. that.address = _address.province + _address.city + _address.district +
  140. _address.poiName
  141. // #endif
  142. }
  143. });
  144. if (that.seconds <= 0) {
  145. that.seconds = 3
  146. that.po_tips = '重新定位'
  147. clearInterval(countdown);
  148. }
  149. }, 1000);
  150. },
  151. openSetting() {
  152. // App跳转系统的设置界面
  153. // #ifdef APP-PLUS
  154. uni.getSystemInfo({
  155. success(res) {
  156. if (res.platform == 'ios') { //IOS
  157. plus.runtime.openURL("app-settings://");
  158. } else if (res.platform == 'android') { //安卓
  159. let main = plus.android.runtimeMainActivity();
  160. let Intent = plus.android.importClass("android.content.Intent");
  161. let mIntent = new Intent('android.settings.ACTION_SETTINGS');
  162. main.startActivity(mIntent);
  163. }
  164. }
  165. });
  166. // #endif
  167. },
  168. // 跳转ios权限界面
  169. judgeIosPermission: function(permisionID) {
  170. var result = permision.judgeIosPermission(permisionID)
  171. console.log(result);
  172. var strStatus = (result) ? "已" : "未"
  173. uni.showModal({
  174. content: permisionID + '权限' + strStatus + "获得授权",
  175. showCancel: false
  176. });
  177. },
  178. // 跳转安卓权限界面
  179. async requestAndroidPermission(permisionID) {
  180. var result = await permision.requestAndroidPermission(permisionID)
  181. var strStatus
  182. if (result == 1) {
  183. strStatus = "已获得授权"
  184. } else if (result == 0) {
  185. strStatus = "未获得授权"
  186. } else {
  187. strStatus = "被永久拒绝权限"
  188. }
  189. uni.showModal({
  190. content: permisionID + strStatus,
  191. showCancel: false
  192. });
  193. },
  194. // 搜索
  195. searchAddress(val) {
  196. // console.log(val)
  197. let that = this;
  198. uni.chooseLocation({
  199. success: function(res) {
  200. console.log(res)
  201. // console.log('位置名称:' + res.name);
  202. // console.log('详细地址:' + res.address);
  203. // console.log('纬度:' + res.latitude);
  204. // console.log('经度:' + res.longitude);
  205. that.list.push(res.name)
  206. this.position = res.name
  207. uni.setStorage({
  208. key: 'SearchList_key',
  209. data: that.list
  210. });
  211. debugger
  212. uni.setStorage({
  213. key: 'setLocaltion',
  214. data: res.name,
  215. success() {
  216. uni.switchTab({
  217. url: "../home"
  218. });
  219. }
  220. })
  221. }
  222. });
  223. },
  224. // 切换城市
  225. loadCity() {
  226. uni.navigateTo({
  227. url: "../selectCity/selectCity"
  228. })
  229. },
  230. toHome(item) {
  231. console.log("跳转首页")
  232. uni.setStorage({
  233. key: 'setLocaltion',
  234. data: item,
  235. success() {
  236. uni.switchTab({
  237. url: "../home",
  238. success(e) {
  239. console.log(e)
  240. }
  241. });
  242. }
  243. })
  244. }
  245. }
  246. }
  247. </script>
  248. <style lang="scss" scoped>
  249. /deep/.u-content {
  250. padding-left: 170rpx;
  251. }
  252. .header {
  253. position: relative;
  254. display: flex;
  255. background: white;
  256. padding: 20rpx;
  257. .city {
  258. top: 0;
  259. bottom: 0;
  260. left: 50rpx;
  261. margin: auto;
  262. position: absolute;
  263. display: flex;
  264. align-items: center;
  265. .select-city {
  266. margin-right: 4rpx;
  267. }
  268. }
  269. }
  270. .header2 {
  271. background: white;
  272. border-radius: 0 0 20rpx 20rpx;
  273. padding: 0 20rpx 34rpx 20rpx;
  274. .header2-tip {
  275. font-size: 28rpx;
  276. color: #AFB3BF;
  277. }
  278. .header2-content {
  279. font-size: 32rpx;
  280. color: #333333;
  281. display: flex;
  282. justify-content: space-between;
  283. margin-top: 12rpx;
  284. .left {
  285. display: flex;
  286. }
  287. .reposition {
  288. font-size: 28rpx;
  289. color: #22C572;
  290. }
  291. }
  292. }
  293. .position-list {
  294. margin-top: 20rpx;
  295. background: white;
  296. border-radius: 20rpx 20rpx 0 0;
  297. padding: 10rpx;
  298. }
  299. .search {
  300. display: flex;
  301. justify-content: space-between;
  302. padding: 0 20rpx;
  303. }
  304. .search-list {
  305. padding: 20rpx;
  306. }
  307. .search-list-item {
  308. display: inline-block;
  309. background: #F5F6F9;
  310. border-radius: 32rpx;
  311. padding: 16rpx 24rpx;
  312. margin: 0 20rpx 20rpx 0;
  313. }
  314. </style>