QuestionInfoEdit.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. <div class="box-flex">
  73. <property-select
  74. v-model="properties.coursePropertyId"
  75. :course-id="modalForm.courseId"
  76. @change="coursePropertyChange"
  77. ></property-select>
  78. <span class="prop-label">一级</span>
  79. <property-sub-select
  80. v-model="properties.firstPropertyId"
  81. :parent-id="properties.coursePropertyId"
  82. data-type="first"
  83. @change="firstPropertyChange"
  84. ></property-sub-select>
  85. <span class="prop-label">二级</span>
  86. <property-sub-select
  87. v-model="properties.secondPropertyId"
  88. :parent-id="properties.firstPropertyId"
  89. data-type="second"
  90. @change="secondPropertyChange"
  91. ></property-sub-select>
  92. <el-button
  93. class="margin-lr-10"
  94. type="primary"
  95. icon="icon icon-plus-white"
  96. :disabled="!propSelected"
  97. @click="addProperty"
  98. >新增属性</el-button
  99. >
  100. </div>
  101. </el-form-item>
  102. <el-form-item v-if="modalForm.quesProperties.length" label="属性列表">
  103. <el-tag
  104. v-for="content in modalForm.quesProperties"
  105. :key="content.key"
  106. closable
  107. effect="dark"
  108. type="primary"
  109. style="margin-right: 5px; margin-bottom: 5px"
  110. @close="removeProperty(content)"
  111. >
  112. {{ content.courseProperty && content.courseProperty.name }}
  113. <span style="margin: 0 3px">/</span>
  114. {{ content.firstProperty && content.firstProperty.name }}
  115. <span
  116. v-if="content.secondProperty && content.secondProperty.name"
  117. style="margin: 0 3px"
  118. >/</span
  119. >
  120. {{ content.secondProperty && content.secondProperty.name }}
  121. </el-tag>
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. </template>
  126. <script>
  127. import { DIFFICULTY_LIST } from "@/constants/constants";
  128. const initModalForm = {
  129. editMode: "question",
  130. courseId: "",
  131. difficulty: "易",
  132. quesProperties: [],
  133. score: 0,
  134. publicity: true,
  135. control: { maxAnswerTime: 0 },
  136. };
  137. export default {
  138. name: "QuestionInfoEdit",
  139. props: {
  140. question: {
  141. type: Object,
  142. default() {
  143. return {};
  144. },
  145. },
  146. labelWidth: {
  147. type: String,
  148. default: "100px",
  149. },
  150. },
  151. data() {
  152. return {
  153. DIFFICULTY_LIST,
  154. modalForm: {
  155. ...initModalForm,
  156. },
  157. properties: {
  158. coursePropertyId: "",
  159. firstPropertyId: "",
  160. secondPropertyId: "",
  161. },
  162. selection: {
  163. courseProperty: {},
  164. firstProperty: {},
  165. secondProperty: {},
  166. },
  167. publicityList: [
  168. { label: "公开", value: true },
  169. { label: "非公开", value: false },
  170. ],
  171. };
  172. },
  173. computed: {
  174. propSelected() {
  175. return (
  176. this.properties.coursePropertyId && this.properties.firstPropertyId
  177. );
  178. },
  179. IS_PAPER_MODE() {
  180. return this.modalForm.editMode === "paper";
  181. },
  182. },
  183. mounted() {
  184. this.initData();
  185. },
  186. methods: {
  187. initData() {
  188. let modalForm = this.$objAssign(initModalForm, this.question);
  189. if (modalForm.editMode === "paper" && this.question.control) {
  190. modalForm.control = this.$objAssign(
  191. initModalForm.control,
  192. this.question.control
  193. );
  194. }
  195. if (modalForm.quesProperties && modalForm.quesProperties.length) {
  196. modalForm.quesProperties.forEach((item) => {
  197. let ids = [item.courseProperty.id, item.firstProperty.id];
  198. if (item.secondProperty && item.secondProperty.id) {
  199. ids.push(item.secondProperty.id);
  200. }
  201. item.key = ids.join("_");
  202. });
  203. } else {
  204. modalForm.quesProperties = [];
  205. }
  206. this.modalForm = modalForm;
  207. },
  208. coursePropertyChange(val) {
  209. this.selection.courseProperty = val || {};
  210. },
  211. firstPropertyChange(val) {
  212. this.selection.firstProperty = val || {};
  213. },
  214. secondPropertyChange(val) {
  215. this.selection.secondProperty = val || {};
  216. },
  217. removeProperty(property) {
  218. this.modalForm.quesProperties = this.modalForm.quesProperties.filter(
  219. (item) => property.key !== item.key
  220. );
  221. this.emitChange();
  222. },
  223. addProperty() {
  224. if (!this.propSelected) return;
  225. let ids = [
  226. this.properties.coursePropertyId,
  227. this.properties.firstPropertyId,
  228. ];
  229. if (this.properties.secondPropertyId) {
  230. ids.push(this.properties.secondPropertyId);
  231. }
  232. const newProperty = {
  233. key: ids.join("_"),
  234. ...this.selection,
  235. };
  236. const propertyExist = this.modalForm.quesProperties.find(
  237. (item) => item.key === newProperty.key
  238. );
  239. if (propertyExist) {
  240. this.$message.error("属性已存在!");
  241. return;
  242. }
  243. this.modalForm.quesProperties.push(newProperty);
  244. this.emitChange();
  245. },
  246. emitChange() {
  247. this.$emit("change", this.modalForm);
  248. },
  249. },
  250. };
  251. </script>