feat: 新增需求

This commit is contained in:
caijun
2026-01-19 17:34:15 +08:00
parent 8fa31df250
commit 9f5b2a92c4
67 changed files with 7518 additions and 481 deletions

View File

@@ -3,7 +3,7 @@
<view class="jnpf-tree-select-body">
<view class="jnpf-tree-select-title">
<text class="icon-ym icon-ym-report-icon-preview-pagePre backIcon" @tap="close()"></text>
<view class="title">组织选择</view>
<view class="title">选择申请人单位</view>
</view>
<view class="jnpf-tree-select-search">
<u-search :placeholder="$t('app.apply.pleaseKeyword')" v-model="keyword" height="72"
@@ -20,20 +20,20 @@
<view class="jnpf-tree-selected-box">
<scroll-view scroll-y="true" class="select-list">
<u-tag closeable @close="delSelect(index)" v-for="(item,index) in selectedList" :key="index"
:text="item.orgNameTree" class="u-selectTag" />
:text="item.deptName" class="u-selectTag" />
</scroll-view>
</view>
</view>
<view class="jnpf-tree-selected-line"></view>
<view class="jnpf-tree-selected-tabs">
<view class="tab-item" :class="{'tab-item-active':activeKey==='1'}" @click="toggloActive('1')">组织构架
</view>
<!-- <view class="jnpf-tree-selected-tabs">
<view class="tab-item" :class="{'tab-item-active':activeKey==='1'}" @click="toggloActive('1')">组织构架</view>
<view class="tab-item" :class="{'tab-item-active':activeKey==='2'}" @click="toggloActive('2')"
v-if="selectType === 'all'">
当前组织
</view>
</view>
</view> -->
<view class="jnpf-tree-select-tree">
<!-- 树形结构区域 -->
<scroll-view :scroll-y="true" style="height: 100%" v-if="activeKey==='1' && !hasPage">
<ly-tree v-if="selectType !== 'all'" :tree-data="options" :node-key="realProps.value"
default-expand-all :props="realProps" :filter-node-method="filterNode"
@@ -46,18 +46,19 @@
@node-click="handleTreeNodeClick" :show-checkbox="multiple" :show-radio="!multiple"
:expandOnClickNode="false" :checkOnClickNode="true" :expandOnCheckNode="false" checkStrictly />
</scroll-view>
<!-- 列表/搜索结果区域 -->
<scroll-view :scroll-y="true" style="height: 100%" :refresher-enabled="false" :refresher-threshold="100"
:scroll-with-animation='true' :refresher-triggered="triggered" @scrolltolower="handleScrollToLower"
v-if="activeKey==='2'|| (activeKey==='1' && hasPage)">
<view class="jnpf-selcet-list" v-if="list.length">
<view class="jnpf-selcet-cell" v-for="item in list" :key="item.id"
<view class="jnpf-selcet-cell" v-for="item in list" :key="item.deptId"
@click.stop="handleNodeClick(item)">
<view class="jnpf-selcet-cell-action">
<lyCheckbox :type="multiple ? 'checkbox' : 'radio'"
:checked="selectedIds.includes(item.id)" />
:checked="selectedIds.includes(item.deptId)" />
</view>
<view class="jnpf-selcet-cell-name">
{{item.orgNameTree}}
{{item.deptName}}
</view>
</view>
</view>
@@ -73,6 +74,7 @@
</view>
</u-popup>
</template>
<script>
import {
getOrgByOrganizeCondition,
@@ -81,12 +83,15 @@
import lyCheckbox from '@/components/ly-tree/components/ly-checkbox.vue';
import Empty from '../Empty/index.vue'
// 适配接口返回的字段
const defaultProps = {
label: 'fullName',
value: 'id',
label: 'deptName', // 对应接口的deptName
value: 'deptId', // 对应接口的deptId
icon: 'icon',
children: 'children'
children: 'children',// 子节点字段
isLeaf: 'isLeaf' // 叶子节点标识
}
export default {
props: {
selectedData: {
@@ -101,25 +106,21 @@
type: String,
default: 'all'
},
// 通过双向绑定控制组件的弹出与收起
type: {
type: String,
default: 'all'
},
modelValue: {
type: Boolean,
default: false
},
// 弹出的z-index值
zIndex: {
type: [String, Number],
default: 0
},
props: {
type: Object,
default: () => ({
label: 'fullName',
value: 'id',
icon: 'icon',
children: 'children',
isLeaf: 'isLeaf'
})
default: () => ({})
},
multiple: {
type: Boolean,
@@ -138,7 +139,7 @@
keyword: '',
showPopup: false,
options: [],
lazyOptions: [],
lazyOptions: [{}], // 懒加载根节点占位
activeKey: '1',
hasPage: false,
pagination: {
@@ -152,7 +153,6 @@
};
},
watch: {
// 在select弹起的时候重新初始化所有数据
modelValue: {
handler(val) {
this.showPopup = val
@@ -163,7 +163,8 @@
},
selectedList: {
handler(val) {
this.selectedIds = val.map((o) => o.id);
// 适配deptId字段
this.selectedIds = val.map((o) => o.deptId);
this.$refs.tree && this.$refs.tree.setCheckedKeys(this.selectedIds)
},
deep: true
@@ -171,7 +172,6 @@
},
computed: {
uZIndex() {
// 如果用户有传递z-index值优先使用
return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
},
realProps() {
@@ -184,23 +184,55 @@
const userInfo = uni.getStorageSync('userInfo') || {}
const list = (userInfo.organizeList || []).map((o) => ({
...o,
orgNameTree: o.treeName
deptName: o.treeName || o.deptName,
deptId: o.id || o.deptId
}))
return list
}
},
methods: {
init() {
this.keyword = ""
this.hasPage = 0
this.activeKey = '1'
this.finish = false
this.pagination.currentPage = 1
this.$nextTick(() => {
this.triggered = true
})
this.selectedList = JSON.parse(JSON.stringify(this.selectedData))
if (this.selectType !== 'all') this.getConditionOptions()
this.keyword = ""
this.hasPage = 0
this.activeKey = '1'
this.finish = false
this.pagination.currentPage = 1
this.$nextTick(() => {
this.triggered = false
})
// 深拷贝选中数据
this.selectedList = JSON.parse(JSON.stringify(this.selectedData)).map(item => ({
deptId: item.id || item.deptId,
deptName: item.orgNameTree || item.deptName || item.fullName,
...item
}))
// 如果是全量选择,预加载根节点
if (this.selectType === 'all') {
this.preloadRootNodes()
} else {
this.getConditionOptions()
}
},
preloadRootNodes() {
const data = {
type: this.type,
}
getOrganizeSelector(data).then(res => {
const list = res.data || []
// 构建根节点树
this.options = this.buildTree(list, 'deptId', 'deptPid', '0')
console.log('预加载的根节点:', this.options)
// 设置初始选中状态
this.$nextTick(() => {
if (this.$refs.tree && this.selectedIds.length > 0) {
this.$refs.tree.setCheckedKeys(this.selectedIds)
}
})
})
},
getConditionOptions() {
if (!this.ableIds.length) return
@@ -208,90 +240,263 @@
ids: this.ableIds
}
getOrgByOrganizeCondition(query).then(res => {
this.options = res.data.list || []
// 适配接口返回的扁平数据为树形结构
this.options = this.buildTree(res.data.list || [], 'deptId', 'deptPid', '0')
this.$refs.tree && this.$refs.tree.setCheckedKeys(this.selectedIds)
})
},
// 扁平数组转树形结构
buildTree(data, idKey, pidKey, rootPid) {
const result = []
const map = {}
// 先构建ID映射
data.forEach(item => {
map[item[idKey]] = { ...item, children: [] }
})
// 组装父子关系
data.forEach(item => {
const parent = map[item[pidKey]]
if (item[pidKey] === rootPid) {
result.push(map[item[idKey]])
} else if (parent) {
parent.children.push(map[item[idKey]])
}
})
return result
},
// 树形节点过滤
filterNode(value, data) {
if (!value) return true;
return data[this.realProps.label].indexOf(value) !== -1;
return data.deptName && data.deptName.indexOf(value) !== -1;
},
// 懒加载节点
loadNode(node, resolve) {
const id = node.key || '0'
const data = {
keyword: '',
parentId: id
}
getOrganizeSelector(data).then(res => {
resolve(res.data?.list)
this.$refs.tree && this.$refs.tree.setCheckedKeys(this.selectedIds)
const parentId = node.key || '0'
// 获取该节点的深度信息
const level = node.level || 0
console.log('加载节点:', { parentId, level, node })
// 如果是根节点level为0直接使用已经构建好的options
if (level === 0 && this.options.length > 0) {
resolve(this.options)
return
}
const data = {
type: this.type,
}
getOrganizeSelector(data).then(res => {
const list = res.data || []
// 将返回的扁平数据转换为树形节点
const treeData = this.buildTree(list, 'deptId', 'deptPid', parentId)
// 设置节点的isLeaf属性根据是否有子节点判断
treeData.forEach(item => {
// 判断该节点是否还有子节点(根据实际情况调整)
// 如果知道接口返回是否有子节点的字段,可以替换这个判断
item.isLeaf = !item.children || item.children.length === 0
})
console.log(`加载父节点 ${parentId} 的子节点:`, treeData)
resolve(treeData)
}).catch(() => {
resolve([]) // 异常时返回空数组,避免组件报错
})
},
// 滚动加载(仅搜索列表使用)
handleScrollToLower() {
if (this.finish || this.activeKey === '2') return
if (this.finish || this.activeKey === '2' || !this.keyword) return
this.getTreeData()
},
// 获取搜索列表数据
getTreeData() {
let data = {
keyword: this.keyword,
parentId: '0',
...this.pagination
const data = {
type: this.type,
// keyword: this.keyword,
// parentId: '0',
// ...this.pagination
}
getOrganizeSelector(data).then(res => {
const list = res.data.list || []
const list = res.data || []
if (list.length < this.pagination.pageSize) this.finish = true;
this.list = this.list.concat(list);
this.pagination.currentPage++
})
},
onTreeCheck(item) {
this.handleTreeNodeClick(item);
},
// 树形节点点击
handleTreeNodeClick(item) {
const data = item.data
const data = item.data || item
this.handleNodeClick(data)
},
// 列表节点点击
handleNodeClick(data) {
const index = this.selectedList.findIndex((o) => o.id === data.id);
if (index !== -1) return this.selectedList.splice(index, 1);
this.multiple ? this.selectedList.push(data) : (this.selectedList = [data]);
// 适配deptId字段
const index = this.selectedList.findIndex((o) => o.deptId === data.deptId);
if (index !== -1) {
this.selectedList.splice(index, 1);
} else {
this.multiple ? this.selectedList.push(data) : (this.selectedList = [data]);
}
},
// 删除选中项
delSelect(index) {
this.selectedList.splice(index, 1);
},
// 清空选中
setCheckAll() {
this.selectedIds = []
this.selectedList = []
},
// 确认选择
handleConfirm() {
this.$emit('confirm', this.selectedList, this.selectedIds);
// 转换回原始字段格式,兼容父组件
const resultList = this.selectedList.map(item => ({
id: item.deptId,
orgNameTree: item.deptName,
...item
}))
const resultIds = resultList.map(item => item.id)
console.log(resultIds,resultList,'数据')
this.$emit('confirm', resultList, resultIds);
this.close();
},
// 关闭弹窗
close() {
this.$emit('update:modelValue', false); // 双向绑定规范
this.$emit('close', false);
},
// 切换标签
toggloActive(key) {
if (this.activeKey === key) return
this.keyword = ''
this.$nextTick(() => {
this.activeKey = key
if (this.activeKey === '2') this.list = this.getCurrOrgList
})
},
handleSearch(val) {
this.keyword = val
if (this.selectType !== 'all') return this.$refs.tree && this.$refs.tree.filter(val)
this.hasPage = !!val
this.list = []
if (this.activeKey != '1') this.activeKey = '1'
this.$nextTick(() => {
if (this.keyword) {
this.pagination.currentPage = 1
this.finish = false
this.$u.debounce(this.getTreeData, 300)
if (this.activeKey === '2') {
this.list = this.getCurrOrgList
} else {
this.list = []
}
})
},
// 搜索处理
handleSearch(val) {
this.keyword = val.trim()
// 非全量选择时,使用树形过滤
if (this.selectType !== 'all') {
this.$refs.tree && this.$refs.tree.filter(this.keyword)
return
}
// 有搜索关键词时,切换为列表展示
this.hasPage = !!this.keyword
this.list = []
this.finish = false
this.pagination.currentPage = 1
this.activeKey = '1'
if (this.keyword) {
this.$u.debounce(this.getTreeData, 300)() // 执行防抖函数
}
},
}
};
</script>
</script>
<style scoped>
/* 保留原有样式,如需补充可添加 */
.jnpf-tree-select-body {
height: 100vh;
display: flex;
flex-direction: column;
background: #fff;
}
.jnpf-tree-select-title {
display: flex;
align-items: center;
padding: 16rpx;
border-bottom: 1rpx solid #eee;
}
.backIcon {
font-size: 32rpx;
margin-right: 16rpx;
}
.title {
font-size: 32rpx;
font-weight: 500;
}
.jnpf-tree-select-search {
padding: 16rpx;
}
.jnpf-tree-selected {
padding: 0 16rpx;
}
.jnpf-tree-selected-head {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12rpx 0;
}
.clear-btn {
color: #007aff;
font-size: 28rpx;
}
.select-list {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
padding: 8rpx 0;
max-height: 200rpx;
}
.u-selectTag {
margin-bottom: 8rpx;
}
.jnpf-tree-selected-line {
height: 1rpx;
background: #eee;
margin: 8rpx 0;
}
.jnpf-tree-selected-tabs {
display: flex;
}
.tab-item {
flex: 1;
text-align: center;
padding: 16rpx;
font-size: 28rpx;
}
.tab-item-active {
color: #007aff;
border-bottom: 2rpx solid #007aff;
}
.jnpf-tree-select-tree {
flex: 1;
padding: 16rpx;
}
.jnpf-selcet-cell {
display: flex;
align-items: center;
padding: 16rpx 0;
border-bottom: 1rpx solid #f5f5f5;
}
.jnpf-selcet-cell-action {
margin-right: 16rpx;
}
.jnpf-tree-select-actions {
display: flex;
padding: 16rpx;
gap: 16rpx;
}
.buttom-btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
}
.h-full {
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>

View File

@@ -3,16 +3,16 @@
<selectBox v-model="innerValue" :placeholder="placeholder" @openSelect="openSelect" :select-open="selectShow"
:disabled="disabled" />
<SelectPopup v-model="selectShow" :multiple="multiple" :selectedData="selectedData" @close="handleClose"
@confirm="handleConfirm" :selectType="selectType" :ableIds="ableIds" />
@confirm="handleConfirm" :selectType="selectType" :type="type" :ableIds="ableIds" />
</view>
</template>
<script>
import SelectPopup from './SelectPopup';
import selectBox from '@/components/selectBox'
import {
getOrgSelectedList
} from '@/api/common'
// 移除接口导入:不再需要 getOrgSelectedList
// import { getOrgSelectedList } from '@/api/common'
export default {
name: 'jnpf-organize-select',
components: {
@@ -39,9 +39,17 @@
type: String,
default: 'all'
},
type: {
type: String,
default: 'all'
},
ableIds: {
type: Array,
default: () => []
},
innerSelectedData: {
type: Array,
default: () => []
}
},
data() {
@@ -53,24 +61,40 @@
},
watch: {
modelValue: {
handler() {
this.setDefault()
handler(val) {
this.setDefault(val) // 传入modelValue直接处理赋值
},
immediate: true
},
innerSelectedData: {
handler(val) {
if(val.length){
const data = val[0]
this.selectedData = val
this.setDefault(data['id'])
}
},
immediate: true,
deep: true
},
},
methods: {
setDefault() {
if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
const ids = this.multiple ? this.modelValue : [this.modelValue];
getOrgSelectedList({
ids
}).then((res) => {
if (!this.modelValue || !this.modelValue.length) return this.setNullValue();
const selectedData = res.data.list || []
this.selectedData = selectedData
this.innerValue = this.selectedData.map(o => o.orgNameTree).join();
});
// 重构setDefault:不再调用接口,直接处理赋值
setDefault(val) {
if (!val || !val.length) {
return this.setNullValue();
}
// 场景1父组件传入初始值modelValue直接匹配已选数据赋值
// 如果没有初始选中数据innerValue为空即可无需请求接口
// 重点这里不再调用getOrgSelectedList直接用已有的selectedData或空值
if (this.selectedData.length > 0) {
// 有已选数据时,直接拼接名称
this.innerValue = this.selectedData.map(o => o.deptName || o.orgNameTree).join();
} else {
// 无已选数据时若modelValue是ID暂时显示空或根据需要处理
this.innerValue = '';
}
},
setNullValue() {
this.innerValue = '';
@@ -80,7 +104,16 @@
if (this.disabled) return
this.selectShow = true
},
// 核心修改:确认选择时,直接用弹窗返回的原始数据赋值
handleConfirm(selectedData, selectedIds) {
// 1. 保存选中的原始数据
this.selectedData = selectedData;
// 2. 直接拼接名称到显示框innerValue无需接口
this.innerValue = selectedData.map(o => o.deptName || o.orgNameTree).join();
// 3. 向父组件传递选中值(保持原有逻辑)
console.log(this.multiple,'this.multiple')
console.log(selectedData[0],'selectedData[0]')
console.log(selectedIds[0],'selectedIds[0]')
if (!this.multiple) {
this.$emit('update:modelValue', selectedIds[0])
this.$emit('change', selectedIds[0], selectedData[0])
@@ -88,6 +121,8 @@
this.$emit('update:modelValue', selectedIds)
this.$emit('change', selectedIds, selectedData)
}
// 4. 关闭弹窗
this.selectShow = false;
},
handleClose() {
this.selectShow = false