| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- <template>
- <view>
- <view class="address">
- <view
- class="address_item"
- :class="addressList.length ? '' : 'flex'"
- @click="addressClick"
- >
- <template v-if="addressList.length">
- <view class="_item">
- <view class="_item_top">
- <view class="_top_left">
- <view class="name"
- >{{ selectItem.firstName }} {{
- selectItem.lastName
- }}</view
- >
- <view class="phone">{{ selectItem.phoneNo }}</view>
- <view class="code">{{ selectItem.zipCode }}</view>
- </view>
- <i class="icon-font icon-left"></i>
- </view>
- <view class="_item_middle">
- {{ selectItem.country }} {{ selectItem.province }},{{
- selectItem.city
- }},{{ selectItem.address }}
- </view>
- <view class="_item_bottom">
- <view class="default_btn" v-if="selectItem.default == 1">
- <trans _t="默认" />
- </view>
- <view class="label_btn" v-if="selectItem.label">{{
- selectItem.label
- }}</view>
- </view>
- </view>
- </template>
- <template v-else>
- <view class="address_empty">
- <trans _t="请选择地址" />
- <up-icon name="arrow-right"></up-icon>
- </view>
- </template>
- </view>
- </view>
- <popup title="请选择地址" isClose ref="popRef">
- <template #content>
- <view class="pop_cont">
- <view
- class="cont_list"
- v-for="(item, index) in addressList"
- :key="index"
- @click="listClick(item)"
- >
- <view class="_list_item">
- <view class="_item_top">
- <view class="_top_left">
- <view class="name"
- >{{ item.firstName }} {{ item.lastName }}</view
- >
- <view class="phone">{{ item.phoneNo }}</view>
- </view>
- </view>
- <view class="_item_middle">
- {{ item.country }} {{ item.province }},{{ item.city }},{{
- item.address
- }}
- </view>
- <view class="_item_bottom">
- <view class="default_btn" v-if="item.default == 1">
- <trans _t="默认" />
- </view>
- <view class="label_btn" v-if="item.label">{{
- item.label
- }}</view>
- </view>
- </view>
- <view @click.stop="editAddress(item)">
- <i class="icon-font icon-edit"></i>
- </view>
- </view>
- </view>
- </template>
- <template #footer>
- <view class="footer_btn" @click="addressOpen">
- <trans _t="添加送货地址" />
- </view>
- </template>
- </popup>
- <Address ref="addressRef" />
- </view>
- </template>
- <script setup>
- import { computed, ref, reactive, nextTick } from "vue";
- import Popup from "@/components/popup.vue";
- import { t } from "@/locale";
- import { useShopStore } from "@/store";
- import Address from "@/components/address";
- import { onShow } from "@dcloudio/uni-app";
- const emit = defineEmits(["confirm", "open", "close"]);
- const popRef = ref(null);
- const addressRef = ref(null);
- const useShop = useShopStore();
- const ids = ref([]);
- const addressList = computed(() => {
- const list = useShop.getAddressList;
- const items = list.length && (list.find((item) => item.default == 1) || {});
- let obj = list.length && (JSON.stringify(items) === "{}" ? list[0] : items);
- ids.value = [obj.id || ""];
- return list;
- });
- const selectItem = computed(() => {
- let item = {};
- if (addressList.value.length) {
- item = addressList.value.find((item) => item.id == ids.value[0]) || {};
- getCheck(item);
- return item;
- }
- return item;
- });
- const getCheck = (item) => {
- emit("confirm", item || selectItem.value);
- };
- const form = reactive({
- id: "",
- express_name: "",
- express_no: "",
- });
- const open = () => {
- emit("open");
- popRef.value && popRef.value.open();
- };
- const close = () => {
- emit("close");
- popRef.value && popRef.value.close();
- };
- const addressClick = () => {
- popRef.value && popRef.value.open();
- };
- const listClick = (item) => {
- ids.value = [item.id];
- nextTick(() => {
- getCheck();
- popRef.value && popRef.value.close();
- });
- };
- const editAddress = (item) => {
- popRef.value && popRef.value.close();
- addressRef.value && addressRef.value.open(item);
- };
- const addressOpen = () => {
- popRef.value && popRef.value.close();
- addressRef.value && addressRef.value.open();
- };
- onShow(() => {
- nextTick(() => {
- useShop.setAddressList();
- });
- });
- defineExpose({ open, close });
- </script>
- <style lang="less" scoped>
- @import url("@/style.less");
- .address {
- margin-top: 24rpx;
- background: url("@/static/address_bg.png") no-repeat 50%;
- background-size: cover;
- padding: 2px;
- border-radius: 16rpx;
- &_item {
- padding: 24rpx 20rpx;
- background-color: var(--light);
- border-radius: 16rpx;
- min-height: 160rpx;
- .address_empty {
- height: inherit;
- flex: 1;
- .flex_position(space-between);
- color: var(--text-01);
- line-height: 60rpx;
- .size(28rpx);
- .icon-left {
- .size(36rpx);
- transform: rotate(180deg);
- }
- }
- ._item {
- overflow: hidden;
- &_top {
- .flex_position(space-between);
- padding-right: 30rpx;
- line-height: 60rpx;
- ._top_left {
- .ver();
- .name {
- .size(36rpx);
- font-weight: 700;
- color: var(--text);
- }
- .phone,
- .code {
- color: var(--text-01);
- margin-left: 30rpx;
- .size(28rpx);
- font-weight: 700;
- }
- }
- .icon-left {
- color: var(--text-01);
- transform: rotate(180deg);
- .size();
- }
- }
- &_middle {
- text-wrap: wrap;
- white-space: pre-wrap;
- word-wrap: break-word;
- .size(28rpx);
- color: var(--text-01);
- margin-top: 8rpx;
- line-height: 48rpx;
- margin-bottom: 12rpx;
- }
- &_bottom {
- .flex();
- flex-wrap: wrap;
- gap: 24rpx;
- .default_btn,
- .label_btn {
- padding: 8rpx 16rpx;
- .size(24rpx);
- border-radius: 8rpx;
- }
- .default_btn {
- color: var(--danger);
- background-color: #e62e2e1a;
- }
- .label_btn {
- background-color: #ff66331a;
- color: var(--primary);
- }
- }
- }
- }
- }
- .pop_cont {
- .cont_list {
- .ver();
- ._list_item {
- flex: 1;
- margin-left: 12rpx;
- ._item_top {
- line-height: 48rpx;
- ._top_left {
- .ver();
- color: var(--text);
- .name,
- .phone {
- .size(28rpx);
- font-weight: 700;
- }
- .phone {
- margin-left: 16rpx;
- }
- }
- }
- ._item_middle {
- color: var(--text-02);
- .size(24rpx);
- line-height: 40rpx;
- text-wrap: wrap;
- white-space: pre-wrap;
- word-wrap: break-word;
- margin-bottom: 12rpx;
- word-break: break-all;
- }
- ._item_bottom {
- .flex();
- flex-wrap: wrap;
- gap: 24rpx;
- .default_btn,
- .label_btn {
- padding: 8rpx 16rpx;
- .size(24rpx);
- border-radius: 8rpx;
- }
- .default_btn {
- color: var(--danger);
- background-color: #e62e2e1a;
- }
- .label_btn {
- background-color: #ff66331a;
- color: var(--primary);
- }
- }
- }
- .icon-edit {
- .size(36rpx);
- color: var(--primary);
- }
- }
- }
- .footer_btn {
- height: 38px;
- padding: 16rpx 30rpx;
- background-color: var(--black);
- color: var(--light);
- .flex_center();
- border-radius: 16rpx;
- .size(24rpx);
- }
- </style>
|