建材商城系统20241014
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.

226 lines
4.7 KiB

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