铝交易,微信公众号
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.

222 lines
5.3 KiB

9 months ago
8 months ago
9 months ago
8 months ago
9 months ago
8 months ago
9 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. <uv-input v-model="addressDetail.address" placeholder="请选择所在地区" border="none">
  16. </uv-input>
  17. <template #right>
  18. <view style="padding-right: 40rpx;color: #FBAB32;" @click.stop="selectAddr">
  19. <image src="../../static/address/selectIcon.png" mode="aspectFit"></image>
  20. 定位
  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.addressDetail.addressDetail = this.addressDetail.address + this.addressDetail.addressDetail
  66. this.$emit('saveOrUpdate', this.addressDetail)
  67. },
  68. //验证用户参数合法性
  69. parameterVerification(addressDetaila) {
  70. let {
  71. name,
  72. phone,
  73. address,
  74. addressDetail
  75. } = addressDetaila
  76. if (name.trim() == '') {
  77. return {
  78. title: '请填写联系人',
  79. auth: false
  80. }
  81. } else if (phone.trim() == '') {
  82. return {
  83. title: '请填写手机号',
  84. auth: false
  85. }
  86. } else if (address.trim() == '') {
  87. return {
  88. title: '请填写所在地区',
  89. auth: false
  90. }
  91. } else if (addressDetail.trim() == '') {
  92. return {
  93. title: '请填写详细地址',
  94. auth: false
  95. }
  96. } else if (phone.trim() != '') {
  97. if (!this.$utils.verificationPhone(phone)) {
  98. return {
  99. title: '手机号格式不合法',
  100. auth: false
  101. }
  102. }
  103. }
  104. return {
  105. title: '验证通过',
  106. auth: true
  107. }
  108. },
  109. //地图上选择地址
  110. selectAddr() {
  111. Position.getLocation(res => {
  112. Position.selectAddress(res.longitude, res.latitude, success => {
  113. this.setAddress(success)
  114. })
  115. })
  116. },
  117. //提取用户选择的地址信息复制给表单数据
  118. setAddress(res) {
  119. //经纬度信息
  120. this.addressDetail.latitude = res.latitude
  121. this.addressDetail.longitude = res.longitude
  122. if (!res.address && res.name) { //用户直接选择城市的逻辑
  123. return this.addressDetail.address = res.name
  124. }
  125. if (res.address || res.name) {
  126. return this.addressDetail.address = res.address + res.name
  127. }
  128. this.addressDetail.address = '' //用户啥都没选就点击勾选
  129. },
  130. }
  131. }
  132. </script>
  133. <style lang="scss" scoped>
  134. .redact-address {
  135. box-sizing: border-box;
  136. .redact-address-title {
  137. height: 80rpx;
  138. line-height: 80rpx;
  139. font-size: 30rpx;
  140. color: #333333;
  141. font-weight: 600;
  142. }
  143. .save {
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. width: 90%;
  148. height: 80rpx;
  149. border-radius: 40rpx;
  150. color: white;
  151. font-size: 28rpx;
  152. margin: 0rpx auto;
  153. background: $uni-color;
  154. margin-top: 150rpx;
  155. }
  156. image {
  157. width: 25rpx;
  158. height: 25rpx;
  159. }
  160. //修改组件默认样式
  161. .uv-form {
  162. padding: 30rpx 0rpx;
  163. }
  164. &::v-deep .uv-cell {
  165. padding: 0rpx 0rpx;
  166. font-size: 26rpx;
  167. &::after {
  168. border: none !important;
  169. }
  170. .uv-field__label {
  171. display: flex;
  172. align-items: center;
  173. height: 80rpx;
  174. }
  175. .uv-field__control,
  176. .uv-field__right-icon {
  177. height: 80rpx;
  178. font-size: 26rpx;
  179. border-bottom: 2rpx solid #cbc8c8;
  180. }
  181. .uv-field__right-icon {
  182. display: flex;
  183. align-items: center;
  184. height: 78rpx;
  185. color: #5FCC9F;
  186. }
  187. .uv-cell__value {
  188. height: 120rpx;
  189. }
  190. }
  191. &::v-deep .uv-field__error-message {
  192. color: #5AC796;
  193. font-size: 20rpx;
  194. margin-top: 10rpx;
  195. }
  196. }
  197. </style>