<!-- 会员中心-我的地址 -->
<template>
    <app-view>
        <app-table :data="dataList" v-model:columns="columns" :loading="loading">
            <template #header>
                <app-auth-operation :menus="['add']" @closed="getUserAddressList" />
            </template>
            <!-- 证件类型 -->
            <template #cardtypeid="{ value }">
                {{ getCertificateTypeName(value) }}
            </template>
            <!-- 收货地址 -->
            <template #address="{ row }">
                {{ [row.provincename, row.cityname, row.districtname, row.address].join(' ') }}
            </template>
            <!-- 是否默认 -->
            <template #isdefault="{ value }">
                {{ value ? '是' : '否' }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="['edit', 'default', 'delete']" :options="{ selectedRow: row }"
                    @closed="getUserAddressList" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="getUserAddressList" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { ElMessage } from 'element-plus'
import { useAddress } from '@/business/user'
import { getCertificateTypeName } from '@/constants/certificate'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'

const { loading, dataList, columns, total, pageIndex, pageSize, getUserAddressList } = useAddress()

getUserAddressList().catch((err) => ElMessage.error(err))
</script>