|
|
|
@ -1,81 +1,14 @@ |
|
|
|
|
import {FC, useEffect, useState} from "react"; |
|
|
|
|
import React, {FC, useEffect, useState} from "react"; |
|
|
|
|
import {AddDepProps, ManageApi} from "@/api/manage"; |
|
|
|
|
import {Button, View, Input, Form} from "@tarojs/components"; |
|
|
|
|
import {View, Input} from "@tarojs/components"; |
|
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
import {Profile} from '@/store' |
|
|
|
|
import './depAdmin.scss' |
|
|
|
|
import PopPut from "@/components/popPut/popPut"; |
|
|
|
|
import folder from '@/static/img/folder.png' |
|
|
|
|
import {getCurrentInstance} from "@tarojs/runtime"; |
|
|
|
|
import CustomPageContainer from "@/components/custom-page-container/custom-page-container"; |
|
|
|
|
import ShowModel from "@/components/showModel/showModel"; |
|
|
|
|
|
|
|
|
|
interface ChangeDataProps { |
|
|
|
|
putCompany: Manage | null |
|
|
|
|
parent_id: number |
|
|
|
|
getDeps: () => Promise<void> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const ChangeData: FC<ChangeDataProps> = ({putCompany, getDeps, parent_id}: ChangeDataProps) => { |
|
|
|
|
const {company} = Profile.useContainer() |
|
|
|
|
const [name, setName] = useState<string>('') |
|
|
|
|
const [disable, setDisable] = useState(false) |
|
|
|
|
const company_id = putCompany?.company_id || company?.id || 0 |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (putCompany) { |
|
|
|
|
setName(putCompany.name) |
|
|
|
|
} |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
async function submit() { |
|
|
|
|
if (!name) { |
|
|
|
|
Taro.showToast({title: "请认真填写", icon: "error"}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
setDisable(true) |
|
|
|
|
Taro.showLoading() |
|
|
|
|
try { |
|
|
|
|
const data: AddDepProps = { |
|
|
|
|
id: putCompany?.id || null, |
|
|
|
|
name, |
|
|
|
|
parent_id: putCompany?.parent_id || parent_id || 0, |
|
|
|
|
company_id: company_id, |
|
|
|
|
sort: putCompany?.sort || 0 |
|
|
|
|
} |
|
|
|
|
if (putCompany) { |
|
|
|
|
await ManageApi.putDep(data) |
|
|
|
|
} else { |
|
|
|
|
await ManageApi.addDep(data) |
|
|
|
|
} |
|
|
|
|
setTimeout(() => Taro.showToast({title: '操作成功'})) |
|
|
|
|
await getDeps() |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
setDisable(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View className='depForm'> |
|
|
|
|
<View className='mt-2 text-center font-weight font-34'>{putCompany ? '修改' + putCompany.name : '添加部门'}</View> |
|
|
|
|
<Form className='form mt-3'> |
|
|
|
|
<View className='item'> |
|
|
|
|
<View>名称:</View> |
|
|
|
|
<Input |
|
|
|
|
focus |
|
|
|
|
confirmHold |
|
|
|
|
holdKeyboard |
|
|
|
|
cursorSpacing={151} |
|
|
|
|
placeholder='请输入部门名称' |
|
|
|
|
value={name} |
|
|
|
|
onInput={(event) => setName(event.detail.value)}/> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<Button className='mt-3 button' formType='submit' onClick={submit} disabled={disable}>保存</Button> |
|
|
|
|
</Form> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const DepAdmin: FC = () => { |
|
|
|
|
const params = getCurrentInstance()?.router?.params as { dep_id: string, name: string, id: string } |
|
|
|
@ -83,6 +16,9 @@ const DepAdmin: FC = () => { |
|
|
|
|
const [show, setShow] = useState(false) |
|
|
|
|
const [users, setUsers] = useState<User[]>([]) |
|
|
|
|
const [putCompany, setPutCompany] = useState<Manage | null>(null) |
|
|
|
|
const [depName, setDepName] = useState('') |
|
|
|
|
const {company} = Profile.useContainer() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getData() { |
|
|
|
|
show && setShow(false) |
|
|
|
@ -94,6 +30,11 @@ const DepAdmin: FC = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function showPop(company: Manage | null) { |
|
|
|
|
if (company) { |
|
|
|
|
setDepName(company.name) |
|
|
|
|
} else { |
|
|
|
|
setDepName('') |
|
|
|
|
} |
|
|
|
|
setPutCompany(company) |
|
|
|
|
setShow(true) |
|
|
|
|
} |
|
|
|
@ -129,12 +70,12 @@ const DepAdmin: FC = () => { |
|
|
|
|
case 0: |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depCur/depCur?id=${item.id}`}) |
|
|
|
|
break |
|
|
|
|
case 2: |
|
|
|
|
showPop(item) |
|
|
|
|
break |
|
|
|
|
case 1: |
|
|
|
|
Taro.navigateTo({url: `/pages/manage/depAdmin/depAdmin?dep_id=${item.id}&name=${item.name}&id=${item.id}`}) |
|
|
|
|
break |
|
|
|
|
case 2: |
|
|
|
|
showPop(item) |
|
|
|
|
break |
|
|
|
|
case 3: |
|
|
|
|
del(item.name, item.id) |
|
|
|
|
break |
|
|
|
@ -216,8 +157,32 @@ const DepAdmin: FC = () => { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Taro.useDidShow(getData) |
|
|
|
|
async function addDep() { |
|
|
|
|
if (!depName) { |
|
|
|
|
Taro.showToast({title: "请认真填写", icon: "error"}) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
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) |
|
|
|
|
} else { |
|
|
|
|
await ManageApi.addDep(data) |
|
|
|
|
} |
|
|
|
|
setTimeout(() => Taro.showToast({title: '操作成功'})) |
|
|
|
|
await getData() |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Taro.useDidShow(getData) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
Taro.setNavigationBarTitle({ |
|
|
|
@ -226,7 +191,7 @@ const DepAdmin: FC = () => { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Profile.Provider> |
|
|
|
|
<> |
|
|
|
|
<View> |
|
|
|
|
{manages.map(d => <PopPut |
|
|
|
|
key={d.id} |
|
|
|
@ -236,15 +201,13 @@ const DepAdmin: FC = () => { |
|
|
|
|
leftImage={folder} |
|
|
|
|
/>)} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
users.map(d => <PopPut |
|
|
|
|
key={d.id} |
|
|
|
|
leftImage={d.avatar} |
|
|
|
|
title={d.name} |
|
|
|
|
onClick={() => userManagesSheet(d)} |
|
|
|
|
content={['学员', '管理员', '超级管理员'][d.role_type]} |
|
|
|
|
/>) |
|
|
|
|
} |
|
|
|
|
{users.map(d => <PopPut |
|
|
|
|
key={d.id} |
|
|
|
|
leftImage={d.avatar} |
|
|
|
|
title={d.name} |
|
|
|
|
onClick={() => userManagesSheet(d)} |
|
|
|
|
content={['学员', '管理员', '超级管理员'][d.role_type]} |
|
|
|
|
/>)} |
|
|
|
|
|
|
|
|
|
<View className='text-center text-muted mt-3'>- 暂无更多 -</View> |
|
|
|
|
|
|
|
|
@ -256,13 +219,27 @@ const DepAdmin: FC = () => { |
|
|
|
|
</View> |
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
|
<CustomPageContainer show={show} round onAfterLeave={() => setShow(false)}> |
|
|
|
|
<View> |
|
|
|
|
{show && <ChangeData getDeps={getData} putCompany={putCompany} parent_id={Number(params.id)}/>} |
|
|
|
|
</View> |
|
|
|
|
</CustomPageContainer> |
|
|
|
|
<ShowModel |
|
|
|
|
show={show} |
|
|
|
|
title={putCompany?.name ? `修改${putCompany.name}` : '添加部门'} |
|
|
|
|
onClickOverlay={() => setShow(false)} |
|
|
|
|
onOk={addDep} |
|
|
|
|
> |
|
|
|
|
<Input placeholder='添加部门名称' |
|
|
|
|
className='depInput' |
|
|
|
|
value={depName} |
|
|
|
|
onInput={(e) => setDepName(e.detail.value)}/> |
|
|
|
|
</ShowModel> |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const DepAdminIndex: FC = () => { |
|
|
|
|
return ( |
|
|
|
|
<Profile.Provider> |
|
|
|
|
<DepAdmin/> |
|
|
|
|
</Profile.Provider> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default DepAdmin |
|
|
|
|
export default DepAdminIndex |
|
|
|
|