index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. import { defineComponent, onMounted, reactive, 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. NTooltip,
  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 add from './images/add.png';
  19. import { useRoute, useRouter } from 'vue-router';
  20. import { getStudentList, schoolDetail } from './api';
  21. import { classGroupList } from '@/views/classList/api';
  22. import AddStudentModel from './modals/addStudentModel';
  23. import Studentguide from '@/custom-plugins/guide-page/student-guide';
  24. import TheEmpty from '/src/components/TheEmpty';
  25. // import NoticeModal from './modals/noticeModal';
  26. import { useUserStore } from '/src/store/modules/users';
  27. import UpdateStudent from './modals/update-student';
  28. import { initCache, setCache } from '/src/hooks/use-async';
  29. export default defineComponent({
  30. name: 'student-studentList',
  31. setup(props, { emit }) {
  32. const userStore = useUserStore();
  33. const state = reactive({
  34. searchForm: {
  35. keyword: '',
  36. gender: '' as any,
  37. classGroupId: '' as any,
  38. membership: '' as any
  39. },
  40. searchWord: '',
  41. orchestraType: null,
  42. courseTypeCode: null,
  43. subjectId: null,
  44. classId: null,
  45. studentType: null,
  46. loading: false,
  47. pagination: {
  48. page: 1,
  49. rows: 10,
  50. pageTotal: 4
  51. },
  52. tableList: [] as any,
  53. classList: [],
  54. addStudentVisible: false,
  55. editStatus: false,
  56. activeRow: {} as any
  57. });
  58. const route = useRoute();
  59. const router = useRouter();
  60. const showGuide = ref(false);
  61. const message = useMessage();
  62. const search = () => {
  63. state.pagination.page = 1;
  64. getList();
  65. setCache({ current: state.searchForm, saveKey: route.path });
  66. };
  67. const getClasslist = async () => {
  68. try {
  69. const res = await classGroupList({ page: 1, rows: 999 });
  70. state.classList = res.data.rows.map((item: any) => {
  71. return {
  72. label: item.name,
  73. value: item.id
  74. };
  75. });
  76. } catch (e) {
  77. console.log(e);
  78. }
  79. };
  80. const copyTo = (text: string) => {
  81. const input = document.createElement('input');
  82. input.value = text;
  83. document.body.appendChild(input);
  84. input.select();
  85. input.setSelectionRange(0, input.value.length);
  86. document.execCommand('Copy');
  87. document.body.removeChild(input);
  88. message.success('复制成功');
  89. };
  90. const onReset = () => {
  91. state.searchForm = {
  92. keyword: '',
  93. gender: '' as any,
  94. classGroupId: '' as any,
  95. membership: '' as any
  96. };
  97. search();
  98. setCache({ current: state.searchForm, saveKey: route.path });
  99. };
  100. initCache({
  101. current: state.searchForm,
  102. callBack: (active: any) => {
  103. state.searchForm = active;
  104. }
  105. });
  106. const getList = async () => {
  107. try {
  108. const res = await getStudentList({
  109. ...state.searchForm,
  110. ...state.pagination
  111. });
  112. state.tableList = res.data.rows;
  113. state.pagination.pageTotal = res.data.total;
  114. if (state.tableList.length > 0) {
  115. setTimeout(() => {
  116. showGuide.value = true;
  117. }, 500);
  118. }
  119. } catch (e) {
  120. console.log(e);
  121. }
  122. console.log('getList');
  123. };
  124. onMounted(() => {
  125. getList();
  126. getClasslist();
  127. });
  128. const columns = () => {
  129. return [
  130. {
  131. title: '学生姓名',
  132. key: 'nickname',
  133. render: (row: any) => {
  134. return (
  135. <NTooltip showArrow={false} placement="top-start">
  136. {{
  137. trigger: () => (
  138. <div
  139. style={{ userSelect: 'all', cursor: 'pointer' }}
  140. onClick={() => copyTo(row.nickname)}>
  141. {row.nickname}
  142. </div>
  143. ),
  144. default: '点击复制'
  145. }}
  146. </NTooltip>
  147. );
  148. }
  149. },
  150. {
  151. title: '手机号',
  152. key: 'phone',
  153. render: (row: any) => {
  154. return (
  155. <NTooltip showArrow={false} placement="top-start">
  156. {{
  157. trigger: () => (
  158. <div
  159. style={{ userSelect: 'all', cursor: 'pointer' }}
  160. onClick={() => copyTo(row.phone)}>
  161. {row.phone}
  162. </div>
  163. ),
  164. default: '点击复制'
  165. }}
  166. </NTooltip>
  167. );
  168. }
  169. },
  170. {
  171. title: '性别',
  172. key: 'gender',
  173. render(row: any) {
  174. return (
  175. <>
  176. {row.gender + '' != 'null'
  177. ? row.gender == '0'
  178. ? '女'
  179. : '男'
  180. : '--'}
  181. </>
  182. );
  183. }
  184. },
  185. {
  186. title: '年级班级',
  187. key: 'classGroupName'
  188. },
  189. {
  190. title: '学生类型',
  191. key: 'vipMember',
  192. render(row: any) {
  193. return <>{row.vipMember ? '会员' : '普通'}</>;
  194. }
  195. },
  196. {
  197. title: '操作',
  198. key: 'id',
  199. width: 300,
  200. render(row: any, index: number) {
  201. return (
  202. <NSpace>
  203. {index == 0 ? (
  204. <NButton
  205. {...{ id: 'student-1' }}
  206. text
  207. type="primary"
  208. onClick={() => gotoDetail(row)}>
  209. 详情
  210. </NButton>
  211. ) : (
  212. <NButton text type="primary" onClick={() => gotoDetail(row)}>
  213. 详情
  214. </NButton>
  215. )}
  216. <NButton text type="primary" onClick={() => onUpdate(row)}>
  217. 修改
  218. </NButton>
  219. </NSpace>
  220. );
  221. }
  222. }
  223. ];
  224. };
  225. const gotoDetail = (row: any) => {
  226. router.push({
  227. path: '/studentDetail',
  228. query: { ...route.query, studentId: row.id, studentName: row.nickname }
  229. });
  230. };
  231. // 修改
  232. const onUpdate = (row: any) => {
  233. state.editStatus = true;
  234. state.activeRow = row;
  235. };
  236. return () => (
  237. <div class={styles.listWrap}>
  238. <div class={styles.searchList}>
  239. <NForm label-placement="left" inline>
  240. <NFormItem>
  241. <SearchInput
  242. {...{ placeholder: '请输入学生姓名' }}
  243. class={styles.searchInput}
  244. searchWord={state.searchForm.keyword}
  245. onChangeValue={(val: string) =>
  246. (state.searchForm.keyword = val)
  247. }></SearchInput>
  248. </NFormItem>
  249. <NFormItem>
  250. <CSelect
  251. {...({
  252. options: [
  253. {
  254. label: '全部性别',
  255. value: ''
  256. },
  257. {
  258. label: '男',
  259. value: 1
  260. },
  261. {
  262. label: '女',
  263. value: 0
  264. }
  265. ],
  266. placeholder: '性别',
  267. clearable: true,
  268. inline: true
  269. } as any)}
  270. v-model:value={state.searchForm.gender}></CSelect>
  271. </NFormItem>
  272. <NFormItem>
  273. <CSelect
  274. {...({
  275. options: [
  276. { label: '全部年级班级', value: '' },
  277. ...state.classList
  278. ],
  279. placeholder: '年级班级',
  280. clearable: true,
  281. inline: true
  282. } as any)}
  283. v-model:value={state.searchForm.classGroupId}></CSelect>
  284. </NFormItem>
  285. <NFormItem>
  286. <CSelect
  287. {...({
  288. options: [
  289. {
  290. label: '全部类型',
  291. value: ''
  292. },
  293. {
  294. label: '会员',
  295. value: true
  296. },
  297. {
  298. label: '普通',
  299. value: false
  300. }
  301. ],
  302. placeholder: '学生类型',
  303. clearable: true,
  304. inline: true
  305. } as any)}
  306. v-model:value={state.searchForm.membership}></CSelect>
  307. </NFormItem>
  308. <NFormItem>
  309. <NSpace justify="end">
  310. <NButton type="primary" class="searchBtn" onClick={search}>
  311. 搜索
  312. </NButton>
  313. <NButton
  314. type="primary"
  315. ghost
  316. class="resetBtn"
  317. onClick={onReset}>
  318. 重置
  319. </NButton>
  320. </NSpace>
  321. </NFormItem>
  322. </NForm>
  323. </div>
  324. <NButton
  325. {...{ id: 'student-0' }}
  326. onClick={async () => {
  327. // state.addStudentVisible = true;
  328. try {
  329. const { schoolInfos } = userStore.getUserInfo;
  330. const schoolId =
  331. schoolInfos.length > 0 ? schoolInfos[0].id : null;
  332. if (schoolId) {
  333. const { data } = await schoolDetail({ id: schoolId });
  334. state.activeRow = data;
  335. state.addStudentVisible = true;
  336. }
  337. } catch {
  338. //
  339. }
  340. }}
  341. class={styles.addBtn}
  342. type="primary"
  343. v-slots={{
  344. icon: () => (
  345. <>
  346. <NImage
  347. class={styles.addBtnIcon}
  348. previewDisabled
  349. src={add}></NImage>
  350. </>
  351. )
  352. }}>
  353. 邀请学生
  354. </NButton>
  355. <div class={styles.tableWrap}>
  356. <NDataTable
  357. v-slots={{
  358. empty: () => <TheEmpty></TheEmpty>
  359. }}
  360. class={styles.classTable}
  361. loading={state.loading}
  362. columns={columns()}
  363. data={state.tableList}></NDataTable>
  364. <Pagination
  365. v-model:page={state.pagination.page}
  366. v-model:pageSize={state.pagination.rows}
  367. v-model:pageTotal={state.pagination.pageTotal}
  368. onList={getList}
  369. sync
  370. />
  371. </div>
  372. {state.addStudentVisible ? (
  373. <div v-model:show={state.addStudentVisible} class="n-modal-mask">
  374. <AddStudentModel
  375. activeRow={state.activeRow}
  376. onClose={() => {
  377. state.addStudentVisible = false;
  378. }}></AddStudentModel>
  379. </div>
  380. ) : null}
  381. {/* <NModal
  382. v-model:show={state.addStudentVisible}
  383. showIcon={false}
  384. style={{ width: '400px' }}>
  385. <NoticeModal
  386. data={state.activeRow}
  387. onClose={() => (state.addStudentVisible = false)}
  388. />
  389. </NModal> */}
  390. <NModal
  391. v-model:show={state.editStatus}
  392. class={['modalTitle background', styles.updateStudent]}
  393. preset="card"
  394. title="修改信息">
  395. <UpdateStudent
  396. onClose={() => (state.editStatus = false)}
  397. onConfirm={() => getList()}
  398. row={state.activeRow}
  399. />
  400. </NModal>
  401. {showGuide.value ? <Studentguide></Studentguide> : null}
  402. </div>
  403. );
  404. }
  405. });