index.tsx 8.5 KB

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