EditOtherQuestion.vue 16 KB

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