ModifyPrintTask.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <el-dialog
  3. class="modify-print-task"
  4. :visible.sync="modalIsShow"
  5. 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. >{{ instance.examStartTime | timestampFilter }} 至
  21. {{ instance.examEndTime | timestampFilter }}
  22. </el-form-item>
  23. <el-form-item prop="classId" label="考试对象:">
  24. <clazz-select
  25. v-model="classIds"
  26. placeholder="请选择"
  27. multiple
  28. clearable
  29. :datas="classList"
  30. style="width:100%;"
  31. @change="classChange"
  32. ></clazz-select>
  33. </el-form-item>
  34. <el-form-item prop="studentCount" label="人数:">
  35. <el-input-number
  36. v-model="modalForm.studentCount"
  37. :min="0"
  38. :step="1"
  39. step-strictly
  40. disabled
  41. :controls="false"
  42. ></el-input-number>
  43. </el-form-item>
  44. <el-form-item prop="printHouseId" label="印刷室:">
  45. <el-select
  46. v-model="modalForm.printHouseId"
  47. placeholder="请选择"
  48. @change="printHouseChange"
  49. >
  50. <el-option
  51. v-for="room in printHouses"
  52. :key="room.houseId"
  53. :value="room.houseId"
  54. :label="room.houseName"
  55. ></el-option>
  56. </el-select>
  57. </el-form-item>
  58. </el-form>
  59. <el-form
  60. ref="extendFieldFormComp"
  61. label-width="100px"
  62. :rules="extendFieldRules"
  63. :model="extendFieldModal"
  64. >
  65. <el-form-item
  66. v-for="item in extendFields"
  67. :key="item.code"
  68. :label="`${item.name}:`"
  69. :prop="item.code"
  70. >
  71. <el-input
  72. v-model="extendFieldModal[item.code]"
  73. :placeholder="`请填写${item.name}`"
  74. clearable
  75. ></el-input>
  76. </el-form-item>
  77. </el-form>
  78. <div slot="footer">
  79. <el-button type="primary" :disabled="isSubmit" @click="submit"
  80. >确认</el-button
  81. >
  82. <el-button @click="cancel">取消</el-button>
  83. </div>
  84. </el-dialog>
  85. </template>
  86. <script>
  87. import { calcSum } from "@/plugins/utils";
  88. export default {
  89. name: "modify-print-task",
  90. props: {
  91. instance: {
  92. type: Object,
  93. default() {
  94. return {};
  95. }
  96. },
  97. extendFields: {
  98. type: Array,
  99. default() {
  100. return [];
  101. }
  102. },
  103. printHouses: {
  104. type: Array,
  105. default() {
  106. return [];
  107. }
  108. },
  109. classList: {
  110. type: Array,
  111. default() {
  112. return [];
  113. }
  114. }
  115. },
  116. data() {
  117. return {
  118. modalIsShow: false,
  119. isSubmit: false,
  120. modalForm: {},
  121. tableData: [],
  122. teachers: [],
  123. classIds: [],
  124. rules: {
  125. classId: [
  126. {
  127. required: true,
  128. message: "请选择考试对象",
  129. trigger: "change"
  130. }
  131. ],
  132. studentCount: [
  133. {
  134. required: true,
  135. message: "请输入人数",
  136. trigger: "change"
  137. }
  138. ],
  139. printHouseId: [
  140. {
  141. required: true,
  142. message: "请选择印刷室",
  143. trigger: "change"
  144. }
  145. ]
  146. },
  147. // extend field
  148. extendFieldModal: {},
  149. extendFieldRules: {}
  150. };
  151. },
  152. methods: {
  153. visibleChange() {
  154. this.modalForm = { ...this.instance };
  155. this.classIds = this.modalForm.classId
  156. ? this.modalForm.classId.split(",")
  157. : [];
  158. const extendVals = this.instance.extends;
  159. let extendFieldModal = {};
  160. this.extendFields.forEach(field => {
  161. extendFieldModal[field.code] = extendVals ? extendVals[field.code] : "";
  162. });
  163. this.extendFieldModal = extendFieldModal;
  164. this.extendFieldRules = {};
  165. this.extendFields.forEach(field => {
  166. this.extendFieldRules[field.code] = [
  167. {
  168. required: true,
  169. message: `请输入${field.name}`,
  170. trigger: "change"
  171. },
  172. {
  173. max: 100,
  174. message: `${field.name}不能超过100个字符`,
  175. trigger: "change"
  176. }
  177. ];
  178. });
  179. this.$nextTick(() => {
  180. this.$refs.modalFormComp.clearValidate();
  181. this.$refs.extendFieldFormComp.clearValidate();
  182. });
  183. },
  184. cancel() {
  185. this.modalIsShow = false;
  186. },
  187. open() {
  188. this.modalIsShow = true;
  189. },
  190. classChange(classes) {
  191. this.modalForm.className = classes.map(item => item.name).join();
  192. this.modalForm.classId = this.classIds.join();
  193. this.modalForm.studentCount = calcSum(
  194. classes.map(item => item.studentCount)
  195. );
  196. this.$refs.modalFormComp.validateField("classId", () => {});
  197. },
  198. printHouseChange(val) {
  199. const curHouse = this.printHouses.find(item => item.houseId === val);
  200. if (curHouse) {
  201. this.modalForm.printHouseName = curHouse.houseName;
  202. }
  203. },
  204. async submit() {
  205. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  206. if (!valid) return;
  207. const extendValid = await this.$refs.extendFieldFormComp
  208. .validate()
  209. .catch(() => {});
  210. if (!extendValid) return;
  211. let datas = { ...this.modalForm };
  212. datas.extends = { ...this.extendFieldModal };
  213. this.$emit("modified", datas);
  214. this.cancel();
  215. }
  216. }
  217. };
  218. </script>