EditFillLine.vue 7.6 KB

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