edit.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. append-to-body
  8. width="60%"
  9. class="dialog question-dialog"
  10. top="6vh"
  11. @close="closeDialog"
  12. @open="getQuestionData"
  13. >
  14. <el-form
  15. ref="form"
  16. :label-width="formLabelWidth"
  17. :model="form"
  18. :rules="rules"
  19. class="question-form"
  20. :class="readonly ? 'readonly-form' : ''"
  21. @submit.native.prevent
  22. >
  23. <div class="inline-item">
  24. <el-form-item label="题型:" prop="ti_xing_">
  25. <el-select
  26. v-model="form.ti_xing_"
  27. filterable
  28. width="100%"
  29. placeholder="请选择题型"
  30. :disabled="readonly"
  31. @change="changeQuestionType"
  32. >
  33. <el-option
  34. v-for="item in questionType"
  35. :key="item.value"
  36. :label="item.label"
  37. :value="item.value"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="出题人:" prop="chu_ti_ren_">
  42. <el-select
  43. v-model="form.chu_ti_ren_"
  44. filterable
  45. width="100%"
  46. :disabled="readonly"
  47. placeholder="请选择出题人"
  48. >
  49. <el-option
  50. v-for="item in userList"
  51. :key="item.userId"
  52. :label="item.userName"
  53. :value="item.userId"
  54. />
  55. </el-select>
  56. </el-form-item>
  57. </div>
  58. <div class="inline-item" :class="['单选题', '多选题', '判断题'].includes(form.ti_xing_) ? 'mb-20' : ''">
  59. <el-form-item prop="ping_fen_fang_shi">
  60. <template slot="label">
  61. 评分方式
  62. <el-tooltip effect="dark" content="单选、多选和判断题为系统自动评分,其余为手动评分类型,需选择评分人。" placement="top">
  63. <i class="el-icon-question question-icon">:</i>
  64. </el-tooltip>
  65. </template>
  66. <el-radio-group v-model="questionRateType" disabled>
  67. <el-radio-button label="自动">自动</el-radio-button>
  68. <el-radio-button label="手动">手动</el-radio-button>
  69. </el-radio-group>
  70. </el-form-item>
  71. <el-form-item v-if="questionRateType === '手动'" label="评分人:" prop="ping_fen_ren_">
  72. <el-select
  73. v-model="form.ping_fen_ren_"
  74. filterable
  75. width="100%"
  76. clearable
  77. multiple
  78. collapse-tags
  79. :multiple-limit="16"
  80. :disabled="readonly"
  81. placeholder="请选择评分人"
  82. >
  83. <el-option
  84. v-for="item in userList"
  85. :key="item.userId"
  86. :label="item.userName"
  87. :value="item.userId"
  88. />
  89. </el-select>
  90. </el-form-item>
  91. </div>
  92. <el-form-item label="题干:" prop="ti_gan_">
  93. <el-input
  94. v-model="form.ti_gan_"
  95. type="textarea"
  96. :maxlength="512"
  97. :rows="2"
  98. :autosize="readonly"
  99. :disabled="readonly"
  100. placeholder="请输入题干内容"
  101. />
  102. </el-form-item>
  103. <el-form-item prop="biao_qian_">
  104. <template slot="label">
  105. 标签
  106. <el-tooltip effect="dark" content="可为题目设置标签便于后续检索。" placement="top">
  107. <i class="el-icon-question question-icon">:</i>
  108. </el-tooltip>
  109. </template>
  110. <el-tag
  111. v-for="tag in questionTags"
  112. :key="tag"
  113. closable
  114. size="medium"
  115. class="qustion-tag"
  116. :disable-transitions="false"
  117. :disabled="readonly"
  118. @close="handleTagDelete(tag)"
  119. >
  120. {{ tag }}
  121. </el-tag>
  122. <el-input
  123. v-if="tagInputVisible"
  124. ref="saveTagInput"
  125. v-model="tagValue"
  126. class="input-new-tag"
  127. size="small"
  128. :disabled="readonly"
  129. @keyup.enter.native="handleTagConfirm"
  130. @blur="handleTagConfirm"
  131. />
  132. <el-button v-else class="button-new-tag" size="small" @click="showTagEdit">+ 添 加</el-button>
  133. </el-form-item>
  134. <el-form-item label="附图:" prop="fu_tu_">
  135. <ibps-image
  136. v-model="form.fu_tu_"
  137. height="100"
  138. width="100"
  139. accept=".jpg,.jpeg,.png,.gif,.bmp,.webp"
  140. multiple
  141. download
  142. :disabled="readonly"
  143. size=""
  144. />
  145. </el-form-item>
  146. <el-form-item label="分值:" prop="fen_zhi_" :maxlength="8">
  147. <el-input-number
  148. v-model="form.fen_zhi_"
  149. :min="1"
  150. :max="100"
  151. :precision="0"
  152. type="number"
  153. :disabled="readonly"
  154. placeholder="请输入题目分值"
  155. />
  156. </el-form-item>
  157. <!-- <div class="inline-item" :class="['单选题', '多选题'].includes(form.ti_xing_) ? '' : 'mb-20'">
  158. <el-form-item label="分值:" prop="fen_zhi_" :maxlength="8">
  159. <el-input-number
  160. v-model="form.fen_zhi_"
  161. :min="1"
  162. :max="100"
  163. :precision="0"
  164. type="number"
  165. placeholder="请输入题目分值"
  166. />
  167. </el-form-item>
  168. <el-form-item v-if="['单选题', '多选题'].includes(form.ti_xing_)" label="选项类型:" prop="xuan_xiang_lei_xi">
  169. <el-radio-group v-model="form.xuan_xiang_lei_xi" disabled>
  170. <el-radio-button label="文本">文本</el-radio-button>
  171. <el-radio-button label="图片">图片</el-radio-button>
  172. </el-radio-group>
  173. </el-form-item>
  174. </div> -->
  175. <template v-if="['单选题', '多选题'].includes(form.ti_xing_)">
  176. <el-form-item
  177. v-for="(item, index) in optionList"
  178. :key="`${item.value}${index}`"
  179. class="option-item"
  180. >
  181. <template slot="label">
  182. <div class="custom-label">{{ `选项${item.value}:` }}</div>
  183. </template>
  184. <el-input
  185. v-model="item.content"
  186. type="textarea"
  187. :rows="1"
  188. :autosize="readonly"
  189. :disabled="readonly"
  190. placeholder="请输入选项内容,最多可配置8个选项"
  191. />
  192. <el-radio-group v-if="form.ti_xing_ === '单选题'" v-model="item.radio">
  193. <el-radio :label="item.value" @change="changeRadio(index, item.value)">正确选项</el-radio>
  194. </el-radio-group>
  195. <el-checkbox-group v-else-if="form.ti_xing_ === '多选题'" v-model="item.checkbox">
  196. <el-checkbox :label="item.value">正确选项</el-checkbox>
  197. </el-checkbox-group>
  198. <div class="operate-btn">
  199. <el-button
  200. v-if="index === 0 && optionList.length < 8"
  201. type="primary"
  202. :tabindex="-1"
  203. icon="el-icon-plus"
  204. circle
  205. @click="addOption"
  206. />
  207. <el-button
  208. v-else-if="index === optionList.length - 1"
  209. type="danger"
  210. :tabindex="-1"
  211. icon="el-icon-delete"
  212. circle
  213. @click="subOption"
  214. />
  215. </div>
  216. </el-form-item>
  217. </template>
  218. <template v-else-if="form.ti_xing_ === '填空题'">
  219. <el-form-item
  220. v-for="(item, index) in optionList"
  221. :key="`${item.value}${index}`"
  222. class="option-item"
  223. >
  224. <template slot="label">
  225. <div class="custom-label">{{ `答案${index + 1}:` }}</div>
  226. </template>
  227. <el-input
  228. v-model="item.content"
  229. type="textarea"
  230. :rows="1"
  231. :autosize="readonly"
  232. :disabled="readonly"
  233. placeholder="请输入答案内容,最多可配置20个答案"
  234. />
  235. <div v-if="!readonly" class="operate-btn">
  236. <el-button
  237. v-if="index === 0 && optionList.length < 20"
  238. type="primary"
  239. :tabindex="-1"
  240. icon="el-icon-plus"
  241. circle
  242. @click="addOption"
  243. />
  244. <el-button
  245. v-else-if="index === optionList.length - 1"
  246. type="danger"
  247. :tabindex="-1"
  248. icon="el-icon-delete"
  249. circle
  250. @click="subOption"
  251. />
  252. </div>
  253. </el-form-item>
  254. </template>
  255. <template v-else-if="form.ti_xing_ === '判断题'">
  256. <el-form-item prop="zheng_que_da_an_" label="答案:">
  257. <el-radio-group v-model="form.zheng_que_da_an_">
  258. <el-radio-button label="√">√</el-radio-button>
  259. <el-radio-button label="×">×</el-radio-button>
  260. </el-radio-group>
  261. </el-form-item>
  262. </template>
  263. <template v-else-if="form.ti_xing_ === '简答题'">
  264. <el-form-item prop="zheng_que_da_an_" label="答案:">
  265. <el-input
  266. v-model="form.zheng_que_da_an_"
  267. type="textarea"
  268. :rows="4"
  269. :autosize="readonly"
  270. :disabled="readonly"
  271. placeholder="请输入答案内容"
  272. />
  273. </el-form-item>
  274. </template>
  275. <el-form-item label="备注:" prop="bei_zhu_">
  276. <el-input
  277. v-model="form.bei_zhu_"
  278. type="textarea"
  279. :rows="2"
  280. :autosize="readonly"
  281. :disabled="readonly"
  282. placeholder="请输入题目备注信息"
  283. />
  284. </el-form-item>
  285. </el-form>
  286. <div slot="footer" class="el-dialog--center">
  287. <ibps-toolbar
  288. :actions="toolbars"
  289. @action-event="handleActionEvent"
  290. />
  291. </div>
  292. </el-dialog>
  293. </template>
  294. <script>
  295. import ActionUtils from '@/utils/action'
  296. import { questionType, rateType, defaultOptions } from '../constants'
  297. export default {
  298. components: {
  299. IbpsImage: () => import('@/business/platform/file/image')
  300. },
  301. props: {
  302. visible: {
  303. type: Boolean,
  304. default: false
  305. },
  306. bankId: {
  307. type: String,
  308. default: ''
  309. },
  310. id: {
  311. type: String,
  312. default: ''
  313. },
  314. // 是否复制题目
  315. isCopy: {
  316. type: Boolean,
  317. default: false
  318. },
  319. // 题库题目数据
  320. quesData: {
  321. type: Array,
  322. default: () => []
  323. },
  324. readonly: {
  325. type: Boolean,
  326. default: false
  327. }
  328. },
  329. data () {
  330. const { userList = [], deptList = [], userId } = this.$store.getters || {}
  331. const defaultType = questionType.length ? questionType[0].value : ''
  332. return {
  333. userId,
  334. userList,
  335. questionType,
  336. rateType,
  337. deptList: deptList.filter(i => i.depth === 4),
  338. title: this.readonly ? '题目详情' : this.id ? '编辑题目' : '添加题目',
  339. formLabelWidth: '120px',
  340. dialogVisible: this.visible,
  341. dialogLoading: false,
  342. tagInputVisible: false,
  343. tagValue: '',
  344. form: {
  345. // bu_men_: '',
  346. parent_id_: this.bankId,
  347. chu_ti_ren_: userId,
  348. chu_ti_shi_jian_: this.$common.getDateNow(19),
  349. ti_gan_: '',
  350. ti_xing_: defaultType,
  351. fu_tu_: '',
  352. xuan_xiang_lei_xi: '文本',
  353. da_an_: '',
  354. xuan_xiang_shu_: '',
  355. zheng_que_da_an_: '',
  356. ping_fen_fang_shi: rateType[defaultType] || '',
  357. ping_fen_ren_: [userId],
  358. fen_zhi_: '',
  359. bei_zhu_: '',
  360. zhuang_tai_: '启用'
  361. },
  362. questionTags: [],
  363. toolbars: [
  364. {
  365. key: 'submit',
  366. icon: 'ibps-icon-save',
  367. label: '保存',
  368. hidden: () => {
  369. return this.readonly
  370. }
  371. },
  372. {
  373. key: 'submitAndContinue',
  374. icon: 'ibps-icon-send',
  375. label: '保存并继续',
  376. type: 'warning',
  377. hidden: () => {
  378. return this.readonly || this.id
  379. }
  380. },
  381. {
  382. key: 'reset',
  383. icon: 'ibps-icon-refresh',
  384. label: '重置',
  385. type: 'info',
  386. hidden: () => {
  387. return this.readonly || this.id
  388. }
  389. },
  390. { key: 'cancel', label: '关闭' }
  391. ],
  392. rules: {
  393. ti_gan_: [{ required: true, message: this.$t('validate.required') }],
  394. ti_xing_: [{ required: true, message: this.$t('validate.required') }],
  395. da_an_: [{ required: true, message: this.$t('validate.required') }],
  396. zheng_que_da_an_: [{ required: true, message: this.$t('validate.required') }],
  397. xuan_xiang_lei_xi: [{ required: true, message: this.$t('validate.required') }],
  398. ping_fen_fang_shi: [{ required: true, message: this.$t('validate.required') }],
  399. ping_fen_ren_: [{ required: true, message: this.$t('validate.required') }],
  400. chu_ti_ren_: [{ required: true, message: this.$t('validate.required') }],
  401. fen_zhi_: [{ required: true, message: this.$t('validate.required') }]
  402. },
  403. optionList: JSON.parse(JSON.stringify(defaultOptions))
  404. }
  405. },
  406. computed: {
  407. formData () {
  408. return this.data
  409. },
  410. questionRateType () {
  411. return this.rateType[this.form.ti_xing_] || ''
  412. }
  413. },
  414. watch: {
  415. visible: {
  416. handler (val, oldVal) {
  417. this.dialogVisible = this.visible
  418. }
  419. // immediate: true
  420. }
  421. },
  422. mounted () {
  423. this.getQuestionData()
  424. },
  425. methods: {
  426. addOption () {
  427. this.optionList.push({
  428. value: String.fromCharCode(this.optionList[0].value.charCodeAt(0) + this.optionList.length),
  429. radio: null,
  430. checkbox: [],
  431. content: ''
  432. })
  433. },
  434. subOption () {
  435. this.optionList.pop()
  436. },
  437. changeRadio (index, value) {
  438. this.optionList.map(i => (i.radio = null))
  439. this.optionList[index].radio = value
  440. },
  441. changeQuestionType (value) {
  442. if (value === '填空题') {
  443. this.optionList = [{
  444. value: '',
  445. radio: null,
  446. checkbox: [],
  447. content: ''
  448. }]
  449. } else {
  450. this.optionList = JSON.parse(JSON.stringify(defaultOptions))
  451. }
  452. this.form.da_an_ = ''
  453. this.form.zheng_que_da_an_ = ''
  454. this.questionTags = []
  455. },
  456. handleTagDelete (tag) {
  457. this.questionTags.splice(this.questionTags.indexOf(tag), 1)
  458. },
  459. showTagEdit () {
  460. this.tagInputVisible = true
  461. this.$nextTick(_ => {
  462. this.$refs.saveTagInput.$refs.input.focus()
  463. })
  464. },
  465. handleTagConfirm () {
  466. if (this.tagValue) {
  467. this.questionTags.push(this.tagValue)
  468. }
  469. this.tagInputVisible = false
  470. this.tagValue = ''
  471. },
  472. handleActionEvent ({ key }) {
  473. switch (key) {
  474. case 'submit':
  475. this.handleSubmit(key)
  476. break
  477. case 'submitAndContinue':
  478. this.handleSubmit(key)
  479. break
  480. case 'reset':
  481. this.resetForm()
  482. break
  483. case 'cancel':
  484. this.closeDialog()
  485. break
  486. default:
  487. break
  488. }
  489. },
  490. // 获取题库数据
  491. getQuestionData () {
  492. if (this.$utils.isEmpty(this.id)) {
  493. return
  494. }
  495. const sql = `select id_, chu_ti_ren_, bu_men_, chu_ti_shi_jian_, ti_gan_, ti_xing_, xuan_xiang_lei_xi, biao_qian_, da_an_, zheng_que_da_an_, ping_fen_fang_shi, ping_fen_ren_, fen_zhi_, zhuang_tai_, xuan_xiang_shu_, fu_tu_, bei_zhu_ from t_questions where id_ = '${this.id}'`
  496. this.$common.request('sql', sql).then(res => {
  497. const { data = [] } = res.variables || {}
  498. if (!data.length) {
  499. return this.$message.error('获取题目数据失败!')
  500. }
  501. const item = data[0]
  502. if (item.ti_xing_ === '填空题') {
  503. const rightKey = item.zheng_que_da_an_ ? JSON.parse(item.zheng_que_da_an_) : []
  504. this.optionList = rightKey.map(i => ({
  505. value: '',
  506. radio: null,
  507. checkbox: [],
  508. content: i
  509. }))
  510. } else if (item.ti_xing_ === '单选题') {
  511. const rightKey = item.zheng_que_da_an_ || ''
  512. const options = item.da_an_ ? JSON.parse(item.da_an_) : {}
  513. this.optionList = []
  514. Object.keys(options).forEach(key => {
  515. this.optionList.push({
  516. value: key,
  517. radio: key === rightKey ? key : null,
  518. checkbox: [],
  519. content: options[key]
  520. })
  521. })
  522. } else if (item.ti_xing_ === '多选题') {
  523. const rightKey = item.zheng_que_da_an_ ? item.zheng_que_da_an_.split(',') : []
  524. const options = item.da_an_ ? JSON.parse(item.da_an_) : {}
  525. this.optionList = []
  526. Object.keys(options).forEach(key => {
  527. this.optionList.push({
  528. value: key,
  529. radio: null,
  530. checkbox: rightKey,
  531. content: options[key]
  532. })
  533. })
  534. }
  535. item.fen_zhi_ = parseInt(item.fen_zhi_)
  536. item.fu_tu_ = item.fu_tu_ ? JSON.parse(item.fu_tu_) : ''
  537. item.ping_fen_ren_ = item.ping_fen_ren_ ? item.ping_fen_ren_.split(',') : []
  538. this.questionTags = item.biao_qian_ ? item.biao_qian_.split(',') : []
  539. this.form = item
  540. })
  541. },
  542. handleSubmit (action) {
  543. this.$refs.form.validate((valid) => {
  544. if (!valid) {
  545. return ActionUtils.saveErrorMessage()
  546. }
  547. // 验证选项、答案内容(未被表单校验)
  548. const { ti_xing_: questionType } = this.form
  549. if (['单选题', '多选题', '填空题'].includes(questionType)) {
  550. const emptyIndex = this.optionList.findIndex(item => !item.content)
  551. if (emptyIndex !== -1) {
  552. const tip1 = `答案${(emptyIndex + 1)}内容为空,请填写后再保存!`
  553. const tip2 = `选项${(String.fromCharCode('A'.charCodeAt(0) + emptyIndex))}内容为空,请填写后再保存!`
  554. return ActionUtils.saveErrorMessage(questionType === '填空题' ? tip1 : tip2)
  555. }
  556. const hasRadioKey = this.optionList.some(item => item.radio)
  557. const hasMultipleKey = this.optionList.some(item => item.checkbox && item.checkbox.length)
  558. const hasKey = {
  559. '单选题': hasRadioKey,
  560. '多选题': hasMultipleKey
  561. }
  562. if (['单选题', '多选题'].includes(questionType) && !hasKey[questionType]) {
  563. return ActionUtils.saveErrorMessage('请至少选择一个正确答案!')
  564. }
  565. }
  566. this.getSubmitData()
  567. // 复制题目保存时不经过接口提交
  568. if (this.isCopy) {
  569. return this.updateQuesData()
  570. }
  571. this.submitForm(action)
  572. })
  573. },
  574. getSubmitData () {
  575. let a1 = ''
  576. const a2 = []
  577. const a3 = []
  578. const options = {}
  579. this.optionList.forEach(item => {
  580. options[item.value] = item.content
  581. if (item.radio) {
  582. a1 = item.radio
  583. }
  584. if (item.checkbox && item.checkbox.length) {
  585. a2.push(item.checkbox[0])
  586. }
  587. a3.push(item.content)
  588. })
  589. const { first, second } = this.$store.getters.level || {}
  590. this.form.di_dian_ = second || first
  591. this.form.biao_qian_ = this.questionTags.join(',')
  592. this.form.ping_fen_fang_shi = this.questionRateType
  593. switch (this.form.ti_xing_) {
  594. case '单选题':
  595. this.form.ping_fen_ren_ = ''
  596. this.form.da_an_ = JSON.stringify(options)
  597. this.form.zheng_que_da_an_ = a1
  598. break
  599. case '多选题':
  600. this.form.ping_fen_ren_ = ''
  601. this.form.da_an_ = JSON.stringify(options)
  602. this.form.zheng_que_da_an_ = a2.join(',')
  603. break
  604. case '填空题':
  605. this.form.ping_fen_ren_ = this.form.ping_fen_ren_ ? this.form.ping_fen_ren_.join(',') : ''
  606. this.form.xuan_xiang_lei_xi = ''
  607. this.form.da_an_ = ''
  608. this.form.xuan_xiang_shu_ = a3.length
  609. this.form.zheng_que_da_an_ = JSON.stringify(a3)
  610. break
  611. case '判断题':
  612. this.form.ping_fen_ren_ = ''
  613. this.form.xuan_xiang_lei_xi = ''
  614. this.form.da_an_ = ''
  615. break
  616. case '简答题':
  617. this.form.ping_fen_ren_ = this.form.ping_fen_ren_ ? this.form.ping_fen_ren_.join(',') : ''
  618. this.form.xuan_xiang_lei_xi = ''
  619. this.form.da_an_ = ''
  620. break
  621. default:
  622. break
  623. }
  624. },
  625. updateQuesData () {
  626. const newData = {
  627. quesId: this.id,
  628. creator: this.userId,
  629. createDept: '',
  630. createTime: this.$common.getDateNow(19),
  631. sn: '',
  632. content: this.form.ti_gan_,
  633. quesType: this.form.ti_xing_,
  634. img: this.form.fu_tu_,
  635. optionType: this.form.xuan_xiang_lei_xi,
  636. answer: this.form.da_an_,
  637. rightKey: this.form.zheng_que_da_an_,
  638. rateType: this.form.ping_fen_fang_shi,
  639. rater: this.form.ping_fen_ren_,
  640. score: this.form.fen_zhi_,
  641. note: this.form.bei_zhu_,
  642. optionCount: this.form.xuan_xiang_shu_,
  643. quesTag: this.form.biao_qian_,
  644. quesState: this.form.zhuang_tai_
  645. }
  646. const temp = JSON.parse(JSON.stringify(this.quesData))
  647. temp.forEach((item, index) => {
  648. if (item.quesId === this.id) {
  649. temp[index] = newData
  650. }
  651. })
  652. this.$emit('update', temp)
  653. this.closeDialog()
  654. },
  655. submitForm (action) {
  656. const addParams = {
  657. tableName: 't_questions',
  658. paramWhere: [this.form]
  659. }
  660. const updateParams = {
  661. tableName: 't_questions',
  662. updList: [
  663. {
  664. where: {
  665. id_: this.id
  666. },
  667. param: this.form
  668. }
  669. ]
  670. }
  671. // console.log(this.form, addParams)
  672. // return
  673. const type = this.id && !this.isCopy ? 'update' : 'add'
  674. const params = type === 'add' ? addParams : updateParams
  675. this.$common.request(type, params).then(() => {
  676. this.$message.success(this.id ? '保存题目成功' : '添加题目成功')
  677. this.updatePaper()
  678. // 题库中编辑后更新题库处显示的题目信息
  679. if (this.id && !this.isCopy) {
  680. return this.updateQuesData()
  681. }
  682. if (action === 'submit') {
  683. this.closeDialog()
  684. } else {
  685. this.resetForm()
  686. }
  687. })
  688. },
  689. resetForm () {
  690. this.id = ''
  691. const quesType = this.form.ti_xing_
  692. this.$refs.form.resetFields()
  693. this.changeQuestionType(quesType)
  694. },
  695. updatePaper () {
  696. const sql = `select fen_zhi_ from t_questions where parent_id_ = '${this.bankId}'`
  697. this.$common.request('sql', sql).then(res => {
  698. const { data = [] } = res.variables || {}
  699. const params = {
  700. tableName: 't_question_bank',
  701. updList: [
  702. {
  703. where: {
  704. id_: this.bankId
  705. },
  706. param: {
  707. ti_shu_: data.length,
  708. zong_fen_: data.reduce((sum, item) => sum + parseInt(item.fen_zhi_), 0)
  709. }
  710. }
  711. ]
  712. }
  713. this.$common.request('update', params).then(() => {
  714. console.log('更新题库信息成功')
  715. })
  716. })
  717. },
  718. // 关闭当前窗口
  719. closeDialog () {
  720. this.$emit('close', false)
  721. }
  722. }
  723. }
  724. </script>
  725. <style lang="scss" scoped>
  726. .question-dialog {
  727. ::v-deep {
  728. .el-dialog {
  729. min-width: 1080px;
  730. }
  731. .el-dialog__body {
  732. height: calc(88vh - 200px);
  733. }
  734. .el-form-item {
  735. margin-bottom: 14px !important;
  736. &:last-child {
  737. margin-bottom: 0 !important;
  738. }
  739. .el-form-item__label {
  740. font-size: 14px !important;
  741. }
  742. }
  743. .el-form-item--small .el-form-item__error {
  744. padding-top: 6px;
  745. }
  746. .el-radio-button__orig-radio {
  747. &:disabled + .el-radio-button__inner {
  748. color: #606266;
  749. }
  750. &:disabled:checked + .el-radio-button__inner {
  751. color: #fff;
  752. background-color: #409EFF;
  753. }
  754. }
  755. }
  756. .readonly-form {
  757. ::v-deep {
  758. .el-radio, .el-checkbox, .el-radio-button, .el-input, .el-select, .el-textarea, .el-input-number, .el-button, .el-upload {
  759. pointer-events: none;
  760. }
  761. }
  762. }
  763. .qustion-tag {
  764. margin-right: 10px;
  765. height: 32px;
  766. line-height: 30px;
  767. ::v-deep {
  768. .el-icon-close {
  769. top: 0px;
  770. }
  771. }
  772. }
  773. .button-new-tag {
  774. height: 32px;
  775. line-height: 30px;
  776. padding-top: 0;
  777. padding-bottom: 0;
  778. }
  779. .input-new-tag {
  780. width: 100px;
  781. vertical-align: bottom;
  782. }
  783. .question-form {
  784. padding: 20px;
  785. }
  786. .ibps-image {
  787. font-size: 0;
  788. ::v-deep {
  789. .el-upload--picture-card {
  790. font-size: 24px;
  791. }
  792. }
  793. }
  794. .inline-item {
  795. display: flex;
  796. .el-form-item {
  797. flex: 1;
  798. .el-select {
  799. width: 100%;
  800. }
  801. }
  802. }
  803. .mb-20 {
  804. margin-bottom: 20px;
  805. }
  806. .option-item {
  807. ::v-deep {
  808. .el-form-item__content {
  809. display: flex;
  810. .el-input {
  811. flex: 1;
  812. }
  813. .el-radio-group, .el-checkbox-group {
  814. width: 100px;
  815. margin-left: 10px;
  816. line-height: 28px;
  817. .el-radio {
  818. line-height: 28px;
  819. }
  820. }
  821. .operate-btn {
  822. width: 32px;
  823. min-width: 32px;
  824. margin-left: 10px;
  825. line-height: 30px;
  826. }
  827. }
  828. }
  829. .custom-label {
  830. &::before {
  831. content: '*';
  832. color: #F56C6C;
  833. margin-right: 4px;
  834. }
  835. }
  836. }
  837. }
  838. </style>