EditFillLine.vue 8.1 KB

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