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