position.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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">重新定位</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. src: {},
  53. addressObj: {}
  54. }
  55. },
  56. onLoad(e) {
  57. debugger
  58. if (e.city) {
  59. this.city = e.city
  60. }
  61. let that = this
  62. uni.getStorage({
  63. key: 'SearchList_key',
  64. success: function(res) {
  65. debugger
  66. that.list = res.data
  67. }
  68. });
  69. // 获取定位
  70. this.utils.getLocation().then(function(res) {
  71. debugger
  72. console.log("定位信息",res)
  73. if (res.errMsg != "getLocation:ok") {
  74. // 定位权限未开启,引导设置
  75. uni.showModal({
  76. title: '温馨提示',
  77. content: '您已拒绝定位,请开启',
  78. confirmText: '去设置',
  79. success(res) {
  80. if (res.confirm) {
  81. //打开授权设置
  82. this.utils.openSetting()
  83. }
  84. }
  85. })
  86. }
  87. })
  88. },
  89. methods: {
  90. // 删除最近搜索
  91. delList() {
  92. uni.setStorage({
  93. key: 'SearchList_key',
  94. data: []
  95. });
  96. },
  97. // 重新定位
  98. reloadPosition() {
  99. // this.getLocation()
  100. },
  101. openSetting() {
  102. // App跳转系统的设置界面
  103. // #ifdef APP-PLUS
  104. uni.getSystemInfo({
  105. success(res) {
  106. if (res.platform == 'ios') { //IOS
  107. plus.runtime.openURL("app-settings://");
  108. } else if (res.platform == 'android') { //安卓
  109. let main = plus.android.runtimeMainActivity();
  110. let Intent = plus.android.importClass("android.content.Intent");
  111. let mIntent = new Intent('android.settings.ACTION_SETTINGS');
  112. main.startActivity(mIntent);
  113. }
  114. }
  115. });
  116. // #endif
  117. },
  118. // 跳转ios权限界面
  119. judgeIosPermission: function(permisionID) {
  120. var result = permision.judgeIosPermission(permisionID)
  121. console.log(result);
  122. var strStatus = (result) ? "已" : "未"
  123. uni.showModal({
  124. content: permisionID + '权限' + strStatus + "获得授权",
  125. showCancel: false
  126. });
  127. },
  128. // 跳转安卓权限界面
  129. async requestAndroidPermission(permisionID) {
  130. var result = await permision.requestAndroidPermission(permisionID)
  131. var strStatus
  132. if (result == 1) {
  133. strStatus = "已获得授权"
  134. } else if (result == 0) {
  135. strStatus = "未获得授权"
  136. } else {
  137. strStatus = "被永久拒绝权限"
  138. }
  139. uni.showModal({
  140. content: permisionID + strStatus,
  141. showCancel: false
  142. });
  143. },
  144. // 搜索
  145. searchAddress(val) {
  146. console.log(val)
  147. let that = this;
  148. uni.chooseLocation({
  149. success: function(res) {
  150. console.log('位置名称:' + res.name);
  151. console.log('详细地址:' + res.address);
  152. console.log('纬度:' + res.latitude);
  153. console.log('经度:' + res.longitude);
  154. that.list.push(res.name)
  155. this.src = res
  156. uni.setStorage({
  157. key: 'SearchList_key',
  158. data: that.list
  159. });
  160. }
  161. });
  162. },
  163. // 切换城市
  164. loadCity() {
  165. uni.navigateTo({
  166. url: "../selectCity/selectCity"
  167. })
  168. },
  169. toHome(item) {
  170. uni.navigateTo({
  171. url: "../home?src=" + this.src
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. /deep/.u-content {
  179. padding-left: 170rpx;
  180. }
  181. .header {
  182. position: relative;
  183. display: flex;
  184. background: white;
  185. padding: 20rpx;
  186. .city {
  187. top: 0;
  188. bottom: 0;
  189. left: 50rpx;
  190. margin: auto;
  191. position: absolute;
  192. display: flex;
  193. align-items: center;
  194. .select-city {
  195. margin-right: 4rpx;
  196. }
  197. }
  198. }
  199. .header2 {
  200. background: white;
  201. border-radius: 0 0 20rpx 20rpx;
  202. padding: 0 20rpx 34rpx 20rpx;
  203. .header2-tip {
  204. font-size: 28rpx;
  205. color: #AFB3BF;
  206. }
  207. .header2-content {
  208. font-size: 32rpx;
  209. color: #333333;
  210. display: flex;
  211. justify-content: space-between;
  212. margin-top: 12rpx;
  213. .left {
  214. display: flex;
  215. }
  216. .reposition {
  217. font-size: 28rpx;
  218. color: #22C572;
  219. }
  220. }
  221. }
  222. .position-list {
  223. margin-top: 20rpx;
  224. background: white;
  225. border-radius: 20rpx 20rpx 0 0;
  226. padding: 10rpx;
  227. }
  228. .search {
  229. display: flex;
  230. justify-content: space-between;
  231. padding: 0 20rpx;
  232. }
  233. .search-list {
  234. padding: 20rpx;
  235. }
  236. .search-list-item {
  237. display: inline-block;
  238. background: #F5F6F9;
  239. border-radius: 32rpx;
  240. padding: 16rpx 24rpx;
  241. margin: 0 20rpx 20rpx 0;
  242. }
  243. </style>