2023-04-19 05:20:02 +08:00
|
|
|
import {onChildEvent} from '../services/dom';
|
|
|
|
import {Component} from './component';
|
2021-01-01 01:25:20 +08:00
|
|
|
|
2022-11-16 00:04:46 +08:00
|
|
|
export class UserSelect extends Component {
|
2021-01-01 01:25:20 +08:00
|
|
|
|
|
|
|
setup() {
|
2022-11-16 23:46:41 +08:00
|
|
|
this.container = this.$el;
|
2021-01-01 01:25:20 +08:00
|
|
|
this.input = this.$refs.input;
|
|
|
|
this.userInfoContainer = this.$refs.userInfo;
|
|
|
|
|
2022-11-16 23:46:41 +08:00
|
|
|
onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
|
2021-01-01 01:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
selectUser(event, userEl) {
|
2021-03-21 23:04:32 +08:00
|
|
|
event.preventDefault();
|
2022-11-16 00:04:46 +08:00
|
|
|
this.input.value = userEl.getAttribute('data-id');
|
2021-01-01 01:25:20 +08:00
|
|
|
this.userInfoContainer.innerHTML = userEl.innerHTML;
|
2021-03-21 23:04:32 +08:00
|
|
|
this.input.dispatchEvent(new Event('change', {bubbles: true}));
|
2021-01-01 01:25:20 +08:00
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
|
2022-11-16 23:46:41 +08:00
|
|
|
hide() {
|
2023-04-19 05:20:02 +08:00
|
|
|
/** @var {Dropdown} * */
|
2022-11-16 23:46:41 +08:00
|
|
|
const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
|
|
|
|
dropdown.hide();
|
|
|
|
}
|
|
|
|
|
2023-04-19 05:20:02 +08:00
|
|
|
}
|