<template>
  <el-table v-loading="loading" :data="tableData" :stripe="true" class="m-t-20px">
    <el-table-column label="用户名" align="center" prop="name" />
    <el-table-column label="联系电话" align="center" prop="phone" />
    <el-table-column label="邮箱" align="center" prop="email" />
    <!-- <el-table-column label="性别" align="center" prop="sex">
      <template #default="scope">
        <dict-tag v-if="scope.row.sex !== '0'" :type="DICT_TYPE.MENDUNER_SEX" :value="scope.row.sex" />
        <span v-else></span>
      </template>
    </el-table-column> -->
    <el-table-column label="用户类型" align="center" prop="userType">
      <template #default="scope">
        {{ scope.row.userType === '1' ? '管理员': '普通用户' }}
      </template>
    </el-table-column>
    <el-table-column label="最后登录IP" align="center" prop="loginIp" />
    <el-table-column
      label="最后登录时间"
      align="center"
      prop="loginDate"
      :formatter="dateFormatter"
      width="180px"
    />
    <el-table-column
      label="创建时间"
      align="center"
      prop="createTime"
      :formatter="dateFormatter"
      width="180px"
    />
  </el-table>

  <Pagination
    :total="total"
    v-model:page="queryParams.pageNo"
    v-model:limit="queryParams.pageSize"
    @pagination="getList"
  />
</template>

<script setup>
defineOptions({ name: 'EnterpriseUserList'})
import { EnterpriseApi } from '@/api/menduner/system/enterprise/message'
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'

const props = defineProps({
  id: String
})

const loading = ref(false)
const tableData = ref([])
const total = ref(0)
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  enterpriseId: props.id
})

const getList = async () => {
  loading.value = true
  try {
    const data = await EnterpriseApi.getEnterpriseUserPage(queryParams)
    tableData.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
getList()
</script>
