You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
350 lines
8.5 KiB
350 lines
8.5 KiB
<script setup lang="tsx">
|
|
import { reactive, ref, unref } from 'vue'
|
|
import {
|
|
getRepSetRuleListApi,
|
|
saveRepSetRuleApi,
|
|
delRepSetRuleListApi,
|
|
delRepSetRuleApi,
|
|
queryRepSetRuleApi,
|
|
importExcelApiUrl,
|
|
exportExcelApi
|
|
} from '@/api/dataset/RepSetRule'
|
|
import { TableData } from '@/api/dataset/RepSetRule/types'
|
|
import { useTable } from '@/hooks/web/useTable'
|
|
import { useI18n } from '@/hooks/web/useI18n'
|
|
import { Table, TableColumn } from '@/components/Table'
|
|
import { ElButton, ElLink, ElLoading, ElPopconfirm, ElMessage,ElDropdown,ElDropdownMenu,ElDropdownItem } from 'element-plus'
|
|
import { Search } from '@/components/Search'
|
|
import { FormSchema } from '@/components/Form'
|
|
import { ContentWrap } from '@/components/ContentWrap'
|
|
import Write from './components/Write.vue'
|
|
import { Dialog } from '@/components/Dialog'
|
|
import { getWidth } from '@/utils';
|
|
import { Upload } from '@/components/Upload'
|
|
import { RULE_TYPE_LIST,RULE_CYCLE_LIST,RULE_IS_VALID_LIST } from '@/views/IndexProcess/constants'
|
|
|
|
const { t } = useI18n()
|
|
|
|
const ids = ref<string[]>([])
|
|
|
|
const { tableRegister, tableState, tableMethods } = useTable({
|
|
fetchDataApi: async () => {
|
|
const { currentPage, pageSize } = tableState
|
|
const res = await getRepSetRuleListApi({
|
|
pageNum: unref(currentPage),
|
|
pageSize: unref(pageSize),
|
|
...unref(searchParams)
|
|
})
|
|
return {
|
|
list: res.body.list,
|
|
total: res.body.total
|
|
}
|
|
},
|
|
fetchDelApi: async () => {
|
|
const res = await delRepSetRuleListApi(unref(ids));
|
|
return !!res;
|
|
},
|
|
})
|
|
|
|
const { loading, dataList, total, currentPage, pageSize } = tableState
|
|
const { getList, getElTableExpose, delList, refresh } = tableMethods
|
|
|
|
const tableColumns = reactive<TableColumn[]>([
|
|
{
|
|
field: 'selection',
|
|
type: 'selection',
|
|
fixed: true
|
|
},
|
|
{
|
|
field: 'ruleCode',
|
|
label: '规则编码'
|
|
},
|
|
{
|
|
field: 'ruleName',
|
|
label: '规则名称',
|
|
align: "left",
|
|
},
|
|
{
|
|
field: 'itemId',
|
|
label: '指标代码'
|
|
},
|
|
{
|
|
field: 'itemName',
|
|
label: '指标名称'
|
|
},
|
|
{
|
|
field: 'ruleClass',
|
|
label: '规则分类',
|
|
slots:{
|
|
default:(data:any)=>{
|
|
return RULE_TYPE_LIST.find(item=>item.name==data.row.ruleClass)?.label;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'ruleCycle',
|
|
label: '规则周期',
|
|
slots:{
|
|
default:(data:any)=>{
|
|
return RULE_CYCLE_LIST.find(item=>item.value==data.row.ruleCycle)?.label;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'ruleStatus',
|
|
label: '是否有效',
|
|
slots:{
|
|
default:(data:any)=>{
|
|
return RULE_IS_VALID_LIST.find(item=>item.value==data.row.ruleStatus)?.label;
|
|
}
|
|
}
|
|
},
|
|
{
|
|
field: 'description',
|
|
label: '规则描述'
|
|
},
|
|
{
|
|
field: 'createDate',
|
|
label: '创建日期'
|
|
},
|
|
{
|
|
field: 'createAccount',
|
|
label: '创建账户',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'createOrgan',
|
|
label: '创建机构',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'ruleJson',
|
|
label: '规则json',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'ruleSql',
|
|
label: '规则sql',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'organCode',
|
|
label: '机构编码',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'startDate',
|
|
label: '启用日期'
|
|
},
|
|
{
|
|
field: 'failDate',
|
|
label: '失效日期'
|
|
},
|
|
{
|
|
field: 'indexCode',
|
|
label: '指标集编码',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'machFormulas',
|
|
label: '公式',
|
|
hidden:true
|
|
},
|
|
{
|
|
field: 'action',
|
|
label: t('tableDemo.action'),
|
|
width: 120,
|
|
fixed: 'right',
|
|
slots: {
|
|
default: (data: any) => {
|
|
return (
|
|
<>
|
|
<ElLink type="primary" underline={false} onClick={() => AddAction(data.row.ruleClass,'edit',data.row)}>
|
|
{t('tableDemo.edit')}
|
|
</ElLink>
|
|
<ElPopconfirm
|
|
title={t('common.delTableMsg')}
|
|
width={200}
|
|
v-slots={{
|
|
reference: () => {
|
|
return (
|
|
<>
|
|
<ElLink type="primary" underline={false}>
|
|
{t('tableDemo.del')}
|
|
</ElLink>
|
|
</>
|
|
)
|
|
}
|
|
}}
|
|
onConfirm={() => delData(data.row)}
|
|
></ElPopconfirm>
|
|
{/* <ElLink type="primary" underline={false} onClick={() => action(data.row, 'detail')}>
|
|
{t('tableDemo.detail')}
|
|
</ElLink> */}
|
|
</>
|
|
)
|
|
}
|
|
}
|
|
}
|
|
].map(item => ({ minWidth: item.label ? getWidth(item.label) : 120, ...item }) as TableColumn))
|
|
|
|
const searchSchema = reactive<FormSchema[]>([
|
|
{
|
|
field: 'ruleCode',
|
|
label: '规则编码',
|
|
componentProps: {},
|
|
component: 'Input'
|
|
},
|
|
{
|
|
field: 'ruleName',
|
|
label: '规则名称',
|
|
componentProps: {},
|
|
component: 'Input'
|
|
},
|
|
{
|
|
field: 'itemId',
|
|
label: '指标代码',
|
|
componentProps: {},
|
|
component: 'Input'
|
|
},
|
|
{
|
|
field: 'itemName',
|
|
label: '指标名称',
|
|
componentProps: {},
|
|
component: 'Input'
|
|
}
|
|
])
|
|
|
|
const searchParams = ref({})
|
|
const setSearchParams = (data: any) => {
|
|
searchParams.value = data
|
|
getList()
|
|
}
|
|
|
|
const dialogVisible = ref(false)
|
|
const dialogTitle = ref('')
|
|
|
|
let currentRow = ref()
|
|
let actionType = ref('')
|
|
|
|
const writeRef = ref<ComponentRef<typeof Write>>()
|
|
|
|
let RuleType = ref('');
|
|
const AddAction = (ruleType: string,actiontype: string,currentrow) => {
|
|
console.log(currentrow,"currentRow信息");
|
|
RuleType.value = ruleType;
|
|
dialogTitle.value = actiontype=='add'?`新增规则`:`编辑规则`;
|
|
currentRow.value = currentrow;
|
|
dialogVisible.value = true;
|
|
actionType.value = actiontype;
|
|
}
|
|
const saveLoading = ref(false)
|
|
|
|
/** 保存 **/
|
|
const save = async () => {
|
|
const write = unref(writeRef)
|
|
const formData = await write?.submit()
|
|
if (formData) {
|
|
saveLoading.value = true
|
|
const res = await saveRepSetRuleApi(formData)
|
|
.catch(() => {})
|
|
.finally(() => {
|
|
saveLoading.value = false
|
|
})
|
|
if (res) {
|
|
dialogVisible.value = false
|
|
currentPage.value = 1
|
|
getList()
|
|
}
|
|
}
|
|
}
|
|
|
|
const delLoading = ref(false)
|
|
|
|
/** 批量删除 **/
|
|
const delDataBatch = async () => {
|
|
const elTableExpose = await getElTableExpose()
|
|
ids.value = elTableExpose?.getSelectionRows().map((v: TableData) => { v.ruleCode }) || []
|
|
delLoading.value = true
|
|
await delList(unref(ids).length).finally(() => {
|
|
delLoading.value = false
|
|
})
|
|
}
|
|
|
|
/** 单行删除 */
|
|
const delData = async (row: TableData) => {
|
|
const res = await delRepSetRuleApi(row.ruleCode)
|
|
if (res) {
|
|
const { code, errMsg } = res.head
|
|
if (code === '0') {
|
|
ElMessage.success('删除成功!')
|
|
getList()
|
|
} else {
|
|
ElMessage.error(errMsg || '删除失败!')
|
|
}
|
|
}
|
|
}
|
|
|
|
const disabled = ref(true)
|
|
|
|
const onSelectionChange = (selection: TableData[]) => {
|
|
disabled.value = selection.length === 0
|
|
}
|
|
|
|
/** 导出Excel */
|
|
const exportExcel = async () => {
|
|
const data = { ...unref(searchParams),fileName:'指标加工.xls' }
|
|
await exportExcelApi(data)
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<ContentWrap>
|
|
<Search :schema="searchSchema" @reset="setSearchParams" @search="setSearchParams" />
|
|
|
|
<Table
|
|
headerAlign="center"
|
|
align="center"
|
|
:columns="tableColumns"
|
|
v-model:pageSize="pageSize"
|
|
v-model:currentPage="currentPage"
|
|
default-expand-all
|
|
node-key="ruleCode"
|
|
:data="dataList"
|
|
:loading="loading"
|
|
:pagination="{
|
|
total
|
|
}"
|
|
@selection-change="onSelectionChange"
|
|
@register="tableRegister"
|
|
@refresh="refresh"
|
|
>
|
|
<template #buttons>
|
|
<!-- <ElDropdown placement="bottom">
|
|
<ElButton type="primary">添加规则</ElButton>
|
|
<template #dropdown>
|
|
<ElDropdownMenu>
|
|
<ElDropdownItem v-for="item in RULE_TYPE_LIST" :key="item.name" @click="AddAction(item.name,'add',{})">{{ item.label }}</ElDropdownItem>
|
|
</ElDropdownMenu>
|
|
</template>
|
|
</ElDropdown> -->
|
|
|
|
<Upload :url="importExcelApiUrl" :callback="getList"> <ElButton type="primary">导入</ElButton> </Upload>
|
|
<ElButton type="primary" @click="exportExcel()">导出</ElButton>
|
|
<ElButton :loading="delLoading" type="primary" :disabled="disabled" @click="delDataBatch()">
|
|
{{ t('tableDemo.del') }}
|
|
</ElButton>
|
|
</template>
|
|
</Table>
|
|
</ContentWrap>
|
|
<!-- :ISFullScreen="true" -->
|
|
<Dialog v-model="dialogVisible" :title="dialogTitle" style="overflow: hidden;min-width:800px;">
|
|
<Write
|
|
ref="writeRef"
|
|
:current-row="currentRow"
|
|
:action-type="actionType"
|
|
:rule-type="RuleType"
|
|
@close-dialog="dialogVisible=false;getList();"
|
|
/>
|
|
</Dialog>
|
|
</template> |