// 将当前下标的元素，在数组中向上移动一位
export function sortUp (dataList, index) {
  if (index !== 0) {
    const row = dataList[index]
    dataList[index] = dataList[index - 1]
    dataList[index - 1] = row
    return {dataList: dataList, index: index - 1}
  }
  return {dataList: dataList, index: index}
}
// 将当前下标的元素，在数组中向下移动一位
export function sortDown (dataList, index) {
  if (index !== dataList.length - 1) {
    const row = dataList[index]
    dataList[index] = dataList[index + 1]
    dataList[index + 1] = row
    return {dataList: dataList, index: index + 1}
  }
  return {dataList: dataList, index: index}
}
// 将当前下标的元素，移动到数组的第一位
export function sortTop (dataList, index) {
  const row = dataList[index]
  for (let i = index; i > 0; i--) {
    dataList[i] = dataList[i - 1]
  }
  dataList[0] = row
  return {dataList: dataList, index: 0}
}
// 将当前下标的元素，移动到数组的最后一位
export function sortBottom (dataList, index) {
  const row = dataList[index]
  for (let i = index; i < dataList.length - 1; i++) {
    dataList[i] = dataList[i + 1]
  }
  dataList[dataList.length - 1] = row
  return {dataList: dataList, index: dataList.length - 1}
}
export default { sortUp, sortDown, sortTop, sortBottom }
