h5-chat-config-dialog.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div v-if="localDialog && localDialog.text " :class="visible?'dialog-config-active':'dialog-config'">
  3. <div class="question-section">
  4. <div class="section-label">提问</div>
  5. <el-input v-model="localDialog.text" placeholder="选择问题" style="width: 100%">
  6. </el-input>
  7. </div>
  8. <div class="answer-options" v-if="localDialog.options && localDialog.options.length > 0">
  9. <div class="section-label">回复</div><el-button
  10. type="text"
  11. class="config-button"
  12. @click="add">
  13. 新增
  14. </el-button>
  15. <draggable v-model="localDialog.options" @end="">
  16. <div v-for="(option, index) in localDialog.options" :key="option.id || index" class="option-item">
  17. <div class="option-label">选项{{ index + 1 }}: <el-input v-model="option.text" placeholder="对话" />
  18. <br/>
  19. <br/>
  20. <el-input type="textarea" v-model="option.answer" placeholder="回复"></el-input>
  21. <el-button
  22. type="text"
  23. class="config-button"
  24. @click="del(index)">
  25. 删除
  26. </el-button>
  27. </div>
  28. </div>
  29. </draggable>
  30. </div>
  31. <div class="answer-options" v-else>
  32. <el-button
  33. type="text"
  34. class="config-button"
  35. @click="add">
  36. 新增
  37. </el-button>
  38. </div>
  39. <div class="action-buttons">
  40. <el-button type="primary" @click="saveAndReturn">保存并返回</el-button>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import draggable from 'vuedraggable'
  46. export default {
  47. name: 'DialogConfig',
  48. components: { draggable },
  49. props: {
  50. visible: {
  51. type: Boolean,
  52. default: false
  53. },
  54. dialog: {
  55. type: Object,
  56. required: false,
  57. default: () => ({
  58. id: 2,
  59. sender: 'agent',
  60. text: '您的年龄?',
  61. options: [
  62. { id: 1, text: '45-55岁' },
  63. { id: 2, text: '55-60岁' },
  64. { id: 3, text: '60-65岁' },
  65. { id: 4, text: '65岁以上' }
  66. ],
  67. userSelection: null
  68. })
  69. },
  70. dialogIndex: {
  71. type: Number,
  72. required: false
  73. }
  74. },
  75. watch: {
  76. dialog: {
  77. immediate: true,
  78. handler(newVal) {
  79. this.localDialog = { ...newVal }
  80. console.log('localDialog', this.localDialog)
  81. }
  82. },
  83. visible: {
  84. immediate: true,
  85. handler(newVal) {
  86. this.$nextTick(()=>{
  87. // 隐藏通用表单
  88. if (newVal) {
  89. document.querySelector("#h5-config-common").style.display = "none";
  90. } else {
  91. document.querySelector("#h5-config-common").style.display = "block";
  92. }
  93. });
  94. }
  95. }
  96. },
  97. data() {
  98. return {
  99. localDialog: {
  100. options:[],
  101. ...this.dialog
  102. }
  103. }
  104. },
  105. methods: {
  106. del(index) {
  107. this.localDialog.options.splice(index, 1);
  108. },
  109. add() {
  110. if (!this.localDialog.options) {
  111. this.$set(this.localDialog, 'options', []);
  112. }
  113. this.localDialog.options.push({ text: '', answer: '' ,id: this.localDialog.options.length});
  114. console.log(this.localDialog)
  115. },
  116. saveAndReturn() {
  117. // this.$emit('update:dialog', this.localDialog);
  118. this.$emit('update:dialog', { ...this.localDialog });
  119. this.$emit('update:visible', false)
  120. }
  121. }
  122. }
  123. </script>
  124. <style scoped>
  125. .dialog-config {
  126. padding: 100px;
  127. visibility: hidden;
  128. display: none;
  129. }
  130. .dialog-config-active {
  131. position: absolute;
  132. top: 0;
  133. width: 100%;
  134. height: 100%;
  135. z-index: 9999;
  136. background-color: white;
  137. }
  138. .section-label {
  139. font-size: 14px;
  140. color: #606266;
  141. margin-bottom: 10px;
  142. }
  143. .question-section, .answer-options {
  144. margin-bottom: 25px;
  145. z-index: 99999;
  146. background-color: white;
  147. }
  148. .editor-content textarea {
  149. width: 100%;
  150. min-height: 100px;
  151. border: none;
  152. outline: none;
  153. resize: vertical;
  154. }
  155. .option-item {
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. padding: 10px 0;
  160. border-bottom: 1px solid #ebeef5;
  161. }
  162. .config-button {
  163. color: #409EFF;
  164. }
  165. .action-buttons {
  166. margin-top: 30px;
  167. text-align: center;
  168. }
  169. </style>