<template>
  <el-card>
    <el-row :gutter="20" class="header">
      <el-col :span="7">
        <el-input placeholder="后端暂无查询接口..." clearable v-model="queryForm"></el-input>
      </el-col>
      <el-button type="button" :icon="Search" @click="initRatingList" >搜索</el-button>
      <el-button type="primary" :icon="DocumentAdd" @click="handleDialogValue()" >添加 商品大类</el-button>
      <el-button v-if="params.product!==undefined" >商家名称：{{JSON.parse(params.product).businessName}}</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"  />
      <el-table-column  prop="groupName" label="商品分类名称"  />
      <el-table-column prop="isTopping" label="商品级别" />

      <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.groupName)"></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="CdialogVisible"  :dialogTitle="dialogTitle"
          @initRatingList="initRatingList"></Dialog>

</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 { ElMessage,ElMessageBox } from "element-plus";
import {parseTime} from "element-plus/es/components/time-select/src/utils";
import Dialog from '@/views/category/addDialog/index.vue'
import {useRoute} from "vue-router";

const queryForm=ref({
  current:1,
  pageSize:10
})
let params=useRoute().query

//删除

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(() => {
      })

}
const dialogTitle=ref()
const CdialogVisible=ref(false)

const handleDialogValue=()=>{
    dialogTitle.value="商品分类添加"
    // console.log(dialogTitle.value)
    CdialogVisible.value=true
}

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

const initRatingList=async()=>{

  const res = await axios.get("group/queryGroupVO");
   //  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>