EditFillLine.vue 8.1 KB

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