<template>
  <div>
    <el-form :model="searchForm" inline label-width="0">
      <el-form-item>
        <el-input v-model="searchForm.name" placeholder="教员名称" />
      </el-form-item>
      <el-form-item>
        <el-select v-model="searchForm.auditType" clearable filterable placeholder="审核状态">
          <el-option label="待审核" :value="1" />
          <el-option label="已通过" :value="2" />
          <el-option label="未通过" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery"> 搜索 </el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableList" border stripe>
      <el-table-column type="index" width="50" />
      <el-table-column prop="name" label="教员姓名" />
      <el-table-column prop="phone" label="联系方式" />
      <el-table-column prop="remark" label="备注" />
      <el-table-column prop="createTime" label="申请时间" />
      <el-table-column prop="auditRemark" label="审核状态" />
      <el-table-column prop="auditUser" label="审核人" />
      <el-table-column prop="auditTime" label="审核时间" />
      <!-- 操作 -->
      <el-table-column label="操作" fixed="right" width="150">
        <template #default="{ row }">
          <el-button
            v-if="row.auditType == 1"
            type="primary"
            link
            v-hasPermi="['JoinUs:Station:audit']"
            @click="handleDetail(row, 'audit')"
          >
            审核
          </el-button>
          <el-button
            v-else
            type="primary"
            link
            v-hasPermi="['JoinUs:Station:audit']"
            @click="handleDetail(row, 'detail')"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="searchForm.pageNo"
      v-model:limit="searchForm.pageSize"
      @pagination="getList"
    />

    <Dialog v-model="dialogVisible" title="教员详情" style="width: 600px">
      <el-form
        :model="form"
        ref="formRef"
        :rules="rules"
        label-width="80px"
        :disabled="form.auditType != 1"
      >
        <el-form-item label="教员姓名" prop="applyUser">
          <el-input v-model="form.applyUser" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="备注" prop="xcwa">
          <el-input
            v-model="form.name"
            type="textarea"
            :autosize="{ minRows: 2 }"
            placeholder="请输入"
          />
        </el-form-item>
        <div v-if="dialogType == 'audit'">
          <el-divider direction="horizontal" content-position="left">审核信息</el-divider>
          <el-form-item label="审核结果" prop="shjg">
            <el-radio-group v-model="form.shjg">
              <el-radio :label="2" :value="2">通过</el-radio>
              <el-radio :label="3" :value="3">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核说明" prop="shsm">
            <el-input
              v-model="form.shsm"
              type="textarea"
              :autosize="{ minRows: 2 }"
              placeholder="请输入"
            />
          </el-form-item>
        </div>
      </el-form>
      <template #footer>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </template>
    </Dialog>
  </div>
</template>

<script setup name="Coach">
const searchForm = ref({
  name: '',
  auditType: 1,
  pageNo: 1,
  pageSize: 20
})

const tableList = ref([])
const total = ref(0)

const form = ref({})
const rules = {
  name: { required: true, message: '请输入名称', trigger: 'blur' },
  phone: { required: true, message: '请输入手机号', trigger: 'blur' }
}
const dialogVisible = ref(false)
const dialogType = ref('audit')

onMounted(() => {
  handleQuery()
})

function handleQuery() {
  searchForm.value.pageNo = 1
  getList()
}

function getList() {
  //   getStationList(searchForm.value).then((res) => {
  //     console.log(res)
  //   })
  tableList.value = [
    {
      id: 1,
      name: '教员1',
      createTime: '2021-01-01',
      phone: '18888888888',
      auditType: 2,
      auditTime: '2021-02-01',
      auditUser: 'admin',
      auditRemark: '审核通过'
    },
    {
      id: 2,
      name: '教员2',
      auditType: 1,
      phone: '19999999999'
    }
  ]
  total.value = 2
}

function handleDetail(row, type) {
  console.log(type)
  dialogVisible.value = true
  form.value = { ...row }
}

function submitForm() {
  dialogVisible.value = false
}
</script>

<style lang="scss" scoped></style>
