RuleSign.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div class="rule-sign part-box part-box-pad">
  3. <h4 class="part-box-tips">签到表字段配置:</h4>
  4. <el-form
  5. ref="modalFormComp"
  6. :model="modalForm"
  7. :rules="rules"
  8. label-width="170px"
  9. >
  10. <el-form-item prop="basic" label="签到表表头字段:">
  11. <rule-field-edit
  12. v-model="modalForm.basic"
  13. :data="basicSources"
  14. @change="validateField('basic')"
  15. ></rule-field-edit>
  16. </el-form-item>
  17. <el-form-item prop="table" label="签到表考生信息字段:">
  18. <rule-field-edit
  19. v-model="modalForm.table"
  20. :data="tableSources"
  21. @change="validateField('table')"
  22. ></rule-field-edit>
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button
  26. type="primary"
  27. :disabled="isSubmit"
  28. style="width: 140px"
  29. @click="submit"
  30. >保存</el-button
  31. >
  32. </el-form-item>
  33. </el-form>
  34. </div>
  35. </template>
  36. <script>
  37. import { examRuleDetail, saveExamRule } from "../api";
  38. import RuleFieldEdit from "./RuleFieldEdit.vue";
  39. export default {
  40. name: "rule-sign",
  41. components: {
  42. RuleFieldEdit
  43. },
  44. data() {
  45. return {
  46. isSubmit: false,
  47. examRule: {},
  48. basicSources: [],
  49. tableSources: [],
  50. modalForm: {
  51. basic: [],
  52. table: []
  53. },
  54. stdInfoCodes: [
  55. "siteNumber",
  56. "studentName",
  57. "studentCode",
  58. "clazzName",
  59. "ticketNumber"
  60. ],
  61. rules: {
  62. basic: [
  63. {
  64. required: true,
  65. validator: (rule, value, callback) => {
  66. if (!value || !value.length) {
  67. return callback(new Error(`请选择签到表表头字段`));
  68. }
  69. callback();
  70. },
  71. trigger: "change"
  72. }
  73. ],
  74. table: [
  75. {
  76. required: true,
  77. validator: (rule, value, callback) => {
  78. if (!value || !value.length) {
  79. return callback(new Error(`请选择签到表考生信息字段`));
  80. }
  81. callback();
  82. },
  83. trigger: "change"
  84. }
  85. ]
  86. }
  87. };
  88. },
  89. mounted() {
  90. this.getFields();
  91. },
  92. methods: {
  93. async getFields() {
  94. const examRule = await examRuleDetail();
  95. this.examRule = examRule;
  96. let fields = [...JSON.parse(examRule.requiredFields)];
  97. if (examRule.extendFields)
  98. fields.push(...JSON.parse(examRule.extendFields));
  99. const fieldSources = fields
  100. .filter(item => item.enable)
  101. .map(item => {
  102. return {
  103. code: item.code,
  104. name: item.name
  105. };
  106. });
  107. this.basicSources = fieldSources.filter(
  108. item => !this.stdInfoCodes.includes(item.code)
  109. );
  110. this.tableSources = fieldSources.filter(item =>
  111. this.stdInfoCodes.includes(item.code)
  112. );
  113. this.modalForm = examRule.signScope
  114. ? JSON.parse(examRule.signScope)
  115. : { basic: [], table: [] };
  116. },
  117. validateField(field) {
  118. this.$refs.modalFormComp.validateField(field, () => {});
  119. },
  120. async submit() {
  121. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  122. if (!valid) return;
  123. if (this.isSubmit) return;
  124. this.isSubmit = true;
  125. this.examRule.signScope = JSON.stringify(this.modalForm);
  126. const data = await saveExamRule(this.examRule).catch(() => {});
  127. this.isSubmit = false;
  128. if (!data) return;
  129. this.$message.success("保存成功!");
  130. }
  131. }
  132. };
  133. </script>