ModifyCardRule.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <div>
  3. <el-dialog
  4. class="modify-card-rule"
  5. :visible.sync="modalIsShow"
  6. :title="title"
  7. top="10px"
  8. width="900px"
  9. :close-on-click-modal="false"
  10. :close-on-press-escape="false"
  11. append-to-body
  12. @open="visibleChange"
  13. >
  14. <el-form
  15. ref="modalFormComp"
  16. label-width="130px"
  17. :rules="rules"
  18. :model="modalForm"
  19. :key="modalForm.id"
  20. >
  21. <el-form-item prop="name" label="题卡规则名称:">
  22. <el-input
  23. v-model.trim="modalForm.name"
  24. placeholder="建议不超过30个字,规则名称不允许重复"
  25. style="width: 100%"
  26. clearable
  27. ></el-input>
  28. </el-form-item>
  29. <el-form-item prop="modeType" label="模板选择:">
  30. <el-radio-group
  31. v-model="modalForm.modeType"
  32. :disabled="isEdit"
  33. @change="modeTypeChange"
  34. >
  35. <el-radio label="POSTGRADUATE">研究生题卡模板</el-radio>
  36. <el-radio label="EDUCATIONAL">教务处题卡模板A3</el-radio>
  37. </el-radio-group>
  38. </el-form-item>
  39. <template v-if="IS_EDUCATIONAL_MODE">
  40. <el-form-item
  41. prop="examNumberStyle"
  42. label="学号版式:"
  43. class="inline-block"
  44. >
  45. <el-select
  46. v-model="modalForm.examNumberStyle"
  47. placeholder="请选择"
  48. @change="numStyleChange"
  49. >
  50. <el-option
  51. v-for="(val, key) in EXAM_NUMBER_STYLE"
  52. :key="key"
  53. :value="key"
  54. :label="val"
  55. ></el-option>
  56. </el-select>
  57. </el-form-item>
  58. <el-form-item
  59. v-if="modalForm.examNumberStyle === 'FILL'"
  60. prop="examNumberDigit"
  61. label="学号位数:"
  62. class="inline-block"
  63. >
  64. <el-input-number
  65. v-model="modalForm.examNumberDigit"
  66. :min="5"
  67. :max="15"
  68. :step="1"
  69. step-strictly
  70. :controls="false"
  71. ></el-input-number>
  72. </el-form-item>
  73. <el-form-item>
  74. <el-checkbox v-model="modalForm.examAbsent"
  75. >启用“缺考填涂”</el-checkbox
  76. >
  77. <el-checkbox v-model="modalForm.discipline"
  78. >启用“违纪填涂”</el-checkbox
  79. >
  80. </el-form-item>
  81. <el-form-item prop="studentFields" label="考生信息设置:">
  82. <el-input
  83. v-model.trim="modalForm.studentFields"
  84. clearable
  85. ></el-input>
  86. <p class="tips-info">
  87. 提示:填写字段名,字段间用","隔开,例如:姓名,学号,班级。
  88. </p>
  89. </el-form-item>
  90. </template>
  91. <el-form-item prop="title" label="题卡正标题:">
  92. <el-input v-model.trim="modalForm.title" clearable></el-input>
  93. </el-form-item>
  94. <el-form-item prop="subTitle" label="题卡副标题:">
  95. <el-input v-model.trim="modalForm.subTitle" clearable></el-input>
  96. </el-form-item>
  97. <el-form-item prop="attention" label="注意事项:">
  98. <el-input
  99. type="textarea"
  100. :rows="4"
  101. v-model="modalForm.attention"
  102. ></el-input>
  103. <p class="tips-info">
  104. 提示:换行之后,题卡注意事项会展示为多条内容,内容序号会被自动添加。
  105. </p>
  106. </el-form-item>
  107. <el-form-item prop="objectiveAttention" label="客观题注意事项:">
  108. <el-input v-model.trim="modalForm.objectiveAttention"></el-input>
  109. </el-form-item>
  110. <el-form-item prop="subjectiveAttention" label="主观题注意事项:">
  111. <el-input v-model.trim="modalForm.subjectiveAttention"></el-input>
  112. </el-form-item>
  113. </el-form>
  114. <div slot="footer">
  115. <el-button type="primary" :disabled="isSubmit" @click="submit"
  116. >确认</el-button
  117. >
  118. <el-button @click="cancel">取消</el-button>
  119. </div>
  120. </el-dialog>
  121. </div>
  122. </template>
  123. <script>
  124. import { EXAM_NUMBER_STYLE } from "../enumerate";
  125. import { cardHeadDetailApi, cardHeadUpdateApi } from "../api";
  126. const initModalForm = {
  127. id: null,
  128. name: "",
  129. modeType: "EDUCATIONAL",
  130. pageSize: "A3",
  131. examNumberStyle: "",
  132. examNumberDigit: 10,
  133. examAbsent: true,
  134. discipline: true,
  135. studentFields: "",
  136. title: "",
  137. subTitle: "",
  138. attention: "",
  139. objectiveAttention: "",
  140. subjectiveAttention: "",
  141. };
  142. export default {
  143. name: "modify-card-rule",
  144. props: {
  145. instance: {
  146. type: Object,
  147. default() {
  148. return {};
  149. },
  150. },
  151. },
  152. computed: {
  153. isEdit() {
  154. return !!this.instance.id;
  155. },
  156. title() {
  157. return (this.isEdit ? "编辑" : "新增") + "题卡规则";
  158. },
  159. IS_EDUCATIONAL_MODE() {
  160. return this.modalForm.modeType === "EDUCATIONAL";
  161. },
  162. },
  163. data() {
  164. return {
  165. modalIsShow: false,
  166. isSubmit: false,
  167. modalForm: { ...initModalForm },
  168. EXAM_NUMBER_STYLE,
  169. rules: {
  170. name: [
  171. {
  172. required: true,
  173. message: "题卡规则名称不能超过30个字",
  174. max: 30,
  175. trigger: "change",
  176. },
  177. ],
  178. modeType: [
  179. {
  180. required: true,
  181. message: "请选择模板",
  182. trigger: "change",
  183. },
  184. ],
  185. examNumberStyle: [
  186. {
  187. required: true,
  188. message: "请选择学号版式",
  189. trigger: "change",
  190. },
  191. ],
  192. examNumberDigit: [
  193. {
  194. required: true,
  195. message: "请输入学号位数",
  196. trigger: "change",
  197. },
  198. ],
  199. studentFields: [
  200. {
  201. required: true,
  202. message: "请输入考生信息设置",
  203. trigger: "change",
  204. },
  205. {
  206. validator: (rule, value, callback) => {
  207. const vals = value.split(/,|,/);
  208. if (vals.length > 10) {
  209. return callback(new Error("最多只能输入10个字段名"));
  210. }
  211. if (vals.some((val) => val.length > 8)) {
  212. return callback(new Error("每个字段名最多只能输入8字符"));
  213. }
  214. return callback();
  215. },
  216. trigger: "change",
  217. },
  218. ],
  219. title: [
  220. {
  221. required: true,
  222. message: "请输入题卡正标题",
  223. trigger: "change",
  224. },
  225. {
  226. message: "题卡正标题不能超过26个字",
  227. max: 26,
  228. trigger: "change",
  229. },
  230. ],
  231. subTitle: [
  232. {
  233. required: false,
  234. message: "题卡副标题不能超过40个字",
  235. max: 40,
  236. trigger: "change",
  237. },
  238. ],
  239. attention: [
  240. {
  241. required: true,
  242. message: "请输入注意事项",
  243. trigger: "change",
  244. },
  245. {
  246. validator: (rule, value, callback) => {
  247. const val = value.replace(/\n/g, "");
  248. if (val.length > 200) {
  249. callback(new Error("注意事项最多只能输入200个字符"));
  250. } else {
  251. callback();
  252. }
  253. },
  254. trigger: "change",
  255. },
  256. ],
  257. objectiveAttention: [
  258. {
  259. required: false,
  260. message: "请输入客观题注意事项",
  261. trigger: "change",
  262. },
  263. {
  264. max: 40,
  265. message: "客观题注意事项最多只能输入40个汉字",
  266. trigger: "change",
  267. },
  268. ],
  269. subjectiveAttention: [
  270. {
  271. required: false,
  272. message: "请输入主观题注意事项",
  273. trigger: "change",
  274. },
  275. {
  276. max: 40,
  277. message: "主观题注意事项最多只能输入40个汉字",
  278. trigger: "change",
  279. },
  280. ],
  281. },
  282. };
  283. },
  284. methods: {
  285. async initData(val) {
  286. if (val.id) {
  287. const res = await cardHeadDetailApi(val.id);
  288. this.modalForm = this.$objAssign(initModalForm, res.data);
  289. } else {
  290. this.modalForm = this.$objAssign(initModalForm, val);
  291. }
  292. this.modalForm.examNumberDigit =
  293. this.modalForm.examNumberDigit || initModalForm.examNumberDigit;
  294. },
  295. visibleChange() {
  296. this.initData(this.instance);
  297. this.$nextTick(() => {
  298. this.$refs.modalFormComp.clearValidate();
  299. });
  300. },
  301. cancel() {
  302. this.modalIsShow = false;
  303. },
  304. open() {
  305. this.modalIsShow = true;
  306. },
  307. modeTypeChange(val) {
  308. if (val === "POSTGRADUATE") {
  309. this.modalForm.pageSize = "8K";
  310. this.modalForm.examAbsent = false;
  311. this.modalForm.discipline = false;
  312. this.modalForm.studentFields = "";
  313. } else {
  314. this.modalForm.pageSize = "A3";
  315. this.modalForm.examAbsent = true;
  316. this.modalForm.discipline = true;
  317. }
  318. },
  319. numStyleChange() {
  320. if (this.modalForm.examNumberStyle !== "FILL") {
  321. this.modalForm.examNumberDigit = 10;
  322. }
  323. },
  324. async submit() {
  325. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  326. if (!valid) return;
  327. if (this.isSubmit) return;
  328. this.isSubmit = true;
  329. const data = await cardHeadUpdateApi(this.modalForm).catch(() => {});
  330. this.isSubmit = false;
  331. if (!data) return;
  332. this.$message.success("保存成功!");
  333. this.$emit("modified");
  334. this.cancel();
  335. },
  336. },
  337. };
  338. </script>