addAddress.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="switch-roles">
  3. <nav-bar title="岗位描述" color="#000"></nav-bar>
  4. <view class="roles-content">
  5. <view class="content">
  6. <view class="title">添加地址</view>
  7. <!-- 地图选点入口 -->
  8. <view class="map-selector" @click="openMapSelector">
  9. <u-icon name="map" size="36rpx" color="#007AFF" marginRight="16rpx"></u-icon>
  10. <text class="map-text">通过地图选择地址</text>
  11. </view>
  12. <view class="form-item">
  13. <view class="item-label"> 工作地址 </view>
  14. <u-input
  15. placeholder="请输入办公大楼名称,例:碧桂园凤凰智谷"
  16. v-model="address"
  17. clearable
  18. class="custom-input"
  19. :customStyle="{ padding: '8rpx 24rpx ' }"
  20. >
  21. <template #prefix>
  22. <u-icon name="map" size="36rpx" color="#999" marginRight="20rpx"></u-icon>
  23. </template>
  24. </u-input>
  25. </view>
  26. <view class="form-item">
  27. <view class="item-label"> 楼层/单元室 </view>
  28. <u-input
  29. placeholder="楼层/单元室/门牌号,例:3层302室"
  30. v-model="addressDetail"
  31. clearable
  32. class="custom-input"
  33. :customStyle="{ padding: '8rpx 24rpx ' }"
  34. >
  35. <template #prefix>
  36. <u-icon name="home" size="36rpx" color="#999" marginRight="20rpx"></u-icon>
  37. </template>
  38. </u-input>
  39. </view>
  40. <!-- 经纬度信息(可选显示) -->
  41. <view class="location-info" v-if="latitude && longitude">
  42. <text>当前地址经纬度:{{ latitude }}, {{ longitude }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="submit-btn" @click="confirmAddress">确定</view>
  47. </view>
  48. </template>
  49. <script>
  50. import navBar from "@/components/nav-bar/index.vue";
  51. export default {
  52. data() {
  53. return {
  54. address: "", // 办公大楼名称
  55. addressDetail: '', // 楼层/单元室详情
  56. latitude: '', // 纬度
  57. longitude: '' // 经度
  58. };
  59. },
  60. components: {
  61. navBar,
  62. },
  63. onLoad(options) {
  64. // 回显上一页传递的地址信息
  65. if (options.address) this.address = decodeURIComponent(options.address);
  66. if (options.addressDetail) this.addressDetail = decodeURIComponent(options.addressDetail);
  67. if (options.latitude) this.latitude = options.latitude;
  68. if (options.longitude) this.longitude = options.longitude;
  69. },
  70. methods: {
  71. // 打开地图选择地址
  72. openMapSelector() {
  73. // 使用uni-app的地图选择API
  74. uni.chooseLocation({
  75. success: (res) => {
  76. // 地图选点成功后自动填充地址信息
  77. this.address = res.name || res.address;
  78. this.latitude = res.latitude; // 获取纬度
  79. this.longitude = res.longitude; // 获取经度
  80. // 解析详细地址(尝试提取门牌号等信息)
  81. const addressParts = this.parseAddressDetail(res.address);
  82. if (addressParts.detail) {
  83. this.addressDetail = addressParts.detail;
  84. }
  85. },
  86. fail: (err) => {
  87. console.error('地图选择失败:', err);
  88. if (err.errMsg.includes('auth')) {
  89. uni.showToast({
  90. title: '请开启位置权限',
  91. icon: 'none'
  92. });
  93. }
  94. }
  95. });
  96. },
  97. // 解析地址详情(提取门牌号等信息)
  98. parseAddressDetail(fullAddress) {
  99. // 简单的地址解析逻辑,可根据实际需求优化
  100. const reg = /(\d+层|\d+栋|\d+单元|\d+室)/g;
  101. const details = fullAddress.match(reg);
  102. return {
  103. detail: details ? details.join('') : ''
  104. };
  105. },
  106. // 确认地址并回传
  107. confirmAddress() {
  108. if (!this.address.trim()) {
  109. return uni.showToast({
  110. title: '请输入或选择办公大楼名称',
  111. icon: 'none'
  112. });
  113. }
  114. // 合并完整地址信息(包含经纬度)
  115. const fullAddress = {
  116. address: this.address.trim(),
  117. addressDetail: this.addressDetail.trim(),
  118. latitude: this.latitude,
  119. longitude: this.longitude,
  120. fullText: this.address.trim() + (this.addressDetail.trim() ? ' ' + this.addressDetail.trim() : '')
  121. };
  122. // 通知上一页
  123. uni.$emit('addressData', fullAddress);
  124. uni.navigateBack();
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .switch-roles {
  131. background-color: #fff;
  132. position: absolute;
  133. left: 0;
  134. right: 0;
  135. top: 0;
  136. bottom: 0;
  137. display: flex;
  138. flex-direction: column;
  139. .roles-content {
  140. width: 100%;
  141. flex: 1;
  142. overflow: hidden;
  143. overflow-y: auto;
  144. .content {
  145. padding: 40rpx;
  146. box-sizing: border-box;
  147. display: flex;
  148. flex-direction: column;
  149. .title {
  150. color: #333;
  151. width: 100%;
  152. font-family: DM Sans;
  153. font-size: 40rpx;
  154. font-weight: 600;
  155. margin-bottom: 30rpx;
  156. }
  157. // 地图选择器样式
  158. .map-selector {
  159. display: flex;
  160. align-items: center;
  161. padding: 20rpx 24rpx;
  162. background-color: #f5f7fa;
  163. border-radius: 16rpx;
  164. margin-bottom: 30rpx;
  165. color: #007AFF;
  166. font-size: 28rpx;
  167. cursor: pointer;
  168. transition: background-color 0.2s;
  169. &:active {
  170. background-color: #e8ebf0;
  171. }
  172. }
  173. // 经纬度信息样式
  174. .location-info {
  175. margin-top: 10rpx;
  176. font-size: 24rpx;
  177. color: #999;
  178. padding-left: 4rpx;
  179. }
  180. }
  181. }
  182. .submit-btn {
  183. flex-shrink: 0;
  184. border-radius: 999px;
  185. box-shadow: 0px 2px 4px 0px rgba(9, 196, 116, 0.3);
  186. background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
  187. color: rgba(255, 255, 255, 1);
  188. font-family: DM Sans;
  189. font-size: 32rpx;
  190. font-weight: 400;
  191. line-height: 48rpx;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. padding: 16rpx 32rpx;
  196. box-sizing: border-box;
  197. margin: 60rpx 20rpx;
  198. height: 96rpx;
  199. transition: all 0.2s ease;
  200. &:active {
  201. transform: scale(0.98);
  202. opacity: 0.9;
  203. }
  204. }
  205. }
  206. .form-item {
  207. margin-bottom: 32rpx;
  208. width: 100%;
  209. }
  210. .item-label {
  211. color: rgba(18, 26, 44, 1);
  212. font-family: Roboto;
  213. font-size: 32rpx;
  214. font-weight: 400;
  215. line-height: 51.2rpx;
  216. letter-spacing: 0px;
  217. text-align: left;
  218. padding: 10rpx 0;
  219. box-sizing: border-box;
  220. }
  221. .custom-input {
  222. box-sizing: border-box;
  223. border: 2rpx solid rgba(158, 161, 168, 1);
  224. border-radius: 100rpx;
  225. background: rgba(255, 255, 255, 1);
  226. padding: 8rpx 24rpx !important;
  227. height: 96rpx;
  228. }
  229. /* 输入框聚焦样式优化 */
  230. ::v-deep .u-input input:focus {
  231. border-color: #007AFF !important;
  232. }
  233. ::v-deep .u-input {
  234. text-align: left !important;
  235. }
  236. </style>