<script setup>
|
import {onMounted, reactive, ref} from "vue";
|
import {VXETable} from "vxe-table";
|
import {ElMessage} from "element-plus";
|
import request from "@/utils/request"
|
import CreateBasicData from "@/views/sd/basicData/CreateBasicData.vue"
|
import {useRouter,useRoute} from "vue-router"
|
import {useI18n} from "vue-i18n"
|
const { t } = useI18n()
|
|
let dialogTableVisible = ref(false)
|
const router = useRouter()
|
const xGrid = ref()
|
const gridOptions = reactive({
|
border: "full",//表格加边框
|
keepSource: true,//保持源数据
|
align: 'center',//文字居中
|
stripe:true,//斑马纹
|
rowConfig: {isCurrent: true, isHover: true,height: 30},//鼠标移动或选择高亮
|
id: 'OrderList',
|
printConfig: {},
|
importConfig: {},
|
exportConfig: {},
|
scrollY:{ enabled: true },//开启虚拟滚动
|
showOverflow:true,
|
columnConfig: {
|
resizable: true,
|
useKey: true
|
},
|
filterConfig: { //筛选配置项
|
remote: true
|
},
|
customConfig: {
|
storage: true
|
},
|
editConfig: {
|
trigger: 'click',
|
mode: 'row',
|
showStatus: true
|
},
|
|
//表头参数
|
columns:[
|
{title: t('basicData.operate'), width: 110, slots: { default: 'button_slot' },fixed:"left",},
|
{type: 'seq', title: '序号', width: 80 ,fixed:"left",},
|
{field:'level',title: '类别等级'},
|
{field:'typeName',title: '名称'},
|
{field:'createTime',title: '创建日期'}
|
],
|
|
//表头按钮
|
toolbarConfig: {
|
buttons: [
|
{'code': 'add', 'name': '新增',status: 'primary'},
|
],
|
|
// import: false,
|
// export: true,
|
// print: true,
|
zoom: true,
|
custom: true
|
},
|
})
|
const rowIndex = ref(null)
|
const glassType = reactive([
|
{
|
value:1,
|
label:'一级类别'
|
},
|
{
|
value: 2,
|
label: '二级类别',
|
children: []
|
}
|
])
|
const submit = ref({
|
glassLevel:[null,null],
|
value:null,
|
type:null,
|
id:null
|
})
|
|
onMounted(()=>{
|
request.get(`/basicGlassType/findAll`).then(res => {
|
xGrid.value.reloadData(res.data)
|
console.log(res.data)
|
})
|
|
request.get(`/basicGlassType/getOneLevelListMap`).then(res => {
|
glassType[1].children = res.data
|
})
|
})
|
|
const gridEvents = {
|
toolbarButtonClick ({ code }) {
|
const $grid = xGrid.value
|
if ($grid) {
|
switch (code) {
|
case 'add': {
|
dialogTableVisible.value = true
|
break
|
}
|
}
|
}
|
}
|
}
|
|
const getTableRow = (row,type) => {
|
switch (type) {
|
case 'edit': {
|
rowIndex.value = row
|
submit.value.glassLevel = row.belong===''?[parseInt(row.level)]:[parseInt(row.level),row.belong]
|
submit.value.value = row.typeName
|
submit.value.id = row.id
|
dialogTableVisible.value = true
|
break
|
}
|
case 'delete': {
|
request.get(`/basicGlassType/deleteById/${row.id}`).then((res) => {
|
if(res.code==='200' && res.data===true){
|
ElMessage.success(t('searchOrder.msgDeleteSuccess'))
|
router.push({
|
path:'/main/orderBasicData/searchGlassType',
|
query:{random:Math.random()
|
}
|
})
|
}else{
|
ElMessage.warning(t('searchOrder.msgDeleteFail'))
|
}
|
})
|
break
|
}
|
|
}
|
}
|
|
|
const saveBasicData = (type) =>{
|
submit.value.type = type
|
request.post(`/basicGlassType/add`, submit.value).then(res => {
|
if (res.code==='200') {
|
ElMessage.success('保存成功')
|
router.push({
|
path:'/main/orderBasicData/searchGlassType',
|
query:{random:Math.random()
|
}
|
})
|
}
|
})
|
}
|
|
|
</script>
|
|
<template>
|
<div>
|
<vxe-grid
|
style="width: 40vw;"
|
class="mytable-scrollbar"
|
max-height="500px"
|
ref="xGrid"
|
v-bind="gridOptions"
|
v-on="gridEvents"
|
>
|
<template #button_slot="{ row }">
|
<el-button @click="getTableRow(row,'edit')" link type="primary" size="small">{{ $t('basicData.edit') }}</el-button>
|
<el-popconfirm @confirm="getTableRow(row,'delete')" :title="$t('searchOrder.deleteConfirm')">
|
<template #reference>
|
<el-button link type="primary" size="small">{{ $t('basicData.delete') }}</el-button>
|
</template>
|
</el-popconfirm>
|
</template>
|
</vxe-grid>
|
<el-dialog
|
v-model="dialogTableVisible"
|
destroy-on-close
|
style="width: 30%;height:30% ">
|
<el-row>
|
<el-cascader
|
v-model="submit.glassLevel"
|
:options="glassType"
|
clearable
|
placeholder=""
|
:disabled="rowIndex"
|
/>
|
</el-row>
|
<el-row>
|
<el-input v-model="submit.value"/>
|
</el-row>
|
<el-row>
|
<el-button v-if="!rowIndex" @click="saveBasicData('add')" type="primary">新增</el-button>
|
<el-button v-else @click="saveBasicData('update')" type="primary">修改</el-button>
|
</el-row>
|
</el-dialog>
|
|
</div>
|
|
</template>
|
|
<style scoped>
|
.el-row{
|
margin-top: 10px;
|
}
|
</style>
|