newTask.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import { ref, computed, inject } from 'vue';
  2. import { GetTaskTeachingTypeList, GetTaskModeList, GetTeacherListByCourseID, GetCourseStudentList } from '@/api/select';
  3. import { GetTreeNodeInfo_BookChapterStruct, GetTaskInfo, GetCSItem } from '@/api/course';
  4. import { useRoute } from 'vue-router/composables';
  5. import { Message } from 'element-ui';
  6. import { fileUpload } from '@/api/app';
  7. import { fileTypeSizeLimit } from '@/utils/validate';
  8. import i18n from '@/locales/i18n';
  9. const allStudent = {
  10. student_id: '',
  11. student_name: i18n.t('Key110')
  12. };
  13. export function useInit(form, student_list, custom_student_list, { liveForm, basicForm, courseForm }) {
  14. const route = useRoute();
  15. const { params, query } = route;
  16. const task_id = query.task_id;
  17. const is_template = 'is_template' in query ? JSON.parse(query.is_template) : false;
  18. const id = params.id;
  19. const cs_item_id = params.curItemID;
  20. const time_type = ref(params.time_type);
  21. let cs_item_begin_time = ref('');
  22. let cs_item_end_time = ref('');
  23. // 处理任务信息
  24. function handleTaskInfo({
  25. begin_time,
  26. end_time,
  27. time_type: tType,
  28. teaching_type,
  29. name,
  30. teacher_id,
  31. teacher_name,
  32. content,
  33. courseware_list,
  34. accessory_list,
  35. task_mode,
  36. is_enable_homework,
  37. is_enable_message,
  38. courseware_visible_mode,
  39. zhibo_record_mode,
  40. cs_item_begin_time: csItemBTime,
  41. cs_item_end_time: csItemETime,
  42. is_custom_student,
  43. custom_student_list: cusStudentList
  44. }) {
  45. if (begin_time.length > 0) {
  46. const begin = begin_time.split(' ');
  47. form.value.begin_date = begin[0];
  48. const bTime = begin[1].split(':');
  49. form.value.begin_date_hour = bTime[0];
  50. form.value.begin_date_minute = bTime[1];
  51. }
  52. if (end_time.length > 0) {
  53. const end = end_time.split(' ');
  54. form.value.end_date = end[0];
  55. const eTime = end[1].split(':');
  56. form.value.end_date_hour = eTime[0];
  57. form.value.end_date_minute = eTime[1];
  58. }
  59. cs_item_begin_time.value = csItemBTime;
  60. cs_item_end_time.value = csItemETime;
  61. time_type.value = tType;
  62. form.value.teaching_type = teaching_type;
  63. form.value.name = name;
  64. form.value.teacher_id = teacher_id;
  65. form.value.teacher_name = teacher_name;
  66. form.value.content = content;
  67. if (teaching_type === 10) {
  68. liveForm.value.coursewareInfo = courseware_list;
  69. liveForm.value.file_info_list = accessory_list;
  70. liveForm.value.courseware_visible_mode = courseware_visible_mode;
  71. liveForm.value.zhibo_record_mode = zhibo_record_mode;
  72. }
  73. if (teaching_type === 11) {
  74. courseForm.value.coursewareInfo = courseware_list;
  75. courseForm.value.file_info_list = accessory_list;
  76. courseForm.value.task_mode = task_mode;
  77. }
  78. if (teaching_type === 12) {
  79. basicForm.value.file_info_list = accessory_list;
  80. basicForm.value.is_enable_homework = is_enable_homework === 'true';
  81. basicForm.value.is_enable_message = is_enable_message === 'true';
  82. }
  83. if (is_custom_student === 'true') custom_student_list.value = cusStudentList;
  84. }
  85. let teacher_list = ref([]); // 课节教师列表
  86. // 初始化时需要同步的请求
  87. let initRequest = computed(() => {
  88. let list = [];
  89. let dataList = [];
  90. if (task_id) {
  91. list.push(GetTaskInfo({ id: task_id }));
  92. dataList.push('taskInfo');
  93. }
  94. if (!is_template) {
  95. list.push(GetTeacherListByCourseID({ course_id: id }));
  96. list.push(GetCourseStudentList({ course_id: id, audit_status_list: [1], pay_status: 1 }));
  97. dataList.push('teacher_list', 'student_list');
  98. }
  99. return { promiseList: list, dataList };
  100. });
  101. Promise.all(initRequest.value.promiseList).then((values) => {
  102. initRequest.value.dataList.forEach((item, i) => {
  103. if (item === 'taskInfo') return handleTaskInfo(values[i]);
  104. if (item === 'teacher_list') return (teacher_list.value = values[i].teacher_list);
  105. if (item === 'student_list') return (student_list.value = values[i].student_list);
  106. });
  107. if (form.value.teacher_id.length > 0) {
  108. // 如果课程删除了任务中的老师,任务中的老师需要添加进教师列表
  109. let isHas = teacher_list.value.some(({ teacher_id }) => {
  110. if (teacher_id === form.value.teacher_id) return true;
  111. });
  112. if (!isHas) {
  113. teacher_list.value.push({ teacher_id: form.value.teacher_id, teacher_name: form.value.teacher_name });
  114. }
  115. }
  116. if (student_list.value.length > 0 && custom_student_list.value.length <= 0) {
  117. custom_student_list.value.push(allStudent);
  118. }
  119. });
  120. let type_list = ref([]);
  121. GetTaskTeachingTypeList().then(({ type_list: list }) => {
  122. type_list.value = list;
  123. });
  124. let mode_list = ref([]);
  125. GetTaskModeList().then(({ mode_list: list }) => {
  126. mode_list.value = list;
  127. });
  128. GetCSItem({ id: cs_item_id }).then(({ begin_time, end_time }) => {
  129. cs_item_begin_time.value = begin_time;
  130. cs_item_end_time.value = end_time;
  131. });
  132. let hourArr = ref([]);
  133. let minuteArr = ref([]);
  134. for (let i = 0; i < 60; i++) {
  135. let item = String(i);
  136. if (i < 10) item = `0${item}`;
  137. if (i < 24) hourArr.value.push(item);
  138. minuteArr.value.push(item);
  139. }
  140. return {
  141. cs_item_begin_time,
  142. cs_item_end_time,
  143. time_type,
  144. teacher_list,
  145. type_list,
  146. mode_list,
  147. hourArr,
  148. minuteArr
  149. };
  150. }
  151. /**
  152. * 表单及操作
  153. */
  154. export function useForm(liveForm, courseForm, basicForm) {
  155. const $t = inject('$t');
  156. const route = useRoute();
  157. const { query } = route;
  158. const is_template = 'is_template' in query ? JSON.parse(query.is_template) : false;
  159. let form = ref({
  160. name: '',
  161. teacher_id: '',
  162. teacher_name: '',
  163. begin_date: '',
  164. begin_date_hour: '00',
  165. begin_date_minute: '00',
  166. end_date: '',
  167. end_date_hour: '00',
  168. end_date_minute: '00',
  169. teaching_type: 12,
  170. content: ''
  171. });
  172. const validateTeacher = (rule, value, callback) => {
  173. if (form.value.teaching_type === 10 && !value && !is_template) {
  174. callback(new Error($t('Key382')));
  175. } else {
  176. callback();
  177. }
  178. };
  179. const validateNmae = (rule, value, callback) => {
  180. if (value.length <= 0) {
  181. callback(new Error($t('Key384')));
  182. } else {
  183. callback();
  184. }
  185. };
  186. let rules = ref({
  187. name: { trigger: 'blur', validator: validateNmae },
  188. teacher_id: { trigger: 'blur', validator: validateTeacher }
  189. });
  190. function upload(file) {
  191. if (fileTypeSizeLimit(file.file.name, file.file.size)) {
  192. return Message.warning(`${file.file.name}文件大小超出限制`);
  193. }
  194. fileUpload('Open', file).then(({ file_info_list }) => {
  195. const type = form.value.teaching_type;
  196. if (type === 10) {
  197. liveForm.value.file_info_list = liveForm.value.file_info_list.concat(file_info_list);
  198. return;
  199. }
  200. if (type === 11) {
  201. courseForm.value.file_info_list = courseForm.value.file_info_list.concat(file_info_list);
  202. }
  203. if (type === 12) {
  204. basicForm.value.file_info_list = basicForm.value.file_info_list.concat(file_info_list);
  205. }
  206. });
  207. }
  208. function closeFile(i, arr) {
  209. arr.splice(i, 1);
  210. }
  211. let student_list = ref([]); // 课节学生列表
  212. let custom_student_list = ref([]); // 自定义学生列表
  213. function selectStudent(i) {
  214. if (student_list.value.length <= 0) return;
  215. if (typeof i === 'string') {
  216. custom_student_list.value = [allStudent];
  217. return;
  218. }
  219. const list = custom_student_list.value;
  220. const index = list.findIndex(({ student_id }) => student_id === student_list.value[i].student_id);
  221. if (index === -1) {
  222. list.push(student_list.value[i]);
  223. // 如果自定义学生列表中有【全部】,删除【全部】
  224. list.some(({ student_id }) => student_id === allStudent.student_id) &&
  225. list.splice(
  226. list.findIndex(({ student_id }) => student_id === allStudent.student_id),
  227. 1
  228. );
  229. } else {
  230. list.splice(index, 1);
  231. list.length <= 0 && custom_student_list.value.push(allStudent);
  232. }
  233. }
  234. function deleteStudentItem(id) {
  235. if (id.length <= 0) return;
  236. custom_student_list.value.splice(
  237. custom_student_list.value.findIndex(({ student_id }) => student_id === id),
  238. 1
  239. );
  240. if (custom_student_list.value.length <= 0 && student_list.value.length > 0) {
  241. custom_student_list.value.push(allStudent);
  242. }
  243. }
  244. return { form, rules, upload, closeFile, student_list, custom_student_list, selectStudent, deleteStudentItem };
  245. }
  246. /**
  247. * 选择课件
  248. * @param {Object} form
  249. */
  250. export function useCourse(form, liveForm, courseForm) {
  251. const $t = inject('$t');
  252. let dialogVisible = ref(false);
  253. function dialogClose() {
  254. dialogVisible.value = false;
  255. }
  256. /**
  257. * 选择课件
  258. * @param {String} course_id 课件id
  259. * @param {String} previewGroupId 预览分组id
  260. */
  261. function selectCourse(course_id, previewGroupId) {
  262. if (course_id.length === 0) {
  263. Message.warning($t('Key385'));
  264. return;
  265. }
  266. dialogVisible.value = false;
  267. let _form = form.value.teaching_type === 10 ? liveForm : courseForm;
  268. if (_form.value.coursewareInfo.some(({ courseware_id }) => courseware_id === course_id)) return;
  269. GetTreeNodeInfo_BookChapterStruct({ id: course_id }).then(({ name, id }) => {
  270. _form.value.coursewareInfo.push({
  271. courseware_id: id,
  272. courseware_name: name,
  273. group_id_selected_info: previewGroupId
  274. });
  275. });
  276. }
  277. /**
  278. * 修改课件名称
  279. * @param {Number} i
  280. * @param {String} type
  281. * @param {String} name
  282. */
  283. function changeCourseName(i, type, name) {
  284. (type === 'live' ? liveForm.value : courseForm.value).coursewareInfo[i].courseware_name = name;
  285. (type === 'live' ? liveForm.value : courseForm.value).coursewareInfo[i].is_custom_name = 'true';
  286. }
  287. /**
  288. * 删除课件
  289. * @param {Number} i
  290. * @param {String} type
  291. */
  292. function closeCourse(i, type) {
  293. (type === 'live' ? liveForm.value : courseForm.value).coursewareInfo.splice(i, 1);
  294. }
  295. return {
  296. dialogVisible,
  297. changeCourseName,
  298. dialogClose,
  299. selectCourse,
  300. closeCourse
  301. };
  302. }