position.vue 7.5 KB

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