addressSelection.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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>
  26. <div class="mx-1">
  27. <v-btn color="primary" variant="text" @click="onSelectAddress">{{ state.addressInfo?.name ? '切换' : '去添加'}}</v-btn>
  28. </div>
  29. </div>
  30. </v-card>
  31. <CtDialog :visible="selectAddress" titleClass="text-h6" :footer="true" :widthType="1" title="选择收货地址" @submit="handleSubmit" @close="selectAddress = false">
  32. <div style="min-height: 60vh;">
  33. <addressPage ref="addressPageRef" showSelect></addressPage>
  34. </div>
  35. </CtDialog>
  36. </div>
  37. </template>
  38. <script setup>
  39. import { computed, ref } from 'vue';
  40. import { isEmpty1 } from '@/utils/is'
  41. import addressPage from '@/views/recruit/personal/PersonalCenter/shippingAddress/index.vue'
  42. import Snackbar from '@/plugins/snackbar'
  43. const props = defineProps({
  44. modelValue: {
  45. type: Object,
  46. default() {},
  47. },
  48. });
  49. const emits = defineEmits(['update:modelValue']);
  50. // computed 解决父子组件双向数据同步
  51. const state = computed({
  52. get() {
  53. return new Proxy(props.modelValue, {
  54. set(obj, name, val) {
  55. emits('update:modelValue', {
  56. ...obj,
  57. [name]: val,
  58. });
  59. return true;
  60. },
  61. });
  62. },
  63. set(val) {
  64. emits('update:modelValue', val);
  65. },
  66. });
  67. const selectAddress = ref(false)
  68. // 选择地址
  69. function onSelectAddress() {
  70. selectAddress.value = true
  71. }
  72. const addressPageRef = ref()
  73. const handleSubmit = () => {
  74. const selected = addressPageRef.value?.getSelected() || []
  75. if (!selected) return Snackbar.warning('请选择收货地址')
  76. changeConsignee(selected)
  77. selectAddress.value = false
  78. }
  79. // 更改收货人地址&计算订单信息
  80. async function changeConsignee(addressInfo = {}) {
  81. if (!isEmpty1(addressInfo)) {
  82. if (state.value.deliveryType === 1) {
  83. state.value.addressInfo = addressInfo;
  84. }
  85. if (state.value.deliveryType === 2) {
  86. state.value.pickUpInfo = addressInfo;
  87. }
  88. }
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .allAddress .font-color {
  93. color: #e93323 !important;
  94. }
  95. .address .addressCon .name {
  96. font-size: 16px;
  97. color: #282828;
  98. font-weight: bold;
  99. // margin-bottom: 10px;
  100. }
  101. </style>