<template>
  <div class="container-feedbackDlg">
    <el-dialog v-dialogDrag :visible.sync="showFeedbackDlg" :close-on-click-modal="false" :modal-append-to-body="false" @close="cancelHandle" center title="交流反馈">
      <div>
        <el-input type="textarea" :rows="3" placeholder="请输入反馈内容" v-model="feedbackText"> </el-input>
        <div class="save-box">
          <el-button type="primary" @click="addHandler">保存</el-button>
        </div>
        <el-table border :data="tableData" style="margin: 20px 0">
          <el-table-column align="center" prop="Content" label="反馈内容"> </el-table-column>
          <el-table-column align="center" prop="CreateTime" label="创建时间"> </el-table-column>
          <el-table-column align="center" prop="date" label="操作">
            <template slot-scope="{ row }">
              <span class="deletesty" @click="deleteHandler(row)"> 删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

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

export default {
  name: "",
  components: {},
  props: {
    showFeedbackDlg: {
      type: Boolean,
      default: false,
    },
    remindList: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      tableData: [],
      feedbackText: "",
    };
  },
  computed: {},
  watch: {
    showFeedbackDlg: {
      handler(val) {
        if (val) {
          this.getDataList();
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    // 获取数据
    async getDataList() {
      const res = await equityContacts.userFeedbacklist({
        UserId: this.remindList.UserId,
      });
      if (res.Ret === 200) {
        this.tableData = res.Data.List || [];
      }
    },
    // 删除
    async deleteHandler(item) {
      const res = await equityContacts.userFeedbackDel({
        UserFeedbackId: item.UserFeedbackId,
      });
      if (res.Ret === 200) {
        this.getDataList();
      }
    },
    // 添加
    async addHandler() {
      if (!this.feedbackText) return this.$message.error("请输入内容");
      const res = await equityContacts.userFeedbackAdd({
        Content: this.feedbackText,
        UserId: this.remindList.UserId,
      });
      if (res.Ret === 200) {
        this.feedbackText = "";
        this.getDataList();
      }
    },
    cancelHandle() {
      this.$emit("update:showFeedbackDlg", false);
      this.$emit("update:remindList", {});
    },
  },
};
</script>
<style scoped lang="scss">
.container-feedbackDlg {
  .save-box {
    margin: 20px auto;
    display: flex;
    justify-content: center;
  }
}
</style>
