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.
 
 
 
 

144 lines
3.8 KiB

<template>
<Dialog :title="dialogTitle" v-model="searchDialogVisible" :width="'80%'">
<ContentWrap>
<Table
ref="searchTableRef"
:columns="tableColumns"
:data="tableObjectRef.tableList"
:loading="tableObjectRef.loading"
:selection="true"
:reserveSelection="true"
row-key="number"
>
<template #qty="{ row }">
<el-input v-model="row.qty" type="number" placeholder="请输入数量" />
</template>
</Table>
</ContentWrap>
<template #footer>
<div class="flex items-center">
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="searchDialogVisible = false"> </el-button>
</div>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as defaultButtons from '@/utils/disposition/defaultButtons'
// const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const route = useRoute() // 路由信息
const routeName = ref()
routeName.value = route.name
const searchDialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
/** 打开弹窗 */
const getListRef = ref()
const setSearchParamsRef = ref()
const tableObjectRef = ref({
tableList: '',
loading: false,
params: {}
})
const getPage: any = ref()
const searchSchema = ref()
const tableColumns = ref()
const formFieldRef = ref()
const searchFieldRef = ref()
const typeRef = ref()
const rowRef = ref()
const allSchemasRef = ref()
const multipleBol = ref(false)
const searchConditionRef = ref()
const open = (
titleName: any,
allSchemas: any,
getApiPage: any,
formField: any,
searchField: any,
multiple: any,
type: any,
row: any,
searchCondition: any,
isCountRequestRe: any
) => {
searchDialogVisible.value = true
formFieldRef.value = formField
searchFieldRef.value = searchField
allSchemasRef.value = allSchemas
searchSchema.value = allSchemas.searchSchema
tableColumns.value = allSchemas.tableColumns.filter((item) => item.field !== 'action')
getPage.value = getApiPage
typeRef.value = type
rowRef.value = row
multipleBol.value = multiple
dialogTitle.value = titleName
const getList = async () => {
await getPage.value(searchCondition).then((res) => {
tableObjectRef.value.tableList = res
})
}
console.log(tableObjectRef.value)
getList()
}
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
// Table 组件 ref
const searchTableRef = ref()
/** 提交表单 */
const emit = defineEmits(['searchTableSuccess']) // 定义 searchTableSuccess 事件,用于操作成功后的回调
const submitForm = async () => {
// 提交请求
formLoading.value = true
const selections = searchTableRef.value.selections
// 如果不是多选的
if (!multipleBol.value) {
if (selections.length > 1 || selections.length == 0) {
message.warning('请选择一条数据!')
formLoading.value = false
return
}
// 多选
} else {
if (selections.length == 0) {
message.warning('至少选择一条数据!')
formLoading.value = false
return
}
}
let isQtyNone = selections.filter((item) => !item.qty)
if (isQtyNone && isQtyNone.length > 0) {
message.warning('请填写数量')
formLoading.value = false
return
}
try {
searchDialogVisible.value = false
console.log(selections)
// 发送操作成功的事件
emit(
'searchTableSuccess',
formFieldRef.value,
searchFieldRef.value,
selections,
typeRef.value,
rowRef.value
)
} finally {
formLoading.value = false
}
}
</script>
<style scoped lang="scss">
</style>