<template>
  <el-card>
    <el-row :gutter="20" class="header">
      <el-col :span="7">
        <el-input placeholder="请输入用户昵称..." clearable v-model="queryForm.username"></el-input>
      </el-col>
      <el-button type="button" :icon="Search" @click="initRatingList" >搜索</el-button>
      <el-button type="primary" :icon="DocumentAdd" @click="handleAddDialogValue()" >添加评论</el-button>
    </el-row>
    <el-table :data="tableData" stripe style="width: 100%;" showOverflowTooltip>
      <el-table-column fixed prop="id" label="#ID" width="80" />
      <el-table-column  prop="businessId" label="商家id" width="80" />
      <el-table-column  prop="userId" label="用户id" width="80" />
      <el-table-column  prop="manicuristId" label="美甲师id" width="80" />
      <el-table-column  prop="orderId" label="订单id" width="80" />
      <el-table-column  prop="rating" label="评分" width="80" />
      <el-table-column  prop="review" label="评论" width="200" />
      <el-table-column  prop="businessReview" label="商家评论" width="200" />
      <el-table-column prop="createTime" label="注册日期" width="200"/>

      <el-table-column prop="action" fixed="right" label="操作" min-width="170">
<!--        <template v-slot="scope" >-->
<!--          <el-button  type="success" size="small" @click="handleDialogValue(scope.row.id)">-->
<!--            详情-->
<!--          </el-button>-->
<!--          <el-button  type="primary" size="small" :icon="Edit" @click="handleUpdateDialogValue(scope.row.id)"></el-button>-->
<!--          <el-button  type="danger" size="small"  :icon="Delete" @click="handleDelete(scope.row.id)"></el-button>-->
<!--        </template>-->
      </el-table-column>
    </el-table>
    <el-pagination
        v-model:currentPage="queryForm.current"
        v-model:page-size="queryForm.pageSize"
        :page-sizes="[10, 20, 30, 40,50]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />
<!--    {{total}}-->
  </el-card>


  <Dialog v-model="UdialogVisible" :id="id" :dialogTitle="dialogTitle"
          @initUserList="initUserList"></Dialog>
  <AddDialog v-model="UdialogaddVisible"  :dialogTitle="dialogTitle"
          @initUserList="initUserList"></AddDialog>
  <UpdateDialog v-model="UdialogUpdateVisible" :id="id" :dialogTitle="dialogTitle"
             @initUserList="initUserList"></UpdateDialog>

</template>
<script setup>
import {Search,Delete,Edit,DocumentAdd,Close,Check} from '@element-plus/icons-vue'
import {ref, watch} from 'vue'
import axios from "@/util/axios";
import Dialog from '@/views/user/dialog/index.vue'
import AddDialog from '@/views/user/addDialog/index.vue'
import UpdateDialog from '@/views/user/updateDialog/index.vue'
import { ElMessage,ElMessageBox } from "element-plus";
import {parseTime} from "element-plus/es/components/time-select/src/utils";


const queryForm=ref({
  username: '',
  current:1,
  pageSize:10
})

// const id=ref('')
// const dialogTitle=ref('');
// const UdialogaddVisible=ref(false)
// const UdialogVisible=ref(false)
// const UdialogUpdateVisible=ref(false)




// const handleDialogValue=(ids)=>{
//   id.value=ids;
//   dialogTitle.value="用户详情"
//   UdialogVisible.value=true
// }
//
//   const handleUpdateDialogValue=(ids)=>{
//     id.value=ids;
//     dialogTitle.value="用户修改"
//     UdialogUpdateVisible.value=true
//   }
//
// const handleAddDialogValue=()=>{
//   dialogTitle.value="用户添加"
//   UdialogaddVisible.value=true
// }




//删除

const handleDelete=(ids)=>{
 // console.log(id)
  ElMessageBox.confirm(
      '您确定要删除这条记录吗？',
      '系统提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
  )
      .then(async() => {
        let res=await axios.post('level/delete',{id:ids})
        if(res.data.code==0){
          ElMessage({
            type: 'success',
            message: '删除成功',
          })
          initSmallTypeList();
        }else{
          ElMessage({
            type: 'error',
            message: res.data.description,
          })
        }
      })
      .catch(() => {
      })
  // initUserList();
}



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

const initRatingList=async()=>{

  const res = await axios.post("level/list");
     console.log(res.data.data)
  if (res.data.data) {
    tableData.value = res.data.data;
    //console.log(res.data.data)
    total.value = Number(res.data.data.length);
  }
  else{
    ElMessage.error(res.data.description);
  }
}
initRatingList();
const handleSizeChange = (pageSize) => {
  queryForm.value.current=1;
  queryForm.value.pageSize=pageSize;
  initRatingList();
}
const handleCurrentChange = (current1) => {
  queryForm.value.current=current1;
  initRatingList();
}
</script>
<style lang="scss" scoped>
.header{
  padding-bottom: 16px;
  box-sizing: border-box;

}
.el-pagination{
  padding-top: 15px;
  box-sizing: border-box;
}
</style>