QAEdit.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-loading="loading"
  5. :show-close="false"
  6. :close-on-click-modal="false"
  7. :visible.sync="isShow"
  8. :title="curObj.id ? '编辑问答' : '新增问答'"
  9. :fullscreen="false"
  10. width="700px"
  11. custom-class="xl-dialog"
  12. center
  13. >
  14. <base-form ref="ruleForm" class="lib-edit" :data="formData" :is-inline="false" label-width="110px">
  15. <div slot="footer" style="padding-top: 20px;">
  16. <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
  17. <el-button class="xl-form-btn t1" @click="close('confirm')">确定</el-button>
  18. </div>
  19. </base-form>
  20. </el-dialog>
  21. </div>
  22. </template>
  23. <script>
  24. export default {
  25. components: { },
  26. mixins,
  27. props: {
  28. isShow: Boolean,
  29. curObj: Object
  30. },
  31. inject: ['parentData'],
  32. data() {
  33. return {
  34. formData: [],
  35. loading: true,
  36. cObj: {},
  37. isShowMap: false
  38. }
  39. },
  40. watch: {
  41. isShow: function(val) {
  42. if (val) {
  43. this.getDef()
  44. }
  45. },
  46. },
  47. methods: {
  48. getDef() {
  49. let disabled = false
  50. if (this.curObj.id) disabled = true
  51. this.formData = [
  52. { label: '标签', key: 'question_tag', rules: 1, type: 'select', options: this.$dictData.question_tag },
  53. { label: '问题', key: 'question_cont', type: 'textarea', rules: 1 },
  54. { label: '答案', key: 'answer_cont', type: 'textarea', rules: 1 },
  55. ]
  56. },
  57. close(str) {
  58. if (str === 'confirm') {
  59. this.$refs['ruleForm'].$refs['baseForm'].validate((valid) => {
  60. if (valid) {
  61. const oldform = this.$refs.ruleForm.baseForm
  62. const newForm = { ...oldform }
  63. if (this.curObj.id) {
  64. newForm.id = this.curObj.id
  65. }
  66. let apiStr = 'admqaadd'
  67. // newForm.question_tag = newForm.question_tag.join(',')
  68. if (newForm.id) apiStr = 'admqaedit'
  69. this.$api.other[apiStr](newForm).then(data => {
  70. this.$msgs(newForm.id ? '编辑成功' : '新增成功')
  71. this.$emit('close', newForm)
  72. })
  73. }
  74. })
  75. } else {
  76. this.$emit('close')
  77. this.setDefaultValue()
  78. }
  79. }
  80. }
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. @import '../../../../styles/libEdit.scss';
  85. .lib-edit {
  86. padding-top: 0;
  87. ::v-deep .el-form-item {
  88. margin-bottom: 10px;
  89. }
  90. ::v-deep .el-date-editor.el-input {
  91. width: 100%;
  92. }
  93. }
  94. </style>