k94314517
2025-04-08 76664d76edb8d6b28d11975bd7fe09c5e27caa34
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
<template>
  <TableLayout>
    <!--        :permissions="['business:company:query']"-->
    <!-- 搜索表单 -->
    <!--        <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>-->
    <!--            <el-form-item label="组织名称" prop="name">-->
    <!--                <el-input v-model="searchForm.name" placeholder="请输入组织名称" @keypress.enter.native="search"></el-input>-->
    <!--            </el-form-item>-->
    <!--            <el-form-item label="所属上级组织" prop="parentName">-->
    <!--                <el-input v-model="searchForm.parentName" placeholder="请输入所属上级组织" @keypress.enter.native="search"></el-input>-->
    <!--            </el-form-item>-->
    <!--            <section>-->
    <!--                <el-button type="primary" @click="search">搜索</el-button>-->
    <!--                <el-button @click="reset">重置</el-button>-->
    <!--            </section>-->
    <!--        </el-form>-->
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['business:company:create', 'business:company:sync']">
<!--        <li><el-button type="primary" v-permissions="['business:company:create']"-->
<!--            @click="$refs.OperaInternalCompanyWindow.open('新建企业', null, null)">新建</el-button></li>-->
        <li><el-button @click="sort('top')" :loading="sorting" icon="el-icon-sort-up"
            v-permissions="['business:company:sort']">上移</el-button></li>
        <li><el-button @click="sort('bottom')" :loading="sorting" icon="el-icon-sort-down"
            v-permissions="['business:company:sort']">下移</el-button></li>
        <li><el-button type="primary" v-permissions="['business:company:sync']" :loading="loading"
            @click="synchronous()">同步</el-button></li>
      </ul>
      <el-table :max-height="tableHeight" v-loading="isWorking.search" :data="list" stripe
        :tree-props="{ children: 'childList', hasChildren: 'hasChildren' }" row-key="id"
        @selection-change="handleSelectionChange" default-expand-all>
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="name" label="组织名称" min-width="100px"></el-table-column>
        <el-table-column prop="name" label="组织类型" min-width="80px">
          <template scope="{row}">
            <span v-if="row.type == 0">相关方组织</span>
            <span v-if="row.type == 1">内部组织</span>
          </template>
        </el-table-column>
        <el-table-column prop="companyNamePath" label="组织路径" min-width="100px"></el-table-column>
        <el-table-column prop="editorName" label="操作人" width="100px"></el-table-column>
        <el-table-column prop="editDate" label="最后更新时间" min-width="100px"></el-table-column>
        <el-table-column label="操作" width="230" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text"
              @click="$refs.OperaInternalCompanyWindow.open('编辑企业信息', { id: row.parentId, name: row.parentName, type: row.parentType, companyPath: row.parentCompanyPath }, row, 'edit')"
              icon="el-icon-edit" v-permissions="['business:company:update']">编辑</el-button>
            <el-button type="text" @click="$refs.OperaInternalCompanyWindow.open('新建子级', row, null, 'add')"
              icon="el-icon-plus">新建子级</el-button>
            <el-button type="text" @click="deleteById(row)" style="color: red" icon="el-icon-delete"
              v-permissions="['business:company:delete']" v-if="row.type !== -1">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <!-- 新建/修改 -->
    <OperaInternalCompanyWindow ref="OperaInternalCompanyWindow" :list="list" @success="handlePageChange" />
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import { companySync, sort } from '@/api/business/company'
import OperaInternalCompanyWindow from '@/components/business/OperaInternalCompanyWindow'
export default {
  name: 'internalCompany',
  extends: BaseTable,
  components: { TableLayout, OperaInternalCompanyWindow },
  data() {
    return {
      // 搜索
      loading: false,
      sorting: false,
      searchForm: {
        // type: 1
      },
      list: [],
      total: 0
    }
  },
  created() {
    this.config({
      module: '企业信息表',
      api: '/business/company',
      'field.id': 'id',
      'field.main': 'id'
    })
    this.search()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = document.body.scrollHeight - 220
    })
  },
  methods: {
    // 页码变更处理
    handlePageChange(pageIndex) {
      this.__checkApi()
      this.isWorking.search = true
      this.api.fetchList(this.searchForm.type)
        .then(data => {
          this.list = data
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking.search = false
        })
    },
    // 同步信息
    async synchronous() {
      this.$dialog.actionConfirm('该操作将系统清空已有组织信息,您确认同步全部信息吗?', '操作确认提醒')
        .then(() => {
          this.loading = true
          companySync({})
            .then(res => {
              this.$tip.apiSuccess(res || '同步成功')
              this.search()
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.loading = false
            })
        })
        .catch(() => { })
    },
    // 排序
    sort(direction) {
      if (this.sorting) {
        return
      }
      if (this.tableData.selectedRows.length === 0) {
        this.$tip.warning('请选择一条数据')
        return
      }
      if (this.tableData.selectedRows.length > 1) {
        this.$tip.warning('排序时仅允许选择一条数据')
        return
      }
      const menuId = this.tableData.selectedRows[0].id
      // 找到菜单范围
      let menuPool
      for (const rootMenu of this.list) {
        console.log(this.list)
        const parent = this.__findParent(menuId, rootMenu)
        if (parent != null) {
          menuPool = parent.children
        }
      }
      menuPool = menuPool || this.list
      const menuIndex = menuPool.findIndex(menu => menu.id === menuId)
      // 上移校验
      if (direction === 'top' && menuIndex === 0) {
        this.$tip.warning('菜单已到顶部')
        return
      }
      // 下移校验
      if (direction === 'bottom' && menuIndex === menuPool.length - 1) {
        this.$tip.warning('菜单已到底部')
        return
      }
      this.sorting = true
      sort({
        id: this.tableData.selectedRows[0].id,
        direction
      })
        .then(() => {
          /* if (direction === 'top') {
             menuPool.splice(menuIndex, 0, menuPool.splice(menuIndex - 1, 1)[0])
           } else {
             menuPool.splice(menuIndex, 0, menuPool.splice(menuIndex + 1, 1)[0])
           }*/
          this.search()
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.sorting = false
        })
    },
    // 查询父节点
    __findParent(id, parent) {
      if (parent.childList === 0) {
        return
      }
      for (const menu of parent.childList) {
        if (menu.id === id) {
          return parent
        }
        if (menu.childList.length > 0) {
          const m = this.__findParent(id, menu)
          if (m != null) {
            return m
          }
        }
      }
      return null
    }
  }
}
</script>