lchao 1 anno fa
parent
commit
7ec0aa50dd
2 ha cambiato i file con 91 aggiunte e 10 eliminazioni
  1. 16 0
      src/api/asking/question.js
  2. 75 10
      src/views/asking/question/index.vue

+ 16 - 0
src/api/asking/question.js

@@ -25,6 +25,14 @@ export function addQuestion(data) {
     data: data
     data: data
   })
   })
 }
 }
+// 新增问答列-答案
+export function addAnswer(data) {
+  return request({
+    url: '/asking/answer',
+    method: 'post',
+    data: data
+  })
+}
 
 
 // 修改问答列-问题
 // 修改问答列-问题
 export function updateQuestion(data) {
 export function updateQuestion(data) {
@@ -43,6 +51,14 @@ export function delQuestion(id) {
   })
   })
 }
 }
 
 
+// 删除问答列-答案
+export function delAnswer(id) {
+  return request({
+    url: '/asking/answer/' + id,
+    method: 'delete'
+  })
+}
+
 //查询类型配置
 //查询类型配置
 export function listType(query) {
 export function listType(query) {
   return request({
   return request({

+ 75 - 10
src/views/asking/question/index.vue

@@ -169,6 +169,21 @@
       </div>
       </div>
     </el-dialog>
     </el-dialog>
 
 
+
+    <!-- 新增答案对话框 -->
+    <el-dialog :visible.sync="addAnswerDialogVisible" title="新增答案" width="30%">
+      <el-form :model="newAnswerForm" ref="newAnswerForm" :rules="newAnswerRules" label-width="100px">
+        <el-form-item label="答案" prop="answer">
+          <el-input v-model="newAnswerForm.answer" placeholder="请输入答案"></el-input>
+        </el-form-item>
+      </el-form>
+      <span slot="footer" class="dialog-footer">
+                <el-button type="primary" @click="handleAddAnswer">确定</el-button>
+        <el-button @click="addAnswerDialogVisible = false">取消</el-button>
+
+      </span>
+    </el-dialog>
+
     <!-- 审核 -->
     <!-- 审核 -->
     <el-dialog :title="title" :visible.sync="open1" width="700px" append-to-body>
     <el-dialog :title="title" :visible.sync="open1" width="700px" append-to-body>
       <el-form ref="form1" :model="form1"  label-width="100px">
       <el-form ref="form1" :model="form1"  label-width="100px">
@@ -204,13 +219,20 @@
         <el-form-item label="图片" prop="path">
         <el-form-item label="图片" prop="path">
           <image-upload v-model="form1.path"/>
           <image-upload v-model="form1.path"/>
         </el-form-item>
         </el-form-item>
-        <el-form-item label="答案列表">
-          <ul>
-            <li v-for="(answer, index) in form1.answerList" :key="index">
-              <p>{{ answer.answer }}</p>
-            </li>
-          </ul>
-        </el-form-item>
+
+        <!-- 新增答案按钮 -->
+        <el-button type="primary" @click="addAnswerDialogVisible = true">新增答案</el-button>
+        <!-- 答案列表 -->
+        <el-form :model="form1" ref="form1" :rules="rules" label-width="100px">
+          <el-form-item label="答案列表">
+            <ul>
+              <li v-for="(answer, index) in form1.answerList" :key="index">
+                <p>{{ answer.answer }}</p>
+                <el-button type="danger" icon="el-icon-delete" @click="removeAnswer(index)">删除</el-button>
+              </li>
+            </ul>
+          </el-form-item>
+        </el-form>
       </el-form>
       </el-form>
       <div slot="footer" class="dialog-footer">
       <div slot="footer" class="dialog-footer">
         <el-button v-if="form1.a == '1'" type="primary" @click="through(1)">通 过</el-button>
         <el-button v-if="form1.a == '1'" type="primary" @click="through(1)">通 过</el-button>
@@ -222,7 +244,8 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import { listQuestion, getQuestion, delQuestion, addQuestion, updateQuestion, listType,through } from "@/api/asking/question";
+import { listQuestion, getQuestion, delQuestion, addQuestion, updateQuestion, listType,through,addAnswer,delAnswer } from "@/api/asking/question";
+import {addType, updateType} from "@/api/asking/type";
 
 
 export default {
 export default {
   name: "Question",
   name: "Question",
@@ -241,6 +264,8 @@ export default {
       showSearch: true,
       showSearch: true,
       // 总条数
       // 总条数
       total: 0,
       total: 0,
+      newAnswer: { answer: '' }, // 新增答案对象
+      addAnswerDialogVisible: false, // 控制新增答案对话框的显示状态
       // 问答列-问题表格数据
       // 问答列-问题表格数据
       questionList: [],
       questionList: [],
       //类型配置
       //类型配置
@@ -250,6 +275,7 @@ export default {
       // 是否显示弹出层
       // 是否显示弹出层
       open: false,
       open: false,
       open1: false,
       open1: false,
+      open2: false,
       // 查询参数
       // 查询参数
       queryParams: {
       queryParams: {
         pageNum: 1,
         pageNum: 1,
@@ -268,7 +294,10 @@ export default {
       form: {
       form: {
         whetherShow:'N'
         whetherShow:'N'
       },
       },
-      form1:{},
+      newAnswerForm:{},
+      form1:{
+        answerList: [], // 存放答案列表
+      },
       // 表单校验
       // 表单校验
       rules: {
       rules: {
         title: [
         title: [
@@ -283,7 +312,9 @@ export default {
         score: [
         score: [
           { required: true, message: "悬赏积分不能为空", trigger: "blur" }
           { required: true, message: "悬赏积分不能为空", trigger: "blur" }
         ],
         ],
-      }
+      },
+
+      newAnswerRules: { answer: [{ required: true, message: '请输入答案', trigger: 'blur' }] }, // 新增答案的校验规则
     };
     };
   },
   },
   created() {
   created() {
@@ -321,6 +352,7 @@ export default {
     cancel() {
     cancel() {
       this.open = false;
       this.open = false;
       this.open1 = false;
       this.open1 = false;
+      this.open2 = false;
       this.reset();
       this.reset();
     },
     },
     // 表单重置
     // 表单重置
@@ -355,7 +387,9 @@ export default {
         delFlag: null
         delFlag: null
       };
       };
       this.resetForm("form1");
       this.resetForm("form1");
+
     },
     },
+
     /** 搜索按钮操作 */
     /** 搜索按钮操作 */
     handleQuery() {
     handleQuery() {
       this.queryParams.pageNum = 1;
       this.queryParams.pageNum = 1;
@@ -378,6 +412,20 @@ export default {
       this.open = true;
       this.open = true;
       this.title = "添加问答列-问题";
       this.title = "添加问答列-问题";
     },
     },
+
+    //新增答案
+    handleAddAnswer() {
+      this.$refs["newAnswerForm"].validate(valid => {
+            this.newAnswerForm.questionId = this.form1.id;
+            addAnswer(this.newAnswerForm).then(response => {
+              this.form1.answerList.push(this.newAnswerForm);
+              this.newAnswer.answer = ''; // 清空输入框
+              this.addAnswerDialogVisible = false; // 关闭新增答案对话框
+              this.$message.success('新增答案成功');
+            });
+      })
+    },
+
     /** 修改按钮操作 */
     /** 修改按钮操作 */
     handleUpdate(row) {
     handleUpdate(row) {
       this.reset();
       this.reset();
@@ -447,6 +495,23 @@ export default {
         this.$modal.msgSuccess("删除成功");
         this.$modal.msgSuccess("删除成功");
       }).catch(() => {});
       }).catch(() => {});
     },
     },
+
+    // 删除答案
+    removeAnswer(index) {
+      const answer = this.form1.answerList[index];
+      console.log("this.form1",this.form1)
+      const id = answer.id; // 假设答案对象有一个id字段来标识唯一性
+      delAnswer(id)
+        .then(() => {
+          this.form1.answerList.splice(index, 1);
+          this.$message.success('删除答案成功');
+        })
+        .catch(error => {
+          console.error('删除答案失败:', error);
+          this.$message.error('删除答案失败,请重试');
+        });
+    },
+
     /** 导出按钮操作 */
     /** 导出按钮操作 */
     handleExport() {
     handleExport() {
       this.download('asking/question/export', {
       this.download('asking/question/export', {