|
|
|
@ -1,48 +1,48 @@ |
|
|
|
|
import React, {FC, useEffect, useState} from "react"; |
|
|
|
|
import {AddDepProps, ManageApi} from "@/api/manage"; |
|
|
|
|
import React, {FC, useCallback, useEffect, useState} from "react"; |
|
|
|
|
import {ManageApi} from "@/api/manage"; |
|
|
|
|
import {View, Input} from "@tarojs/components"; |
|
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
import {Profile} from '@/store' |
|
|
|
|
import Taro, {useRouter} from "@tarojs/taro"; |
|
|
|
|
import './depAdmin.scss' |
|
|
|
|
import PopPut from "@/components/popPut/popPut"; |
|
|
|
|
import folder from '@/static/img/folder.png' |
|
|
|
|
import {getCurrentInstance} from "@tarojs/runtime"; |
|
|
|
|
import ShowModel from "@/components/showModel/showModel"; |
|
|
|
|
import Empty from "@/components/empty/empty"; |
|
|
|
|
|
|
|
|
|
import {Profile} from '@/store' |
|
|
|
|
|
|
|
|
|
const DepAdmin: FC = () => { |
|
|
|
|
const params = getCurrentInstance()?.router?.params as { dep_id: string, name: string, id: string } |
|
|
|
|
const router = useRouter() |
|
|
|
|
// const params = getCurrentInstance()?.router?.params as { dep_id: string, name: string, id: string }
|
|
|
|
|
const [manages, setManages] = useState<Manage[]>([]) |
|
|
|
|
const [show, setShow] = useState(false) |
|
|
|
|
const [users, setUsers] = useState<User[]>([]) |
|
|
|
|
const [putCompany, setPutCompany] = useState<Manage | null>(null) |
|
|
|
|
const [isPut, setIsPut] = useState(false) |
|
|
|
|
const [depName, setDepName] = useState('') |
|
|
|
|
const {company} = Profile.useContainer() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getData() { |
|
|
|
|
show && setShow(false) |
|
|
|
|
const res = await ManageApi.depList(params.dep_id || 0) |
|
|
|
|
const res = await ManageApi.depList(router.params.dep_id || 0) |
|
|
|
|
if (res) { |
|
|
|
|
setManages(res.department) |
|
|
|
|
setUsers(res.data) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function showPop(company: Manage | null) { |
|
|
|
|
if (company) { |
|
|
|
|
setDepName(company.name) |
|
|
|
|
function showPop(name: string | undefined) { |
|
|
|
|
if (name) { |
|
|
|
|
setDepName(name) |
|
|
|
|
setIsPut(true) |
|
|
|
|
} else { |
|
|
|
|
setIsPut(false) |
|
|
|
|
setDepName('') |
|
|
|
|
} |
|
|
|
|
setPutCompany(company) |
|
|
|
|
setShow(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function del(name: string, id: number) { |
|
|
|
|
function del(name: string, id: string) { |
|
|
|
|
Taro.showModal({ |
|
|
|
|
title: name + '删除后将不可恢复', |
|
|
|
|
title: name + ' 删除后将不可恢复', |
|
|
|
|
async success({confirm}) { |
|
|
|
|
if (confirm) { |
|
|
|
|
try { |
|
|
|
@ -50,6 +50,7 @@ const DepAdmin: FC = () => { |
|
|
|
|
await ManageApi.delDep(id) |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
Taro.showToast({title: "删除成功"}) |
|
|
|
|
Taro.navigateBack() |
|
|
|
|
await getData() |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
@ -58,27 +59,27 @@ const DepAdmin: FC = () => { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function managesSheet(item: Manage) { |
|
|
|
|
function jumpDepAdmin(item: Manage) { |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?dep_id=${item.id}&name=${encodeURI(item.name)}&id=${item.id}`}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function managesSheet() { |
|
|
|
|
Taro.showActionSheet({ |
|
|
|
|
itemList: [ |
|
|
|
|
'查看部门课程', |
|
|
|
|
'查看子部门和学员', |
|
|
|
|
'修改部门', |
|
|
|
|
'修改当前部门名称', |
|
|
|
|
'删除部门' |
|
|
|
|
], |
|
|
|
|
success({tapIndex}) { |
|
|
|
|
switch (tapIndex) { |
|
|
|
|
case 0: |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depCur/depCur?id=${item.id}`}) |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depCur/depCur?id=${router.params.id}`}) |
|
|
|
|
break |
|
|
|
|
case 1: |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?dep_id=${item.id}&name=${encodeURI(item.name)}&id=${item.id}`}) |
|
|
|
|
showPop(decodeURI(router.params.name!)) |
|
|
|
|
break |
|
|
|
|
case 2: |
|
|
|
|
showPop(item) |
|
|
|
|
break |
|
|
|
|
case 3: |
|
|
|
|
del(item.name, item.id) |
|
|
|
|
del(decodeURI(router.params.name!), router.params.id!) |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
@ -92,40 +93,41 @@ const DepAdmin: FC = () => { |
|
|
|
|
Taro.navigateTo({url: '/pages/manage/addStudent/addStudent'}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function addDep() { |
|
|
|
|
if (!depName) { |
|
|
|
|
Taro.showToast({title: "请认真填写", icon: "error"}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
const addDep = useCallback(async () => { |
|
|
|
|
try { |
|
|
|
|
const company_id = putCompany?.company_id || company?.id || 0 |
|
|
|
|
const data: AddDepProps = { |
|
|
|
|
id: putCompany?.id || null, |
|
|
|
|
name: depName, |
|
|
|
|
parent_id: putCompany ? putCompany?.parent_id : manages.length, |
|
|
|
|
company_id: company_id, |
|
|
|
|
sort: putCompany?.sort || 0 |
|
|
|
|
} |
|
|
|
|
if (putCompany) { |
|
|
|
|
await ManageApi.putDep(data) |
|
|
|
|
if (isPut) { |
|
|
|
|
await ManageApi.putDep(router.params.id!, depName) |
|
|
|
|
router.params.name = depName |
|
|
|
|
Taro.setNavigationBarTitle({ |
|
|
|
|
title: depName |
|
|
|
|
}) |
|
|
|
|
} else { |
|
|
|
|
await ManageApi.addDep(data) |
|
|
|
|
await ManageApi.addDep({ |
|
|
|
|
name: depName, |
|
|
|
|
parent_id: Number(router.params.dep_id) || 0, |
|
|
|
|
company_id: company?.id!, |
|
|
|
|
sort: manages.length, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
setTimeout(() => Taro.showToast({title: '操作成功'})) |
|
|
|
|
await getData() |
|
|
|
|
setShow(false) |
|
|
|
|
} catch (e) { |
|
|
|
|
Taro.showToast({title: '操作失败', icon: 'error'}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Taro.useDidShow()
|
|
|
|
|
}, [isPut, depName]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getData() |
|
|
|
|
Taro.setNavigationBarTitle({ |
|
|
|
|
title: decodeURI(params.name) ?? '部门管理' |
|
|
|
|
title: decodeURI(router.params.name!) || '部门管理' |
|
|
|
|
}) |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
Taro.useDidShow(() => { |
|
|
|
|
if (manages.length) { |
|
|
|
|
getData() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<View> |
|
|
|
@ -133,7 +135,7 @@ const DepAdmin: FC = () => { |
|
|
|
|
{manages.map(d => <PopPut |
|
|
|
|
key={d.id} |
|
|
|
|
title={d.name} |
|
|
|
|
onClick={() => managesSheet(d)} |
|
|
|
|
onClick={() => jumpDepAdmin(d)} |
|
|
|
|
chevron |
|
|
|
|
leftImage={folder} |
|
|
|
|
/>)} |
|
|
|
@ -151,14 +153,17 @@ const DepAdmin: FC = () => { |
|
|
|
|
<View className='operation'> |
|
|
|
|
<View className='safeAreaInsetBottom'> |
|
|
|
|
<View onClick={jumpAddStudent}>添加学员</View> |
|
|
|
|
<View onClick={() => showPop(null)}>添加部门</View> |
|
|
|
|
<View onClick={() => showPop(undefined)}>添加部门</View> |
|
|
|
|
{ |
|
|
|
|
router.params.id && <View onClick={managesSheet}>更多操作</View> |
|
|
|
|
} |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<ShowModel |
|
|
|
|
show={show} |
|
|
|
|
title={putCompany?.name ? `修改${putCompany.name}` : '添加部门'} |
|
|
|
|
title={router.params.name ? `修改${decodeURI(router.params.name)}` : '添加部门'} |
|
|
|
|
onClickOverlay={() => setShow(false)} |
|
|
|
|
onOk={addDep} |
|
|
|
|
> |
|
|
|
|