EditOtherQuestion.vue 17 KB

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