EditFillLine.vue 8.1 KB

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