<template>
  <div class="address-list">
    <div class="table">
      <el-table
        ref="orderTable"
        v-loading="listLoading"
        :data="dataList"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row stripe
      >
        <el-table-column align="center" label="收货人" prop="name"></el-table-column>
        <el-table-column align="center" label="手机号" prop="phone"></el-table-column>
        <el-table-column align="center" label="地址信息" prop="address" min-width="200"></el-table-column>
        <el-table-column align="center" label="是否默认地址" prop="defaultAddr">
          <template slot-scope="{ row }">
            {{ row.defaultAddr ? '是' : '否' }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination clearfix">
      <div class="fr">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listTotal">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {getMemberAddressList} from "@/api/member";

export default {
  name: 'MemberAddress',
  componentName: 'MemberAddress',
  props: ['user'],
  data() {
    return {
      dataList: [], // 数据列表
      listLoading: true, // 列表加载loading
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0 // 列表总数
    }
  },
  created() {
    this.getAddressList()
  },
  methods: {
    getAddressList() {
      let params = {
        userId: this.user.userId,
        pageNum: this.currentPage,
        pageSize: this.pageSize
      }

      getMemberAddressList(params).then(res => {
        this.dataList = res.data.records
        this.listTotal = res.data.total
        this.listLoading = false
      })
    },
    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getList()
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getList()
    },
  }
}
</script>

<style scoped>

</style>
