| <template> | 
|   <TableLayout> | 
|     <template v-slot:table-wrap> | 
|       <ul class="toolbar" v-permissions="['business:shop:create', 'business:shop:sync','business:shop:sort']"> | 
|         <li><el-button type="primary" @click="$refs.OperaShopImportWindow.open('初始化导入')"  icon="el-icon-plus" v-permissions="['business:shop:create']">初始化导入</el-button></li> | 
|         <li><el-button @click="resetRelations" type="primary" :loading="sorting" icon="el-icon-edit" v-permissions="['business:shop:update']">重置上下级关系</el-button></li> | 
|         <li><el-button type="primary" @click="$refs.OperaFcodeImportWindow.open('Fcode信息导入')"  icon="el-icon-plus" v-permissions="['business:shop:create']">Fcode信息导入</el-button></li> | 
|         <li><el-button type="primary" @click="$refs.OperaCategoryImportWindow.open('品类初始化导入')"  icon="el-icon-plus" v-permissions="['business:shop:create']">品类初始化导入</el-button></li> | 
|         <li><el-button @click="sort('top')" :loading="sorting" icon="el-icon-sort-up" v-permissions="['business:shop:sort']">上移</el-button></li> | 
|         <li><el-button @click="sort('bottom')" :loading="sorting" icon="el-icon-sort-down" v-permissions="['business:shop:sort']">下移</el-button></li> | 
|       </ul> | 
|   | 
|       <!-- | 
|       default-expand-all | 
|           @expand-change="handleExpandChange" | 
|           :tree-props="{children: 'childList',hasChildren: 'hasChildren'}"--> | 
|       <el-table | 
|           v-loading="isWorking.search" | 
|           :data="list" | 
|           stripe | 
|           lazy | 
|           :load="loadChild" | 
|           :tree-props="{children: 'childList',hasChildren: 'hasChildren'}" | 
|           row-key="id" | 
|           @selection-change="handleSelectionChange" | 
|       > | 
|         <el-table-column type="selection" width="55"></el-table-column> | 
|         <el-table-column prop="name" label="组织名称" min-width="300px"></el-table-column> | 
|         <el-table-column prop="type" label="一级类型" min-width="100px"> | 
|           <template scope="{row}"> | 
|             <span v-if="row.type == 1">HR</span> | 
|             <span v-if="row.type == 2">加盟商</span> | 
|             <span v-if="row.type == 3">虚拟组织</span> | 
|           </template> | 
|         </el-table-column> | 
|         <el-table-column prop="type" label="二级类型" min-width="100px"> | 
|           <template scope="{row}"> | 
|             <span v-if="row.secondType == 1">S</span> | 
|             <span v-if="row.secondType == 2">F</span> | 
|             <span v-if="row.secondType == 3">店面</span> | 
|             <span v-if="row.secondType == 4">部门</span> | 
|             <span v-if="row.secondType == 5">虚拟店面</span> | 
|           </template> | 
|         </el-table-column> | 
|         <el-table-column prop="attribute" label="部门属性" min-width="80px"> | 
|           <template scope="{row}"> | 
|             <span v-if="row.attribute == 1">实体店面</span> | 
|             <span v-if="row.attribute == 2">虚拟店面</span> | 
|             <span v-if="row.attribute == 3">电商部</span> | 
|             <span v-if="row.attribute == 4">渠道部</span> | 
|             <span v-if="row.attribute == 5">财务部</span> | 
|           </template> | 
|         </el-table-column> | 
|         <el-table-column prop="status" label="状态" min-width="80px"> | 
|           <template scope="{row}"> | 
|             <span v-if="row.status == 0" style="color: red">停用</span> | 
|             <span v-if="row.status == 1" style="color: green">正常</span> | 
|             <span v-if="row.status == 2" style="color: grey">已删除</span> | 
|           </template> | 
|         </el-table-column> | 
| <!-- | 
|         <el-table-column prop="namePath" label="组织路径" min-width="200px"></el-table-column> | 
| --> | 
| <!-- | 
|         <el-table-column prop="syncDate" label="最后同步时间" min-width="120px"></el-table-column> | 
| --> | 
|         <el-table-column prop="editDate" label="最后更新时间" min-width="120px"></el-table-column> | 
|         <!--      <el-table-column | 
|                  label="操作" | 
|                  width="230" | 
|                  fixed="right" | 
|              > | 
|                <template slot-scope="{row}"> | 
|                 <el-button type="text" @click="$refs.OperaShopWindow.open('编辑组织信息',{  id: row.parentId,name:row.parentName,type:row.parentType, companyPath:row.parentCompanyPath}, row)" icon="el-icon-edit" v-permissions="['business:shop:update']">编辑</el-button> | 
|                  <el-button type="text" @click="$refs.OperaShopWindow.open('新建子级',  row,null)" icon="el-icon-plus">新建子级</el-button> | 
|                  <el-button type="text" @click="deleteById(row)" style="color: red" icon="el-icon-delete" v-permissions="['business:shop:delete']">删除</el-button> | 
|           </template> | 
|         </el-table-column>--> | 
|       </el-table> | 
|     </template> | 
|     <!-- 新建/修改 --> | 
|     <OperaShopWindow ref="OperaShopWindow" :list="list" @success="handlePageChange"/> | 
|     <OperaShopImportWindow ref="OperaShopImportWindow"  @success="handlePageChange"/> | 
|     <OperaFcodeImportWindow ref="OperaFcodeImportWindow"  @success="handlePageChange"/> | 
|     <OperaCategoryImportWindow ref="OperaCategoryImportWindow"  @success="handlePageChange"/> | 
|   </TableLayout> | 
| </template> | 
|   | 
| <script> | 
| import BaseTable from '@/components/base/BaseTable' | 
| import TableLayout from '@/layouts/TableLayout' | 
| import { companySync, sort, resetRelations } from '@/api/business/shop' | 
| import OperaShopImportWindow from '@/components/business/OperaShopImportWindow' | 
| import OperaFcodeImportWindow from '@/components/business/OperaFcodeImportWindow' | 
| import OperaCategoryImportWindow from '@/components/business/OperaCategoryImportWindow' | 
| import OperaShopWindow from '@/components/business/OperaShopWindow' | 
| export default { | 
|   name: 'shopTree', | 
|   extends: BaseTable, | 
|   components: { TableLayout, OperaShopImportWindow, OperaShopWindow, OperaFcodeImportWindow,OperaCategoryImportWindow }, | 
|   data () { | 
|     return { | 
|       // 搜索 | 
|       loading: false, | 
|       sorting: false, | 
|       searchForm: { | 
|       }, | 
|       list: [], | 
|       total: 0 | 
|     } | 
|   }, | 
|   created () { | 
|     this.config({ | 
|       module: '组织信息表', | 
|       api: '/business/shop', | 
|       'field.id': 'id', | 
|       'field.main': 'id' | 
|     }) | 
|     this.search() | 
|   }, | 
|   methods: { | 
|     handleExpandChange (row, expandedRows) { | 
|       console.log(row) | 
|       console.log(expandedRows) | 
|       if (row) { | 
|         this.loadChild(row, (data) => { | 
|           this.$set(row, 'childList', data) | 
|         }) | 
|       } | 
|     }, | 
|     loadChild (row, treeNode, resolve) { | 
|       // 模拟异步加载子节点数据 | 
|       var that = this | 
|       setTimeout(() => { | 
|         that.isWorking.search = true | 
|         that.api.fetchListByParent(row.orgId) | 
|           .then(data => { | 
|             resolve(data) | 
|           }) | 
|           .catch(e => { | 
|           }) | 
|           .finally(() => { | 
|             that.isWorking.search = false | 
|           }) | 
|       }, 10) | 
|     }, | 
|     // 页码变更处理 | 
|     handlePageChange (pageIndex) { | 
|       this.__checkApi() | 
|       this.isWorking.search = true | 
|       this.api.fetchListByParent(null) | 
|         .then(data => { | 
|           this.list = data | 
|           this.list.forEach(item =>{ | 
|             item.hasChildern = true | 
|             item.childList = [] | 
|           }) | 
|         }) | 
|         .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 => { | 
|             }) | 
|             .finally(() => { | 
|               this.loading = false | 
|             }) | 
|         }) | 
|         .catch(() => {}) | 
|     }, | 
|     resetRelations () { | 
|       if (this.sorting) { | 
|         return | 
|       } | 
|       this.sorting = true | 
|       resetRelations({}) | 
|         .then(() => { | 
|           this.$tip.apiSuccess('发起重置上下级关系任务成功,请稍后刷新页面查看') | 
|         }) | 
|         .catch(e => { | 
|         }) | 
|         .finally(() => { | 
|           this.sorting = false | 
|         }) | 
|     }, | 
|     // 排序 | 
|     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 => { | 
|         }) | 
|         .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> |