edit.vue 31 KB

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