address.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <view class="container">
  4. <view class="flex align-center" style="padding: 20upx 30upx;">
  5. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;">收货人:</view>
  6. <u-input v-model="address.consignee" placeholder="收货人姓名" :clearable="false" />
  7. </view>
  8. <view class="flex align-center" style="padding: 20upx 30upx;">
  9. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;">联系方式:</view>
  10. <u-input v-model="address.phone" placeholder="收货人手机号" :clearable="false" />
  11. </view>
  12. <view class="flex align-center" style="padding: 20upx 30upx;" >
  13. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;">所在地区:</view>
  14. <view @click="regionShow=true" class="flex align-center" :class="address.area ? '': 'eg'" style="height: 70upx;">
  15. <text v-if="address.area">{{address.area}}</text>
  16. <text v-else>{{region}}</text>
  17. </view>
  18. <city-select v-model="regionShow" @city-change="getRegion"></city-select>
  19. </view>
  20. <view class="flex align-center" style="padding: 20upx 30upx;">
  21. <view style="width: 160upx;font-family: PingFang SC;font-weight: bold;color: #000000;">详细地址:</view>
  22. <u-input v-model="address.detail" placeholder="具体到门牌号" :clearable="false" />
  23. </view>
  24. </view>
  25. <view class="margin">
  26. <u-button @click="confirm" class="custom-style" shape="circle">确定</u-button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import citySelect from '@/components/basic/u-city-select.vue';
  32. export default {
  33. components: {
  34. citySelect
  35. },
  36. data() {
  37. return {
  38. region:"例:广东省广州市天河区",
  39. regionShow:false,
  40. address:{
  41. userId:"",
  42. consignee:"",
  43. phone:"",
  44. area:"",
  45. detail:""
  46. }
  47. }
  48. },
  49. onLoad(options) {
  50. this.address.userId=options.userId || '-1'
  51. this.getAddress()
  52. },
  53. methods: {
  54. async getAddress(){
  55. let res=await this.$u.api.user.userAddress({userId:this.address.userId})
  56. if (!this.$u.test.isEmpty(res.records)) {
  57. this.address=res.records[0]
  58. }
  59. },
  60. getRegion(data) {
  61. this.address.area = data.province.label + '-' + data.city.label + '-' + data.area.label
  62. },
  63. confirm(){
  64. if (this.$u.test.isEmpty(this.address.userId)) {
  65. this.$u.toast("系统错误,用户为登录")
  66. return
  67. }
  68. if (this.$u.test.isEmpty(this.address.phone)) {
  69. this.$u.toast("请输入收货人手机号")
  70. return
  71. }
  72. if (this.$u.test.isEmpty(this.address.consignee)) {
  73. this.$u.toast("请输入收货人姓名")
  74. return
  75. }
  76. if (this.$u.test.isEmpty(this.address.area)) {
  77. this.$u.toast("请输入所在地区")
  78. return
  79. }
  80. if (this.$u.test.isEmpty(this.address.detail)) {
  81. this.$u.toast("请输入详细地址")
  82. return
  83. }
  84. this.$u.api.user.userAddressSubmit(this.address).then(res=>{
  85. this.address.id=res
  86. uni.navigateBack({
  87. delta:1
  88. })
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. .container {
  96. background-color: #ffffff;
  97. margin: 20upx;
  98. border-radius: 16upx;
  99. }
  100. .eg {
  101. color: #c0c4d6;
  102. }
  103. .custom-style {
  104. background-color: #5b3ee7;
  105. color: #ffffff;
  106. }
  107. </style>