Fixiaobai
2023-10-13 e8308ddac0ba4a1f406e8f63d7e6b6f2541cb770
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
  <el-table class="sortableTable"
  row-key="id"
  :data="orders"
  >
    <el-table-column
      width="60">
      <template slot-scope="scope">
        <i class="icon-jiantou-tuodong pointClass"></i>
        <span>&nbsp;&nbsp;No.{{scope.$index+1}}</span>
      </template>
    </el-table-column>
    <el-table-column
      prop="orderName"
      label="制造订单"
      width="180">
    </el-table-column>
    <el-table-column
      prop="factoryName"
      label="工厂"
      width="180">
    </el-table-column>
    <el-table-column
      prop="partName"
      label="零件"
      width="180">
    </el-table-column>
  </el-table>
</template>
<style>
  @import "~@/assets/icon/orderIcon/iconfont.css";
 
  .sortableTable table{
    width: 100% !important;
  }
 
  .ghostRowClass{
    background-color: darkorange !important;
  }
 
  .pointClass{
    cursor:grab
  }
</style>
<script>
 
  export default {
    name: 'sortable',
    props: {
      orders: {
        type: Array,
        default () {
          return []
        }
      }
    },
    data () {
      return {
      }
    },
    mounted: function () {
      const el = document.querySelectorAll('.sortableTable tbody')[0];
      const selft = this;
      Sortable.create(el, {
        //sort: true,
        draggable: ".el-table__row",
        ghostClass:"ghostRowClass",
        handle:".icon-jiantou-tuodong",
        animation:400,
        // 拖拽结束后的操作
        onEnd({ newIndex, oldIndex }) {
          // 修改data中的数组,
          const targetRow = selft.orders.splice(oldIndex, 1)[0];
          selft.orders.splice(newIndex, 0, targetRow);
 
        }
      });
    }
  }
</script>