|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
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 {curriculum} from "@/api"; |
|
|
|
|
import PopPut from "@/components/popPut/popPut"; |
|
|
|
@ -13,10 +13,9 @@ import Spin from "@/components/spinner"; |
|
|
|
|
* required 是 必修选修 |
|
|
|
|
*/ |
|
|
|
|
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 [deps, setDeps] = useState<Manage[]>([]) |
|
|
|
|
const [required, setRequired] = useState<number[]>([]) |
|
|
|
|
const [enable, setEnable] = useState(true) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -25,7 +24,6 @@ const SelectDep: FC = () => { |
|
|
|
|
}) |
|
|
|
|
setEnable(false) |
|
|
|
|
setIds(JSON.parse(params.depIds)) |
|
|
|
|
setRequired(JSON.parse(params.required || "[]")) |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
const onChange = useCallback((id: number) => { |
|
|
|
@ -35,51 +33,19 @@ const SelectDep: FC = () => { |
|
|
|
|
...ids, |
|
|
|
|
id |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
if (params.required) { |
|
|
|
|
setRequired([...required, 0]) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
const oldIds: number[] = JSON.parse(JSON.stringify(ids)) |
|
|
|
|
oldIds.splice(index, 1) |
|
|
|
|
setIds(oldIds) |
|
|
|
|
|
|
|
|
|
if (params.required) { |
|
|
|
|
const oldRequired: number[] = JSON.parse(JSON.stringify(required)) |
|
|
|
|
oldRequired.splice(index, 1) |
|
|
|
|
setRequired(oldRequired) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, [ids]) |
|
|
|
|
|
|
|
|
|
function ok() { |
|
|
|
|
storageDep.set(ids) |
|
|
|
|
storageDep.setRequired(required) |
|
|
|
|
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 ( |
|
|
|
|
<View className='px-2 bg-white'> |
|
|
|
|
<Spin overlay enable={enable}/> |
|
|
|
@ -90,21 +56,10 @@ const SelectDep: FC = () => { |
|
|
|
|
key={d.id} |
|
|
|
|
title={d.name} |
|
|
|
|
chevron |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
/> |
|
|
|
|
leftImage={folder}/> |
|
|
|
|
</View> |
|
|
|
|
</View>)} |
|
|
|
|
<View className='text-center font-24 text-dark mt-3'>暂无更多</View> |
|
|
|
|
|
|
|
|
|
<View className={'my-3'}> |
|
|
|
|
<MyButton onClick={ok}>确定</MyButton> |
|
|
|
|