index.vue 4.19 KB
<template>
  <!-- 搜索栏 -->
  <ContentWrap>
    <el-form :model="queryParams" ref="queryFormRef" :inline="true" label-width="68px">
      <el-form-item label="昵称" prop="nickname">
        <el-input
          v-model="queryParams.nickname"
          placeholder="请输入昵称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表栏 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="编号" align="center" prop="id" width="80" />
      <el-table-column label="头像" align="center" prop="avatar" width="80">
        <template #default="scope">
          <el-avatar :src="scope.row.avatar" size="small" />
        </template>
      </el-table-column>
      <el-table-column label="昵称" align="center" prop="nickname" />
      <el-table-column label="真实姓名" align="center" prop="realname" />
      <el-table-column label="手机号" align="center" prop="phone" width="120" />
      <el-table-column label="性别" align="center" prop="sexStr" width="100">
        <template #default="scope">
          <el-tag :type="scope.row.sex === 1 ? 'primary' : 'danger'">
            {{ scope.row.sexStr || (scope.row.sex === 1 ? '男' : '女') }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template #default="scope">
          <el-tag :type="scope.row.status === 1 ? 'success' : 'info'">
            {{ scope.row.statusStr || (scope.row.status === 1 ? '正常' : '禁用') }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="openForm(scope.row.id)"
          >
            编辑
          </el-button>
          <el-button
            link
            type="primary"
            @click="openHealthData(scope.row.id)"
          >
            健康资料
          </el-button>
        </template>
      </el-table-column>
    </el-table>

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

  <!-- 表单弹窗:修改用户 -->
  <StudentForm ref="formRef" @success="getList" />

  <!-- 抽屉:学员健康资料 -->
  <StudentHealthData ref="healthDataRef" />
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import * as StudentApi from '@/api/store/student'
import StudentForm from './StudentForm.vue'
import StudentHealthData from './StudentHealthData.vue'

const loading = ref(true)
const total = ref(0)
const list = ref([])
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  phone: undefined,
  nickname: undefined
})
const queryFormRef = ref()
const formRef = ref()
const healthDataRef = ref()

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await StudentApi.getStudentPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields()
  handleQuery()
}

/** 打开修改弹窗 */
const openForm = (id) => {
  formRef.value.open(id)
}

/** 打开健康资料抽屉 */
const openHealthData = (userId) => {
  healthDataRef.value.open(userId)
}

/** 初始化 */
onMounted(() => {
  getList()
})
</script>