123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <template>
- <u-popup class="jnpf-tree-select-popup" mode="right" :popup="false" v-model="showPopup" length="auto"
- :z-index="uZIndex" width="100%" @close="close">
- <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>
- <view class="jnpf-tree-select-search">
- <u-search :placeholder="$t('app.apply.pleaseKeyword')" v-model="keyword" height="72"
- :show-action="false" @change="handleSearch" bg-color="#f0f2f6" shape="square">
- </u-search>
- </view>
- <view class="jnpf-tree-selected">
- <view class="jnpf-tree-selected-head">
- <view>{{$t('component.jnpf.common.selected')}}</view>
- <view v-if="multiple" class="clear-btn" @click="setCheckAll">
- {{$t('component.jnpf.common.clearAll')}}
- </view>
- </view>
- <view class="jnpf-tree-selected-box">
- <scroll-view scroll-y="true" class="select-list">
- <u-tag closeable @close="delSelect(index)" v-for="(list,index) in selectList" :key="index"
- :text="list.fullName" class="u-selectTag" />
- </scroll-view>
- </view>
- </view>
- <view class="jnpf-tree-select-tree">
- <scroll-view :scroll-y="true" style="height: 100%">
- <ly-tree ref="tree" v-if="selectType === 'all'" :props="realProps" :node-key="realProps.value"
- :load="loadNode" lazy :tree-data="lazyOptions" show-node-icon :defaultExpandAll='false'
- @node-click="handleNodeClick" />
- <ly-tree v-else ref="tree" :node-key="realProps.value" :tree-data="options"
- @node-click="handleNodeClick" :props="realProps" show-node-icon
- :filter-node-method="filterNode" />
- </scroll-view>
- </view>
- <view class="jnpf-tree-select-actions">
- <u-button class="buttom-btn" @click="close()">{{$t('common.cancelText')}}</u-button>
- <u-button class="buttom-btn" type="primary"
- @click.stop="handleConfirm()">{{$t('common.okText')}}</u-button>
- </view>
- </view>
- </u-popup>
- </template>
- <script>
- const defaultProps = {
- label: 'fullName',
- value: 'id',
- icon: 'icon',
- children: 'children'
- }
- import {
- selectAsyncList
- } from '@/api/common.js'
- export default {
- props: {
- options: {
- type: Array,
- default () {
- return [];
- }
- },
- selectedData: {
- type: Array,
- default () {
- return [];
- }
- },
- ids: {
- default: ''
- },
- selectType: {
- default: ''
- },
- modelValue: {
- type: Boolean,
- default: false
- },
- zIndex: {
- type: [String, Number],
- default: 0
- },
- props: {
- type: Object,
- default: () => ({
- label: 'fullName',
- value: 'id',
- icon: 'icon',
- children: 'children',
- isLeaf: 'isLeaf'
- })
- },
- multiple: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- moving: false,
- selectList: [],
- selectListId: [],
- newListId: [],
- keyword: '',
- showPopup: false,
- lazyOptions: []
- };
- },
- watch: {
- // 在select弹起的时候,重新初始化所有数据
- modelValue: {
- handler(val) {
- this.showPopup = val
- if (val) setTimeout(() => this.init(), 10);
- },
- immediate: true
- },
- },
- computed: {
- uZIndex() {
- return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
- },
- realProps() {
- return {
- ...defaultProps,
- ...this.props
- }
- }
- },
- methods: {
- init() {
- this.keyword = ""
- this.selectListId = Array.isArray(this.ids) ? JSON.parse(JSON.stringify(this.ids.filter(item => item
- ?.trim() !== ''))) : []
- this.selectList = JSON.parse(JSON.stringify(this.selectedData))
- },
- loadNode(node, resolve) {
- let id = node.key === null ? 0 : node.key
- this.level = node.level
- let data = {
- keyword: '',
- currOrgId: 0
- }
- selectAsyncList(data, id).then(res => {
- resolve(res.data?.list)
- })
- },
- selectAsyncList() {
- let data = {
- keyword: this.keyword,
- currOrgId: 0
- }
- this.lazyOptions = []
- selectAsyncList(data, 0).then(res => {
- this.lazyOptions = res.data.list || []
- })
- },
- handleNodeClick(obj) {
- let data = obj.data
- if (data.type === 'company') return
- if (this.multiple) {
- this.selectListId.push(data.id)
- this.selectListId = [...new Set(this.selectListId)];
- } else {
- this.selectList = []
- this.selectListId = data.id
- }
- this.selectList.push({
- fullName: this.selectType === 'all' ? data.fullName : data.lastFullName,
- id: data.id
- })
- //数组对象去重--[...new Set(this.selectList.map(JSON.stringify))].map(JSON.parse)
- //数组去重--[...new Set(this.selectList)]
- this.selectList = [...new Set(this.selectList.map(JSON.stringify))].map(JSON.parse);
- },
- delSelect(index) {
- this.selectList.splice(index, 1);
- this.selectListId.splice(index, 1);
- },
- setCheckAll() {
- this.selectListId = [];
- this.selectList = [];
- this.$refs.tree.setCheckAll(false);
- },
- filterNode(value, data) {
- if (!value) return true;
- return data[this.realProps.label].indexOf(value) !== -1;
- },
- handleSearch(val) {
- this.keyword = val
- if (this.selectType === 'all') return this.$u.debounce(this.selectAsyncList, 600)
- this.$refs.tree && this.$refs.tree.filter(val)
- },
- handleConfirm() {
- this.$emit('confirm', this.selectList, this.selectListId);
- this.close();
- },
- close() {
- this.$emit('close', false);
- }
- }
- };
- </script>
|