From 14b6f2ba2e358f676a397aaffd3e1910393abca4 Mon Sep 17 00:00:00 2001 From: zhangwenzan Date: Fri, 19 Sep 2025 08:44:57 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=9F=A5=E8=AF=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/crm/mixins/Table.js | 257 ++++++++++++++++++++++++++++++++-- src/views/crm/seas/index.vue | 120 ++++++++-------- 2 files changed, 299 insertions(+), 78 deletions(-) diff --git a/src/views/crm/mixins/Table.js b/src/views/crm/mixins/Table.js index f65cb607..af5376c4 100644 --- a/src/views/crm/mixins/Table.js +++ b/src/views/crm/mixins/Table.js @@ -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 }) }, diff --git a/src/views/crm/seas/index.vue b/src/views/crm/seas/index.vue index c7640a1f..8612247b 100644 --- a/src/views/crm/seas/index.vue +++ b/src/views/crm/seas/index.vue @@ -102,7 +102,7 @@ type="primary" size="small" style="margin-left: 2px;height: 40px" - @click="queryGsdjxxByDate" + @click="crmSearch" > 查询 @@ -110,14 +110,6 @@ - - -
- -
-
- -
{ - 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 }