import classNames from 'classnames'; import PropTypes from '../_util/vue-types'; import { isValidElement, initDefaultProps, getListeners } from '../_util/props-util'; import BaseMixin from '../_util/BaseMixin'; import Checkbox from '../checkbox'; import Search from './search'; import defaultRenderList from './renderListBody'; import triggerEvent from '../_util/triggerEvent'; import addEventListener from '../vc-util/Dom/addEventListener'; const defaultRender = () => null; const TransferItem = { key: PropTypes.string.isRequired, title: PropTypes.string.isRequired, description: PropTypes.string, disabled: PropTypes.bool, }; function isRenderResultPlainObject(result) { return ( result && !isValidElement(result) && Object.prototype.toString.call(result) === '[object Object]' ); } export const TransferListProps = { prefixCls: PropTypes.string, titleText: PropTypes.string, dataSource: PropTypes.arrayOf(PropTypes.shape(TransferItem).loose), filter: PropTypes.string, filterOption: PropTypes.func, checkedKeys: PropTypes.arrayOf(PropTypes.string), handleFilter: PropTypes.func, handleSelect: PropTypes.func, handleSelectAll: PropTypes.func, handleClear: PropTypes.func, renderItem: PropTypes.func, showSearch: PropTypes.bool, searchPlaceholder: PropTypes.string, notFoundContent: PropTypes.any, itemUnit: PropTypes.string, itemsUnit: PropTypes.string, body: PropTypes.any, renderList: PropTypes.any, footer: PropTypes.any, lazy: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]), disabled: PropTypes.bool, direction: PropTypes.string, showSelectAll: PropTypes.bool, }; function renderListNode(h, renderList, props) { let bodyContent = renderList ? renderList(props) : null; const customize = !!bodyContent; if (!customize) { bodyContent = defaultRenderList(h, props); } return { customize, bodyContent, }; } export default { name: 'TransferList', mixins: [BaseMixin], props: initDefaultProps(TransferListProps, { dataSource: [], titleText: '', showSearch: false, lazy: {}, }), data() { this.timer = null; this.triggerScrollTimer = null; return { filterValue: '', }; }, // mounted() { // this.timer = setTimeout(() => { // this.setState({ // mounted: true, // }); // }, 0); // this.$nextTick(() => { // if (this.$refs.listContentWrapper) { // const listContentWrapperDom = this.$refs.listContentWrapper.$el; // this.scrollEvent = addEventListener(listContentWrapperDom, 'scroll', this.handleScroll); // } // }); // }, beforeDestroy() { clearTimeout(this.triggerScrollTimer); // if (this.scrollEvent) { // this.scrollEvent.remove(); // } }, updated() { this.$nextTick(() => { if (this.scrollEvent) { this.scrollEvent.remove(); } if (this.$refs.listContentWrapper) { const listContentWrapperDom = this.$refs.listContentWrapper.$el; this.scrollEvent = addEventListener(listContentWrapperDom, 'scroll', this.handleScroll); } }); }, methods: { handleScroll(e) { this.$emit('scroll', e); }, getCheckStatus(filteredItems) { const { checkedKeys } = this.$props; if (checkedKeys.length === 0) { return 'none'; } if (filteredItems.every(item => checkedKeys.indexOf(item.key) >= 0 || !!item.disabled)) { return 'all'; } return 'part'; }, getFilteredItems(dataSource, filterValue) { const filteredItems = []; const filteredRenderItems = []; dataSource.forEach(item => { const renderedItem = this.renderItemHtml(item); const { renderedText } = renderedItem; // Filter skip if (filterValue && filterValue.trim() && !this.matchFilter(renderedText, item)) { return null; } filteredItems.push(item); filteredRenderItems.push(renderedItem); }); return { filteredItems, filteredRenderItems }; }, getListBody( prefixCls, searchPlaceholder, filterValue, filteredItems, notFoundContent, bodyDom, filteredRenderItems, checkedKeys, renderList, showSearch, disabled, ) { const search = showSearch ? (