<template>
  <el-dialog
    title="订单评价"
    :visible.sync="dialogVisible"
    width="30%"
    :close-on-click-modal="false"
    :before-close="close"
  >
    <div class="text">
      <el-input type="textarea" v-model="form.desc"></el-input>
      <el-button type="primary" @click="submitReview">提交评价</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { push } from "@/api/comment.js";

export default {
  name: "orderReview",
  data() {
    return {
      dialogVisible: false,
      data: {},
      orderInfo: {},
      form: {
        desc: "",
      },
    };
  },
  methods: {
    close() {
      this.dialogVisible = false;
    },
    open(data) {
      console.log(data);
      this.dialogVisible = true;
      this.data = data;
    },
    async submitReview() {
      // 提交订单评价
      let data = {
        userId: localStorage.getItem("userId"),
        carId: this.data.carId,
        text: this.form.desc,
        parking_id: this.data.parking_id,
        userName: this.data.userName,
      };

      try {
        let result = await this.$API.comment.push(data);
        if (result.status === 200) {
          this.$message.success("订单评价提交成功！");
          // this.dialogVisible = false; // 关闭对话框
        } else {
          console.error("提交订单评价失败：");
          this.$message.error("订单评价提交失败，请稍后重试！");
        }
      } catch (error) {
        console.error("提交订单评价失败：", error);
        this.$message.error("订单评价提交失败，请稍后重试！");
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.text {
  height: 100%;
  font-size: 18px;
}
</style>
