瑶都万能墙
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
4.8 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
  1. <template>
  2. <uv-popup round="40rpx" ref="addressPopup" :customStyle="{ height: 'auto' , width : '100%' , padding : '20rpx'}">
  3. <view class="redact-address">
  4. <view class="redact-address-title">{{title}}</view>
  5. <uv-form label-width="210rpx" :model="addressDetail" ref="form">
  6. <uv-form-item label="联系人" prop="name">
  7. <uv-input v-model="addressDetail.name" placeholder="请输入联系人姓名" border="none">
  8. </uv-input>
  9. </uv-form-item>
  10. <uv-form-item label="手机号" prop="phone">
  11. <uv-input v-model="addressDetail.phone" placeholder="请输入手机号" border="none">
  12. </uv-input>
  13. </uv-form-item>
  14. <uv-form-item label="所在地区" prop="address"
  15. @click.stop="selectAddr">
  16. <uv-input v-model="addressDetail.address" placeholder="请选择所在地区" border="none">
  17. </uv-input>
  18. <template #right>
  19. <view style="padding-right: 40rpx;color: #FBAB32;">
  20. <image src="../../static/address/selectIcon.png" mode="aspectFit"></image>定位
  21. </view>
  22. </template>
  23. </uv-form-item>
  24. <uv-form-item label="详细地址" prop="addressDetail">
  25. <uv-input v-model="addressDetail.addressDetail" placeholder="请输入详细地址" border="none">
  26. </uv-input>
  27. </uv-form-item>
  28. </uv-form>
  29. <view @click="onSubmit" class="save">{{ addressDetail.id ? '修改地址' : '新增地址'}}</view>
  30. </view>
  31. </uv-popup>
  32. </template>
  33. <script>
  34. import Position from '@/utils/position.js'
  35. export default {
  36. data() {
  37. return {
  38. addressDetail: {}
  39. }
  40. },
  41. props: {
  42. title: {
  43. type: String,
  44. default: '新增地址'
  45. }
  46. },
  47. methods: {
  48. open(addressDetail) {
  49. this.addressDetail = addressDetail
  50. this.$refs.addressPopup.open('bottom')
  51. },
  52. close(){
  53. this.$refs.addressPopup.close()
  54. },
  55. //新增和修改地址
  56. onSubmit() {
  57. let isOk = this.parameterVerification(this.addressDetail)
  58. if (isOk && !isOk.auth) {
  59. return uni.showToast({
  60. icon: 'none',
  61. title: isOk.title,
  62. 'zIndex': 10000
  63. })
  64. }
  65. this.$emit('saveOrUpdate', this.addressDetail)
  66. },
  67. //验证用户参数合法性
  68. parameterVerification(addressDetaila) {
  69. let {
  70. name,
  71. phone,
  72. address,
  73. addressDetail
  74. } = addressDetaila
  75. if (name.trim() == '') {
  76. return {
  77. title: '请填写联系人',
  78. auth: false
  79. }
  80. } else if (phone.trim() == '') {
  81. return {
  82. title: '请填写手机号',
  83. auth: false
  84. }
  85. } else if (address.trim() == '') {
  86. return {
  87. title: '请填写所在地区',
  88. auth: false
  89. }
  90. } else if (addressDetail.trim() == '') {
  91. return {
  92. title: '请填写详细地址',
  93. auth: false
  94. }
  95. } else if (phone.trim() != '') {
  96. if (!this.$utils.verificationPhone(phone)) {
  97. return {
  98. title: '手机号格式不合法',
  99. auth: false
  100. }
  101. }
  102. }
  103. return {
  104. title: '验证通过',
  105. auth: true
  106. }
  107. },
  108. //地图上选择地址
  109. selectAddr() {
  110. Position.getLocation(res => {
  111. Position.selectAddress(res.longitude, res.latitude, success => {
  112. this.setAddress(success)
  113. })
  114. })
  115. },
  116. //提取用户选择的地址信息复制给表单数据
  117. setAddress(res) {
  118. //经纬度信息
  119. this.addressDetail.latitude = res.latitude
  120. this.addressDetail.longitude = res.longitude
  121. if (!res.address && res.name) { //用户直接选择城市的逻辑
  122. return this.addressDetail.address = res.name
  123. }
  124. if (res.address || res.name) {
  125. return this.addressDetail.address = res.address + res.name
  126. }
  127. this.addressDetail.address = '' //用户啥都没选就点击勾选
  128. },
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .redact-address {
  134. box-sizing: border-box;
  135. .redact-address-title {
  136. height: 80rpx;
  137. line-height: 80rpx;
  138. font-size: 30rpx;
  139. color: #333333;
  140. font-weight: 600;
  141. }
  142. .save {
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. width: 90%;
  147. height: 80rpx;
  148. border-radius: 40rpx;
  149. color: white;
  150. font-size: 28rpx;
  151. margin: 0rpx auto;
  152. background: $uni-color;
  153. margin-top: 150rpx;
  154. }
  155. image {
  156. width: 25rpx;
  157. height: 25rpx;
  158. }
  159. //修改组件默认样式
  160. .uv-form {
  161. padding: 30rpx 0rpx;
  162. }
  163. &::v-deep .uv-cell {
  164. padding: 0rpx 0rpx;
  165. font-size: 26rpx;
  166. &::after {
  167. border: none !important;
  168. }
  169. .uv-field__label {
  170. display: flex;
  171. align-items: center;
  172. height: 80rpx;
  173. }
  174. .uv-field__control,
  175. .uv-field__right-icon {
  176. height: 80rpx;
  177. font-size: 26rpx;
  178. border-bottom: 2rpx solid #cbc8c8;
  179. }
  180. .uv-field__right-icon {
  181. display: flex;
  182. align-items: center;
  183. height: 78rpx;
  184. color: #5FCC9F;
  185. }
  186. .uv-cell__value {
  187. height: 120rpx;
  188. }
  189. }
  190. &::v-deep .uv-field__error-message {
  191. color: #5AC796;
  192. font-size: 20rpx;
  193. margin-top: 10rpx;
  194. }
  195. }
  196. </style>