InsertPaperTitle.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <section class="content">
  3. <!-- 正文信息 -->
  4. <div class="box-body">
  5. <el-form :inline="true" :model="paperTitleForm" label-width="150px">
  6. <el-row>
  7. <el-form-item label="课程名称(代码)" class="pull-left">
  8. <el-select
  9. class="dialog_input_width"
  10. @change="searchGenPaper"
  11. v-model="paperTitleForm.courseNo"
  12. filterable
  13. clearable
  14. remote
  15. placeholder="请输入课程名称(代码)"
  16. :remote-method="queryCoursesByKeyword"
  17. @focus="e => queryCoursesByKeyword(e.target.value)"
  18. >
  19. <el-option
  20. v-for="item in courseInfoSelect"
  21. :key="item.courseNo"
  22. :label="item.courseInfo"
  23. :value="item.courseNo"
  24. >
  25. </el-option>
  26. </el-select>
  27. </el-form-item>
  28. </el-row>
  29. <el-row v-if="paperTitelDisable">
  30. <el-form-item label="试卷名称" class="pull-left">
  31. <el-select
  32. class="dialog_input_width"
  33. v-model="paperTitleForm.paperId"
  34. filterable
  35. placeholder="请选择"
  36. @change="searchPaperDetail"
  37. sytle="width:220px;"
  38. >
  39. <el-option
  40. v-for="item in paperInfoSelect"
  41. :label="item.name"
  42. :value="item.id"
  43. :key="item.id"
  44. >
  45. </el-option>
  46. </el-select>
  47. <span style="padding-left:5px;">
  48. <el-button type="primary" @click="insertPaper"
  49. ><i class="el-icon-plus"></i> 新增试卷</el-button
  50. >
  51. </span>
  52. </el-form-item>
  53. </el-row>
  54. <el-row v-if="paperDetailDisable">
  55. <el-form-item label="试卷大题" class="pull-left">
  56. <el-select
  57. class="dialog_input_width"
  58. v-model="paperTitleForm.paperDetailId"
  59. filterable
  60. placeholder="请选择"
  61. >
  62. <el-option
  63. v-for="item in paperDetailInfoSelect"
  64. :label="item.name"
  65. :value="item.id"
  66. :key="item.id"
  67. >
  68. </el-option>
  69. </el-select>
  70. </el-form-item>
  71. </el-row>
  72. <el-row>
  73. <el-form-item label="题型" class="pull-left">
  74. <el-select
  75. class="dialog_input_width"
  76. v-model="paperTitleForm.value"
  77. filterable
  78. placeholder="请选择"
  79. >
  80. <el-option
  81. v-for="item in quesTypes"
  82. :label="item.label"
  83. :value="item.value"
  84. :key="item.id"
  85. >
  86. </el-option>
  87. </el-select>
  88. </el-form-item>
  89. </el-row>
  90. <el-row>
  91. <el-form-item label=" " class="pull-left">
  92. <el-button
  93. type="primary"
  94. :disabled="nextDisabled"
  95. @click="submitForm"
  96. >下一步
  97. </el-button>
  98. </el-form-item>
  99. </el-row>
  100. </el-form>
  101. <!-- 添加试卷弹出框 -->
  102. <el-dialog title="新增试卷" :visible.sync="paperDialog" width="500px">
  103. <el-form
  104. :model="paperForm"
  105. ref="paperForm"
  106. :rules="rules"
  107. label-position="right"
  108. label-width="120px"
  109. inline-message
  110. >
  111. <el-row>
  112. <el-form-item label="试卷名称" label-width="120px" prop="name">
  113. <el-input
  114. class="dialog_input_width"
  115. v-model="paperForm.name"
  116. placeholder="请输入试卷名称"
  117. ></el-input>
  118. </el-form-item>
  119. </el-row>
  120. <el-row class="margin_top_10 margin_left_120">
  121. <el-button type="primary" @click="submitPaperForm('paperForm')"
  122. >保 存</el-button
  123. >
  124. <el-button @click="resetPaperForm('paperForm')"
  125. ><i class="el-icon-refresh"></i> 重 置</el-button
  126. >
  127. </el-row>
  128. </el-form>
  129. </el-dialog>
  130. </div>
  131. </section>
  132. </template>
  133. <script>
  134. import { CORE_API, QUESTION_API } from "@/constants/constants";
  135. import { mapState } from "vuex";
  136. export default {
  137. data() {
  138. return {
  139. paperTitleForm: {
  140. courseNo: "",
  141. courseName: "",
  142. paperId: "",
  143. paperDetailId: "",
  144. value: ""
  145. },
  146. paperForm: {
  147. name: ""
  148. },
  149. paperDialog: false,
  150. courseList: [],
  151. tableData: [],
  152. detailsData: [],
  153. quesTypes: [
  154. { value: "SINGLE_ANSWER_QUESTION", label: "单选" },
  155. { value: "MULTIPLE_ANSWER_QUESTION", label: "多选" },
  156. { value: "BOOL_ANSWER_QUESTION", label: "判断" },
  157. { value: "FILL_BLANK_QUESTION", label: "填空" },
  158. { value: "TEXT_ANSWER_QUESTION", label: "问答" }
  159. ],
  160. rules: {
  161. name: [{ required: true, message: "请输入试卷名称", trigger: "blur" }]
  162. }
  163. };
  164. },
  165. methods: {
  166. //远端查询课程
  167. queryCoursesByKeyword(query) {
  168. query = query.trim();
  169. this.courseLoading = true;
  170. this.$http
  171. .get(CORE_API + "/course/query?name=" + query + "&enable=true")
  172. .then(response => {
  173. this.courseList = response.data;
  174. this.courseLoading = false;
  175. });
  176. },
  177. //根据课程查询试卷集合
  178. searchGenPaper() {
  179. this.$http
  180. .get(
  181. QUESTION_API +
  182. "/importPaper/1/500/?courseNo=" +
  183. this.paperTitleForm.courseNo
  184. )
  185. .then(response => {
  186. this.tableData = response.data.content;
  187. });
  188. this.paperTitleForm.paperId = "";
  189. this.paperTitleForm.paperDetailId = "";
  190. },
  191. //根据试卷查询大题
  192. searchPaperDetail() {
  193. this.$http
  194. .get(QUESTION_API + "/paperDetail/paper/" + this.paperTitleForm.paperId)
  195. .then(response => {
  196. this.detailsData = response.data;
  197. console.log("response.data:", response.data);
  198. console.log("this.detailsData:", this.detailsData);
  199. for (var i = 0; i < this.detailsData.length; i++) {
  200. if (!this.detailsData[i].name) {
  201. this.detailsData[i].name = "默认大题";
  202. }
  203. }
  204. });
  205. this.paperTitleForm.paperDetailId = "";
  206. },
  207. //新增试卷
  208. insertPaper() {
  209. this.paperDialog = true;
  210. },
  211. //重置
  212. resetPaperForm(formData) {
  213. this.$refs[formData].resetFields();
  214. },
  215. //提交新增试卷
  216. submitPaperForm(formData) {
  217. this.$refs[formData].validate(valid => {
  218. if (valid) {
  219. for (let course of this.courseList) {
  220. if (course.code == this.paperTitleForm.courseNo) {
  221. this.paperTitleForm.courseName = course.name;
  222. }
  223. }
  224. console.log("课程名称:" + this.paperTitleForm.courseName);
  225. this.$http
  226. .post(
  227. QUESTION_API +
  228. "/importPaper/saveBlankPaper/" +
  229. this.paperTitleForm.courseNo +
  230. "/" +
  231. this.paperForm.name
  232. )
  233. .then(response => {
  234. var paperId = response.data.paper.id;
  235. this.$http
  236. .get(
  237. QUESTION_API +
  238. "/importPaper/1/500/?courseNo=" +
  239. this.paperTitleForm.courseNo
  240. )
  241. .then(response => {
  242. this.tableData = response.data.content;
  243. this.paperTitleForm.paperDetailId = "";
  244. this.paperTitleForm.paperId = paperId;
  245. this.searchPaperDetail();
  246. });
  247. this.paperDialog = false;
  248. })
  249. .catch(error => {
  250. this.$notify({ type: "error", message: error.response.data.msg });
  251. this.paperDialog = false;
  252. });
  253. } else {
  254. return false;
  255. }
  256. });
  257. },
  258. //提交
  259. submitForm() {
  260. var path = "";
  261. switch (this.paperTitleForm.value) {
  262. case "SINGLE_ANSWER_QUESTION":
  263. case "MULTIPLE_ANSWER_QUESTION":
  264. path = "edit_select_question";
  265. break;
  266. case "TEXT_ANSWER_QUESTION":
  267. case "FILL_BLANK_QUESTION":
  268. case "BOOL_ANSWER_QUESTION":
  269. path = "edit_other_question";
  270. break;
  271. }
  272. for (let course of this.courseList) {
  273. if (course.code == this.paperTitleForm.courseNo) {
  274. this.paperTitleForm.courseName = course.name;
  275. }
  276. }
  277. console.log(path);
  278. this.$router.push({
  279. path:
  280. path +
  281. "/" +
  282. this.paperTitleForm.paperId +
  283. "/" +
  284. this.paperTitleForm.paperDetailId +
  285. "/" +
  286. this.paperTitleForm.value +
  287. "/" +
  288. this.paperTitleForm.courseNo +
  289. "/" +
  290. this.paperTitleForm.courseName
  291. });
  292. }
  293. },
  294. computed: {
  295. paperTitelDisable() {
  296. if (this.paperTitleForm.courseNo) {
  297. return true;
  298. } else {
  299. return false;
  300. }
  301. },
  302. paperDetailDisable() {
  303. console.log(
  304. "this.paperTitleForm.courseNo:",
  305. this.paperTitleForm.courseNo
  306. );
  307. console.log("this.paperTitleForm.paperId:", this.paperTitleForm.paperId);
  308. console.log("this.detailsData.length:", this.detailsData.length);
  309. if (
  310. this.paperTitleForm.courseNo &&
  311. this.paperTitleForm.paperId &&
  312. this.detailsData.length > 0
  313. ) {
  314. return true;
  315. } else {
  316. return false;
  317. }
  318. },
  319. nextDisabled() {
  320. if (
  321. this.paperTitleForm.courseNo &&
  322. this.paperTitleForm.paperId &&
  323. this.paperTitleForm.paperDetailId &&
  324. this.paperTitleForm.value
  325. ) {
  326. return false;
  327. } else {
  328. return true;
  329. }
  330. },
  331. //获取课程的集合
  332. courseInfoSelect() {
  333. var courseList = [];
  334. for (let course of this.courseList) {
  335. var courseInfo = course.name + "(" + course.code + ")";
  336. var courseNo = course.code;
  337. courseList.push({ courseNo: courseNo, courseInfo: courseInfo });
  338. }
  339. return courseList;
  340. },
  341. //获取试卷的集合
  342. paperInfoSelect() {
  343. var paperList = [];
  344. for (let paper of this.tableData) {
  345. var paperId = paper.id;
  346. var paperName = paper.name;
  347. paperList.push({ id: paperId, name: paperName });
  348. }
  349. return paperList;
  350. },
  351. //获取大题的集合
  352. paperDetailInfoSelect() {
  353. var paperDetaliList = [];
  354. for (let paperDetail of this.detailsData) {
  355. var paperDetailId = paperDetail.id;
  356. var paperDetailName = paperDetail.name;
  357. paperDetaliList.push({ id: paperDetailId, name: paperDetailName });
  358. }
  359. return paperDetaliList;
  360. },
  361. routeType() {
  362. return this.$route.params.type;
  363. },
  364. ...mapState({ user: state => state.user })
  365. },
  366. //初始化
  367. created() {}
  368. };
  369. </script>
  370. <style scoped src="../styles/Common.css"></style>
  371. <style scoped>
  372. .box_width_lg {
  373. width: 600px;
  374. }
  375. </style>