EditOtherQuestion.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. <!-- 编辑填空,问答,判断题 -->
  2. <template>
  3. <div id="editOtherApp">
  4. <section class="content" v-loading="fullscreenLoading">
  5. <div class="box box-info">
  6. <div class="box-header with-border">
  7. <h3 class="box-title">
  8. <span v-if="!quesModel.id">试题新增</span>
  9. <span v-if="quesModel.id">试题修改</span>
  10. </h3>
  11. </div>
  12. <div class="box-body">
  13. <el-form
  14. :model="quesModel"
  15. ref="quesModel"
  16. :rules="rules"
  17. label-position="right"
  18. label-width="80px"
  19. >
  20. <el-row :gutter="10">
  21. <el-col :xs="10" :sm="10" :md="10" :lg="10">
  22. <el-form-item label="题型">
  23. <el-select
  24. :disabled="true"
  25. v-model="quesModel.questionType"
  26. placeholder="请输入题型"
  27. >
  28. <el-option
  29. v-for="item in questionTypes"
  30. :label="item.label"
  31. :value="item.value"
  32. :key="item.value"
  33. >
  34. </el-option>
  35. </el-select>
  36. </el-form-item>
  37. </el-col>
  38. </el-row>
  39. <!-- created by weiwenhai -->
  40. <el-form-item label="难度">
  41. <el-select
  42. v-model="quesModel.difficultyDegree"
  43. placeholder="请输入难度"
  44. >
  45. <el-option
  46. v-for="item in difficultyDegreeList"
  47. :label="item.label"
  48. :value="item.value"
  49. :key="item.value"
  50. >
  51. </el-option>
  52. </el-select>
  53. </el-form-item>
  54. <el-form-item label="公开度">
  55. <el-select
  56. v-model="quesModel.publicity"
  57. placeholder="请输入公开度"
  58. >
  59. <el-option
  60. v-for="item in publicityList"
  61. :label="item.label"
  62. :value="item.value"
  63. :key="item.value"
  64. >
  65. </el-option>
  66. </el-select>
  67. </el-form-item>
  68. <el-form-item label="属性列表">
  69. <el-tooltip
  70. placement="top"
  71. v-for="(content, index) in quesModel.quesProperties"
  72. :key="index"
  73. >
  74. <div slot="content">
  75. <span v-if="content.firstProperty != null"
  76. >一级属性:{{ content.firstProperty.name }}</span
  77. ><br />
  78. <span v-if="content.secondProperty != null"
  79. >二级属性:{{ content.secondProperty.name }}</span
  80. >
  81. </div>
  82. <el-tag
  83. style="margin-right:5px;"
  84. :key="content.id"
  85. closable
  86. type="primary"
  87. @close="handleClose(content)"
  88. >
  89. {{ content.coursePropertyName }}
  90. </el-tag>
  91. </el-tooltip>
  92. </el-form-item>
  93. <el-row :gutter="20">
  94. <el-col :xs="6" :sm="6" :md="6" :lg="6">
  95. <el-form-item label="属性名">
  96. <el-select
  97. v-model="coursePropertyName"
  98. placeholder="属性名"
  99. @change="searchFirst"
  100. class="property_with"
  101. >
  102. <el-option
  103. v-for="item in coursePropertyList"
  104. :label="item.name"
  105. :value="item.name"
  106. :key="item.name"
  107. >
  108. </el-option>
  109. </el-select>
  110. </el-form-item>
  111. </el-col>
  112. <el-col :xs="6" :sm="6" :md="6" :lg="6">
  113. <el-form-item label="一级">
  114. <el-select
  115. v-model="firstPropertyId"
  116. placeholder="一级"
  117. @change="searchSecond"
  118. class="property_with"
  119. >
  120. <el-option
  121. v-for="item in firstPropertyList"
  122. :label="item.name"
  123. :value="item.id"
  124. :key="item.id"
  125. >
  126. </el-option>
  127. </el-select>
  128. </el-form-item>
  129. </el-col>
  130. <el-col :xs="6" :sm="6" :md="6" :lg="6">
  131. <el-form-item label="二级">
  132. <el-select
  133. v-model="secondPropertyId"
  134. placeholder="二级"
  135. class="property_with"
  136. >
  137. <el-option
  138. v-for="item in secondPropertyList"
  139. :label="item.name"
  140. :value="item.id"
  141. :key="item.id"
  142. >
  143. </el-option>
  144. </el-select>
  145. </el-form-item>
  146. </el-col>
  147. <el-col :xs="3" :sm="3" :md="3" :lg="3">
  148. <el-form-item>
  149. <el-button
  150. type="info"
  151. @click="insertProperty"
  152. style="margin-left:-30px;"
  153. >新增属性</el-button
  154. >
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. <!-- end -->
  159. <el-row :gutter="10">
  160. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  161. <el-form-item label="题干" prop="quesBody">
  162. <ckeditor v-model="quesModel.quesBody"></ckeditor>
  163. </el-form-item>
  164. </el-col>
  165. </el-row>
  166. <el-row
  167. :gutter="10"
  168. v-for="quesOption in quesModel.quesOptions"
  169. :key="quesOption"
  170. >
  171. <el-col :xs="30" :sm="30" :md="30" :lg="30">
  172. <el-form-item :label="quesOption.number">
  173. <ckeditor v-model="quesOption.quesBody"></ckeditor>
  174. </el-form-item>
  175. </el-col>
  176. </el-row>
  177. <!-- 非套题 -->
  178. <div
  179. v-if="
  180. quesModel.questionType !== 'NESTED_ANSWER_QUESTION' &&
  181. quesModel.questionType !== 'BOOL_ANSWER_QUESTION'
  182. "
  183. >
  184. <el-form-item label="答案" prop="quesAnswer">
  185. <ckeditor v-model="quesModel.quesAnswer"></ckeditor>
  186. </el-form-item>
  187. </div>
  188. <div v-if="quesModel.questionType == 'BOOL_ANSWER_QUESTION'">
  189. <el-row>
  190. <el-col>
  191. <el-form-item label="答案" prop="quesAnswer">
  192. <el-select
  193. v-model="quesModel.quesAnswer"
  194. placeholder="请选择"
  195. >
  196. <el-option
  197. v-for="op in options"
  198. :label="op"
  199. :value="op"
  200. :key="op"
  201. >
  202. </el-option>
  203. </el-select>
  204. </el-form-item>
  205. </el-col>
  206. </el-row>
  207. </div>
  208. <div class="paper-top">
  209. <el-form-item>
  210. <el-button type="primary" @click="saveQues('quesModel')"
  211. >保存</el-button
  212. >
  213. <el-button
  214. type="primary"
  215. icon="caret-left"
  216. @click="backToQuesList()"
  217. >返回列表</el-button
  218. >
  219. </el-form-item>
  220. </div>
  221. </el-form>
  222. </div>
  223. </div>
  224. </section>
  225. </div>
  226. </template>
  227. <script>
  228. import { QUESTION_API } from "@/constants/constants";
  229. import { QUESTION_TYPES } from "../constants/constants";
  230. import ckeditor from "../component/ckeditor.vue";
  231. export default {
  232. name: "editOtherApp",
  233. components: { ckeditor },
  234. data() {
  235. return {
  236. fullscreenLoading: false,
  237. questionTypes: QUESTION_TYPES,
  238. courseName: "",
  239. courseNo: "",
  240. paperDetailId: "",
  241. paperId: "",
  242. quesModel: {
  243. courseName: "",
  244. courseNo: "",
  245. quesAnswer: "",
  246. quesBody: "",
  247. questionType: "",
  248. difficultyDegree: "",
  249. publicity: true,
  250. quesProperties: [],
  251. score: 0
  252. },
  253. options: ["正确", "错误"],
  254. difficultyDegreeList: [
  255. { label: 0.1, value: 0.1 },
  256. { label: 0.2, value: 0.2 },
  257. { label: 0.3, value: 0.3 },
  258. { label: 0.4, value: 0.4 },
  259. { label: 0.5, value: 0.5 },
  260. { label: 0.6, value: 0.6 },
  261. { label: 0.7, value: 0.7 },
  262. { label: 0.8, value: 0.8 },
  263. { label: 0.9, value: 0.9 },
  264. { label: 1.0, value: 1.0 }
  265. ],
  266. publicityList: [
  267. { label: "公开", value: true },
  268. { label: "非公开", value: false }
  269. ],
  270. coursePropertyList: [],
  271. coursePropertyName: "", //课程属性名
  272. firstPropertyList: [], //一级属性集合
  273. firstPropertyId: "", //一级属性id
  274. secondPropertyList: [], //二级属性集合
  275. secondPropertyId: "", //二级属性id
  276. //验证
  277. rules: {
  278. // quesBody: [
  279. // {required: true, message: '请输入题干', trigger: 'blur'}
  280. // ],
  281. quesAnswer: [{ required: true, message: "请输入答案", trigger: "blur" }]
  282. }
  283. };
  284. },
  285. methods: {
  286. saveQues(formName) {
  287. if (!this.quesModel.difficultyDegree) {
  288. this.$notify({
  289. message: "请选择试题难度",
  290. type: "error"
  291. });
  292. return false;
  293. }
  294. this.$refs[formName].validate(valid => {
  295. if (valid) {
  296. if (this.questionId) {
  297. this.fullscreenLoading = true;
  298. //修改逻辑
  299. this.$http
  300. .put(QUESTION_API + "/question", this.quesModel)
  301. .then(() => {
  302. this.$notify({
  303. message: "保存成功",
  304. type: "success"
  305. });
  306. this.fullscreenLoading = false;
  307. });
  308. } else {
  309. //新增逻辑
  310. this.quesModel.courseNo = this.courseNo;
  311. this.quesModel.courseName = this.courseName;
  312. this.fullscreenLoading = true;
  313. this.$http
  314. .post(
  315. QUESTION_API +
  316. "/paper/addQuestion/" +
  317. this.paperId +
  318. "/" +
  319. this.paperDetailId,
  320. this.quesModel
  321. )
  322. .then(() => {
  323. this.fullscreenLoading = false;
  324. this.$notify({
  325. type: "info",
  326. message: `保存成功`
  327. });
  328. this.$router.push({ path: "/questions/question_list/0" });
  329. })
  330. .catch(() => {
  331. this.fullscreenLoading = false;
  332. console.log("添加失败");
  333. });
  334. }
  335. } else {
  336. return false;
  337. }
  338. });
  339. },
  340. getQues(id) {
  341. this.$http.get(QUESTION_API + "/question/" + id).then(response => {
  342. this.quesModel = response.data;
  343. this.initCourseProperty();
  344. });
  345. },
  346. backToQuesList() {
  347. this.$router.push({
  348. path: "/questions/question_list/0"
  349. });
  350. },
  351. //查询所有课程属性名
  352. initCourseProperty() {
  353. console.log(this.quesModel);
  354. var code = this.quesModel.course.code;
  355. this.$http
  356. .get(QUESTION_API + "/courseProperty/code/" + code)
  357. .then(response => {
  358. this.coursePropertyList = response.body;
  359. });
  360. },
  361. //查询一级属性
  362. searchFirst() {
  363. this.firstPropertyId = "";
  364. this.secondPropertyId = "";
  365. this.secondPropertyList = [];
  366. for (let courseProperty of this.coursePropertyList) {
  367. if (courseProperty.name == this.coursePropertyName) {
  368. this.$http
  369. .get(QUESTION_API + "/property/first/" + courseProperty.id)
  370. .then(response => {
  371. this.firstPropertyList = response.data;
  372. });
  373. }
  374. }
  375. },
  376. //查询二级属性
  377. searchSecond() {
  378. this.secondPropertyId = "";
  379. this.$http
  380. .get(QUESTION_API + "/property/second/" + this.firstPropertyId)
  381. .then(response => {
  382. this.secondPropertyList = response.body;
  383. });
  384. },
  385. //新增属性
  386. insertProperty() {
  387. if (!this.checkInsertPro()) {
  388. return false;
  389. }
  390. var quesProperty = {
  391. id: "",
  392. coursePropertyName: "",
  393. firstProperty: {},
  394. secondProperty: {}
  395. };
  396. if (
  397. this.quesModel.quesProperties === undefined ||
  398. this.quesModel.quesProperties.length == 0
  399. ) {
  400. this.quesModel.quesProperties = [];
  401. }
  402. quesProperty.id =
  403. this.coursePropertyName +
  404. "-" +
  405. this.firstPropertyId +
  406. "-" +
  407. this.secondPropertyId;
  408. for (let quesPro of this.quesModel.quesProperties) {
  409. if (quesPro.id == quesProperty.id) {
  410. this.$notify({
  411. message: "该属性已存在,请重新选择",
  412. type: "error"
  413. });
  414. return false;
  415. }
  416. }
  417. quesProperty.coursePropertyName = this.coursePropertyName;
  418. //取到一级属性对象
  419. for (let property of this.firstPropertyList) {
  420. if (property.id == this.firstPropertyId) {
  421. quesProperty.firstProperty = property;
  422. }
  423. }
  424. //判断是否有二级属性
  425. if (
  426. this.secondPropertyList != undefined &&
  427. this.secondPropertyList.length > 0
  428. ) {
  429. if (!this.secondPropertyId) {
  430. this.$notify({
  431. message: "请选择二级属性",
  432. type: "error"
  433. });
  434. return false;
  435. }
  436. }
  437. //取到二级属性对象
  438. for (let property of this.secondPropertyList) {
  439. if (property.id == this.secondPropertyId) {
  440. quesProperty.secondProperty = property;
  441. }
  442. }
  443. this.quesModel.quesProperties.push(quesProperty);
  444. this.quesModel = Object.assign({}, this.quesModel);
  445. console.log(
  446. "this.quesModel.quesProperties:",
  447. this.quesModel.quesProperties
  448. );
  449. //清空下拉框
  450. this.coursePropertyName = "";
  451. this.firstPropertyId = "";
  452. this.secondPropertyId = "";
  453. this.firstPropertyList = [];
  454. this.secondPropertyList = [];
  455. },
  456. //删除属性
  457. handleClose(tag) {
  458. console.log("tag:", tag);
  459. this.quesModel.quesProperties.splice(
  460. this.quesModel.quesProperties.indexOf(tag),
  461. 1
  462. );
  463. this.quesModel = Object.assign({}, this.quesModel);
  464. },
  465. //新增属性验证
  466. checkInsertPro() {
  467. if (!this.coursePropertyName) {
  468. this.$notify({
  469. message: "请选择属性",
  470. type: "error"
  471. });
  472. return false;
  473. }
  474. if (!this.firstPropertyId) {
  475. this.$notify({
  476. message: "请选择一级属性",
  477. type: "error"
  478. });
  479. return false;
  480. }
  481. return true;
  482. }
  483. },
  484. computed: {},
  485. created() {
  486. this.paperId = this.$route.params.paperId;
  487. this.paperDetailId = this.$route.params.paperDetailId;
  488. this.courseName = this.$route.params.courseName;
  489. this.courseNo = this.$route.params.courseNo;
  490. let questionType = this.$route.params.questionType;
  491. if (questionType) {
  492. this.quesModel.questionType = questionType;
  493. }
  494. this.questionId = this.$route.params.id;
  495. if (this.questionId) {
  496. this.quesModel["id"] = this.questionId;
  497. this.getQues(this.questionId);
  498. }
  499. if (this.courseNo) {
  500. this.$http
  501. .get(QUESTION_API + "/courseProperty/enable/" + this.courseNo)
  502. .then(response => {
  503. this.coursePropertyList = response.body;
  504. });
  505. }
  506. },
  507. mounted() {}
  508. };
  509. </script>
  510. <style scoped src="../styles/Common.css"></style>