<template>
  <el-dialog :close-on-click-modal="false" title="编辑问答" width="600px" :visible.sync="updateDialog" custom-class="g-dialog">
    <el-form ref="form" :model="editData" label-position="top" label-width="80px">
      <el-form-item label="回答内容">
        <el-input
          type="textarea"
          v-model="editData.content"
          placeholder="请输入详细描述"
          rows="8"
          minlength="1"
        ></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="updateDialog = false">取 消</el-button>
      <el-button type="success" @click="enSure">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import apiQa from '@/api/modules/qa.js';
  export default{
    props:{
      editData:{
        default:function(){
          return {

          }
        },
        type:Object
      }
    },
    data(){
      return {
        updateDialog:false,
      }
    },
    methods:{
      //确认修改回答
      enSure() {
        if (!this.editData.content.trim()) {
          return this.$message({
            message: '回复内容不能为空',
            type: 'warning'
          });
        }
        this.editData.content = this.editData.content.trim();
        // if(this.editData.content.length<0||this.editData.content.length>255){
        //   return this.$message({
        //     message: '回复内容为0-800个字',
        //     type: 'warning'
        //   });
        // }
        // let {answercontent,}
        let {answerid,content,sysCreateAid,favorites,praises,shares}=this.editData;
        apiQa
          .updateAnswer({id:answerid,sysCreateAid,content})
          .then(res => {
            if (res.status == 200) {
              this.$message({
                message: '修改成功',
                type: 'success'
              });
              this.updateDialog = false;
              this.$emit('enSure',true)
            } else {
              this.$message({
                message: '修改失败',
                type: 'error'
              });
            }
          })
          .catch(err => {
            this.$message({
              message: '修改失败',
              type: 'error'
            });
          });
        // this.$message("修改成功")
        // this.editData={}
        // this.updateDialog = false
      },
    }
  }
</script>

<style>
</style>
