import { textCopy } from "@/utils/index";
import { deleteNote } from "@/api/doc/bookMark";
import AddOrUpdateNoteDialog from "@/views/read/wpsReader/component/addOrUpdateNoteDialog.vue";
export default {
    components: {
        AddOrUpdateNoteDialog
    },
    methods: {
        // 笔记操作
        handleNoteOperation(type, item) {
            switch (type) {
                case "copyOrigin":
                    textCopy(item.bookmarkContent);
                    this.$message.success("已复制到剪贴板");
                    break;
                case "copyNote":
                    textCopy(item.noteContent);
                    this.$message.success("已复制到剪贴板");
                    break;
                case "view":
                    this.$file.handleFileNameClickNew(item);
                    break;
                case "edit":
                    this.handleOpenEditNote(item);
                    break;
                case "delete":
                    this.handleDeleteNote(item);
                    break;
            }
        },

        // 打开笔记
        handleOpenEditNote(item) {
            const { id, docId, bookmarkContent, noteContent, tagName } = item;
            this.form = {
                id,
                docId,
                bookmarkContent,
                noteContent,
                tagsArr: tagName.split(","),
            };
            this.$refs.AddOrUpdateNoteDialog.dialogVisible = true;
        },
        // 删除笔记
        async handleDeleteNote(item) {
            // this.loading = true;
            const params = {
                id: item.id,
            };
            let res = await deleteNote(params);
            // this.loading = false;
            if (res.code == 200) {
                this.$message.success("操作成功");
                this.loadLeftList();
            }
        },
    }
}
