index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import OHeader from '@/components/o-header'
  2. import OPopup from '@/components/o-popup'
  3. import OSticky from '@/components/o-sticky'
  4. import request from '@/helpers/request'
  5. import { Button, Cell, CellGroup, Field, showToast } from 'vant'
  6. import { defineComponent, onMounted } from 'vue'
  7. import styles from '../index.module.less'
  8. import { state as baseState } from '@/state'
  9. import StudentList from '../modal/student-list'
  10. import SubjectList from '../modal/subject-list'
  11. import { createState as state, resestState } from './create'
  12. import { useRouter } from 'vue-router'
  13. import deepClone from '@/helpers/deep-clone'
  14. export default defineComponent({
  15. name: 'create-orchestra',
  16. setup() {
  17. const router = useRouter()
  18. // const state = reactive({
  19. // subjectStatus: false,
  20. // subjectList: [] as any, // 声部列表
  21. // selectSubjectIds: [] as any,
  22. // selectSubjects: [] as any, // 选中的声部
  23. // studentStatus: false,
  24. // teacherStatus: false,
  25. // orchestraList: [] as any, // 乐团列表
  26. // selectSubjectStudents: {} as any
  27. // })
  28. // 获取声部
  29. const getSubjects = async () => {
  30. try {
  31. const { data } = await request.post('/api-school/subjectBasicConfig/page', {
  32. data: {
  33. page: 1,
  34. rows: 50,
  35. enableFlag: true
  36. }
  37. })
  38. state.subjectList = data.rows || []
  39. } catch {
  40. //
  41. }
  42. }
  43. // 获取乐团列表
  44. const getOrchestras = async () => {
  45. try {
  46. const { data } = await request.post('/api-school/orchestra/page', {
  47. data: {
  48. page: 1,
  49. rows: 100,
  50. schoolId: baseState.user.data.school.id,
  51. status: 'DONE'
  52. }
  53. })
  54. const temps = data.rows || []
  55. const s = [] as any
  56. temps.forEach((item: any) => {
  57. s.push({
  58. text: item.name,
  59. value: item.id
  60. })
  61. })
  62. state.orchestraList = [...s]
  63. } catch {
  64. //
  65. }
  66. }
  67. // 初始化选择声部
  68. const onSelectSubject = (ids: any) => {
  69. state.selectSubjectIds = [...ids]
  70. const temps: any = []
  71. console.log(state.selectSubjects, '1212', state.subjectList)
  72. state.subjectList.forEach((item: any) => {
  73. const index = state.selectSubjects.findIndex((select: any) => select.id === item.subjectId)
  74. if (ids.includes(item.subjectId)) {
  75. // 判断是否在数据里,如果在则直接添加,不能重置数据
  76. if (index < 0) {
  77. temps.push({
  78. id: item.subjectId,
  79. name: item.subjectName,
  80. subjectCode: item.subjectCode,
  81. type: null,
  82. teacher: {}, // 老师信息
  83. students: [] as any // 选中的数据数
  84. })
  85. } else {
  86. temps.push(state.selectSubjects.find((select: any) => select.id === item.subjectId))
  87. }
  88. }
  89. })
  90. state.selectSubjects = [...temps]
  91. }
  92. const onSubmit = () => {
  93. if (!state.orchestraName) {
  94. showToast('请输入乐团名称')
  95. return
  96. }
  97. if (state.selectSubjects && state.selectSubjects.length <= 0) {
  98. showToast('请选择声部')
  99. return
  100. }
  101. const selectSubjects = state.selectSubjects || []
  102. let isSelect = false
  103. selectSubjects.forEach((item: any) => {
  104. if (!item.students || (item.students && item.students.length <= 0)) {
  105. isSelect = true
  106. }
  107. })
  108. if (isSelect) {
  109. showToast('请选择学员')
  110. return
  111. }
  112. // 初始化班级
  113. const tempSelect: any = []
  114. // 添加所在学员
  115. const tempStudents: any = []
  116. let largeUpSubject: any = {} // 上低音号和大号合集,目前根据编码处理,待定
  117. state.selectSubjects.forEach((item: any) => {
  118. console.log(item, 'item.name')
  119. tempStudents.push(...item.students)
  120. if (item.subjectCode !== 'BARITONE' && item.subjectCode !== 'TUBA') {
  121. tempSelect.push(item)
  122. } else {
  123. // 获取学员
  124. const temps = largeUpSubject.students ? largeUpSubject.students : []
  125. largeUpSubject = {
  126. id: largeUpSubject.id ? largeUpSubject.id + ',' + item.id : item.id,
  127. name: largeUpSubject.name ? largeUpSubject.name + '-' + item.name : item.name,
  128. type: null,
  129. teacher: {},
  130. students: [...temps, ...item.students]
  131. }
  132. }
  133. })
  134. state.selectLastTeacherSubjects = deepClone(tempSelect)
  135. // 判断是否有大号或者上低音号, 如果有则添加
  136. if (largeUpSubject.id) {
  137. state.selectLastTeacherSubjects.push(largeUpSubject)
  138. }
  139. // 默认添加两个班级
  140. state.selectLastTeacherSubjects.push(
  141. {
  142. id: null,
  143. name: '乐理班',
  144. type: 'MUSIC_THEORY',
  145. teacher: {}, // 老师信息
  146. students: [...tempStudents] as any // 选中的数据数
  147. },
  148. {
  149. id: null,
  150. name: '合奏班',
  151. type: 'INSTRUMENTAL_ENSEMBLE',
  152. teacher: {}, // 老师信息
  153. students: [...tempStudents] as any // 选中的数据数
  154. }
  155. )
  156. // 选择老师
  157. router.push({
  158. path: '/create-orchestra-teacher'
  159. })
  160. }
  161. onMounted(() => {
  162. resestState()
  163. getSubjects()
  164. getOrchestras()
  165. })
  166. return () => (
  167. <div class={styles['create-orchestra']}>
  168. <OHeader />
  169. <CellGroup inset>
  170. <Field
  171. label="乐团名称"
  172. v-model={state.orchestraName}
  173. placeholder="请输入乐团名称"
  174. inputAlign="right"
  175. maxlength={30}
  176. />
  177. <Field
  178. label="乐团声部"
  179. readonly
  180. placeholder={
  181. state.selectSubjects.length > 0 ? `已选${state.selectSubjects.length}个` : '选择声部'
  182. }
  183. isLink
  184. inputAlign="right"
  185. onClick={() => (state.subjectStatus = true)}
  186. />
  187. {state.selectSubjects.map((item: any) => (
  188. <Cell
  189. title={item.name}
  190. isLink
  191. onClick={() => {
  192. state.studentStatus = true
  193. state.selectSubjectStudents = item
  194. }}
  195. >
  196. {{
  197. value: () => (
  198. <>
  199. 已选{' '}
  200. <span style={{ color: 'var(--van-primary-color)' }}>
  201. {item.students?.length || 0}
  202. </span>{' '}
  203. 名学员
  204. </>
  205. )
  206. }}
  207. </Cell>
  208. ))}
  209. </CellGroup>
  210. <OSticky position="bottom">
  211. <div class={['btnGroup']}>
  212. <Button type="primary" block round onClick={onSubmit}>
  213. 下一步
  214. </Button>
  215. </div>
  216. </OSticky>
  217. {/* 选择声部 */}
  218. <OPopup v-model:modelValue={state.subjectStatus} style="background: #F8F8F8;">
  219. {state.subjectStatus && (
  220. <SubjectList
  221. onClose={() => (state.subjectStatus = false)}
  222. subjectList={state.subjectList}
  223. selectSubjects={state.selectSubjectIds}
  224. onSelect={onSelectSubject}
  225. />
  226. )}
  227. </OPopup>
  228. {/* 选择学员 */}
  229. <OPopup v-model:modelValue={state.studentStatus} style="background: #f8f8f8;">
  230. {state.studentStatus && (
  231. <StudentList
  232. orchestraList={state.orchestraList}
  233. subjectId={state.selectSubjectStudents.id}
  234. selectStudentIds={state.selectSubjectStudents.students}
  235. onClose={() => (state.studentStatus = false)}
  236. onSelect={(item: any) => {
  237. // console.log(item, 'select student')
  238. state.selectSubjectStudents.students = [...item]
  239. }}
  240. />
  241. )}
  242. </OPopup>
  243. </div>
  244. )
  245. }
  246. })