import React, {Component} from 'react';
import {
SortableContainer,
SortableElement,
SortableHandle,
arrayMove,
} from 'react-sortable-hoc';
import PropTypes from 'prop-types'
import Select from 'react-select';
import axios from 'axios'
const DragHandle = SortableHandle(() => (
)); // This can be any component you want
class Part extends React.Component {
static propTypes = {
name: PropTypes.string,
title: PropTypes.string,
onChangeTitle: PropTypes.func,
onChangeType: PropTypes.func
};
render() {
const {name, title, type, onChangeTitle, onChangeType} = this.props;
const typeImageTable = [
'/img/scroll.png',
'/img/grid.png',
'/img/list.png',
];
const options = [
{ value: 1, label: '横排(右滚动)' },
{ value: 2, label: '多列(三列)' },
{ value: 3, label: '竖排(下滚动)' }
];
return (
)
}
}
const SortableItem = SortableElement(({value}) => {
return (
{value}
);
});
const SortableList = SortableContainer(({items}) => {
return (
{items.map((value, index) => (
))}
);
});
class SortableComponent extends Component {
state = {
items: data,
};
onSortEnd = ({oldIndex, newIndex}) => {
const {items} = this.state;
this.setState({
items: arrayMove(items, oldIndex, newIndex),
});
};
onChangeTitle = (index, event) => {
let {items} = this.state;
items[index].title = event.target.value;
this.setState({
items
})
};
onChangeType = (index, newType) => {
let {items} = this.state;
items[index].type = newType.value;
this.setState({
items
})
};
submit = () => {
const {items} = this.state;
axios.post(location.href, {
'_csrf-api': csrf,
data: items
}).then((res) => {
if (res.data === 1) {
this.back();
}
})
};
back = () => {
history.go(-1)
};
render() {
const {items} = this.state;
const itemsView = items.map((item, index) => (
));
return (
);
}
}