|
|
@ -1,5 +1,5 @@ |
|
|
|
import React, {FC, useCallback, useEffect, useState} from "react"; |
|
|
|
import React, {FC, useCallback, useEffect, useState} from "react"; |
|
|
|
import {Checkbox, Switch, View} from "@tarojs/components"; |
|
|
|
import {Checkbox, View} from "@tarojs/components"; |
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
import {curriculum} from "@/api"; |
|
|
|
import {curriculum} from "@/api"; |
|
|
|
import PopPut from "@/components/popPut/popPut"; |
|
|
|
import PopPut from "@/components/popPut/popPut"; |
|
|
@ -13,10 +13,9 @@ import Spin from "@/components/spinner"; |
|
|
|
* required 是 必修选修 |
|
|
|
* required 是 必修选修 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const SelectDep: FC = () => { |
|
|
|
const SelectDep: FC = () => { |
|
|
|
const params = Taro.getCurrentInstance()?.router?.params as { depIds: string, required: string | undefined } |
|
|
|
const params = Taro.getCurrentInstance()?.router?.params as { depIds: string} |
|
|
|
const [ids, setIds] = useState<number[]>([]) |
|
|
|
const [ids, setIds] = useState<number[]>([]) |
|
|
|
const [deps, setDeps] = useState<Manage[]>([]) |
|
|
|
const [deps, setDeps] = useState<Manage[]>([]) |
|
|
|
const [required, setRequired] = useState<number[]>([]) |
|
|
|
|
|
|
|
const [enable, setEnable] = useState(true) |
|
|
|
const [enable, setEnable] = useState(true) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
@ -25,7 +24,6 @@ const SelectDep: FC = () => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
setEnable(false) |
|
|
|
setEnable(false) |
|
|
|
setIds(JSON.parse(params.depIds)) |
|
|
|
setIds(JSON.parse(params.depIds)) |
|
|
|
setRequired(JSON.parse(params.required || "[]")) |
|
|
|
|
|
|
|
}, []) |
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
const onChange = useCallback((id: number) => { |
|
|
|
const onChange = useCallback((id: number) => { |
|
|
@ -35,51 +33,19 @@ const SelectDep: FC = () => { |
|
|
|
...ids, |
|
|
|
...ids, |
|
|
|
id |
|
|
|
id |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
if (params.required) { |
|
|
|
|
|
|
|
setRequired([...required, 0]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const oldIds: number[] = JSON.parse(JSON.stringify(ids)) |
|
|
|
const oldIds: number[] = JSON.parse(JSON.stringify(ids)) |
|
|
|
oldIds.splice(index, 1) |
|
|
|
oldIds.splice(index, 1) |
|
|
|
setIds(oldIds) |
|
|
|
setIds(oldIds) |
|
|
|
|
|
|
|
|
|
|
|
if (params.required) { |
|
|
|
|
|
|
|
const oldRequired: number[] = JSON.parse(JSON.stringify(required)) |
|
|
|
|
|
|
|
oldRequired.splice(index, 1) |
|
|
|
|
|
|
|
setRequired(oldRequired) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, [ids]) |
|
|
|
}, [ids]) |
|
|
|
|
|
|
|
|
|
|
|
function ok() { |
|
|
|
function ok() { |
|
|
|
storageDep.set(ids) |
|
|
|
storageDep.set(ids) |
|
|
|
storageDep.setRequired(required) |
|
|
|
|
|
|
|
Taro.navigateBack({delta: 1}) |
|
|
|
Taro.navigateBack({delta: 1}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isRequired(dep_id: number): boolean { |
|
|
|
|
|
|
|
const index = ids.indexOf(dep_id) |
|
|
|
|
|
|
|
if (index === -1) { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return !!required?.[index] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function requiredChange(dep_id: number, value: boolean) { |
|
|
|
|
|
|
|
const index = ids.indexOf(dep_id) |
|
|
|
|
|
|
|
if (index === -1) { |
|
|
|
|
|
|
|
setIds([...ids, dep_id]) |
|
|
|
|
|
|
|
setRequired([...required, value ? 1 : 0]) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
const oldRequired: number[] = JSON.parse(JSON.stringify(required)) |
|
|
|
|
|
|
|
oldRequired.splice(index, 1, value ? 1 : 0) |
|
|
|
|
|
|
|
setRequired(oldRequired) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<View className='px-2 bg-white'> |
|
|
|
<View className='px-2 bg-white'> |
|
|
|
<Spin overlay enable={enable}/> |
|
|
|
<Spin overlay enable={enable}/> |
|
|
@ -90,21 +56,10 @@ const SelectDep: FC = () => { |
|
|
|
key={d.id} |
|
|
|
key={d.id} |
|
|
|
title={d.name} |
|
|
|
title={d.name} |
|
|
|
chevron |
|
|
|
chevron |
|
|
|
leftImage={folder} |
|
|
|
leftImage={folder}/> |
|
|
|
content={ |
|
|
|
|
|
|
|
params?.required ? |
|
|
|
|
|
|
|
<View className='flex align-center'> |
|
|
|
|
|
|
|
必修:<Switch |
|
|
|
|
|
|
|
color='#45d4a8' |
|
|
|
|
|
|
|
onClick={() => event?.stopImmediatePropagation()} |
|
|
|
|
|
|
|
checked={isRequired(d.id)} |
|
|
|
|
|
|
|
onChange={(e) => requiredChange(d.id, e.detail.value)}/> |
|
|
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
: null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</View> |
|
|
|
</View> |
|
|
|
</View>)} |
|
|
|
</View>)} |
|
|
|
|
|
|
|
<View className='text-center font-24 text-dark mt-3'>暂无更多</View> |
|
|
|
|
|
|
|
|
|
|
|
<View className={'my-3'}> |
|
|
|
<View className={'my-3'}> |
|
|
|
<MyButton onClick={ok}>确定</MyButton> |
|
|
|
<MyButton onClick={ok}>确定</MyButton> |
|
|
|