addressSelection.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!-- 下单界面,收货地址 or 自提门店的选择组件 -->
  2. <template>
  3. <div>
  4. <v-card class="allAddress" elevation="1" >
  5. <div class="d-flex justify-space-between align-center">
  6. <div
  7. class="address py-4 px-5"
  8. v-if="state.deliveryType === 1"
  9. >
  10. <div class="addressCon" v-if="state.addressInfo.name">
  11. <div class="name d-flex"
  12. >{{ state.addressInfo.name }}
  13. <div class="phone ml-3">{{ state.addressInfo.mobile }}</div>
  14. </div>
  15. <div class="d-flex mt-1">
  16. <div class="default font-color mr-3" v-if="state.addressInfo.defaultStatus">[默认]</div>
  17. <div class="line2">
  18. {{ state.addressInfo.areaName }} {{ state.addressInfo.detailAddress }}
  19. </div>
  20. </div>
  21. </div>
  22. <div class="addressCon" v-else>
  23. <div class="setaddress">设置收货地址</div>
  24. </div>
  25. <div class="iconfont">
  26. <div class="ss-rest-button">
  27. <div class="_icon-forward" />
  28. </div>
  29. </div>
  30. </div>
  31. <div class="mx-1">
  32. <v-btn color="primary" variant="text" @click="onSelectAddress">切换</v-btn>
  33. </div>
  34. </div>
  35. </v-card>
  36. <CtDialog :visible="selectAddress" titleClass="text-h6" :footer="true" :widthType="1" title="修改收货地址" @submit="handleSubmit" @close="selectAddress = false">
  37. <div style="min-height: 60vh;">
  38. <addressPage ref="addressPageRef" showSelect single returnObject></addressPage>
  39. </div>
  40. </CtDialog>
  41. </div>
  42. </template>
  43. <script setup>
  44. import { computed, ref } from 'vue';
  45. import { isEmpty1 } from '@/utils/is'
  46. import addressPage from '@/views/mall/user/address'
  47. import Snackbar from '@/plugins/snackbar'
  48. const props = defineProps({
  49. modelValue: {
  50. type: Object,
  51. default() {},
  52. },
  53. });
  54. const emits = defineEmits(['update:modelValue']);
  55. // computed 解决父子组件双向数据同步
  56. const state = computed({
  57. get() {
  58. return new Proxy(props.modelValue, {
  59. set(obj, name, val) {
  60. emits('update:modelValue', {
  61. ...obj,
  62. [name]: val,
  63. });
  64. return true;
  65. },
  66. });
  67. },
  68. set(val) {
  69. emits('update:modelValue', val);
  70. },
  71. });
  72. const selectAddress = ref(false)
  73. // 选择地址
  74. function onSelectAddress() {
  75. selectAddress.value = true
  76. }
  77. const addressPageRef = ref()
  78. const handleSubmit = () => {
  79. const selected = addressPageRef.value?.getSelected() || []
  80. if (!selected?.length) return Snackbar.warning('请选择收货地址')
  81. changeConsignee(selected[0])
  82. selectAddress.value = false
  83. }
  84. // 更改收货人地址&计算订单信息
  85. async function changeConsignee(addressInfo = {}) {
  86. if (!isEmpty1(addressInfo)) {
  87. if (state.value.deliveryType === 1) {
  88. state.value.addressInfo = addressInfo;
  89. }
  90. if (state.value.deliveryType === 2) {
  91. state.value.pickUpInfo = addressInfo;
  92. }
  93. }
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. .allAddress .font-color {
  98. color: #e93323 !important;
  99. }
  100. .address .addressCon .name {
  101. font-size: 16px;
  102. color: #282828;
  103. font-weight: bold;
  104. // margin-bottom: 10px;
  105. }
  106. </style>