QuestionInfoEdit.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="question-info-edit">
  3. <el-form :label-width="labelWidth">
  4. <el-form-item v-if="IS_PAPER_MODE" label="分值">
  5. <el-input-number
  6. v-model="modalForm.score"
  7. placeholder="分值"
  8. :precision="1"
  9. :min="0"
  10. :max="999"
  11. :step="0.1"
  12. step-strictly
  13. :controls="false"
  14. @change="emitChange"
  15. ></el-input-number>
  16. </el-form-item>
  17. <el-form-item label="难度" class="question-info-inline">
  18. <el-select
  19. v-model="modalForm.difficulty"
  20. placeholder="请选择"
  21. @change="emitChange"
  22. >
  23. <el-option
  24. v-for="item in DIFFICULTY_LIST"
  25. :key="item.code"
  26. :label="item.name"
  27. :value="item.code"
  28. >
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item
  33. label="时长"
  34. class="question-info-inline"
  35. label-width="60px"
  36. >
  37. <el-input-number
  38. v-model="modalForm.control.maxAnswerTime"
  39. :precision="0"
  40. :min="0"
  41. :max="999"
  42. :step="1"
  43. step-strictly
  44. :controls="false"
  45. @change="emitChange"
  46. ></el-input-number>
  47. </el-form-item>
  48. <el-form-item
  49. label="公开度"
  50. class="question-info-inline"
  51. label-width="60px"
  52. >
  53. <el-select
  54. v-model="modalForm.publicity"
  55. placeholder="请选择"
  56. @change="emitChange"
  57. >
  58. <el-option
  59. v-for="item in publicityList"
  60. :key="item.value"
  61. :label="item.label"
  62. :value="item.value"
  63. >
  64. </el-option>
  65. </el-select>
  66. </el-form-item>
  67. <!-- <el-form-item
  68. class="question-info-prop"
  69. prop="quesProperties"
  70. label="属性名"
  71. > -->
  72. <el-form-item
  73. class="question-info-prop"
  74. prop="quesProperties"
  75. label="知识点"
  76. >
  77. <div class="box-flex">
  78. <KnowledgePoints
  79. :courseId="modalForm.courseId"
  80. @change="addProperty"
  81. :checkedProperties="modalForm.quesProperties"
  82. ></KnowledgePoints>
  83. <!-- <property-select
  84. v-model="properties.coursePropertyId"
  85. :course-id="modalForm.courseId"
  86. :use-cache="useCoursePropertyCache"
  87. @change="coursePropertyChange"
  88. ></property-select>
  89. <span class="prop-label">一级</span>
  90. <property-sub-select
  91. v-model="properties.firstPropertyId"
  92. :parent-id="properties.coursePropertyId"
  93. data-type="first"
  94. @change="firstPropertyChange"
  95. ></property-sub-select>
  96. <span class="prop-label">二级</span>
  97. <property-sub-select
  98. v-model="properties.secondPropertyId"
  99. :parent-id="properties.firstPropertyId"
  100. data-type="second"
  101. @change="secondPropertyChange"
  102. ></property-sub-select>
  103. <el-button
  104. class="margin-lr-10"
  105. type="primary"
  106. icon="icon icon-plus-white"
  107. :disabled="!propSelected"
  108. @click="addProperty"
  109. >新增属性</el-button
  110. > -->
  111. </div>
  112. </el-form-item>
  113. <!-- <el-form-item v-if="modalForm.quesProperties.length" label="知识点列表"> -->
  114. <el-form-item v-if="modalForm.quesProperties.length" label="">
  115. <el-tag
  116. v-for="content in modalForm.quesProperties"
  117. :key="content.key"
  118. closable
  119. effect="dark"
  120. type="primary"
  121. style="margin-right: 5px; margin-bottom: 5px"
  122. @close="removeProperty(content)"
  123. >
  124. <!-- {{ content.courseProperty && content.courseProperty.name }}
  125. <span style="margin: 0 3px">/</span> -->
  126. {{ content.firstProperty && content.firstProperty.name }}
  127. <span style="margin: 0 3px">/</span>
  128. {{ content.secondProperty && content.secondProperty.name }}
  129. </el-tag>
  130. </el-form-item>
  131. </el-form>
  132. </div>
  133. </template>
  134. <script>
  135. import { DIFFICULTY_LIST } from "@/constants/constants";
  136. import KnowledgePoints from "./KnowledgePoints.vue";
  137. import { cloneDeep } from "lodash";
  138. const initModalForm = {
  139. editMode: "question",
  140. courseId: "",
  141. difficulty: "易",
  142. quesProperties: [],
  143. score: 0,
  144. publicity: true,
  145. control: { maxAnswerTime: 0 },
  146. };
  147. export default {
  148. name: "QuestionInfoEdit",
  149. components: { KnowledgePoints },
  150. props: {
  151. question: {
  152. type: Object,
  153. default() {
  154. return {};
  155. },
  156. },
  157. labelWidth: {
  158. type: String,
  159. default: "100px",
  160. },
  161. useCoursePropertyCache: { type: Boolean, default: false },
  162. },
  163. data() {
  164. return {
  165. DIFFICULTY_LIST,
  166. modalForm: {
  167. ...initModalForm,
  168. },
  169. properties: {
  170. // coursePropertyId: "",
  171. firstPropertyId: "",
  172. secondPropertyId: "",
  173. },
  174. selection: {
  175. // courseProperty: {},
  176. firstProperty: {},
  177. secondProperty: {},
  178. },
  179. publicityList: [
  180. { label: "公开", value: true },
  181. { label: "非公开", value: false },
  182. ],
  183. };
  184. },
  185. computed: {
  186. // propSelected() {
  187. // return (
  188. // this.properties.coursePropertyId && this.properties.firstPropertyId
  189. // );
  190. // },
  191. IS_PAPER_MODE() {
  192. return this.modalForm.editMode === "paper";
  193. },
  194. },
  195. mounted() {
  196. this.initData();
  197. },
  198. methods: {
  199. initData() {
  200. let modalForm = this.$objAssign(initModalForm, this.question);
  201. if (modalForm.editMode === "paper" && this.question.control) {
  202. modalForm.control = this.$objAssign(
  203. initModalForm.control,
  204. this.question.control
  205. );
  206. }
  207. if (modalForm.quesProperties && modalForm.quesProperties.length) {
  208. modalForm.quesProperties.forEach((item) => {
  209. // let ids = [item.courseProperty.id, item.firstProperty.id];
  210. let ids = [item.firstProperty.id];
  211. if (item.secondProperty && item.secondProperty.id) {
  212. ids.push(item.secondProperty.id);
  213. }
  214. item.key = ids.join("_");
  215. });
  216. } else {
  217. modalForm.quesProperties = [];
  218. }
  219. this.modalForm = modalForm;
  220. },
  221. // coursePropertyChange(val) {
  222. // this.selection.courseProperty = val || {};
  223. // },
  224. // firstPropertyChange(val) {
  225. // this.selection.firstProperty = val || {};
  226. // },
  227. // secondPropertyChange(val) {
  228. // this.selection.secondProperty = val || {};
  229. // },
  230. removeProperty(property) {
  231. this.modalForm.quesProperties = this.modalForm.quesProperties.filter(
  232. (item) => property.key !== item.key
  233. );
  234. this.emitChange();
  235. },
  236. // addProperty() {
  237. // if (!this.propSelected) return;
  238. // let ids = [
  239. // // this.properties.coursePropertyId,
  240. // this.properties.firstPropertyId,
  241. // ];
  242. // if (this.properties.secondPropertyId) {
  243. // ids.push(this.properties.secondPropertyId);
  244. // }
  245. // const newProperty = {
  246. // key: ids.join("_"),
  247. // ...this.selection,
  248. // };
  249. // const propertyExist = this.modalForm.quesProperties.find(
  250. // (item) => item.key === newProperty.key
  251. // );
  252. // if (propertyExist) {
  253. // this.$message.error("属性已存在!");
  254. // return;
  255. // }
  256. // this.modalForm.quesProperties.push(newProperty);
  257. // this.emitChange();
  258. // },
  259. addProperty(arr) {
  260. this.modalForm.quesProperties = arr;
  261. this.emitChange();
  262. },
  263. emitChange() {
  264. // this.$emit("change", this.modalForm);
  265. let modalFormCopy = cloneDeep(this.modalForm);
  266. if (modalFormCopy.quesProperties?.length) {
  267. modalFormCopy.quesProperties = modalFormCopy.quesProperties.map(
  268. (item) => {
  269. if (item.firstProperty) {
  270. item.firstProperty = {
  271. id: item.firstProperty.id,
  272. name: item.firstProperty.name,
  273. };
  274. }
  275. if (item.secondProperty) {
  276. item.secondProperty = {
  277. id: item.secondProperty.id,
  278. name: item.secondProperty.name,
  279. };
  280. }
  281. return item;
  282. }
  283. );
  284. }
  285. console.log("modalFormCopy", modalFormCopy);
  286. this.$emit("change", modalFormCopy);
  287. },
  288. },
  289. };
  290. </script>