addAddress.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view class="switch-roles">
  3. <nav-bar title="添加地址"></nav-bar>
  4. <view class="roles-content">
  5. <view class="content">
  6. <!-- 城市 -->
  7. <view class="form-item">
  8. <view class="item-label"><text class="required">*</text>所在城市</view>
  9. <view class="item-content flex align-center justify-between" @click="toCityPage">
  10. <view class="content-value">
  11. <text v-if="city">{{ city }}</text>
  12. <text class="placeholder" v-else>请选择城市</text>
  13. </view>
  14. <u-icon name="arrow-down" color="rgba(153, 153, 153, 1)"></u-icon>
  15. </view>
  16. </view>
  17. <!-- 区域 -->
  18. <view class="form-item">
  19. <view class="item-label"><text class="required">*</text>所在区域</view>
  20. <view class="item-content flex align-center justify-between" @click="toCountyPage">
  21. <view class="content-value">
  22. <text v-if="district">{{ district }}</text>
  23. <text class="placeholder" v-else>请选择区域</text>
  24. </view>
  25. <u-icon name="arrow-down" color="rgba(153, 153, 153, 1)"></u-icon>
  26. </view>
  27. </view>
  28. <!-- 详细地址 -->
  29. <view class="form-item">
  30. <view class="item-label"><text class="required">*</text>详细地址</view>
  31. <view class="item-content">
  32. <input v-model="addr" placeholder="请输入公司详细地址" class="input" placeholder-class="input-placeholder" />
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="button-section">
  38. <view class="submit-btn" @click="confirmAddress">确定</view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import navBar from "@/components/nav-bar/index.vue";
  44. // import addr from "@/utils/addr.json";
  45. export default {
  46. data() {
  47. return {
  48. latitude: '', // 纬度(地图选点获取)
  49. longitude: '', // 经度(地图选点获取)
  50. province: '', // 省份
  51. city: '', // 城市
  52. district: '', // 区域
  53. addr: '', // 详情地址
  54. };
  55. },
  56. components: {
  57. navBar,
  58. },
  59. // created() {
  60. // // 初始化省份数据
  61. // this.provinces = addr;
  62. // },
  63. onLoad(options) {
  64. if (options.address) {
  65. let address = JSON.parse(options.address);
  66. this.latitude = address.latitude;
  67. this.longitude = address.longitude;
  68. this.province = decodeURIComponent(address.province) || ''
  69. this.city = decodeURIComponent(address.city)
  70. this.district = decodeURIComponent(address.district)
  71. this.addr = this.setAddress(decodeURIComponent(address.fullText))
  72. }
  73. uni.$on('city', data => {
  74. if (data.city) {
  75. this.city = data.city
  76. }
  77. })
  78. uni.$on('filterCity', data => {
  79. this.city = data.city
  80. this.district = data.county
  81. })
  82. },
  83. onUnload() {
  84. uni.$off('city')
  85. uni.$off('filterCity')
  86. },
  87. methods: {
  88. // 设置详细地址
  89. setAddress(address) {
  90. let preStr = `${this.province}${this.city}${this.district}`
  91. return address.replace(preStr, '')
  92. },
  93. // 跳转选择城市页面
  94. toCityPage() {
  95. uni.navigateTo({
  96. url: '/package/jobIntention/city'
  97. })
  98. },
  99. // 跳转选择区域页面
  100. toCountyPage() {
  101. if (!this.city) {
  102. this.$queue.showToast('请先选择城市')
  103. return
  104. }
  105. uni.navigateTo({
  106. url: `/package/screen/city?city=${this.city}&county=&type=search`
  107. })
  108. },
  109. // 确认地址并回传
  110. confirmAddress() {
  111. let city = this.city
  112. let district = this.district
  113. let address = this.addr.trim()
  114. if (!city) {
  115. return uni.showToast({ title: '请选择城市', icon: 'none' });
  116. }
  117. if (!district) {
  118. return uni.showToast({ title: '请选择区域', icon: 'none' });
  119. }
  120. if (!address) {
  121. return uni.showToast({ title: '请输入详细地址', icon: 'none' });
  122. }
  123. // 合并完整地址信息
  124. const fullAddress = {
  125. province: this.province,
  126. city,
  127. district,
  128. latitude: this.latitude || '',
  129. longitude: this.longitude || '',
  130. fullText: `${this.province}${city}${district}${address}`
  131. };
  132. // 回传上一页
  133. uni.$emit('addressData', fullAddress);
  134. uni.navigateBack();
  135. }
  136. }
  137. };
  138. </script>
  139. <style lang="scss" scoped>
  140. /* 其他原有样式保持不变 */
  141. .switch-roles {
  142. background-color: #fff;
  143. position: absolute;
  144. left: 0;
  145. right: 0;
  146. top: 0;
  147. bottom: 0;
  148. display: flex;
  149. flex-direction: column;
  150. .roles-content {
  151. width: 100%;
  152. flex: 1;
  153. overflow-y: auto;
  154. .content {
  155. padding: 40rpx;
  156. box-sizing: border-box;
  157. .required {
  158. color: #FF0027;
  159. /* 红色必填标记 */
  160. font-size: 28rpx;
  161. }
  162. }
  163. }
  164. .button-section {
  165. padding: 28rpx 40rpx;
  166. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.04);
  167. }
  168. .submit-btn {
  169. flex-shrink: 0;
  170. border-radius: 999px;
  171. box-shadow: 0px -4px 16px 0px rgba(0, 0, 0, 0.04);
  172. background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
  173. color: rgba(255, 255, 255, 1);
  174. font-family: DM Sans;
  175. font-size: 32rpx;
  176. font-weight: 400;
  177. line-height: 48rpx;
  178. display: flex;
  179. justify-content: center;
  180. align-items: center;
  181. padding: 16rpx 32rpx;
  182. box-sizing: border-box;
  183. }
  184. }
  185. .custom-input {
  186. box-sizing: border-box;
  187. border: 2rpx solid #9ea1a8;
  188. border-radius: 100rpx;
  189. padding: 8rpx 36rpx;
  190. height: 96rpx;
  191. }
  192. .form-item {
  193. margin-bottom: 20rpx;
  194. width: 100%;
  195. margin-bottom: 20rpx;
  196. }
  197. .item-label {
  198. color: #1F2C37;
  199. font-size: 28rpx;
  200. line-height: 44rpx;
  201. display: flex;
  202. align-items: center;
  203. margin-bottom: 20rpx;
  204. }
  205. .item-content {
  206. box-sizing: border-box;
  207. border: 1px solid rgba(227, 231, 236, 1);
  208. border-radius: 24px;
  209. background: Colors/White, rgba(255, 255, 255, 1);
  210. padding: 15rpx 32rpx;
  211. line-height: 40rpx;
  212. .placeholder {
  213. color: rgba(153, 153, 153, 1);
  214. }
  215. .input {
  216. font-size: 28rpx;
  217. }
  218. .input-placeholder {
  219. color: rgba(153, 153, 153, 1);
  220. }
  221. }
  222. </style>