From 475570da046b3f7b6c59e36e330b7eb54ea9be76 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Wed, 2 Aug 2023 16:45:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=83=A8=E9=97=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=9C=AC=E5=9C=B0(=E7=BC=93=E5=AD=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.config.ts | 1 + src/pages/manage/addStudent/addStudent.tsx | 55 ++++++------------ .../manage/selectDep/selectDep.config.ts | 3 + src/pages/manage/selectDep/selectDep.tsx | 58 +++++++++++++++++++ 4 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 src/pages/manage/selectDep/selectDep.config.ts create mode 100644 src/pages/manage/selectDep/selectDep.tsx diff --git a/src/app.config.ts b/src/app.config.ts index f72eb8c..063735c 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -61,6 +61,7 @@ export default defineAppConfig({ 'depCur/depCur', 'addCur/addCur', 'spotMeeting/spotMeeting', + 'selectDep/selectDep', ] } ], diff --git a/src/pages/manage/addStudent/addStudent.tsx b/src/pages/manage/addStudent/addStudent.tsx index 5397ab8..f10d161 100644 --- a/src/pages/manage/addStudent/addStudent.tsx +++ b/src/pages/manage/addStudent/addStudent.tsx @@ -1,5 +1,5 @@ import {Button, Form, Input, View} from "@tarojs/components"; -import {useEffect, useState} from "react"; +import {useCallback, useEffect, useState} from "react"; import {ManageApi, Student} from "@/api/manage"; import Icon from "@/components/icon"; import Taro from "@tarojs/taro"; @@ -7,7 +7,6 @@ import {curriculum} from "@/api"; import './addStudent.scss' import {getCurrentInstance} from "@tarojs/runtime"; import {Profile} from '@/store' -import CustomPageContainer from "@/components/custom-page-container/custom-page-container"; interface Department { id: number @@ -17,7 +16,6 @@ interface Department { const AddStudent = () => { const [userInfo, setUerInfo] = useState(null) const [department, setDepartment] = useState([]) - const [show, setShow] = useState(false) const [depIds, setDepIds] = useState([]) const params = getCurrentInstance()?.router?.params as { id?: number } const [disable, setDisable] = useState(false) @@ -53,33 +51,18 @@ const AddStudent = () => { Taro.navigateBack() }, 500) } catch (e) { - console.log(e) } Taro.hideLoading() setDisable(true) } - function changeDepIds(item: Department) { - const ids: number[] = JSON.parse(JSON.stringify(depIds)) - const index = depIds.indexOf(item.id) - if (index === -1) { - ids.push(item.id) - } else { - ids.splice(index, 1) - } - if (ids.length < 1) { - Taro.showToast({title: '最少一个部门'}) - return - } - setDepIds(ids) - } - - function formatDep() { + const formatDep = useCallback(() => { + console.log(depIds,12) const selected = department.filter(d => depIds.includes(d.id)).map(d => d.title) const top4 = selected.splice(0, 3).join('、') return top4 + (selected.length ? "+" + selected.length : '') - } + }, [depIds]) async function getUserInfo() { const res = await ManageApi.userInfo(params.id!) @@ -87,12 +70,24 @@ const AddStudent = () => { setDepIds(res.dep_ids) } + const jumSetDep = useCallback(() => { + Taro.navigateTo({url: `/pages/manage/selectDep/selectDep?depIds=${JSON.stringify(depIds)}`}) + }, [depIds]) + useEffect(() => { getDepartment() if (params.id) { getUserInfo() } - }, [params.id]) + }, []) + + Taro.useDidShow(() => { + const deps = Taro.getStorageSync('selectDep') + if (deps && deps.length) { + setDepIds(deps) + Taro.removeStorageSync('selectDep') + } + }) return ( @@ -116,7 +111,7 @@ const AddStudent = () => { 所属部门 - setShow(true)}> + {depIds.length ? formatDep() : '请选择'} @@ -126,20 +121,6 @@ const AddStudent = () => { - - - setShow(false)}>确定 - - {department?.map(item => { - return ( - changeDepIds(item)}> - {item.title} - - ) - })} - - ) } diff --git a/src/pages/manage/selectDep/selectDep.config.ts b/src/pages/manage/selectDep/selectDep.config.ts new file mode 100644 index 0000000..0238bd6 --- /dev/null +++ b/src/pages/manage/selectDep/selectDep.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '选择部门', +}) diff --git a/src/pages/manage/selectDep/selectDep.tsx b/src/pages/manage/selectDep/selectDep.tsx new file mode 100644 index 0000000..3a6c125 --- /dev/null +++ b/src/pages/manage/selectDep/selectDep.tsx @@ -0,0 +1,58 @@ +import React, {FC, useCallback, useEffect, useState} from "react"; +import {Checkbox, View} from "@tarojs/components"; +import Taro from "@tarojs/taro"; +import {curriculum} from "@/api"; +import PopPut from "@/components/popPut/popPut"; +import folder from "@/static/img/folder.png"; +import MyButton from "@/components/button/MyButton"; + +const SelectDep: FC = () => { + const {depIds} = Taro.getCurrentInstance()?.router?.params as { depIds: string } + const [ids, setIds] = useState([]) + const [deps, setDeps] = useState([]) + + useEffect(() => { + curriculum.department().then(res => { + setDeps(res.data) + }) + + setIds(JSON.parse(depIds)) + }, []) + + const onChange = useCallback((id: number) => { + setIds([ + ...ids, + id + ]) + }, [ids]) + + function ok() { + if (!ids.length) { + Taro.showToast({title: '请选着部门', icon: "error"}) + return + } + Taro.setStorageSync('selectDep', ids) + Taro.navigateBack({delta: 1}) + } + + return ( + + {deps.map(d => onChange(d.id)}> + + + )} + + + 确定 + + + + ) +} + +export default SelectDep