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() { data() {
return { return {
currentDateTime: '', // 开业日期
loading: false, // 加载动画 loading: false, // 加载动画
tableHeight: document.documentElement.clientHeight - 235, // 表的高度 tableHeight: document.documentElement.clientHeight - 235, // 表的高度
list: [], list: [],
@ -130,7 +131,8 @@ export default {
isRequested: false, isRequested: false,
rowIndex: 0, // 行索引 rowIndex: 0, // 行索引
// 忽略勾选数据change 避免触发chang事件 // 忽略勾选数据change 避免触发chang事件
ignoreSelectedChange: false ignoreSelectedChange: false,
selectedOptions: []
} }
}, },
@ -212,13 +214,28 @@ export default {
if (this.selectedData) { if (this.selectedData) {
this.setSelections(this.selectedData) this.setSelections(this.selectedData)
} }
this.setDefaultDateTime()
}, },
methods: { 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() { getList() {
// 保存当前勾选状态
const savedSelection = this.saveSelectionState()
this.loading = true this.loading = true
var crmIndexRequest = this.getIndexRequest() var crmIndexRequest = this.getIndexRequest()
var params = { var params = {
@ -243,6 +260,105 @@ export default {
if (this.filterObj && this.filterObj.length > 0) { if (this.filterObj && this.filterObj.length > 0) {
params.searchList = this.filterObj 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传入参数 // 筛选props传入参数
// 用于相关查询 包含Id的参数 需替换为下划线 通过类似高级筛选形式 实现 // 用于相关查询 包含Id的参数 需替换为下划线 通过类似高级筛选形式 实现
@ -303,6 +419,9 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
document.querySelector('.el-table__body-wrapper').scrollTop = 1 document.querySelector('.el-table__body-wrapper').scrollTop = 1
}) })
if (!this.config.isSelect) {
this.restoreSelectionState(savedSelection)
}
}) })
.catch(() => { .catch(() => {
this.loading = false this.loading = false
@ -754,26 +873,114 @@ export default {
if (this.ignoreSelectedChange) { if (this.ignoreSelectedChange) {
return return
} }
// 单选操作
// 优化单选逻辑
if (this.config.radio && val.length > 1) { if (this.config.radio && val.length > 1) {
const mainTable = this.getMainTable() const mainTable = this.getMainTable()
const lastObj = val[val.length - 1]
// 改用ID比较而不是引用比较更加可靠
const newSelected = val[val.length - 1] // 获取最新选择的项
this.ignoreSelectedChange = true this.ignoreSelectedChange = true
mainTable.clearSelection() mainTable.clearSelection()
this.$nextTick(() => { this.$nextTick(() => {
this.ignoreSelectedChange = false 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 return
} else {
this.selectionList = val
} }
this.selectionList = val
this.$emit('selection-change', val, this.crmType) this.$emit('selection-change', val, this.crmType)
if (this.config.selectionHandle) { if (this.config.selectionHandle && this.$refs.crmTableHead) {
this.$refs.crmTableHead.headSelectionChange(val) 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值 * 设置selections值
*/ */
setSelections(data) { setSelections(data) {
if (!data || !Array.isArray(data) || data.length === 0) {
return
}
const mainTable = this.getMainTable() const mainTable = this.getMainTable()
if (!mainTable) {
return
}
this.ignoreSelectedChange = true
mainTable.clearSelection() mainTable.clearSelection()
// 存储找到的项
const selectedItems = []
this.$nextTick(() => { this.$nextTick(() => {
data.forEach(item => { data.forEach(item => {
// const idKey = `${this.crmType}Id` // 通过ID查找列表中对应的项进行勾选
// const listItem = this.list.find(lItem => lItem[idKey] === item[idKey]) const idKey = `${this.crmType}Id`
// if (listItem) { const listItem = this.list.find(lItem => lItem && item && lItem[idKey] === item[idKey])
// mainTable.toggleRowSelection(listItem) if (listItem) {
// } mainTable.toggleRowSelection(listItem, true)
mainTable.toggleRowSelection(item) 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" type="primary"
size="small" size="small"
style="margin-left: 2px;height: 40px" style="margin-left: 2px;height: 40px"
@click="queryGsdjxxByDate" @click="crmSearch"
> >
查询 查询
</el-button> </el-button>
@ -110,14 +110,6 @@
</el-row> </el-row>
</el-form> </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> </div>
<!-- 添加导入按钮 --> <!-- 添加导入按钮 -->
<el-button <el-button
@ -322,15 +314,13 @@ export default {
month: '', month: '',
xzqhDm: '', xzqhDm: '',
loadingGs: false, loadingGs: false,
currentDateTime: '', //
submitSuccess: false, // submitSuccess: false, //
submitError: false, // submitError: false, //
isSubmitting: false, // isSubmitting: false, //
autoCloseDelay: 3000, // 3 autoCloseDelay: 3000, // 3
successTimer: null, // successTimer: null, //
errorTimer: null, // errorTimer: null, //
xzqhOptions: [], xzqhOptions: []
selectedOptions: []
} }
}, },
computed: { computed: {
@ -397,61 +387,61 @@ export default {
clearTimeout(this.errorTimer) clearTimeout(this.errorTimer)
}, },
methods: { methods: {
/** // /**
* 根据时间查询工商登记开业信息(默认是今天) // * ()
*/ // */
queryGsdjxxByDate() { // queryGsdjxxByDate() {
this.isSubmitting = true // this.isSubmitting = true
this.submitSuccess = false // this.submitSuccess = false
this.submitError = false // this.submitError = false
//
// // //
clearTimeout(this.successTimer) // clearTimeout(this.successTimer)
clearTimeout(this.errorTimer) // clearTimeout(this.errorTimer)
//
const time = this.currentDateTime // const time = this.currentDateTime
let xzqhDm = '' // let xzqhDm = ''
if (this.selectedOptions) { // if (this.selectedOptions) {
xzqhDm = this.selectedOptions[this.selectedOptions.length - 1] // xzqhDm = this.selectedOptions[this.selectedOptions.length - 1]
} // }
let pa = { // let pa = {
rq: time, // rq: time,
xzqhDm: xzqhDm // xzqhDm: xzqhDm
} // }
queryGsdjxxByDate(pa) // queryGsdjxxByDate(pa)
.then(res => { // .then(res => {
console.log('查询成功:', res.data) // console.log('', res.data)
this.list = res.data.list // this.list = res.data.list
this.submitSuccess = true // this.submitSuccess = true
// autoCloseDelay // // autoCloseDelay
this.successTimer = setTimeout(() => { // this.successTimer = setTimeout(() => {
this.submitSuccess = false // this.submitSuccess = false
}, this.autoCloseDelay) // }, this.autoCloseDelay)
}) // })
.catch(error => { // .catch(error => {
console.error('查询失败:', error) // console.error('', error)
this.submitError = true // this.submitError = true
this.errorMessage = '查询失败,请重试' // this.errorMessage = ''
// autoCloseDelay // // autoCloseDelay
this.errorTimer = setTimeout(() => { // this.errorTimer = setTimeout(() => {
this.submitError = false // this.submitError = false
}, this.autoCloseDelay) // }, this.autoCloseDelay)
}) // })
.finally( // .finally(
this.isSubmitting = false // this.isSubmitting = false
) // )
}, // },
/** /**
* 获取当天时间 * 获取当天时间
*/ */
setDefaultDateTime() { // setDefaultDateTime() {
const now = new Date() // const now = new Date()
// YYYY-MM-DD HH:mm:ss // // YYYY-MM-DD HH:mm:ss
const year = now.getFullYear() // const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0') // const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0') // const day = String(now.getDate()).padStart(2, '0')
this.currentDateTime = `${year}-${month}-${day}` // this.currentDateTime = `${year}-${month}-${day}`
}, // },
loadXzqhOptions() { loadXzqhOptions() {
getXzqhList().then(res => { getXzqhList().then(res => {
this.xzqhOptions = res.data this.xzqhOptions = res.data
@ -480,7 +470,7 @@ export default {
}, },
// //
sysGsdjxx() { sysGsdjxx() {
if (!this.selectedOptions || this.month) { if (!this.selectedOptions || !this.month) {
this.$message.error('请选选择参数') this.$message.error('请选选择参数')
return return
} }