// mixins 
// 混入了笔记的复制、预览、编辑、删除等操作，在此文件写的方法和属性可以被共享使用

import { textCopy } from "@/utils/index";
import { deleteNote } from "@/api/doc/bookMark";
import AddOrUpdateNoteDialog from "@/views/read/components/addOrUpdateNoteDialog.vue";
export default {
    components: {
        AddOrUpdateNoteDialog
    },
    data() {
        return {
            form: {
                docId: "", //文档Id
                bookmarkContent: "", //原文内容
                noteContent: "", //笔记内容
                tagsArr: [], //标签
            },
        }
    },
    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, jsonStr } = item;
            this.form = {
                id,
                docId,
                bookmarkContent,
                noteContent,
                jsonStr,
                tagsArr: tagName && tagName.length > 0 ? tagName.split(",") : [],
            };
            this.$refs.AddOrUpdateNoteDialog.dialogVisible = true;
        },
        // 删除笔记
        async handleDeleteNote(item) {
            const params = {
                id: item.id,
            };
            let res = await deleteNote(params);
            if (res.code == 200) {
                this.$message.success("操作成功");
                this.loadNoteList();
            }

        },
    }
}
