QuestionInfoEdit.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div class="question-info-edit">
  3. <el-form label-width="100px" inline>
  4. <el-form-item label="难度">
  5. <el-select
  6. v-model="modalForm.difficulty"
  7. placeholder="请选择难度"
  8. @change="emitChange"
  9. >
  10. <el-option
  11. v-for="item in DIFFICULTY_LIST"
  12. :key="item.code"
  13. :label="item.name"
  14. :value="item.code"
  15. >
  16. </el-option>
  17. </el-select>
  18. </el-form-item>
  19. <el-form-item v-if="IS_PAPER_MODE" label="分值" label-width="50px">
  20. <el-input-number
  21. v-model="modalForm.score"
  22. placeholder="分值"
  23. :precision="1"
  24. :min="0"
  25. :max="999"
  26. :step="0.1"
  27. step-strictly
  28. :controls="false"
  29. ></el-input-number>
  30. </el-form-item>
  31. <el-form-item v-if="IS_PAPER_MODE" label="时长" label-width="50px">
  32. <el-input-number
  33. v-model="modalForm.control.maxAnswerTime"
  34. :precision="0"
  35. :min="1"
  36. :max="999"
  37. :step="1"
  38. step-strictly
  39. :controls="false"
  40. ></el-input-number>
  41. </el-form-item>
  42. <br />
  43. <el-form-item prop="quesProperties" label="属性名">
  44. <div class="box-flex">
  45. <property-select
  46. v-model="properties.coursePropertyId"
  47. :course-id="modalForm.courseId"
  48. @change="coursePropertyChange"
  49. ></property-select>
  50. <span style="margin: 0 12px 0 18px">一级</span>
  51. <property-sub-select
  52. v-model="properties.firstPropertyId"
  53. :parent-id="properties.coursePropertyId"
  54. data-type="first"
  55. @change="firstPropertyChange"
  56. ></property-sub-select>
  57. <span style="margin: 0 12px 0 18px">二级</span>
  58. <property-sub-select
  59. v-model="properties.secondPropertyId"
  60. :parent-id="properties.firstPropertyId"
  61. data-type="second"
  62. @change="secondPropertyChange"
  63. ></property-sub-select>
  64. <el-button
  65. class="margin-lr-10"
  66. type="primary"
  67. icon="icon icon-plus-white"
  68. :disabled="!propSelected"
  69. @click="addProperty"
  70. >新增属性</el-button
  71. >
  72. </div>
  73. </el-form-item>
  74. <br />
  75. <el-form-item label="属性列表">
  76. <el-tag
  77. v-for="content in modalForm.quesProperties"
  78. :key="content.key"
  79. closable
  80. effect="dark"
  81. type="primary"
  82. style="margin-right: 5px; margin-bottom: 5px"
  83. @close="removeProperty(content)"
  84. >
  85. {{ content.courseProperty && content.courseProperty.name }}
  86. <span style="margin: 0 3px">/</span>
  87. {{ content.firstProperty && content.firstProperty.name }}
  88. <span
  89. v-if="content.secondProperty && content.secondProperty.name"
  90. style="margin: 0 3px"
  91. >/</span
  92. >
  93. {{ content.secondProperty && content.secondProperty.name }}
  94. </el-tag>
  95. </el-form-item>
  96. </el-form>
  97. </div>
  98. </template>
  99. <script>
  100. import { DIFFICULTY_LIST } from "@/constants/constants";
  101. const initModalForm = {
  102. editMode: "question",
  103. courseId: "",
  104. difficulty: "易",
  105. quesProperties: [],
  106. score: 0,
  107. control: { maxAnswerTime: 0 },
  108. };
  109. export default {
  110. name: "QuestionInfoEdit",
  111. props: {
  112. question: {
  113. type: Object,
  114. default() {
  115. return {};
  116. },
  117. },
  118. },
  119. data() {
  120. return {
  121. DIFFICULTY_LIST,
  122. modalForm: {
  123. ...initModalForm,
  124. },
  125. properties: {
  126. coursePropertyId: "",
  127. firstPropertyId: "",
  128. secondPropertyId: "",
  129. },
  130. selection: {
  131. courseProperty: {},
  132. firstProperty: {},
  133. secondProperty: {},
  134. },
  135. };
  136. },
  137. computed: {
  138. propSelected() {
  139. return (
  140. this.properties.coursePropertyId && this.properties.firstPropertyId
  141. );
  142. },
  143. IS_PAPER_MODE() {
  144. return this.modalForm.editMode === "paper";
  145. },
  146. },
  147. mounted() {
  148. this.initData();
  149. },
  150. methods: {
  151. initData() {
  152. let modalForm = this.$objAssign(initModalForm, this.question);
  153. if (modalForm.editMode === "paper" && this.question.control) {
  154. modalForm.control = this.$objAssign(
  155. initModalForm.control,
  156. this.question.control
  157. );
  158. }
  159. if (modalForm.quesProperties && modalForm.quesProperties.length) {
  160. modalForm.quesProperties.forEach((item) => {
  161. let ids = [item.courseProperty.id, item.firstProperty.id];
  162. if (item.secondProperty && item.secondProperty.id) {
  163. ids.push(item.secondProperty.id);
  164. }
  165. item.key = ids.join("_");
  166. });
  167. } else {
  168. modalForm.quesProperties = [];
  169. }
  170. this.modalForm = modalForm;
  171. },
  172. coursePropertyChange(val) {
  173. this.selection.courseProperty = val || {};
  174. },
  175. firstPropertyChange(val) {
  176. this.selection.firstProperty = val || {};
  177. },
  178. secondPropertyChange(val) {
  179. this.selection.secondProperty = val || {};
  180. },
  181. removeProperty(property) {
  182. this.modalForm.quesProperties = this.modalForm.quesProperties.filter(
  183. (item) => property.key !== item.key
  184. );
  185. this.emitChange();
  186. },
  187. addProperty() {
  188. if (!this.propSelected) return;
  189. let ids = [
  190. this.properties.coursePropertyId,
  191. this.properties.firstPropertyId,
  192. ];
  193. if (this.properties.secondPropertyId) {
  194. ids.push(this.properties.secondPropertyId);
  195. }
  196. const newProperty = {
  197. key: ids.join("_"),
  198. ...this.selection,
  199. };
  200. const propertyExist = this.modalForm.quesProperties.find(
  201. (item) => item.key === newProperty.key
  202. );
  203. if (propertyExist) {
  204. this.$message.error("属性已存在!");
  205. return;
  206. }
  207. this.modalForm.quesProperties.push(newProperty);
  208. this.emitChange();
  209. },
  210. emitChange() {
  211. this.$emit("change", this.modalForm);
  212. },
  213. },
  214. };
  215. </script>