InfoPrintTask.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div class="info-print-task">
  3. <p class="tips-info mb-2">
  4. 考试需要命题老师提交完整的考务数据,每个卷袋表示一个考场,人数字段为应考人数,备份数量为该考场试卷题卡备用数量
  5. </p>
  6. <el-form ref="modalFormComp" label-position="top">
  7. <el-form-item label="考试时间:" required>
  8. <el-date-picker
  9. v-model="createDate"
  10. type="date"
  11. value-format="timestamp"
  12. placeholder="考试日期"
  13. style="width: 150px"
  14. @change="timeChange"
  15. >
  16. </el-date-picker>
  17. <el-time-picker
  18. is-range
  19. v-model="createTime"
  20. range-separator="至"
  21. start-placeholder="考试开始时间"
  22. end-placeholder="考试结束时间"
  23. placeholder="选择时间范围"
  24. value-format="timestamp"
  25. @change="timeChange"
  26. >
  27. </el-time-picker>
  28. </el-form-item>
  29. <el-form-item label="考试对象:" required></el-form-item>
  30. </el-form>
  31. <div class="part-box">
  32. <div class="box-justify mb-2">
  33. <p>
  34. 共{{ packageInfos.packageCount }}个卷袋,{{
  35. packageInfos.studentCount
  36. }}个考生,共印试卷{{ packageInfos.paperCount }}份(正式{{
  37. packageInfos.paperReleaseCount
  38. }}份,备用{{ packageInfos.paperBackupCount }}份)
  39. </p>
  40. <el-button type="primary" @click="toAdd" :disabled="cannotAdd"
  41. >新增考试对象</el-button
  42. >
  43. </div>
  44. <el-table ref="TableList" :data="tableData" border>
  45. <el-table-column type="index" width="50" label="卷袋序号">
  46. </el-table-column>
  47. <el-table-column prop="className" label="考试对象"> </el-table-column>
  48. <el-table-column prop="studentCount" label="人数" width="60">
  49. </el-table-column>
  50. <el-table-column prop="printHouseName" label="印刷室">
  51. <template slot-scope="scope">
  52. <el-select
  53. v-model="scope.row.printHouseId"
  54. placeholder="请选择"
  55. @change="() => printHouseChange(scope.row)"
  56. >
  57. <el-option
  58. v-for="room in printHouses"
  59. :key="room.houseId"
  60. :value="room.houseId"
  61. :label="room.houseName"
  62. ></el-option>
  63. </el-select>
  64. </template>
  65. </el-table-column>
  66. <el-table-column
  67. v-for="item in extendFields"
  68. :key="item.code"
  69. :label="item.name"
  70. >
  71. <div slot-scope="scope">
  72. <el-input
  73. v-model="scope.row.extends[item.code]"
  74. placeholder="请输入"
  75. clearable
  76. ></el-input>
  77. </div>
  78. </el-table-column>
  79. <el-table-column label="操作" width="100">
  80. <template slot-scope="scope">
  81. <el-button
  82. class="btn-danger"
  83. type="text"
  84. @click="toDelete(scope.row)"
  85. >取消</el-button
  86. >
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </div>
  91. <!-- ModifyPrintTask -->
  92. <modify-print-task
  93. ref="ModifyPrintTask"
  94. :instance="curRow"
  95. :print-houses="printHouses"
  96. :class-list="unusedClassList"
  97. :extend-fields="extendFields"
  98. @modified="modified"
  99. ></modify-print-task>
  100. </div>
  101. </template>
  102. <script>
  103. import { calcSum, getTimeDatestamp } from "@/plugins/utils";
  104. import { examRuleDetail } from "../../../base/api";
  105. import { listTaskPrintHouse, listTaskApplyClass } from "../../api";
  106. import ModifyPrintTask from "./ModifyPrintTask";
  107. export default {
  108. name: "info-print-task",
  109. components: { ModifyPrintTask },
  110. props: {
  111. datas: {
  112. type: Object,
  113. default() {
  114. return {};
  115. }
  116. }
  117. },
  118. data() {
  119. return {
  120. modalForm: {
  121. examStartTime: "",
  122. examEndTime: "",
  123. paperNumber: "",
  124. courseName: "",
  125. courseCode: ""
  126. },
  127. tableData: [],
  128. curRow: {},
  129. classList: [],
  130. validClassList: [],
  131. unusedClassList: [],
  132. printHouses: [],
  133. extendFields: [],
  134. packageInfos: {
  135. packageCount: 0,
  136. studentCount: 0,
  137. paperCount: 0,
  138. paperReleaseCount: 0,
  139. paperBackupCount: 0
  140. },
  141. // date-picker
  142. curCreateTime: [],
  143. createDate: "",
  144. createTime: []
  145. };
  146. },
  147. computed: {
  148. cannotAdd() {
  149. return !this.unusedClassList.length;
  150. }
  151. },
  152. mounted() {
  153. this.getExtendFields();
  154. this.getPrintHouses();
  155. const curDate = getTimeDatestamp(Date.now());
  156. const hour = 60 * 60 * 1000;
  157. this.curCreateTime = [curDate + 8 * hour, curDate + 10 * hour];
  158. this.createTime = [...this.curCreateTime];
  159. },
  160. methods: {
  161. async initData() {
  162. this.modalForm = Object.assign(this.modalForm, {
  163. paperNumber: this.datas.examTask.paperNumber,
  164. courseName: this.datas.examTask.courseName,
  165. courseCode: this.datas.examTask.courseCode
  166. });
  167. await this.getClassList();
  168. const data = this.datas.printTask;
  169. this.tableData =
  170. data.courseCode === this.datas.examTask.courseCode ? data.list : [];
  171. if (data.examStartTime && data.examEndTime) {
  172. this.createTime = [data.examStartTime, data.examEndTime];
  173. this.createDate = getTimeDatestamp(data.examStartTime);
  174. this.modalForm.examStartTime = this.createTime[0];
  175. this.modalForm.examEndTime = this.createTime[1];
  176. }
  177. if (this.tableData.length) {
  178. this.updateUnusedClassList();
  179. } else {
  180. this.buildTableData();
  181. }
  182. this.updatePackageInfos();
  183. },
  184. checkData() {
  185. if (!this.modalForm.examStartTime || !this.modalForm.examEndTime) {
  186. this.$message.error("请选择考试时间!");
  187. return Promise.reject();
  188. }
  189. if (!this.tableData.length) {
  190. this.$message.error("请添加考试对象!");
  191. return Promise.reject();
  192. }
  193. let errorMsg = [];
  194. this.tableData.forEach(row => {
  195. let errorFields = [];
  196. this.extendFields.forEach(field => {
  197. if (!row.extends[field.code]) {
  198. errorFields.push(field.name);
  199. }
  200. });
  201. if (errorFields.length) {
  202. errorMsg.push(
  203. `考试对象${row.className}中,${errorFields.join("、")}必须填写`
  204. );
  205. }
  206. });
  207. if (errorMsg.length) {
  208. this.$message.error(errorMsg.join("。"));
  209. return Promise.reject();
  210. }
  211. return Promise.resolve(true);
  212. },
  213. getData() {
  214. this.tableData.forEach(row => {
  215. let extendFields = this.extendFields.map(field => {
  216. let info = { ...field };
  217. info.value = row.extends[field.code];
  218. return info;
  219. });
  220. row.extendFields = JSON.stringify(extendFields);
  221. row.examStartTime = this.modalForm.examStartTime;
  222. row.examEndTime = this.modalForm.examEndTime;
  223. });
  224. return {
  225. printTask: {
  226. ...this.modalForm,
  227. list: this.tableData
  228. }
  229. };
  230. },
  231. updateData() {
  232. this.$emit("data-change", this.getData());
  233. },
  234. buildTableData() {
  235. this.tableData = this.classList.map(clazz => {
  236. let data = {
  237. examPlace: "",
  238. examRoom: "",
  239. classId: clazz.id,
  240. className: clazz.name,
  241. studentCount: clazz.studentCount,
  242. printHouseId: clazz.printHouseId,
  243. printHouseName: clazz.printHouseName,
  244. extendFields: "",
  245. ...this.modalForm
  246. };
  247. let extendFieldModal = {};
  248. this.extendFields.forEach(field => {
  249. extendFieldModal[field.code] = "";
  250. });
  251. data.extends = extendFieldModal;
  252. return data;
  253. });
  254. console.log(this.tableData);
  255. },
  256. updateUnusedClassList() {
  257. let usedClassIds = [];
  258. this.tableData.forEach(row => {
  259. usedClassIds = [...usedClassIds, ...row.classId.split(",")];
  260. });
  261. this.unusedClassList = this.classList.filter(
  262. item => !usedClassIds.includes(item.id)
  263. );
  264. },
  265. updatePackageInfos() {
  266. this.packageInfos.packageCount = this.tableData.length;
  267. this.packageInfos.studentCount = calcSum(
  268. this.tableData.map(item => item.studentCount)
  269. );
  270. this.packageInfos.paperReleaseCount = this.packageInfos.studentCount;
  271. this.packageInfos.paperBackupCount =
  272. this.packageInfos.packageCount * this.datas.printPlan.backupCount;
  273. this.packageInfos.paperCount =
  274. this.packageInfos.paperReleaseCount +
  275. this.packageInfos.paperBackupCount;
  276. },
  277. async getExtendFields() {
  278. const examRule = await examRuleDetail();
  279. this.extendFields = examRule.extendFields
  280. ? JSON.parse(examRule.extendFields)
  281. : [];
  282. },
  283. async getPrintHouses() {
  284. this.printHouses = await listTaskPrintHouse();
  285. },
  286. async getClassList() {
  287. this.classList = [];
  288. if (!this.datas.examTask.courseCode) return;
  289. const data = await listTaskApplyClass({
  290. courseCode: this.datas.examTask.courseCode
  291. });
  292. if (!data) return;
  293. this.classList = data.map(item => {
  294. return {
  295. id: item.classId,
  296. name: item.className,
  297. studentCount: item.studentCount,
  298. printHouseId: item.printHouseId,
  299. printHouseName: item.printHouseName
  300. };
  301. });
  302. },
  303. timeChange() {
  304. if (!this.createDate || !this.createTime) {
  305. this.modalForm.examStartTime = null;
  306. this.modalForm.examEndTime = null;
  307. return;
  308. }
  309. const curDate = getTimeDatestamp(this.createDate);
  310. const timeDate = getTimeDatestamp(this.createTime[0]);
  311. this.modalForm.examStartTime = curDate + this.createTime[0] - timeDate;
  312. this.modalForm.examEndTime = curDate + this.createTime[1] - timeDate;
  313. },
  314. printHouseChange(row) {
  315. const curHouse = this.printHouses.find(
  316. item => item.houseId === row.printHouseId
  317. );
  318. if (curHouse) {
  319. row.printHouseName = curHouse.houseName;
  320. }
  321. },
  322. toAdd() {
  323. if (!this.modalForm.examStartTime || !this.modalForm.examEndTime) {
  324. this.$message.error("请选择考试时间!");
  325. return;
  326. }
  327. if (this.modalForm.examStartTime === this.modalForm.examEndTime) {
  328. this.$message.error("考试开始时间不能等于考试结束时间!");
  329. return;
  330. }
  331. this.curRow = {
  332. examPlace: "",
  333. examRoom: "",
  334. classId: "",
  335. className: "",
  336. studentCount: null,
  337. printHouseId: null,
  338. printHouseName: null,
  339. extendFields: "",
  340. ...this.modalForm
  341. };
  342. let extendFieldModal = {};
  343. this.extendFields.forEach(field => {
  344. extendFieldModal[field.code] = "";
  345. });
  346. this.curRow.extends = extendFieldModal;
  347. this.$refs.ModifyPrintTask.open();
  348. },
  349. toEdit(row) {
  350. this.curRow = { ...row };
  351. this.$refs.ModifyPrintTask.open();
  352. },
  353. toDelete(row) {
  354. this.tableData = this.tableData.filter(
  355. item => item.classId !== row.classId
  356. );
  357. this.updateUnusedClassList();
  358. this.updatePackageInfos();
  359. },
  360. modified(data) {
  361. this.tableData.push(data);
  362. this.updateUnusedClassList();
  363. this.updatePackageInfos();
  364. }
  365. }
  366. };
  367. </script>