CreatePrintTask.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <el-dialog
  3. class="create-print-task"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10px"
  7. width="600px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. label-width="100px"
  16. :rules="rules"
  17. :model="modalForm"
  18. >
  19. <el-form-item label="印刷计划:">
  20. <span>{{ instance.printPlanName }}</span>
  21. </el-form-item>
  22. <el-form-item label="考试时间:"
  23. >{{ instance.examStartTime | timestampFilter }} 至
  24. {{ instance.examEndTime | timestampFilter }}
  25. </el-form-item>
  26. <el-form-item prop="examRoom" label="考场:">
  27. <el-input
  28. v-model="modalForm.examRoom"
  29. placeholder="请填写考场名称"
  30. clearable
  31. ></el-input>
  32. </el-form-item>
  33. <el-form-item prop="examPlace" label="考点:">
  34. <el-input
  35. v-model="modalForm.examPlace"
  36. placeholder="请填写考点名称"
  37. clearable
  38. ></el-input>
  39. </el-form-item>
  40. <el-form-item prop="classId" label="考试对象:">
  41. <clazz-select
  42. v-if="classList.length"
  43. v-model="classIds"
  44. placeholder="请选择"
  45. multiple
  46. clearable
  47. :datas="classList"
  48. style="width:100%;"
  49. @change="classChange"
  50. ></clazz-select>
  51. </el-form-item>
  52. <el-form-item prop="studentCount" label="人数:">
  53. <el-input-number
  54. v-model="modalForm.studentCount"
  55. :min="0"
  56. :max="10000"
  57. :step="1"
  58. step-strictly
  59. disabled
  60. :controls="false"
  61. ></el-input-number>
  62. </el-form-item>
  63. <el-form-item prop="campusId" label="校区:">
  64. <campus-select
  65. v-model="modalForm.campusId"
  66. @change="campusChange"
  67. ></campus-select>
  68. </el-form-item>
  69. <el-form-item prop="printHouseId" label="印刷室:">
  70. <el-select
  71. v-model="modalForm.printHouseId"
  72. placeholder="请选择"
  73. @change="printHouseChange"
  74. >
  75. <el-option
  76. v-for="room in printRooms"
  77. :key="room.houseId"
  78. :value="room.houseId"
  79. :label="room.houseName"
  80. ></el-option>
  81. </el-select>
  82. </el-form-item>
  83. </el-form>
  84. <el-form
  85. ref="extendFieldFormComp"
  86. label-width="100px"
  87. :rules="extendFieldRules"
  88. :model="extendFieldModal"
  89. >
  90. <el-form-item
  91. v-for="item in extendFields"
  92. :key="item.code"
  93. :label="`${item.name}:`"
  94. :prop="item.code"
  95. >
  96. <el-input
  97. v-model="extendFieldModal[item.code]"
  98. :placeholder="`请填写${item.name}`"
  99. clearable
  100. ></el-input>
  101. </el-form-item>
  102. </el-form>
  103. <div slot="footer">
  104. <el-button type="primary" :disabled="isSubmit" @click="submit"
  105. >确认</el-button
  106. >
  107. <el-button @click="cancel">取消</el-button>
  108. </div>
  109. </el-dialog>
  110. </template>
  111. <script>
  112. import { calcSum } from "@/plugins/utils";
  113. import {
  114. createTaskPrint,
  115. listTaskPrintHouse,
  116. listTaskPrintClass
  117. } from "../api";
  118. export default {
  119. name: "create-print-task",
  120. props: {
  121. instance: {
  122. type: Object,
  123. default() {
  124. return {};
  125. }
  126. },
  127. extendFields: {
  128. type: Array,
  129. default() {
  130. return [];
  131. }
  132. }
  133. },
  134. computed: {
  135. isEdit() {
  136. return !!this.instance.id;
  137. },
  138. title() {
  139. return (this.isEdit ? "编辑" : "新增") + "印刷任务";
  140. }
  141. },
  142. data() {
  143. return {
  144. modalIsShow: false,
  145. isSubmit: false,
  146. modalForm: {},
  147. tableData: [],
  148. printRooms: [],
  149. teachers: [],
  150. classList: [],
  151. classIds: [],
  152. rules: {
  153. examRoom: [
  154. {
  155. required: true,
  156. message: "请输入考场名称",
  157. trigger: "change"
  158. },
  159. {
  160. max: 100,
  161. message: "考场名称不能超过100个字符",
  162. trigger: "change"
  163. }
  164. ],
  165. examPlace: [
  166. {
  167. required: true,
  168. message: "请输入考点名称",
  169. trigger: "change"
  170. },
  171. {
  172. max: 100,
  173. message: "考点名称不能超过100个字符",
  174. trigger: "change"
  175. }
  176. ],
  177. invigilatorTeacher: [
  178. {
  179. required: true,
  180. message: "请选择监考老师",
  181. trigger: "change"
  182. }
  183. ],
  184. classId: [
  185. {
  186. required: true,
  187. message: "请选择考试对象",
  188. trigger: "change"
  189. }
  190. ],
  191. studentCount: [
  192. {
  193. required: true,
  194. message: "请输入人数",
  195. trigger: "change"
  196. }
  197. ],
  198. campusId: [
  199. {
  200. required: true,
  201. message: "请选择校区",
  202. trigger: "change"
  203. }
  204. ],
  205. printHouseId: [
  206. {
  207. required: true,
  208. message: "请选择印刷室",
  209. trigger: "change"
  210. }
  211. ]
  212. },
  213. // extend field
  214. extendFieldModal: {},
  215. extendFieldRules: {}
  216. };
  217. },
  218. created() {
  219. this.getPrintHouses();
  220. this.extendFields.forEach(field => {
  221. this.extendFieldRules[field.code] = [
  222. {
  223. required: true,
  224. message: `请输入${field.name}`,
  225. trigger: "change"
  226. },
  227. {
  228. max: 100,
  229. message: `${field.name}不能超过100个字符`,
  230. trigger: "change"
  231. }
  232. ];
  233. });
  234. },
  235. methods: {
  236. async getPrintHouses() {
  237. this.printRooms = await listTaskPrintHouse();
  238. },
  239. async getClazzs() {
  240. const data = await listTaskPrintClass({
  241. printPlanId: this.instance.printPlanId,
  242. courseCode: this.instance.courseCode,
  243. paperNumber: this.instance.paperNumber,
  244. examTaskPrintId: this.instance.id
  245. });
  246. if (!data) {
  247. this.classList = [];
  248. return;
  249. }
  250. this.classList = data.map(item => {
  251. return {
  252. id: item.classId,
  253. name: item.className,
  254. studentCount: item.studentCount
  255. };
  256. });
  257. },
  258. visibleChange() {
  259. this.getClazzs();
  260. this.modalForm = { ...this.instance };
  261. this.classIds = this.modalForm.classId
  262. ? this.modalForm.classId.split(",")
  263. : [];
  264. const extendVals = this.instance.extends;
  265. let extendFieldModal = {};
  266. this.extendFields.forEach(field => {
  267. extendFieldModal[field.code] = extendVals ? extendVals[field.code] : "";
  268. });
  269. this.extendFieldModal = extendFieldModal;
  270. this.$nextTick(() => {
  271. this.$refs.modalFormComp.clearValidate();
  272. this.$refs.extendFieldFormComp.clearValidate();
  273. });
  274. },
  275. cancel() {
  276. this.modalIsShow = false;
  277. },
  278. open() {
  279. this.modalIsShow = true;
  280. },
  281. classChange(classes) {
  282. this.modalForm.className = classes.map(item => item.name).join();
  283. this.modalForm.classId = this.classIds.join();
  284. this.modalForm.studentCount = calcSum(
  285. classes.map(item => item.studentCount)
  286. );
  287. this.$refs.modalFormComp.validateField("classId", () => {});
  288. },
  289. campusChange(val) {
  290. this.modalForm.printHouseId = val.printHouseId;
  291. this.modalForm.printHouseName = val.printHouseName;
  292. },
  293. printHouseChange(val) {
  294. const curHouse = this.printRooms.find(item => item.houseId === val);
  295. if (curHouse) {
  296. this.modalForm.printHouseName = curHouse.houseName;
  297. }
  298. },
  299. async submit() {
  300. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  301. if (!valid) return;
  302. const extendValid = await this.$refs.extendFieldFormComp
  303. .validate()
  304. .catch(() => {});
  305. if (!extendValid) return;
  306. if (this.isSubmit) return;
  307. this.isSubmit = true;
  308. let datas = { ...this.modalForm };
  309. const extendFields = this.extendFields.map(field => {
  310. let info = { ...field };
  311. info.value = this.extendFieldModal[field.code];
  312. return info;
  313. });
  314. datas.extendFields = JSON.stringify(extendFields);
  315. const data = await createTaskPrint(datas).catch(() => {});
  316. this.isSubmit = false;
  317. if (!data) return;
  318. this.$emit("modified", this.modalForm);
  319. this.cancel();
  320. }
  321. }
  322. };
  323. </script>