EditFillLine.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <div class="edit-fill-line">
  3. <el-form
  4. ref="modalFormComp"
  5. :model="modalForm"
  6. :rules="rules"
  7. :key="modalForm.id"
  8. label-width="120px"
  9. >
  10. <!-- <el-form-item prop="topicNo" label="大题序号:">
  11. <el-input-number
  12. v-model="modalForm.topicNo"
  13. :min="1"
  14. :max="99"
  15. :step="1"
  16. step-strictly
  17. :controls="false"
  18. ></el-input-number>
  19. </el-form-item> -->
  20. <el-form-item prop="topicName" label="题目名称:">
  21. <card-name-edit v-model="modalForm"></card-name-edit>
  22. </el-form-item>
  23. <el-form-item prop="endNumber" label="起止题号:">
  24. <el-input-number
  25. style="width: 40px"
  26. v-model="modalForm.startNumber"
  27. :min="0"
  28. :max="999"
  29. :step="1"
  30. step-strictly
  31. :controls="false"
  32. @change="lineTypeChange"
  33. ></el-input-number>
  34. <span class="el-input-split"></span>
  35. <el-input-number
  36. style="width: 40px"
  37. v-model="modalForm.endNumber"
  38. :min="0"
  39. :max="999"
  40. :step="1"
  41. step-strictly
  42. :controls="false"
  43. @change="lineTypeChange"
  44. ></el-input-number>
  45. </el-form-item>
  46. <el-form-item prop="lineSpacing" label="空位上下间距:">
  47. <el-input-number
  48. style="width: 125px"
  49. v-model.number="modalForm.lineSpacing"
  50. :min="20"
  51. :max="100"
  52. :step="1"
  53. step-strictly
  54. :controls="false"
  55. ></el-input-number>
  56. </el-form-item>
  57. <el-form-item prop="questionNumberPerLine" label="每行空数:">
  58. <el-input-number
  59. style="width: 125px"
  60. v-model="modalForm.questionNumberPerLine"
  61. :min="1"
  62. :max="10"
  63. :step="1"
  64. step-strictly
  65. :controls="false"
  66. ></el-input-number>
  67. <span class="el-input-tips">*指一行显示空位数量</span>
  68. </el-form-item>
  69. <el-form-item label="题号前缀:">
  70. <el-input
  71. style="width: 125px"
  72. v-model.trim="modalForm.numberPre"
  73. :maxlength="6"
  74. clearable
  75. ></el-input>
  76. </el-form-item>
  77. <el-form-item label="空位排列方向:" required>
  78. <el-radio-group v-model="modalForm.questionDirection" size="small">
  79. <el-radio-button
  80. v-for="(val, key) in DIRECTION_TYPE"
  81. :key="key"
  82. :label="key"
  83. >{{ val }}</el-radio-button
  84. >
  85. </el-radio-group>
  86. </el-form-item>
  87. <el-form-item label="小题空数类型:">
  88. <el-radio-group
  89. v-model="modalForm.questionLineType"
  90. size="small"
  91. @change="lineTypeChange"
  92. >
  93. <el-radio-button label="norm">标准</el-radio-button>
  94. <el-radio-button label="custom">自定义</el-radio-button>
  95. </el-radio-group>
  96. </el-form-item>
  97. <el-form-item
  98. v-if="modalForm.questionLineType === 'norm'"
  99. prop="lineNumberPerQuestion"
  100. label="每题空数:"
  101. >
  102. <el-input-number
  103. style="width: 125px"
  104. v-model="modalForm.lineNumberPerQuestion"
  105. :min="1"
  106. :max="15"
  107. :step="1"
  108. step-strictly
  109. :controls="false"
  110. ></el-input-number>
  111. <span class="el-input-tips">*指每一小题的空位数量</span>
  112. </el-form-item>
  113. <el-form-item v-else prop="questionLineNums" label="各小题空数:">
  114. <table class="table table-white table-narrow">
  115. <tr>
  116. <th>题号</th>
  117. <th>空数</th>
  118. </tr>
  119. <tr v-for="option in questionLineNumOptions" :key="option.no">
  120. <td>{{ option.no }}</td>
  121. <td>
  122. <el-input-number
  123. v-model="option.count"
  124. size="mini"
  125. :min="1"
  126. :max="50"
  127. :step="1"
  128. step-strictly
  129. :controls="false"
  130. style="width: 125px"
  131. ></el-input-number>
  132. </td>
  133. </tr>
  134. </table>
  135. </el-form-item>
  136. </el-form>
  137. </div>
  138. </template>
  139. <script>
  140. import { DIRECTION_TYPE } from "../../enumerate";
  141. import CardNameEdit from "../../components/common/CardNameEdit.vue";
  142. const initModalForm = {
  143. id: "",
  144. topicNo: null,
  145. topicName: "",
  146. startNumber: 1,
  147. endNumber: 2,
  148. questionsCount: 2,
  149. questionNumberPerLine: 1,
  150. lineNumberPerQuestion: 1,
  151. lineSpacing: 40,
  152. questionDirection: "horizontal",
  153. questionLineType: "norm",
  154. questionLineNums: [],
  155. numberPre: "",
  156. };
  157. export default {
  158. name: "edit-fill-line",
  159. components: { CardNameEdit },
  160. props: {
  161. instance: {
  162. type: Object,
  163. default() {
  164. return {};
  165. },
  166. },
  167. },
  168. data() {
  169. const numberRangeValidater = (rule, value, callback) => {
  170. if (!this.modalForm.startNumber || !this.modalForm.endNumber) {
  171. return callback(new Error("请输入起止题号"));
  172. }
  173. if (this.modalForm.startNumber > this.modalForm.endNumber) {
  174. callback(new Error("开始题号不能大于结束题号"));
  175. } else {
  176. callback();
  177. }
  178. };
  179. return {
  180. modalForm: { ...initModalForm },
  181. DIRECTION_TYPE,
  182. questionLineNumOptions: [{ no: 1, count: 1 }],
  183. rules: {
  184. topicNo: [
  185. {
  186. required: true,
  187. message: "请输入大题序号",
  188. trigger: "change",
  189. },
  190. ],
  191. topicName: [
  192. {
  193. required: true,
  194. message: "请输入题目名称",
  195. trigger: "change",
  196. },
  197. ],
  198. endNumber: [
  199. {
  200. required: true,
  201. message: "请输入起止题号",
  202. trigger: "change",
  203. },
  204. {
  205. type: "number",
  206. validator: numberRangeValidater,
  207. trigger: "change",
  208. },
  209. ],
  210. lineSpacing: [
  211. {
  212. required: true,
  213. type: "number",
  214. message: "请输入空位上下间距",
  215. trigger: "change",
  216. },
  217. ],
  218. questionNumberPerLine: [
  219. {
  220. required: true,
  221. type: "number",
  222. message: "请输入每行空数",
  223. trigger: "change",
  224. },
  225. ],
  226. lineNumberPerQuestion: [
  227. {
  228. required: true,
  229. type: "number",
  230. message: "请输入每题空数",
  231. trigger: "change",
  232. },
  233. ],
  234. },
  235. };
  236. },
  237. mounted() {
  238. this.initData(this.instance);
  239. },
  240. methods: {
  241. initData(val) {
  242. const valInfo = val.parent || val;
  243. this.modalForm = { ...valInfo };
  244. this.modalForm.endNumber =
  245. this.modalForm.startNumber + this.modalForm.questionsCount - 1;
  246. this.questionLineNumOptions = this.modalForm.questionLineNums;
  247. },
  248. lineTypeChange() {
  249. // check start end number
  250. if (
  251. !this.modalForm.startNumber ||
  252. !this.modalForm.endNumber ||
  253. this.modalForm.startNumber > this.modalForm.endNumber
  254. )
  255. return;
  256. if (this.modalForm.questionLineType === "custom") {
  257. let questionLineNumOptions = [];
  258. for (
  259. let i = this.modalForm.startNumber;
  260. i <= this.modalForm.endNumber;
  261. i++
  262. ) {
  263. questionLineNumOptions.push({
  264. no: i,
  265. count: this.modalForm.lineNumberPerQuestion,
  266. });
  267. }
  268. this.questionLineNumOptions = questionLineNumOptions;
  269. } else {
  270. this.questionLineNumOptions = [];
  271. }
  272. },
  273. async submit() {
  274. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  275. if (!valid) return;
  276. this.modalForm.questionsCount =
  277. this.modalForm.endNumber - this.modalForm.startNumber + 1;
  278. this.modalForm.questionLineNums = this.questionLineNumOptions;
  279. this.modalForm.topicName = this.modalForm.topicName.trim();
  280. this.$emit("modified", this.modalForm);
  281. },
  282. },
  283. };
  284. </script>