永康嘉持电器有限公司前端
小小儁爺
2024-12-25 c6da28cde9dc469ee1e2d4dba4b7234307d9bd5a
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<template>
  <div>
    <div class="body" :style="{height:mainHeight+'px'}">
      <div
        class="elTableDiv"
      >
 
        <div style="width: 300px;background:#fff">
 
          <div style="margin: 20px 10px 0 10px;display: flex;justify-content: space-between;">
            <div style="display: flex;">
              <div
                style="width: 5px;height: 100%;border-radius: 5px;"
                :style="{background:$store.state.settings.theme}"
              />
              <div style="margin-left: 8px;">组织名称</div>
            </div>
 
            <!--            <div style="margin-right:10px">-->
            <!--              <i class="el-icon-plus" style="cursor: pointer;color: #999" />-->
            <!--            </div>-->
            <!--            @click="rolePlusClick"-->
          </div>
 
          <el-tree
            ref="treeLeftRef"
            style="padding: 10px;overflow: auto"
            :style="{height:(tableHeight-20)+'px'}"
            :data="treeLeft"
            node-key="code"
            highlight-current
            :props="defaultPropsLeft"
            :default-expand-all="true"
            :expand-on-click-node="false"
            draggable
            :allow-drop="treeLeftAllowDrop"
          >
            <!--            @node-click="treeLeftNodeClick"-->
 
            <span slot-scope="{ node, data }" class="custom-tree-node">
              <span v-if="!data.isEdit">{{ data.name }}</span>
              <input
                v-if="data.isEdit"
                :ref="data.code"
                v-model="data.name"
                type="text"
                @click.stop
                @blur="treeSave(data)"
                @keyup.enter="treeSave(data)"
              >
 
              <span v-if="!data.isEdit">
                <i
                  class="el-icon-plus"
                  style="margin-right:10px;color: #999"
                  @click.stop="val=>treeAddClick(val,node,data)"
                />
                <i
                  v-if="data.code!=='000'"
                  class="el-icon-edit"
                  style="margin-right:10px;color: #999"
                  @click.stop="val=>treeEditClick(val,node,data)"
                />
                <i
                  v-if="data.code!=='000'"
                  class="el-icon-delete"
                  style="margin-right: 4px;color: #999"
                  @click.stop="val=>treeDeleteClick(val,node,data)"
                />
              </span>
            </span>
          </el-tree>
        </div>
 
        <div
          style="margin-left: 10px;width:100%;position: relative"
        >
 
          <el-table
            ref="tableDataRef"
            class="tableFixed"
            :data="tableData"
            :height="(tableHeight-40)+'px'"
            border
            row-class-name="custom-row"
            :style="{width: 100+'%',height:(tableHeight-40)+'px',marginBottom:'10px'}"
            highlight-current-row
            :header-cell-style="this.$headerCellStyle"
            :cell-style="this.$cellStyle"
            @sort-change="sortChange"
          >
            <!--            prop="RowNum"-->
            <el-table-column
              type="index"
              width="50"
              fixed
              label="序号"
            />
            <el-table-column
              prop="code"
              label="用户编码"
              sortable="custom"
            />
            <!--            <el-table-column-->
            <!--              label="操作"-->
            <!--              width="120"-->
            <!--              fixed="right"-->
            <!--            >-->
            <!--              <template slot-scope="{row}">-->
            <!--                <div class="operationClass">-->
            <!--                  <el-tooltip class="item" effect="dark" content="编辑" placement="top">-->
            <!--                    <i class="el-icon-edit-outline" @click="edit('edit',row)" />-->
            <!--                  </el-tooltip>-->
            <!--                  <el-tooltip v-del-tab-index class="item" effect="dark" content="删除" placement="top">-->
            <!--                    <i class="el-icon-delete" @click="del(row)" />-->
            <!--                  </el-tooltip>-->
            <!--                </div>-->
            <!--              </template>-->
            <!--            </el-table-column>-->
          </el-table>
 
          <!--分页-->
          <pagination
            :total="total"
            :page.sync="form.page"
            :limit.sync="form.rows"
            align="right"
            layout="total,prev, pager, next,sizes,jumper"
            popper-class="select_bottom"
            @pagination="getOrganizationSearch"
          />
 
        </div>
 
      </div>
 
    </div>
 
  </div>
</template>
 
<script>
import waves from '@/directive/waves'
import arrayToTree from 'array-to-tree'
import { throttle } from '@/utils/debounceAndThrottle'
import Pagination from '@/components/Pagination'
 
export default {
  name: 'RoleList',
  directives: { waves },
  components: {
    Pagination
  },
  data() {
    return {
      mainHeight: 0,
      tableHeight: 0,
 
      treeLeft: [
        {
          code: '000',
          name: '大岛电器',
          isEdit: false,
          children: [
            {
              code: '001',
              name: '研发部',
              isEdit: false,
              children: []
            }, {
              code: '002',
              name: '销售部',
              isEdit: false,
              children: []
            }, {
              code: '003',
              name: '生产部',
              isEdit: false,
              children: [
                {
                  code: '004',
                  name: '金工车间一',
                  isEdit: false,
                  children: []
                }, {
                  code: '005',
                  name: '金工车间二',
                  isEdit: false,
                  children: []
                }
              ]
            }
          ]
        }
      ], // 左侧树
      defaultPropsLeft: {
        children: 'children',
        label: 'name'
      },
      tableData: [
        { code: '001' },
        { code: '002' },
        { code: '003' }
      ],
      form: {
        page: 1,
        rows: 20
      },
      total: 0
 
    }
  },
  watch: {
    // treeLeft: {
    //   handler(newValue, oldValue) {
    //     newValue[0].roles.forEach(i => {
    //       if (i.isEdit) {
    //         this.$nextTick(() => {
    //           this.$refs[i.code].focus()
    //         })
    //       }
    //     })
    //   },
    //   deep: true
    // }
  },
 
  activated() {   window.addEventListener('resize', this.getHeight)   this.getHeight() }, created() {
 
  },
  mounted() {
    window.addEventListener('resize', this.getHeight)
    this.getHeight()
  },
  methods: {
    // 获取页面高度
    getHeight() {
      this.$nextTick(() => {
        this.mainHeight = window.innerHeight - 75
        this.tableHeight = this.mainHeight - 50
      })
    },
    // 左侧树形拖动处理
    treeLeftAllowDrop(draggingNode, dropNode, type) {
      // console.log(draggingNode, dropNode, type)
      // 注掉的是同级拖拽
      if (draggingNode.level === dropNode.level) {
        return type === 'prev' || type === 'next'
      } else {
        // 不同级进行处理
        return false
      }
    },
    getTreeAttr(val) {
      console.log(val, 1)
      if (val['children']) {
        val['children'].push({
          code: '',
          name: '',
          isEdit: true,
          children: []
        })
      } else {
        val.children.push(
          { code: '', name: '', isEdit: true }
        )
      }
      this.$nextTick(() => {
        this.$refs[''].focus()
      })
    },
    // 角色名称保存   采用防抖形式
    treeSave: throttle(function(val) {
      val.isEdit = false
 
      console.log('执行了!')
    }, 1000, true),
 
    treeEditClick(val, node, data) {
      data.isEdit = true
      this.$nextTick(() => {
        this.$refs[data.code].focus()
      })
    },
    treeDeleteClick(val, node, data) {
 
    },
    treeAddClick(val, node, data) {
      // console.log(val, node, data, 2)
 
      // this.treeLeft = data.children.push({ code: '', name: '', isEdit: true })
      this.getTreeAttr(data)
 
      // console.log(this.treeLeft, 3)
    },
    sortChange({ column, prop, order }) {
      if (order === 'descending') {
        order = 'desc'
      } else if (order === 'ascending') {
        order = 'asc'
      } else {
        order = 'desc'
      }
      this.form.order = order
      this.form.prop = prop
      // this.getOrganizationSearch()
    },
    getOrganizationSearch() {
 
    }
  }
}
</script>
 
<style scoped lang="scss">
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
 
//::v-deep .el-checkbox__label {
//  width: 55px;
//}
//
.el-icon-plus:hover, .el-icon-edit:hover, .el-icon-delete:hover {
  color: #000 !important;
}
</style>