<template>
  <el-dialog :title="'优化建议 - ' + rows.videoTitle" width="540px" :visible.sync="dialogVisible">
    <el-form :model="form" :rules="rules" ref="suggestionForm" >
      <el-form-item prop="suggestion">
        <el-input type="textarea" :autosize="{ minRows: 6, maxRows: 10 }" placeholder="请输入内容" v-model="form.suggestion">
        </el-input>
      </el-form-item>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" :loading="comfirmLoading" @click="handleConfirm">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { addSuggestion } from "@/api/video";
export default {
  name: "EditSuggestion",
  props: {
  },
  data() {
    return {
      form: {
        suggestion: ''
      },
      dialogVisible: false,
      comfirmLoading: false,
      rules: {
        suggestion: [
          { required: true, message: "请输入建议", trigger: "blur" }
        ]
      },
      rows: {}
    };
  },
  methods: {
    show(row) {
      this.dialogVisible = true;
      this.comfirmLoading = false;
      this.rows = row;
      this.form = {
        suggestion: ''
      }
      this.$nextTick(() => {
        this.$refs.suggestionForm.resetFields()
      })
    },
    handleConfirm() {
      this.$refs.suggestionForm.validate(valid => {
        if (valid) {
          this.comfirmLoading = true;
          const params = {
            "remark": this.form.suggestion,
            "videoId": this.rows.id,
            "operationType": 1
          }
          addSuggestion(params).then(res =>{
            this.dialogVisible = false;
            if(res.code == 200){
              this.$message.success(res.msg || "操作成功");
              this.$emit("confirm");
            }
          }).finally(()=>{
            this.comfirmLoading = false;
          })
        } else {
          return false;
        }
      });
    }
  }
};
</script>


