阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.4 KiB

  1. <template>
  2. <!--表单组件-->
  3. <el-dialog class="sort-dialog" :close-on-click-modal="false" :modal-append-to-body="false" append-to-body title="排序" :visible.sync="sortVisible" @opened="opened">
  4. <div class="setting-dialog">
  5. <i class="drag-tip">提示使用鼠标拖动调整顺序</i>
  6. <el-table :data="sortTableData" :tree-props="{children: 'childrens'}" class="category-sort" style="width: 100%;" :max-height="tableHeight" row-key="id">
  7. <el-table-column type="index" label="序号" width="100" align="center" />
  8. <el-table-column prop="cnName" label="门类名称" />
  9. </el-table>
  10. <div slot="footer" class="dialog-footer">
  11. <el-button @click.native="sortVisible = false">取消</el-button>
  12. <el-button type="primary" @click.native="handleSort">确定</el-button>
  13. </div>
  14. </div>
  15. </el-dialog>
  16. </template>
  17. <script>
  18. import Sortable from 'sortablejs'
  19. import { sort } from '@/api/system/fileLibrary/fileLibrary'
  20. export default {
  21. data() {
  22. return {
  23. sortVisible: false,
  24. sortTableData: [],
  25. tableHeight: 0
  26. }
  27. },
  28. mounted() {
  29. this.$nextTick(() => {
  30. this.tableHeight = window.innerHeight * 0.6
  31. })
  32. },
  33. methods: {
  34. // 行拖拽
  35. rowDrop(className, targetName) {
  36. // 此时找到的元素是要拖拽元素的父容器
  37. const tbody = document.querySelector('.' + className + ' .el-table__body-wrapper tbody')
  38. const that = this
  39. Sortable.create(tbody, {
  40. // 指定父元素下可被拖拽的子元素
  41. draggable: '.el-table__row',
  42. onEnd({ newIndex, oldIndex }) {
  43. if (newIndex === oldIndex) return
  44. that[targetName].splice(newIndex, 0, that[targetName].splice(oldIndex, 1)[0])
  45. }
  46. })
  47. },
  48. opened() {
  49. this.rowDrop('category-sort', 'sortTableData')
  50. },
  51. handleSort() {
  52. const data = this.sortTableData.map((value, index) => {
  53. return { id: value.id, categorySeq: index + 1 }
  54. })
  55. this.sortTableData.forEach((item, index) => {
  56. item.categorySeq = index + 1
  57. })
  58. sort(data).then(() => {
  59. this.sortVisible = false
  60. this.$message({
  61. message: '保存成功',
  62. type: 'success',
  63. duration: 2500
  64. })
  65. this.$emit('treeNodeSort', this.sortTableData)
  66. })
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. </style>