import { tag, WeElement, h, extractClass } from 'omi' import * as css from './index.scss' import '../list' //@ts-ignore import '../theme.ts' interface Props { left: object[], right: object[] } interface Data { } @tag('m-transfer-list') export default class TransferList extends WeElement{ static css = css static propTypes = { left: Array, right: Array } leftToRight = () => { this.props.right = [...this.props.right, ...this.props.left] this.props.left.length = 0 this._checkLeftDisabled() this._checkRightDisabled() this.update(true) this.fire('change', { left: this.props.left, right: this.props.right }) } rightToLeft = () => { this.props.left = [...this.props.left, ...this.props.right] this.props.right.length = 0 this._checkLeftDisabled() this._checkRightDisabled() this.update(true) this.fire('change', { left: this.props.left, right: this.props.right }) } sltLeftToRight = () => { //@ts-ignore const temp = this.props.left.filter(item => !item.checked) this.props.left.forEach(item => { //@ts-ignore item.checked && this.props.right.push(item) //@ts-ignore item.checked = false }) this.props.left = temp this._checkLeftDisabled() this._checkRightDisabled() this.update(true) this.fire('change', { left: this.props.left, right: this.props.right }) } sltRightToRight = () => { //@ts-ignore const temp = this.props.right.filter(item => !item.checked) this.props.right.forEach(item => { //@ts-ignore item.checked && this.props.left.push(item) //@ts-ignore item.checked = false }) this.props.right = temp this._checkLeftDisabled() this._checkRightDisabled() this.update(true) this.fire('change', { left: this.props.left, right: this.props.right }) } _rightBtnDiabled = true _leftBtnDiabled = true _rightAllBtnDiabled = true _leftAllBtnDiabled = true install() { this._checkLeftDisabled() this._checkRightDisabled() } onLeftItemClick = (evt) => { evt.detail.item.checked = !evt.detail.item.checked this._checkLeftDisabled() this.update(true) } _checkLeftDisabled() { const len = this.props.left.length if (len === 0) { this._rightBtnDiabled = true this._rightAllBtnDiabled = true return } else { this._rightAllBtnDiabled = false } for (let i = 0; i < len; i++) { //@ts-ignore if (this.props.left[i].checked) { this._rightBtnDiabled = false return } } this._rightBtnDiabled = true } _checkRightDisabled() { const len = this.props.right.length if (len === 0) { this._leftBtnDiabled = true this._leftAllBtnDiabled = true return } else { this._leftAllBtnDiabled = false } for (let i = 0; i < len; i++) { //@ts-ignore if (this.props.right[i].checked) { this._leftBtnDiabled = false return } } this._leftBtnDiabled = true } onRightItemClick = (evt) => { evt.detail.item.checked = !evt.detail.item.checked this._checkRightDisabled() this.update(true) } render(props) { return (
) } }