fix:查询问题

This commit is contained in:
zhangwenzan 2025-09-19 08:44:57 +08:00
parent 24e79521a4
commit 14b6f2ba2e
2 changed files with 299 additions and 78 deletions

View File

@ -106,6 +106,7 @@ export default {
data() {
return {
currentDateTime: '', // 开业日期
loading: false, // 加载动画
tableHeight: document.documentElement.clientHeight - 235, // 表的高度
list: [],
@ -130,7 +131,8 @@ export default {
isRequested: false,
rowIndex: 0, // 行索引
// 忽略勾选数据change 避免触发chang事件
ignoreSelectedChange: false
ignoreSelectedChange: false,
selectedOptions: []
}
},
@ -212,13 +214,28 @@ export default {
if (this.selectedData) {
this.setSelections(this.selectedData)
}
this.setDefaultDateTime()
},
methods: {
/**
* 获取当天时间
*/
setDefaultDateTime() {
const now = new Date()
// 格式化为 YYYY-MM-DD HH:mm:ss
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0')
this.currentDateTime = `${year}-${month}-${day}`
},
/**
* 获取列表数据
*/
getList() {
// 保存当前勾选状态
const savedSelection = this.saveSelectionState()
this.loading = true
var crmIndexRequest = this.getIndexRequest()
var params = {
@ -243,6 +260,105 @@ export default {
if (this.filterObj && this.filterObj.length > 0) {
params.searchList = this.filterObj
}
if (params.poolId === 34557 && this.currentDateTime) {
if (!params.searchList) {
params.searchList = []
}
const time = {
type: 1,
values: [this.currentDateTime],
formType: 'text',
name: 'website'
}
let to = true
for (let i = 0; i < params.searchList; i++) {
if (params.searchList[i].name === 'website') {
params.searchList[i] = [time]
to = false
}
}
if (to) {
params.searchList.push(
time
)
}
}
if (params.poolId === 34557 && this.currentDateTime) {
if (!params.searchList) {
params.searchList = []
}
const time = {
type: 1,
values: [this.currentDateTime],
formType: 'text',
name: 'website'
}
let to = true
for (let i = 0; i < params.searchList; i++) {
if (params.searchList[i].name === 'website') {
params.searchList[i] = [time]
to = false
}
}
if (to) {
params.searchList.push(
time
)
}
}
if (params.poolId === 34557 && this.currentDateTime) {
if (!params.searchList) {
params.searchList = []
}
const time = {
type: 1,
values: [this.currentDateTime],
formType: 'text',
name: 'website'
}
let to = true
for (let i = 0; i < params.searchList; i++) {
if (params.searchList[i].name === 'website') {
params.searchList[i] = [time]
to = false
}
}
if (to) {
params.searchList.push(
time
)
}
}
if (params.poolId === 34557 && this.selectedOptions) {
if (!params.searchList) {
params.searchList = []
}
const xzqhDm = this.selectedOptions[this.selectedOptions.length - 1]
const remark = {
type: 1,
values: [xzqhDm],
formType: 'textarea',
name: 'remark'
}
let to = true
for (let i = 0; i < params.searchList; i++) {
if (params.searchList[i].name === 'website') {
params.searchList[i] = [remark]
to = false
}
}
if (to) {
params.searchList.push(
remark
)
}
}
if (params.poolId === 34557) {
params.search = ''
}
// 筛选props传入参数
// 用于相关查询 包含Id的参数 需替换为下划线 通过类似高级筛选形式 实现
@ -303,6 +419,9 @@ export default {
this.$nextTick(() => {
document.querySelector('.el-table__body-wrapper').scrollTop = 1
})
if (!this.config.isSelect) {
this.restoreSelectionState(savedSelection)
}
})
.catch(() => {
this.loading = false
@ -754,26 +873,114 @@ export default {
if (this.ignoreSelectedChange) {
return
}
// 单选操作
// 优化单选逻辑
if (this.config.radio && val.length > 1) {
const mainTable = this.getMainTable()
const lastObj = val[val.length - 1]
// 改用ID比较而不是引用比较更加可靠
const newSelected = val[val.length - 1] // 获取最新选择的项
this.ignoreSelectedChange = true
mainTable.clearSelection()
this.$nextTick(() => {
this.ignoreSelectedChange = false
mainTable.toggleRowSelection(lastObj)
if (newSelected) {
mainTable.toggleRowSelection(newSelected)
// 手动更新 selectionList 和通知 CRMTableHead
this.selectionList = [newSelected]
this.$emit('selection-change', [newSelected], this.crmType)
if (this.config.selectionHandle && this.$refs.crmTableHead) {
this.$refs.crmTableHead.headSelectionChange([newSelected])
}
}
})
return
} else {
this.selectionList = val
}
this.selectionList = val
this.$emit('selection-change', val, this.crmType)
if (this.config.selectionHandle) {
if (this.config.selectionHandle && this.$refs.crmTableHead) {
this.$refs.crmTableHead.headSelectionChange(val)
}
},
/**
* 获取表头全选状态
*/
getAllSelectionState() {
const mainTable = this.getMainTable()
if (!mainTable || !this.list || this.list.length === 0) {
return false
}
// 检查当前页是否全部选中
const selection = mainTable.selection || []
return selection.length === this.list.length
},
/**
* 设置表头全选状态
* @param {boolean} select 是否全选
*/
setAllSelection(select) {
const mainTable = this.getMainTable()
if (!mainTable || !this.list || this.list.length === 0) {
return
}
this.ignoreSelectedChange = true
if (select) {
// 全选
this.list.forEach(row => {
mainTable.toggleRowSelection(row, true)
})
// 更新 selectionList 为当前页所有数据
this.selectionList = [...this.list]
} else {
// 取消全选
mainTable.clearSelection()
this.selectionList = []
}
this.$nextTick(() => {
this.ignoreSelectedChange = false
// 通知 selection-change 和 CRMTableHead
this.$emit('selection-change', this.selectionList, this.crmType)
if (this.config.selectionHandle && this.$refs.crmTableHead) {
this.$refs.crmTableHead.headSelectionChange(this.selectionList)
}
})
},
/**
* 保存当前勾选状态
*/
saveSelectionState() {
// 只保存ID而不是整个对象避免引用问题
return this.selectionList.map(item => ({
[`${this.crmType}Id`]: item[`${this.crmType}Id`]
}))
},
/**
* 恢复勾选状态
*/
restoreSelectionState(savedState) {
if (!savedState || !Array.isArray(savedState) || savedState.length === 0) {
return
}
// 在下一个tick中执行确保表格数据已更新
this.$nextTick(() => {
this.setSelections(savedState)
})
},
/**
* 当拖动表头改变了列的宽度的时候会触发该事件
@ -891,17 +1098,41 @@ export default {
* 设置selections值
*/
setSelections(data) {
if (!data || !Array.isArray(data) || data.length === 0) {
return
}
const mainTable = this.getMainTable()
if (!mainTable) {
return
}
this.ignoreSelectedChange = true
mainTable.clearSelection()
// 存储找到的项
const selectedItems = []
this.$nextTick(() => {
data.forEach(item => {
// const idKey = `${this.crmType}Id`
// const listItem = this.list.find(lItem => lItem[idKey] === item[idKey])
// if (listItem) {
// mainTable.toggleRowSelection(listItem)
// }
mainTable.toggleRowSelection(item)
// 通过ID查找列表中对应的项进行勾选
const idKey = `${this.crmType}Id`
const listItem = this.list.find(lItem => lItem && item && lItem[idKey] === item[idKey])
if (listItem) {
mainTable.toggleRowSelection(listItem, true)
selectedItems.push(listItem)
}
})
// 更新 selectionList 并通知 CRMTableHead
this.selectionList = selectedItems
this.$emit('selection-change', selectedItems, this.crmType)
if (this.config.selectionHandle && this.$refs.crmTableHead) {
this.$refs.crmTableHead.headSelectionChange(selectedItems)
}
this.ignoreSelectedChange = false
})
},

View File

@ -102,7 +102,7 @@
type="primary"
size="small"
style="margin-left: 2px;height: 40px"
@click="queryGsdjxxByDate"
@click="crmSearch"
>
查询
</el-button>
@ -110,14 +110,6 @@
</el-row>
</el-form>
<!-- 添加查询按钮 -->
<!-- 操作反馈提示 -->
<div v-if="submitSuccess" class="success-message">
<el-alert :closable="false" title="查询成功!" type="success" show-icon/>
</div>
<div v-if="submitError" class="error-message">
<el-alert :title="errorMessage" :closable="false" type="error" show-icon/>
</div>
</div>
<!-- 添加导入按钮 -->
<el-button
@ -322,15 +314,13 @@ export default {
month: '',
xzqhDm: '',
loadingGs: false,
currentDateTime: '', //
submitSuccess: false, //
submitError: false, //
isSubmitting: false, //
autoCloseDelay: 3000, // 3
successTimer: null, //
errorTimer: null, //
xzqhOptions: [],
selectedOptions: []
xzqhOptions: []
}
},
computed: {
@ -397,61 +387,61 @@ export default {
clearTimeout(this.errorTimer)
},
methods: {
/**
* 根据时间查询工商登记开业信息(默认是今天)
*/
queryGsdjxxByDate() {
this.isSubmitting = true
this.submitSuccess = false
this.submitError = false
//
clearTimeout(this.successTimer)
clearTimeout(this.errorTimer)
const time = this.currentDateTime
let xzqhDm = ''
if (this.selectedOptions) {
xzqhDm = this.selectedOptions[this.selectedOptions.length - 1]
}
let pa = {
rq: time,
xzqhDm: xzqhDm
}
queryGsdjxxByDate(pa)
.then(res => {
console.log('查询成功:', res.data)
this.list = res.data.list
this.submitSuccess = true
// autoCloseDelay
this.successTimer = setTimeout(() => {
this.submitSuccess = false
}, this.autoCloseDelay)
})
.catch(error => {
console.error('查询失败:', error)
this.submitError = true
this.errorMessage = '查询失败,请重试'
// autoCloseDelay
this.errorTimer = setTimeout(() => {
this.submitError = false
}, this.autoCloseDelay)
})
.finally(
this.isSubmitting = false
)
},
// /**
// * ()
// */
// queryGsdjxxByDate() {
// this.isSubmitting = true
// this.submitSuccess = false
// this.submitError = false
//
// //
// clearTimeout(this.successTimer)
// clearTimeout(this.errorTimer)
//
// const time = this.currentDateTime
// let xzqhDm = ''
// if (this.selectedOptions) {
// xzqhDm = this.selectedOptions[this.selectedOptions.length - 1]
// }
// let pa = {
// rq: time,
// xzqhDm: xzqhDm
// }
// queryGsdjxxByDate(pa)
// .then(res => {
// console.log('', res.data)
// this.list = res.data.list
// this.submitSuccess = true
// // autoCloseDelay
// this.successTimer = setTimeout(() => {
// this.submitSuccess = false
// }, this.autoCloseDelay)
// })
// .catch(error => {
// console.error('', error)
// this.submitError = true
// this.errorMessage = ''
// // autoCloseDelay
// this.errorTimer = setTimeout(() => {
// this.submitError = false
// }, this.autoCloseDelay)
// })
// .finally(
// this.isSubmitting = false
// )
// },
/**
* 获取当天时间
*/
setDefaultDateTime() {
const now = new Date()
// YYYY-MM-DD HH:mm:ss
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0')
this.currentDateTime = `${year}-${month}-${day}`
},
// setDefaultDateTime() {
// const now = new Date()
// // YYYY-MM-DD HH:mm:ss
// const year = now.getFullYear()
// const month = String(now.getMonth() + 1).padStart(2, '0')
// const day = String(now.getDate()).padStart(2, '0')
// this.currentDateTime = `${year}-${month}-${day}`
// },
loadXzqhOptions() {
getXzqhList().then(res => {
this.xzqhOptions = res.data
@ -480,7 +470,7 @@ export default {
},
//
sysGsdjxx() {
if (!this.selectedOptions || this.month) {
if (!this.selectedOptions || !this.month) {
this.$message.error('请选选择参数')
return
}