index.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. import { defineComponent, reactive, onMounted, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NDataTable,
  6. NForm,
  7. NFormItem,
  8. NImage,
  9. NModal,
  10. NSelect,
  11. NSpace,
  12. useDialog,
  13. useMessage
  14. } from 'naive-ui';
  15. import SearchInput from '@/components/searchInput';
  16. import CSelect from '@/components/CSelect';
  17. import Pagination from '@/components/pagination';
  18. import { classGroupList, deleteClass } from './api';
  19. import { useUserStore } from '/src/store/modules/users';
  20. import CreateClass from './modals/createClass';
  21. import RestStudentBox from './modals/restStudentBox';
  22. import TrainDetail from './modals/Gotoclass';
  23. import {
  24. sixYearSystem,
  25. fiveYearSystem,
  26. threeYearSystem,
  27. foreYearSystem,
  28. nineYearSystem,
  29. classArray
  30. } from './contants';
  31. import add from '@/views/studentList/images/add.png';
  32. import { useRouter } from 'vue-router';
  33. import { rowDark } from 'naive-ui/es/legacy-grid/styles';
  34. export default defineComponent({
  35. name: 'class-classList',
  36. setup(props, { emit }) {
  37. const state = reactive({
  38. searchForm: {
  39. keyword: null as any,
  40. currentClass: null,
  41. currentGradeNum: null
  42. },
  43. orchestraType: null,
  44. courseTypeCode: null,
  45. loading: false,
  46. pagination: {
  47. page: 1,
  48. rows: 10,
  49. pageTotal: 6
  50. },
  51. gradeNumList: [] as any,
  52. tableList: [] as any,
  53. studentVisible: false,
  54. activeRow: null as any,
  55. showaddClass: false,
  56. goCourseVisiable: false
  57. });
  58. const formRef = ref();
  59. const dialog = useDialog();
  60. const message = useMessage();
  61. const router = useRouter();
  62. const search = () => {
  63. state.pagination.page = 1;
  64. getList();
  65. console.log('search', state);
  66. };
  67. const userInfo = useUserStore();
  68. if (userInfo.getUserInfo.schoolInfos[0].gradeYear == 'THREE_YEAR_SYSTEM') {
  69. state.gradeNumList = threeYearSystem;
  70. } else if (
  71. userInfo.getUserInfo.schoolInfos[0].gradeYear == 'FORE_YEAR_SYSTEM'
  72. ) {
  73. state.gradeNumList = foreYearSystem;
  74. } else if (
  75. userInfo.getUserInfo.schoolInfos[0].gradeYear == 'FIVE_YEAR_SYSTEM'
  76. ) {
  77. state.gradeNumList = fiveYearSystem;
  78. } else if (
  79. userInfo.getUserInfo.schoolInfos[0].gradeYear == 'SIX_YEAR_SYSTEM'
  80. ) {
  81. state.gradeNumList = sixYearSystem;
  82. } else {
  83. state.gradeNumList = nineYearSystem;
  84. }
  85. const onReset = () => {
  86. state.searchForm = {
  87. keyword: null as any,
  88. currentClass: null,
  89. currentGradeNum: null
  90. };
  91. getList();
  92. };
  93. const removeClass = async (row: any) => {
  94. dialog.warning({
  95. title: '警告',
  96. content: `是否删除班级“${row.name}”?`,
  97. positiveText: '确定',
  98. negativeText: '取消',
  99. onPositiveClick: async () => {
  100. try {
  101. await deleteClass({ ids: row.id });
  102. getList();
  103. message.success(`删除成功`);
  104. } catch (e) {
  105. console.log(e);
  106. }
  107. }
  108. });
  109. };
  110. const getList = async () => {
  111. // classGroupList
  112. state.loading = true;
  113. try {
  114. const res = await classGroupList({
  115. ...state.searchForm,
  116. ...state.pagination
  117. });
  118. state.tableList = res.data.rows;
  119. state.pagination.pageTotal = res.data.total;
  120. state.loading = false;
  121. } catch (e) {
  122. state.loading = false;
  123. console.log(e);
  124. }
  125. console.log('getList');
  126. };
  127. const columns = () => {
  128. return [
  129. {
  130. title: '班级名称',
  131. key: 'name'
  132. },
  133. {
  134. title: '学生人数',
  135. key: 'preStudentNum'
  136. },
  137. {
  138. title: '上次学习',
  139. key: 'lastStudy',
  140. render(row: any) {
  141. return <p>{row.lastStudy ? row.lastStudy : '--'}</p>;
  142. }
  143. },
  144. {
  145. title: '操作',
  146. key: 'id',
  147. render(row: any) {
  148. return (
  149. <div>
  150. <NSpace>
  151. <NButton
  152. type="primary"
  153. text
  154. onClick={() => {
  155. router.push({
  156. path: '/classDetail',
  157. query: { name: row.name, id: row.id }
  158. });
  159. }}>
  160. 详情
  161. </NButton>
  162. <NButton
  163. type="primary"
  164. text
  165. onClick={() => {
  166. startResetStudent(row);
  167. }}>
  168. 学生调整
  169. </NButton>
  170. <NButton
  171. type="primary"
  172. text
  173. onClick={() => classesBegin(row)}>
  174. 开始上课
  175. </NButton>
  176. {!(row.preStudentNum > 0) ? (
  177. <p
  178. style={{ color: '#EA4132', cursor: 'pointer' }}
  179. onClick={() => removeClass(row)}>
  180. 删除
  181. </p>
  182. ) : null}
  183. </NSpace>
  184. </div>
  185. );
  186. }
  187. }
  188. ];
  189. };
  190. const startResetStudent = (row: any) => {
  191. state.activeRow = row;
  192. state.studentVisible = true;
  193. };
  194. const classesBegin = (row: any) => {
  195. state.activeRow = row;
  196. state.goCourseVisiable = true;
  197. console.log('classesBegin');
  198. };
  199. onMounted(() => {
  200. getList();
  201. });
  202. return () => (
  203. <div class={styles.listWrap}>
  204. <div class={styles.searchList}>
  205. <NForm label-placement="left" inline ref={formRef}>
  206. <NFormItem>
  207. <SearchInput
  208. {...{ placeholder: '请输入班级名称' }}
  209. class={styles.searchInput}
  210. searchWord={state.searchForm.keyword}
  211. onChangeValue={(val: string) =>
  212. (state.searchForm.keyword = val)
  213. }></SearchInput>
  214. </NFormItem>
  215. <NFormItem>
  216. <CSelect
  217. {...({
  218. options: state.gradeNumList,
  219. placeholder: '选择年级',
  220. clearable: true,
  221. inline: true
  222. } as any)}
  223. v-model:value={state.searchForm.currentGradeNum}></CSelect>
  224. </NFormItem>
  225. <NFormItem>
  226. <CSelect
  227. {...({
  228. options: classArray,
  229. placeholder: '选择班级',
  230. clearable: true,
  231. inline: true
  232. } as any)}
  233. v-model:value={state.searchForm.currentClass}></CSelect>
  234. </NFormItem>
  235. <NFormItem>
  236. <NSpace justify="end">
  237. <NButton type="primary" class="searchBtn" onClick={search}>
  238. 搜索
  239. </NButton>
  240. <NButton
  241. type="primary"
  242. ghost
  243. class="resetBtn"
  244. onClick={onReset}>
  245. 重置
  246. </NButton>
  247. </NSpace>
  248. </NFormItem>
  249. </NForm>
  250. </div>
  251. <NButton
  252. class={styles.addBtn}
  253. type="primary"
  254. onClick={() => (state.showaddClass = true)}
  255. v-slots={{
  256. icon: () => (
  257. <>
  258. <NImage class={styles.addBtnIcon} src={add}></NImage>
  259. </>
  260. )
  261. }}>
  262. 创建班级
  263. </NButton>
  264. <div class={styles.tableWrap}>
  265. <NDataTable
  266. class={styles.classTable}
  267. loading={state.loading}
  268. columns={columns()}
  269. data={state.tableList}></NDataTable>
  270. <Pagination
  271. v-model:page={state.pagination.page}
  272. v-model:pageSize={state.pagination.rows}
  273. v-model:pageTotal={state.pagination.pageTotal}
  274. onList={getList}
  275. sync
  276. saveKey="orchestraRegistration-key"
  277. />
  278. </div>
  279. <NModal
  280. v-model:show={state.studentVisible}
  281. style={{ width: '707px' }}
  282. preset="card"
  283. class={['modalTitle background']}
  284. title={'学员调整'}>
  285. <RestStudentBox
  286. activeRow={state.activeRow}
  287. onClose={() => (state.studentVisible = false)}
  288. onGetList={() => getList()}></RestStudentBox>
  289. </NModal>
  290. <NModal
  291. v-model:show={state.showaddClass}
  292. style={{ width: '500px' }}
  293. preset="card"
  294. class={['modalTitle background']}
  295. title={'创建班级'}>
  296. <CreateClass
  297. gradeNumList={state.gradeNumList}
  298. classArray={classArray}
  299. onGetList={() => getList()}
  300. onClose={() => (state.showaddClass = false)}
  301. />
  302. </NModal>
  303. <NModal
  304. v-model:show={state.goCourseVisiable}
  305. preset="card"
  306. class={['modalTitle background', styles.chioseModel]}
  307. title={'选择课件'}>
  308. <TrainDetail
  309. onClose={() => (state.goCourseVisiable = false)}></TrainDetail>
  310. </NModal>
  311. </div>
  312. );
  313. }
  314. });