import { use } from '../utils'; import Icon from '../icon'; import Loading from '../loading'; import PopupMixin from '../mixins/popup'; const [sfc, bem] = use('actionsheet'); export default sfc({ mixins: [PopupMixin], props: { title: String, value: Boolean, actions: Array, cancelText: String, overlay: { type: Boolean, default: true }, closeOnClickOverlay: { type: Boolean, default: true } }, methods: { onSelect(event, item) { event.stopPropagation(); if (!item.disabled && !item.loading) { if (item.callback) { item.callback(item); } this.$emit('select', item); } }, onCancel() { this.$emit('input', false); this.$emit('cancel'); } }, render(h) { if (!this.shouldRender) { return; } const { title, cancelText, onCancel } = this; const Header = () => (
{title}
); const Option = item => (
{ this.onSelect(event, item); }} > {item.loading ? ( ) : ( [ {item.name}, item.subname && {item.subname} ] )}
); const Footer = cancelText ? (
{cancelText}
) : (
{this.slots()}
); return (
{title ? Header() : this.actions.map(Option)} {Footer}
); } });