| <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> |