<template>
  <div class="main-container">
    <el-card class="box-card !border-none" shadow="never">
      <div class="flex justify-between items-center">
        <span class="text-lg">{{ pageName }}</span>
      </div>

      <el-card
        class="box-card !border-none my-[10px] table-search-wrap"
        shadow="never"
      >
        <el-form
          :inline="true"
          :model="studentCourseUsageTable.searchParam"
          ref="searchFormRef"
        >
          <el-form-item label="家长姓名" prop="name">
            <el-input
              v-model="studentCourseUsageTable.searchParam.name"
              placeholder="请输入家长姓名"
            />
          </el-form-item>
		  
		  
		  <el-form-item label="评分" prop="score">
		    <el-input
		      v-model="studentCourseUsageTable.searchParam.score"
		      placeholder="请输入评分"
		    />
		  </el-form-item>
		  

          <el-form-item>
            <el-button type="primary" @click="loadServiceLogsList()">{{
              t('search')
            }}</el-button>
            <el-button @click="resetForm(searchFormRef)">{{
              t('reset')
            }}</el-button>
          </el-form-item>
        </el-form>
      </el-card>

      <div class="mt-[10px]">
        <el-table
          :data="studentCourseUsageTable.data"
          size="large"
          v-loading="studentCourseUsageTable.loading"
        >
          <template #empty>
            <span>{{
              !studentCourseUsageTable.loading ? t('emptyData') : ''
            }}</span>
          </template>
		  
          <el-table-column prop="name" label="家长姓名" min-width="120" :show-overflow-tooltip="true"/>
		  
		  <el-table-column prop="staff_name" label="教练姓名" min-width="120" :show-overflow-tooltip="true"/>
		  
		  <el-table-column prop="service_name" label="服务内容" min-width="120" :show-overflow-tooltip="true"/>
		  
		  
		  <el-table-column prop="customer_confirmation" label="是否需要反馈" min-width="120" :show-overflow-tooltip="true">
		  	<template #default="{ row }">
				<div v-if="row.customer_confirmation == 1">是</div>
				<div v-if="row.customer_confirmation == 0">否</div>
		  	</template>
		  </el-table-column>
		  
		  
		  <el-table-column prop="score" label="反馈分数" min-width="120" :show-overflow-tooltip="true"/>
		  
		  
		  
        </el-table>
        <div class="mt-[16px] flex justify-end">
          <el-pagination
            v-model:current-page="studentCourseUsageTable.page"
            v-model:page-size="studentCourseUsageTable.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="studentCourseUsageTable.total"
            @size-change="loadServiceLogsList()"
            @current-change="loadServiceLogsList"
          />
        </div>
      </div>

    </el-card>
  </div>
</template>

<script lang="ts" setup>
import { reactive, ref, watch } from 'vue'
import { t } from '@/lang'
import { useDictionary } from '@/app/api/dict'
import {
  getServiceLogsList,
} from '@/app/api/service_logs'

import { img } from '@/utils/common'
import { ElMessageBox, FormInstance } from 'element-plus'
import { useRoute } from 'vue-router'
const route = useRoute()
const pageName = route.meta.title

let studentCourseUsageTable = reactive({
  page: 1,
  limit: 10,
  total: 0,
  loading: true,
  data: [],
  searchParam: {
    name: '',
    score: '',
  },
})

const searchFormRef = ref<FormInstance>()

// 选中数据
const selectData = ref<any[]>([])

// 字典数据

/**
 * 获取学员课时消费记录列表
 */
const loadServiceLogsList = (page: number = 1) => {
  studentCourseUsageTable.loading = true
  studentCourseUsageTable.page = page

  getServiceLogsList({
    page: studentCourseUsageTable.page,
    limit: studentCourseUsageTable.limit,
    ...studentCourseUsageTable.searchParam,
  })
    .then((res) => {
      studentCourseUsageTable.loading = false
      studentCourseUsageTable.data = res.data.data
      studentCourseUsageTable.total = res.data.total
    })
    .catch(() => {
      studentCourseUsageTable.loading = false
    })
}
loadServiceLogsList()


const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>

<style lang="scss" scoped>
/* 多行超出隐藏 */
.multi-hidden {
  word-break: break-all;
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>
