Mr.Shi
2023-08-11 5a7fb4358eb902ce139096f20ef3c0625adcd7f4
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
<template>
  <TableLayout v-permissions="['ext:departmentext:query']">
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['ext:departmentext:delete']">
<!--        <li><el-button type="primary" @click="$refs.operaDepartmentExtWindow.open('新建组织信息')" icon="el-icon-plus" v-permissions="['ext:departmentext:create']">新建</el-button></li>-->
        <li><el-button type="danger" plain @click="deleteByIdInBatch" v-permissions="['ext:departmentext:delete']">删除</el-button></li>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        row-key="id"
        stripe
        border
        default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" fixed="left" width="55"></el-table-column>
        <el-table-column prop="name" label="组织名称" fixed="left" min-width="180px">
          <template slot-scope="{row}">
            <span
              style="max-width: 170px;"
              class="long-title-style"
              :title="row.name"
            >{{ row.name }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="type" label="组织类型" min-width="100px">
          <template slot-scope="{row}">
            {{ typeToStr(row.type) }}
          </template>
        </el-table-column>
        <el-table-column prop="eare" label="省市区" min-width="140px">
          <template slot-scope="{row}">
            {{ row.eare || '-' }}
           </template>
        </el-table-column>
        <el-table-column label="主组织" min-width="140px">
          <template slot-scope="{row}">
            {{ row.isMain == 1 ? '是' : '否' }}
           </template>
        </el-table-column>
        <!-- <el-table-column prop="createName" label="创建人" min-width="100px"></el-table-column> -->
        <el-table-column prop="creatorUsername" label="创建人" min-width="100px"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="140px"></el-table-column>
        <el-table-column prop="updateUsername" label="更新人" min-width="100px">
          <template slot-scope="{row}">
            {{ row.updateUsername || '-' }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="updateName" label="更新人" min-width="100px"></el-table-column> -->
        <el-table-column prop="updateTime" label="更新时间" min-width="140px">
          <template slot-scope="{row}">
            {{ row.updateTime || '-' }}
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="160"
          fixed="right"
        >
          <template slot-scope="{row}">
            <el-button v-if="row.isMain!=1" type="text" @click="editDepartment(row)" v-permissions="['ext:departmentext:update']">编辑</el-button>
            <el-button v-if="row.type!=3" type="text" @click="addSonDepartment(row)" v-permissions="['ext:departmentext:create']">新建子组织</el-button>
            <span v-if="row.isMain!=1" v-permissions="['ext:departmentext:delete']" style="margin-left:8px">
              <el-button type="text" @click="deleteById(row)">删除</el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      >
      </pagination> -->
      <div style="height:20px"></div>
    </template>
    <!-- 新建/修改 -->
    <OperaDepartmentExtWindow ref="operaDepartmentExtWindow" @success="handlePageChange"/>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
// import Pagination from '@/components/common/Pagination'
import OperaDepartmentExtWindow from '@/components/ext/OperaDepartmentExtWindow'
export default {
  name: 'DepartmentExt',
  extends: BaseTable,
  components: { TableLayout, OperaDepartmentExtWindow },
  data () {
    return {
      searchForm: {
        // deleted: 0,
        companyId: this.$store.state.userInfo.company.id
      }
    }
  },
  created () {
    this.config({
      module: '组织信息',
      api: '/ext/departmentExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    this.search()
  },
  methods: {
    typeToStr (type) {
      // 0公司 1工厂 2部门 3班组 4平台组织
      switch (type) {
      case 0:
        return '公司'
      case 1:
        return '工厂'
      case 2:
        return '部门'
      case 3:
        return '班组'
      case 4:
        return '平台组织'
      default:
        return ''
      }
    },
    addSonDepartment (row) {
      // console.log(row)
      const param = {}
      // param.id = row.id
      if (row.isMain) {
        param.pType = 4
      } else {
        param.pType = row.type
      }
      param.parentId = row.id
      param.parentName = row.name
      this.$refs.operaDepartmentExtWindow.open('创建组织', param, false)
    },
    editDepartment (row) {
      console.log(row)
      const param = {}
      if (row.pmodel.id === this.tableData.list[0].id) {
        param.pType = 4
      } else {
        param.pType = row.pmodel.type
      }
      param.id = row.id
      param.parentId = row.pmodel.id
      param.parentName = row.pmodel.name
      param.type = row.type
      param.name = row.name
      this.$refs.operaDepartmentExtWindow.open('编辑组织', param, true)
    },
    handlePageChange (pageIndex) {
      this.__checkApi()
      this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
      this.isWorking.search = true
      this.api.fetchList({
        // page: this.tableData.pagination.pageIndex,
        // capacity: this.tableData.pagination.pageSize,
        // model: this.searchForm,
        // sorts: this.tableData.sorts
      })
        .then(data => {
          const rootData = data
          rootData.isMain = 1
          this.tableData.list = [rootData]
          this.tableData.pagination.total = data.total
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking.search = false
        })
    }
  }
}
</script>