<template>
    <div class="edit-public-ref-container">
        <div v-if="chanFerForm && chanFerForm.length > 0" class="references-h1 level-1">
            <div class="title-content">
                <div class="pMainH1">
                    <div class="pMain">References</div>
                </div>
            </div>
        </div>
        <div class="ref-list-wrapper">
            <div
                :data-id="`ref-${item.p_refer_id}`"
                v-for="(item, index) in chanFerForm"
                :key="index"
                class="ref-item-row"
                :class="{ 'has-change': item.is_change == 1, 'is-repeat': item.is_repeat == 1 }"
            >
                <div class="ref-content-area">
                    <div v-if="item.refer_type == 'journal'" class="reference-item">
                        <b class="ref-number-prefix">{{ index + 1 }}.</b>

                        <span class="author-text">{{ item.author }} </span>
                        <span v-html="formatTitle(item.title)"></span>. <em class="journal-name">{{ item.joura }}</em
                        >. <span :class="getJournalDateno(item.dateno, 'title')">{{ item.dateno }}</span
                        >.

                        <div class="doi-link-container">
                            <a class="doiLink" :href="item.doilink" target="_blank">{{ item.doilink }}</a>
                        </div>
                    </div>

                    <div v-if="item.refer_type == 'book'" class="reference-item">
                        <b class="ref-number-prefix">{{ index + 1 }}.</b>
                        {{ item.author }} <span v-html="formatTitle(item.title)"></span>. {{ item.dateno }}.
                        <br />
                        <a class="doiLink" :href="item.isbn" target="_blank">{{ item.isbn }}</a>
                    </div>

                    <div v-if="item.refer_type == 'other'" class="reference-item">
                        <b class="ref-number-prefix">{{ index + 1 }}.</b>
                        <span v-html="formatTitle(item.refer_frag)"></span>
                    </div>
                </div>

                <div class="ref-actions-area">
                    <i class="el-icon-edit action-icon primary" @click="change(item, 'Edit')"></i>

                    <i class="el-icon-circle-plus-outline action-icon success" @click="addLine(item, 'Add')"></i>

                    <div class="order-icons">
                        <i
                            class="el-icon-caret-top action-icon"
                            :class="{ disabled: index === 0 }"
                            @click="index !== 0 && changeOrder(item, 'up')"
                        ></i>
                        <i
                            class="el-icon-caret-bottom action-icon"
                            :class="{ disabled: index === chanFerForm.length - 1 }"
                            @click="index !== chanFerForm.length - 1 && changeOrder(item, 'down')"
                        ></i>
                    </div>

                    <i class="el-icon-delete action-icon danger" @click="deleteLine(item)"></i>

                    <img v-if="role == 'editor' && item.is_ai_check == 1" src="@/assets/img/ai.png" class="ai-mini-tag" />
                </div>
            </div>
        </div>
        <!-- 编辑引用 -->
        <el-dialog
            :close-on-click-modal="false"
            destroy-on-close
            :append-to-body="true"
            v-loading="addLoading"
            :title="dialogTitle + ' References'"
            :visible.sync="editboxVisible"
            width="1200px"
            @close="cancelSave"
        >
            <p class="yinyongPre c888" style="margin-bottom: 20px; color: #888; line-height: 24px">
                You may add or modify the references. The system will automatically identify and retrieve the reference information. Please
                note that if the reference type is set to “Other”, the “Parse” button will not be available.
            </p>

            <el-form :model="refenceForm" :rules="refenceFormrules" ref="refenceForm" label-width="150px" class="editForm mt10">
                <!-- 内容开关 -->
                <el-form-item label="Source:">
                    <el-select v-model="SourceType" placeholder="please pick">
                        <el-option v-for="item in sourceOptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="Content:" required prop="content">
                    <div class="automatic-parsing-box">
                        <el-input
                            style="border: none"
                            class="automaticParsing"
                            type="textarea"
                            rows="5"
                            v-model="refenceForm.content"
                            placeholder=""
                        ></el-input>
                        <span v-if="isShowParsing" style="color: #409eff"
                            >We have detected updates to the reference content. You need to click the "Automatic parsing" button to
                            recognize them.</span
                        >
                    </div>
                </el-form-item>

                <div v-if="!isShowParsing && isShowParsingData && SourceType != 'other'">
                    <el-form-item style="margin: 0 0 30px">
                        <div class="line" style="border: 1px dashed #dcdfe6"></div>
                    </el-form-item>
                    <!-- Journal -->
                    <div v-show="SourceType == 'journal'">
                        <el-form-item label="Doi:" prop="doi">
                            <el-input v-model="refenceForm.doi">
                                <el-button @click="gotoFormate" slot="append">Formate</el-button>
                            </el-input>
                            <p class="zhushi">
                                You can click the 'Formate' on the right to automatically identify and quickly fill in all the current
                                fields
                            </p>
                        </el-form-item>
                    </div>

                    <div v-show="SourceType != 'other'">
                        <el-form-item label="Author(s):" required prop="author">
                            <el-input
                                v-model="refenceForm.author"
                                placeholder="Patel NM, Stottlemyer BA, Gray MP, Boyce RD, Kane Gill SL"
                            ></el-input>
                            <p class="zhushi">
                                Six or less authors are required to list all authors while more than six authors are required to list three
                                of them with “et al.”
                            </p>
                        </el-form-item>
                        <el-form-item :label="SourceType == 'journal' ? 'Title:' : 'Book'" required prop="title">
                            <el-input
                                v-if="SourceType == 'journal'"
                                v-model="refenceForm.title"
                                placeholder="eg: The role of autophagy in the treatment of osteoporosis by Chinese medicines (natural)"
                            ></el-input>
                            <p class="zhushi" v-if="SourceType == 'journal'">
                                <span style="color: #409eff"
                                    >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                        >Don't add "."!</span
                                    ></span
                                >
                            </p>
                            <el-input
                                v-if="SourceType == 'book'"
                                v-model="refenceForm.title"
                                placeholder="eg: Traditional Medicine Research"
                            ></el-input>
                            <p v-if="SourceType == 'book'" class="zhushi">
                                Full Name of Book
                                <span style="color: #409eff; margin-left: 6px; display: none"
                                    >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                        >Don't add "."!</span
                                    ></span
                                >
                            </p>
                        </el-form-item>
                        <el-form-item label="Publication Details:" required prop="dateno">
                            <div v-if="SourceType == 'journal'">
                                <el-input v-model="refenceForm.dateno" placeholder="eg: 2023;8(9):49-62"></el-input>
                                <p class="zhushi">
                                    Year;Volume(issue):Inclusive page numbers<span style="color: #409eff; margin-left: 6px"
                                        >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                            >Don't add "."!</span
                                        ></span
                                    >
                                </p>
                            </div>
                            <div v-if="SourceType == 'book'">
                                <el-input v-model="refenceForm.dateno" placeholder="eg: New York, NY:McGraw-Hill;2011"></el-input>
                                <p class="zhushi">
                                    City, State (or Country if not in the US) of publisher:Publisher’s name;copyright year<span
                                        style="color: #409eff; display: none; margin-top: -10px"
                                        >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                            >Don't add "."!</span
                                        ></span
                                    >
                                </p>
                            </div>
                        </el-form-item>
                    </div>
                    <div v-show="SourceType == 'journal'">
                        <el-form-item label="Journal:" required prop="joura">
                            <el-input v-model="refenceForm.joura" placeholder="eg: Tradit Med Res"></el-input>
                            <p class="zhushi">
                                Abbreviated Journal Title
                                <span style="color: #409eff; margin-left: 6px"
                                    >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                        >Don't add "."!</span
                                    >
                                </span>
                            </p>
                        </el-form-item>
                        <el-form-item label="DOI/URL:" required prop="doilink">
                            <el-input v-model="refenceForm.doilink" placeholder="eg: 10.1002/cncr.30667"></el-input>
                            <p class="zhushi">
                                <span style="color: #409eff"
                                    >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                        >Don't add "."!</span
                                    ></span
                                >
                            </p>
                        </el-form-item>
                    </div>
                    <!-- Book -->
                    <div v-show="SourceType == 'book'">
                        <el-form-item label="ISBN:" required prop="isbn">
                            <el-input v-model="refenceForm.isbn"></el-input>
                            <p class="zhushi">
                                <span style="color: #409eff; display: none"
                                    >Automatically displayed after publication "."<span style="color: #ff0000ba; margin-left: 4px"
                                        >Don't add "."!</span
                                    ></span
                                >
                            </p>
                        </el-form-item>
                    </div>
                    <!-- others -->
                </div>
                <!-- <div v-if="!isShowParsing && isShowParsingData && SourceType == 'other'">
                    <el-form-item label="Doi:" prop="doi">
                        <el-input v-model="refenceForm.doi">

                        </el-input>

                    </el-form-item>
                </div> -->
            </el-form>

            <span slot="footer" class="dialog-footer">
                <el-button @click="cancelSave">Cancel</el-button>
                <el-button
                    v-if="isShowParsing"
                    type="primary"
                    style="background-color: #409eff !important; border-color: #409eff !important"
                    @click="getParsingData()"
                    >Automatic parsing</el-button
                >

                <el-button v-else type="primary" @click="dialogTitle == 'Edit' ? saveChange() : saveAdd()">Save</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'EditPublicRefTableOnly',
    data() {
        return {
            old_refence_content: '', // 原始参考文献内容
            old_refence_type: '',
            isShowParsingData: false,
            isShowParsing: false,
            dialogTitle: '',
            SourceType: 'journal',
            sourceOptions: [
                {
                    value: 'journal',
                    label: 'journal'
                },
                {
                    value: 'book',
                    label: 'book'
                },
                {
                    value: 'other',
                    label: 'other'
                }
            ],
            // 引用表单
            refenceForm: {
                doi: '',
                p_article_id: null,
                p_refer_id: null, // 当前行一行的引用序号
                pre_p_refer_id: null, // 上一行
                refer_type: '', // 类型
                joura: '',
                author: '',
                doilink: '',
                dateno: '',
                isbn: '',
                content: '',
                title: ''
            },
            refenceFormrules: {
                // doi:[
                // { required: false, message: 'The Doi cannot be empty', trigger: 'blur' },
                // ],
                joura: [{ required: true, message: 'The Journal cannot be empty', trigger: 'blur' }],
                author: [{ required: true, message: 'The Author(s) cannot be empty', trigger: 'blur' }],
                title: [{ required: true, message: 'Please fill in this field', trigger: 'blur' }],
                doilink: [{ required: true, message: 'The doi/url cannot be empty', trigger: 'blur' }],
                dateno: [{ required: true, message: 'The Publication Details cannot be empty', trigger: 'blur' }],
                isbn: [{ required: true, message: 'The ISBN cannot be empty', trigger: 'blur' }],
                content: [{ required: true, message: 'The Content cannot be empty', trigger: 'blur' }]
            },
            addLoading: false,
            editboxVisible: false,
            multipleSelection: [] // 多选
        };
    },
   
    props: {
        p_article_id: {
            type: null,
            required: true
        },
        chanFerFormRepeatList: {
            type: Array,
            default: () => []
        },
        chanFerForm: {
            type: Array,
            required: true
        },
        gridData: {
            type: String,
            default: ''
        },
        role: {
            type: String,
            default: () => 'editor'
        }
    },
    methods: {
        formatTitle(title) {
            if (!title) return '';
            const reg = /\b(Retracted|Retraction)\b/gi;
            return title.replace(reg, (match) => `<span style="color: red; font-weight: bold;">${match}</span>`);
        },
        // 核心算法：处理序号合并逻辑
        formatCiteNumbers(nums) {
            if (!nums || nums.length === 0) return '';
            // 去重并升序排序
            const sorted = [...new Set(nums)].sort((a, b) => a - b);
            const result = [];
            let i = 0;
            while (i < sorted.length) {
                let j = i;
                while (j < sorted.length - 1 && sorted[j + 1] === sorted[j] + 1) {
                    j++;
                }
                // 如果连续数字 >= 3 个，使用连字符 '-'
                if (j - i >= 2) {
                    result.push(`${sorted[i]}-${sorted[j]}`);
                } else {
                    // 否则（1个或2个）逐个列出
                    for (let k = i; k <= j; k++) {
                        result.push(sorted[k]);
                    }
                }
                i = j + 1;
            }
            return result.join(', ');
        },

        // 渲染最终 HTML 的包装器
        // text: 原始文本, annotations: 批注, type: 类型, am_id: ID
        renderFinalHtml(text, annotations, type, am_id) {
            // 1. 调用你现有的 highlightText2 逻辑（见下方修改后的版本）
            let html = this.highlightText2(text, annotations, type, am_id);

            // 2. 借鉴 EndNote：对处理完批注的 HTML 进行引用联动渲染
            // 正则匹配连续的 autocite 标签（允许中间有空格）
            const citeGroupRe = /(<autocite\s+data-id="(\d+)"\s*><\/autocite>\s*)+/gi;

            return html.replace(citeGroupRe, (groupMatch) => {
                const ids = [...groupMatch.matchAll(/data-id="(\d+)"/gi)].map((m) => m[1]);

                // 从全局 citeMap 中获取序号（citeMap 是你根据全文顺序生成的 {ID: Index}）
                const nums = ids.map((id) => this.citeMap[id]).filter((n) => n);

                if (nums.length === 0) return groupMatch;

                const label = this.formatCiteNumbers(nums);

                // 原样保持标签（藏在 display:none 里），外层显示 [4-6]
                return `<span class="cite-rendered-node" style="color:#0052d9; font-weight:bold; cursor:pointer;">
                        [${label}]
                        <span style="display:none">${groupMatch}</span>
                    </span>`;
            });
        },
        getJournalDateno(dateno, type) {
            if (dateno && typeof dateno === 'string') {
                const hasInvalidColon = !dateno.includes(':') || (dateno.includes(':') && dateno.split(':').pop().trim() === '');

                if (hasInvalidColon) {
                    return type === 'title' ? 'text-highlight' : 'warn';
                }
            }
            return '';
        },
        getParsingInfo(data, index) {
            const targetSubArr = this.chanFerFormRepeatList.find((subArr) => subArr.includes(index));
            if (targetSubArr) {
                let warningText = 'Please note that ';
                const refElements = targetSubArr.map((ref, refIndex) => {
                    return `${ref + 1}`;
                });
                if (refElements.length > 0) {
                    if (refElements.length === 1) {
                        warningText += `ref. ${refElements[0]} is a duplicate.`;
                    } else {
                        const lastRef = refElements.pop(); // 取出最后一个 ref
                        warningText += `ref. ${refElements.join(', ')} and ${lastRef} are duplicates.`;
                    }
                }
                return warningText;
            }
        },
        handleContainerClick(e) {
            if (e.target.tagName === 'SPAN' && e.target.hasAttribute('data-ref')) {
                const ref = Number(e.target.getAttribute('data-ref')); // 获取存储的 ref 值
                this.handleClickRef(ref); // 触发实际逻辑
            }
        },

        handleClickRef(ref) {},
        getRepeatRefHtml() {
            let warningText = 'Please note that ';
            this.chanFerFormRepeatList.forEach((pair, index) => {
                let singlePairText = '';
                pair.forEach((ref, refIndex) => {
                    singlePairText += `<span style="font-weight: bold;color: #F56C6C;cursor: pointer;" data-ref="${ref}" >${
                        ref + 1
                    }</span>`;
                    if (refIndex !== pair.length - 1) {
                        singlePairText += ' and ';
                    }
                });
                warningText += `ref. ${singlePairText}`;
                if (index === this.chanFerFormRepeatList.length - 1) {
                    warningText += ' are duplicates.';
                } else {
                    warningText += ', and ';
                }
            });
            return warningText;
        },
        getParsingData() {
            if (this.refenceForm.content == '') {
                this.$message.error('The Content cannot be empty');
                return;
            }
            const loading = this.$loading({
                lock: true,
                text: 'Loading...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            this.$api
                .post('api/References/dealContent', {
                    content: this.refenceForm.content
                })
                .then((res) => {
                    loading.close();
                    this.isShowParsing = false;
                    (this.isShowParsingData = true), (this.refenceForm.joura = res.data.joura);
                    this.refenceForm.author = res.data.author;
                    this.refenceForm.dateno = res.data.dateno;
                    this.refenceForm.doilink = res.data.doilink;
                    this.refenceForm.doi = res.data.doi;
                    this.refenceForm.title = res.data.title;
                    this.refenceForm.isbn = this.refenceForm.refer_type == 'book' ? res.data.doilink : res.data.isbn;
                })
                .catch((err) => {
                    loading.close();
                    this.$message.error(err);
                });
        },

        getRefData(id) {
            return this.$api
                .post('api/References/get', {
                    account: localStorage.getItem('U_name'),
                    p_refer_id: id
                })
                .then((res) => {
                    if (res.status == 1) {
                        return res.data;
                    }
                    throw res.msg;
                })
                .catch((err) => {
                    this.$message.error(err);
                    return Promise.reject(err);
                });
        },
        tableRowStyle({ row }) {
            if (row.is_repeat === 1) {
                return { backgroundColor: '#ffececa1' }; // 浅红色
            }
            return {};
        },
        init() {
            this.$nextTick(() => {
                if (this.$refs.multipleTable) {
                    this.$refs.multipleTable.doLayout();
                }
            });
        },
        RefenceSelectionChange(val) {
            // //console.log(val,666666)
            this.multipleSelection = val;
            // //console.log(this.multipleSelection,'this.multipleSelection')
        },
        // 取消选择
        toggleSelection() {
            this.multipleSelection = [];
            this.$refs.multipleTable.clearSelection();
        },
        // 选中所有
        selectAllRef() {
            this.$refs.multipleTable.toggleAllSelection();
        },
        sendEmail() {
            this.$confirm('Are you sure you want to send an email to the Editor?', 'Tips', {
                confirmButtonText: 'Sure',
                cancelButtonText: 'Cancel',
                type: 'warning'
            }).then(() => {
                const loading = this.$loading({
                    lock: true,
                    text: 'please wait',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                this.$api
                    .post('api/References/finishSendEmail', {
                        article_id: this.$route.query.id
                    })
                    .then((res) => {
                        loading.close();
                        if (res.status == 1) {
                            this.$message.success('Email sent successfully!');
                        } else {
                            this.$message.error(res.msg);
                        }
                    })
                    .catch((err) => {
                        loading.close();
                    });
            });
        },

        // 删除部分引用
        deleteSomeRefs() {
            var ids = [];
            ids = this.multipleSelection.map((item) => {
                return item.p_refer_id;
            });
            this.$confirm('Are you sure you want to remove the selected references?', 'Tips', {
                confirmButtonText: 'Sure',
                cancelButtonText: 'Cancel',
                type: 'warning'
            })
                .then(() => {
                    const loading = this.$loading({
                        lock: true,
                        text: 'please wait',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)'
                    });
                    this.$api
                        .post('api/Preaccept/delRefers', {
                            ids: ids
                        })
                        .then((res) => {
                            loading.close();
                            if (res.code == 0) {
                                //console.log(res);
                                this.changeRefer();
                            } else {
                                this.$message.error(res.msg);
                            }
                        })
                        .catch((err) => {
                            loading.close();
                            //console.log(err);
                        });
                })
                .catch(() => {});
        },
        // 刷新组件
        refrashComp() {
            this.$emit('refrashComp', true);
        },
        // 重新获取参考文献
        changeRefer() {
            this.$emit('changeRefer', true);
        },
        // 向上合并某一项
        ChanFerMashUp(e) {
            ////console.log(e,'5555')
            this.$emit('ChanFerMashUp', e);
        },
        // 显示修改引用
        async change(row, optitle) {
            this.dialogTitle = optitle;
            this.isShowParsing = false;
            this.isShowParsingData = false;
            const loading = this.$loading({
                lock: true,
                text: 'Loading...',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            try {
                var data = await this.getRefData(row.p_refer_id);
                this.SourceType = data.refer_type ? data.refer_type : '';

                this.refenceForm = {
                    doi: '',
                    p_article_id: null,
                    p_refer_id: row.p_refer_id, // 当前行一行的引用序号
                    pre_p_refer_id: null, // 上一行
                    refer_type: data.refer_type ? data.refer_type : '', // 类型

                    author: data.author ? data.author : '',
                    doilink: data.doilink ? data.doilink : '',
                    dateno: data.dateno ? data.dateno : '',
                    isbn: data.isbn ? data.isbn : '',
                    joura: data.joura ? data.joura : '',

                    content: data.deal_content ? data.deal_content : '',
                    title: data.title ? data.title : ''
                };

                this.old_refence_content = JSON.parse(JSON.stringify(data.deal_content));
                this.old_refence_type = JSON.parse(JSON.stringify(data.refer_type));
                if (this.SourceType == 'book') {
                    this.refenceForm.isbn = data.doilink ? data.doilink : '';
                }
                if (this.SourceType == 'other' || this.role == 'user') {
                    this.refenceForm.doi = data.refer_doi ? data.refer_doi : '';
                } else {
                    this.refenceForm.doi = '';
                }

                //console.log('this.refenceForm at line 883:', this.refenceForm)
                this.editboxVisible = true;
                this.$nextTick(() => {
                    // this.refenceForm.content = row.refer_frag;
                });
                loading.close();
            } catch (error) {
                loading.close();
            }
        },
        // 编辑引用
        saveChange() {
            var journalValid = false;
            var bookValid = false;
            var otherValid = false;
            if (this.SourceType == 'journal') {
                // Journal形式
                // var doi = ''
                var author = '';
                var title = '';
                var dateno = '';
                var joura = '';
                var doilink = '';
                // this.$refs['refenceForm'].validateField('doi',(callback)=>{
                // 	doi = callback
                // })
                this.$refs['refenceForm'].validateField('author', (callback) => {
                    author = callback;
                });
                this.$refs['refenceForm'].validateField('title', (callback) => {
                    title = callback;
                });
                this.$refs['refenceForm'].validateField('dateno', (callback) => {
                    dateno = callback;
                });
                this.$refs['refenceForm'].validateField('joura', (callback) => {
                    joura = callback;
                });
                this.$refs['refenceForm'].validateField('doilink', (callback) => {
                    doilink = callback;
                });
                author == '' && title == '' && dateno == '' && joura == '' && doilink == '' ? (journalValid = true) : '';
            } else if (this.SourceType == 'book') {
                // book 形式
                var author = '';
                var title = '';
                var dateno = '';
                var isbn = '';
                this.$refs['refenceForm'].validateField('author', (callback) => {
                    author = callback;
                });
                this.$refs['refenceForm'].validateField('title', (callback) => {
                    title = callback;
                });
                this.$refs['refenceForm'].validateField('dateno', (callback) => {
                    dateno = callback;
                });
                this.$refs['refenceForm'].validateField('isbn', (callback) => {
                    isbn = callback;
                });
                author == '' && title == '' && dateno == '' && isbn == '' ? (bookValid = true) : '';
            } else if (this.SourceType == 'other') {
                // others 形式
                var content = '';
                this.$refs['refenceForm'].validateField('content', (callback) => {
                    content = callback;
                });
                content == '' ? (otherValid = true) : '';
            }
            // //console.log(otherValid,99)

            if (journalValid || bookValid || otherValid) {
                // 有任意一个模式符合验证规则就提交
                this.editRefSave();
            }
        },
        //  提交引用修改
        editRefSave() {
            this.refenceForm.refer_type = this.SourceType;
            const loading = this.$loading({
                lock: true,
                text: 'Loading...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });

            var form = { ...this.refenceForm };

            if (this.role == 'user') {
                form.article_id = this.$route.query.id;
            }
            this.$api
                .post('api/Preaccept/editRefer', form)
                .then((res) => {
                    if (res.code == 0) {
                        loading.close();
                        this.$message.success('successed！');
                        //this.getRefData()
                        this.changeRefer();
                        this.cancelSave();
                    } else if (res.code == 1) {
                        loading.close();
                        this.$message.error(res.msg);
                    } else {
                        loading.close();
                        this.$message.error(res.msg);
                    }
                })
                .catch((err) => {
                    loading.close();
                    this.$message.error(err);
                });
        },
        // 保存新增
        saveAdd() {
            var journalValid = false;
            var bookValid = false;
            var otherValid = false;
            if (this.SourceType == 'journal') {
                // Journal形式
                // var doi = ''
                var author = '';
                var title = '';
                var dateno = '';
                var joura = '';
                var doilink = '';
                // this.$refs['refenceForm'].validateField('doi',(callback)=>{
                //     doi = callback
                // })
                this.$refs['refenceForm'].validateField('author', (callback) => {
                    author = callback;
                });
                this.$refs['refenceForm'].validateField('title', (callback) => {
                    title = callback;
                });
                this.$refs['refenceForm'].validateField('dateno', (callback) => {
                    dateno = callback;
                });
                this.$refs['refenceForm'].validateField('joura', (callback) => {
                    joura = callback;
                });
                this.$refs['refenceForm'].validateField('doilink', (callback) => {
                    doilink = callback;
                });
                author == '' && title == '' && dateno == '' && joura == '' && doilink == '' ? (journalValid = true) : '';
            } else if (this.SourceType == 'book') {
                // book 形式
                var author = '';
                var title = '';
                var dateno = '';
                var isbn = '';
                this.$refs['refenceForm'].validateField('author', (callback) => {
                    author = callback;
                });
                this.$refs['refenceForm'].validateField('title', (callback) => {
                    title = callback;
                });
                this.$refs['refenceForm'].validateField('dateno', (callback) => {
                    dateno = callback;
                });
                this.$refs['refenceForm'].validateField('isbn', (callback) => {
                    isbn = callback;
                });
                author == '' && title == '' && dateno == '' && isbn == '' ? (bookValid = true) : '';
            } else if (this.SourceType == 'other') {
                // others 形式
                var content = '';
                this.$refs['refenceForm'].validateField('content', (callback) => {
                    content = callback;
                });
                content == '' ? (otherValid = true) : '';
            }
            // //console.log(otherValid,99)

            if (journalValid || bookValid || otherValid) {
                // 有任意一个模式符合验证规则就提交

                this.refenceForm.refer_type = this.SourceType;
                // //console.log(this.refenceForm,99)
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                var form = { ...this.refenceForm };
                if (this.role == 'user') {
                    form.article_id = this.$route.query.id;
                }
                this.$api
                    .post(this.role == 'user' ? 'api/Preaccept/addRefer' : 'api/Preaccept/addReferByParticleid', form)
                    .then((res) => {
                        if (res.code == 0) {
                            loading.close();
                            this.$message.success('successed！');

                            this.changeRefer();
                            this.cancelSave();
                        } else if (res.code == 1) {
                            // doi 错误
                            loading.close();
                            this.$message.error(res.msg);
                        } else {
                            loading.close();
                            this.$message.error(res.msg);
                        }
                    })
                    .catch((err) => {
                        loading.close();
                        this.$message.error(err);
                    });
            } else {
                return false;
            }
        },
        cancelSave() {
            this.editboxVisible = false;
            // refenceForm
            // this.$refs['refenceForm'].clearValidate();
            // this.$refs['refenceForm'].resetFields();
            this.refenceForm.doi = '';
            this.dialogTitle = '';
        },
        // 格式化
        gotoFormate() {
            // this.$refs['refenceForm'].validateField('doi', (callback)=>{
            if (this.refenceForm.doi && this.refenceForm.doi != '') {
                const loading = this.$loading({
                    lock: true,
                    text: 'Loading...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                this.$api
                    .post('/api/Preaccept/searchDoi', { doi: this.refenceForm.doi })
                    .then((res) => {
                        loading.close();
                        ////console.log(res)
                        if (res.code == 0) {
                            //this.tableData = res.data.refers
                            this.$nextTick(() => {
                                this.refenceForm.author = res.data.formate.author;
                                this.refenceForm.title = res.data.formate.title;
                                this.refenceForm.joura = res.data.formate.joura;
                                this.refenceForm.dateno = res.data.formate.dateno;
                                this.refenceForm.doilink = res.data.formate.doilink;
                            });
                        } else {
                            this.$message.error(res.msg);
                        }
                    })
                    .catch((e) => {
                        loading.close();
                        this.$message.error(e.msg);
                    });
            } else {
                //  //console.log('不合格')
                this.$message.error('The Doi cannot be empty!');
                return false;
            }
            // })
        },
        // 添加一行
        addLine(row, optitle) {
            this.dialogTitle = optitle;
            this.old_refence_type = '';
            this.old_refence_content = '';
            this.SourceType = 'journal';
            (this.refenceForm = {
                doi: '',
                p_article_id: this.p_article_id,
                p_refer_id: null, // 当前行一行的引用序号
                pre_p_refer_id: row.p_refer_id, // 上一行
                refer_type: '', // 类型
                joura: '',
                author: '',
                doilink: '',
                dateno: '',
                isbn: '',
                content: '',
                title: ''
            }),
                (this.isShowParsing = true);
            this.isShowParsingData = false;
            this.editboxVisible = true;

            this.$nextTick(() => {
                if (this.$refs['refenceForm']) {
                    this.$refs['refenceForm'].clearValidate(['content']);
                    this.$refs['refenceForm'].clearValidate(['doi']);
                }
            });
        },

        // 删除一行
        deleteLine(row) {
            this.$confirm('Are you sure you want to remove this reference?', 'Tips', {
                confirmButtonText: 'Sure',
                cancelButtonText: 'Cancel',
                type: 'warning'
            })
                .then(() => {
                    const loading = this.$loading({
                        lock: true,
                        text: 'Loading...',
                        spinner: 'el-icon-loading',
                        background: 'rgba(0, 0, 0, 0.7)'
                    });
                    this.$api
                        .post('api/Preaccept/delRefer', {
                            p_refer_id: row.p_refer_id
                        })
                        .then((res) => {
                            loading.close();
                            if (res.code == 0) {
                                this.$message.success('remove successed!');
                                this.changeRefer();
                                // this.getRefData()
                            } else {
                                this.$message.error(res.msg);
                            }
                        })
                        .catch((err) => {
                            loading.close();
                            this.$message.error(err);
                        });
                })
                .catch(() => {
                    loading.close();
                });
        },

        // 调整顺序
        changeOrder(row, opName) {
            let optitle = '';
            opName == 'up' ? (optitle = 'Move up this line?') : (optitle = 'Move down this line?');
            // this.$confirm(optitle, 'Tips', {
            // confirmButtonText: 'Sure',
            // cancelButtonText: 'Cancel',
            // type: 'warning'
            // }).then(() => {
            this.$api
                .post('api/Preaccept/sortRefer', {
                    p_refer_id: row.p_refer_id,
                    act: opName
                })
                .then((res) => {
                    if (res.code == 0) {
                        //	this.$message.success('successed!')
                        this.changeRefer();
                        // this.getRefData()
                    } else {
                        this.$message.error(res.msg);
                    }
                })
                .catch((err) => {
                    this.$message.error(err);
                });
            // this.$message({
            //     type: 'success',
            //     message: 'remove successed!'
            // });
            // }).catch(()=>{});
        }
    },
    watch: {
        SourceType: {
            handler(newVal, oldVal) {
                this.$nextTick(() => {
                    this.refenceForm.refer_type = this.SourceType;
                    if (this.$refs['refenceForm']) {
                        this.$refs['refenceForm'].clearValidate();
                    }

                    if (
                        (this.SourceType != this.old_refence_type || this.refenceForm.content != this.old_refence_content) &&
                        this.SourceType != 'other'
                    ) {
                        this.isShowParsing = true;
                    } else {
                        this.isShowParsing = false;
                    }
                });
            },
            immediate: true,
            deep: true // 可以深度检测到 person 对象的属性值的变化
        },
        'refenceForm.content': {
            handler(newVal, oldVal) {
                if (this.SourceType != 'other') {
                    if (this.dialogTitle == 'Edit') {
                        if (this.refenceForm.content != this.old_refence_content) {
                            this.isShowParsing = true;
                        } else {
                            this.isShowParsing = false;
                        }
                    } else {
                        if (this.refenceForm.content == '' || this.refenceForm.content != this.old_refence_content) {
                            this.isShowParsing = true;
                        } else {
                            this.isShowParsing = false;
                        }
                    }
                } else {
                    this.isShowParsing = false;
                }
            },
            immediate: true, // 初始化时立即执行一次handler
            deep: true // 这里如果content是普通类型（如字符串），deep可以省略；如果content是对象，才需要deep: true
        }
    }
};
</script>

<style scoped>
.edit-public-ref-table-only {
    width: 100%;
    box-sizing: border-box;
}

.references-h1 {
    width: 100%;
    /* padding: 6px 16px; */
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    box-sizing: border-box;
    transition: background-color 0.1s;
}
.pMainH1 {
    width: 100%;
    font-family: 'Charis SIL';
    min-height: 12px;
    background: rgb(222, 235, 247);
    color: rgb(210, 90, 90) !important;
    text-align: center !important;
    border: 1px solid rgba(222, 234, 247, 0.1);
    border-radius: 10px;
    font-size: 16px;

    margin-top: 15px !important;
    margin-bottom: 10px !important;
    box-shadow: rgba(222, 234, 247, 0.6) 0px 4px 4px;
}
::v-deep .pMainH1 .pMain {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    line-height: 30px !important;
    text-align: center;
    font-size: 16px;
    font-weight: bold !important;
}
/* 1级标题 */
.level-1 {
    padding-left: 0px;
}
.level-1 .title-content {
    width: 100%;
    font-weight: bold !important;
    font-style: normal !important;
    font-size: 14px !important;
    line-height: 1.3;
    white-space: nowrap;
    padding: 4px 0px;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Times New Roman 增加学术感 */
    font-family: 'Charis SIL' !important;
    color: #333;
}
/* 隐藏编辑器底部内容 */
/* /deep/ #edui1_bottombar{display: none;}  */
/* 编辑器高度 */
/* /deep/ #edui1_iframeholder{ height: 260px;}  */

.wordDia {
    max-height: 800px;
    overflow-y: scroll;
}

.logtips {
    margin-bottom: 15px;
    color: #666;
}

/* .itemIndex{position: relative;} */
.itemChanged {
    position: absolute;
    display: inline-block;
    background: #006699;
    color: #fff;
    padding: 5px;
    border-radius: 0 0 7px 7px;
    left: 0;
    top: 0;
}

.status {
    display: block;
    width: 36px;
    height: 36px;
    border-radius: 36px;
    font-size: 22px;
    line-height: 36px;
    color: #fff;
    text-align: center;
}

.status.ok {
    background: #a7e389;
}

.status.warn {
    background: #ffd192;
}

.status.float {
    display: inline-block;
}

.doiLink {
    color: #006699;
}

.talkDialog {
    height: 500px;
    overflow-y: scroll;
}

.contactAuthor {
    margin-top: 50px;
    color: #8c939d;
}

.contactAuthor > p {
    font-size: 12px;
    margin-left: 0 !important;
}

.contactAuthor > p > .btnCliArt {
    color: #409eff;
}

.contactAuthor > h4 {
    margin-bottom: 10px;
}

.handle-box {
    margin-bottom: 20px;
}

.title_header {
    margin-bottom: 20px;
}

.tab_post {
    background-color: #fafafa;
    position: absolute;
    left: 25px;
    top: 60px;
    /* width: 220px; */
    z-index: 50;
}

.tab_post > div {
    margin-bottom: 30px;
    cursor: pointer;
    position: relative;
}

.tab_post > div h5 {
    padding: 10px 10px 0 0;
    margin-bottom: 5px;
    border-radius: 10px;
    font-size: 16px;
    color: #333;
    font-weight: bold;
    letter-spacing: -0.6px;
}

.tab_post > div h5 span {
    border: 2px solid #333;
    padding: 0 7px;
    margin: 0 5px 0 0;
    border-radius: 15px;
    font-size: 12px;
    display: inline-block;
}

.tab_post > div p {
    margin: 0 20px 0 33px;
    color: #999;
    font-size: 14px;
    line-height: 18px;
}

.tab_post > div .line {
    top: 50px;
    left: 11px;
    bottom: -25px;
    position: absolute;
    border: 1px dashed #999;
}

.tab_post > div:nth-child(7) .line {
    border: none;
}

.tab_post > div.P_style h5 {
    color: #006699;
}

.tab_post > div.P_style h5 span {
    background-color: #006699;
    border: 2px solid #006699;
    color: #fff;
}

.tab_post > div.P_style p {
    color: #333;
}

.tab_post > div.P_style .line {
    /* border-color: #006699; */
}

.scroll-item {
    margin: 0 30px 50px 255px;
}

.bor_style_onli {
    height: 700px;
    overflow-y: scroll;
    border: 2px solid #0066991a;
    background-color: #fff;
    border-radius: 5px;
    padding: 20px;
}

.bor_style_onli > h4 {
    margin: 0 0 20px 0;
    letter-spacing: -0.5px;
}

.captcha-img.el-switch.is-disabled {
    opacity: 1;
}

.captcha-img.el-switch.is-disabled .el-switch__core {
    cursor: pointer;
}

.message-title {
    cursor: pointer;
}

.guanSty {
    min-width: 1000px;
}

.guanSty .quill-editor {
    margin-bottom: 20px;
    /* height: 200px; */
}

.guanSty .ql-toolbar {
    border: 1px solid #dcdfe6 !important;
}

.guanSty .ql-container {
    min-height: 100px !important;
    border: 1px solid #dcdfe6 !important;
}

.guanSty .ql-editor {
    height: 100px;
}

.guanSty .upload-demo .el-upload {
    width: 55px;
    float: left;
    margin-left: 5px;
    border: none;
    text-align: left;
    height: 35px;
}

.guanSty .el-upload-list {
    margin-top: 4px;
    margin-left: 20px;
    float: left;
    width: 35px;
}

.guanSty .el-upload-list .el-upload-list__item {
    width: 30px !important;
}

.guanSty .el-upload-list .el-upload-list__item:hover {
    cursor: pointer;
}

.guanSty .el-upload-list .el-upload-list__item .el-upload-list__item-name {
    width: 30px;
}

.guanSty .el-upload-list .el-upload-list__item .el-upload-list__item-status-label {
    display: none;
}

.guanSty .el-upload-list__item:hover .el-icon-close {
    display: none;
}

.guanSty .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    width: 140px;
    height: 140px;
}

.guanSty .avatar-uploader .el-upload:hover {
    border-color: #409eff;
}

.guanSty .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 140px;
    height: 140px;
    line-height: 140px;
    text-align: center;
}

.guanSty .avatar {
    width: 140px;
    height: 140px;
    display: block;
}

.guanSty .upload-demo .el-upload-list__item:first-child {
    margin-top: 0;
    width: 300px;
}

.suoshu_jigou .el-checkbox__label {
    white-space: normal;
}

.suoshu_jigou .el-checkbox__input {
    vertical-align: top;
    margin-top: 8px;
}

.liter_ture {
    position: relative;
    margin-top: 30px;
}

.chanSelLef {
    width: 100% !important;
    /* position: sticky; */
    top: 10px;
    height: auto;
}

.chanSelLef > p {
    font-size: 14px;
    color: #333;
    margin: 10px 0 30px 0;
    line-height: 22px;
}

.chanSelLef > div {
    margin: 0 0 20px 0;
}

.chanSelLef > div > h3 {
    font-size: 14px;
    letter-spacing: -0.5px;
    color: #999;
}

.chanSelLef > div > h3 > span {
    color: #fff;
    background-color: #999;
    padding: 2px 6px;
    margin: 0 10px 0 0;
}

.chanSelLef > div > div > p {
    font-size: 14px;
    color: #333;
    margin: 10px 0 0 32px;
    line-height: 24px;
}

.chanSelLef > div.C_style > h3 {
    color: #006699;
}

.chanSelLef > div.C_style > h3 > span {
    background-color: #006699;
}

.chanFerAll {
}

.chanFerAll .chanFerBtn {
    cursor: pointer;
}

.chanFerAll .ref_list:nth-child(2n) {
}

.chanFerAll .ref_list:nth-child(2n + 1) {
    background-color: #ecf5ff;
}

.ref_list {
    padding: 20px;
    position: relative;
}

.ref_list > b {
    position: absolute;
    top: 5px;
    left: 10px;
    font-size: 12px;
}

.ref_list > i {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 16px;
    color: #006699;
    cursor: pointer;
}

.ref_list > div:nth-child(1) {
    margin: 0 0 15px 0;
}

.ref_list > div:nth-child(1) input {
}

.ref_list > div:nth-child(1) button {
    float: right;
}

.ref_list > div:nth-child(2) {
    margin: 0 0 15px 0;
}

.ref_list > div.BG_yell {
    background-color: #fdf3e3;
    padding: 15px 0;
}

.RefProBar {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

.RefProBar > div {
    width: 76%;
    position: absolute;
    top: 40%;
    left: 12%;
}

.RefProBar > div > p {
    color: #fff;
    margin: 20px 0 0 0;
}

.RefProBar > div > p > img {
    width: 30px;
    vertical-align: middle;
    margin: 0 10px 0 5px;
}

.RefProBar > div > p > span {
    font-size: 18px;
}

.upload-demo_6 {
    overflow: auto;
}

.upload-demo_6 .el-upload {
    margin-left: 0 !important;
    width: 150px !important;
    height: auto !important;
    text-align: center !important;
}

.upload-demo_6 .el-upload__tip {
    margin-left: 15px;
    float: left;
}

.typeA_MTxt > div > div {
    position: relative;
    border-bottom: 1px solid #d6e5ec;
    padding: 10px 0 12px 0;
}

.typeA_MTxt > div > div .el-button {
    position: absolute;
    right: 5px;
    top: -1px;
}

.typeA_MTxt > h5 {
    margin: 25px 0 15px 0;
    line-height: 18px;
    font-size: 13px;
    color: #bbb;
    font-weight: 400;
}

.bor_style_onli .load_pdf {
    margin-bottom: 20px;
}

.bor_style_onli .load_pdf > img {
    vertical-align: sub;
    margin: 0 15px 0 0;
}

.bor_style_onli .load_pdf a i:hover {
    color: #006699 !important;
    transform: scale(1.3);
}

.con_firm {
    font-size: 14px;
    line-height: 28px;
}

.con_firm b {
    margin-left: 5px;
}

.con_firm i {
    font-size: 18px;
    margin-right: 5px;
    vertical-align: text-bottom;
}

.aMesage {
    font-size: 14px;
    font-family: 'Helvetica Neue', Helvetica, Georgia, sans-serif;
    word-break: break-all;
}

.aMes_typ {
    line-height: 35px;
    border-bottom: 1px solid #f1f1f1;
    color: #7f0202;
    font-weight: bold;
}

.aMes_tit {
    color: #222;
    font-weight: bold;
    margin-top: 8px;
    line-height: 20px;
    font-family: 'Helvetica Neue', Helvetica, Georgia, sans-serif;
}

.aMes_autor {
    margin-top: 5px;
    font-size: 15px;
    font-family: Calibri;
}

.aMes_doi {
    margin-top: 8px;
}

.aMes_doi span {
    margin-left: 20px;
}

.aMes_asbimg {
    margin-top: 20px;
}

.aMes_asbimg img {
    float: left;
    width: 290px;
}

.aMes_asbimg div {
    float: left;
    font-family: Calibri;
    width: 430px;
    padding-left: 30px;
}

.aArticle {
    font-size: 14px;
    font-family: 'Helvetica Neue', Helvetica, Georgia, sans-serif;
    word-break: break-all;
}

.aArt_doi {
}

.aArt_tit {
    font-size: 16px;
    color: #333333;
    font-weight: bold;
    margin: 20px 0 15px 0;
    line-height: 24px;
}

.aArt_autor {
    margin-top: 5px;
    font-size: 15px;
    font-family: Calibri;
}

.aArt_autor img {
    width: 13px;
    margin-left: 3px;
}

.aArt_jigou {
    margin-top: 10px;
    line-height: 20px;
    font-family: Calibri;
}

.aArt_abst {
    margin-top: 30px;
}

.aArt_abst .titTop {
    border-bottom: 1px solid #ddd;
    margin-bottom: 20px;
}

.zhushi {
    color: #999;
    font-size: 12px;
}

.aArt_abst .titTop b {
    font-weight: normal;
    display: inline-block;
    padding: 8px 10px;
    border: 1px solid transparent;
    margin-bottom: -1px;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
}

.aArt_abst .titTop b.Tab_col {
    border: 1px solid #ddd;
    border-bottom-color: #fff;
}

.aArt_abst .titHtml {
    letter-spacing: 0.03em;
    margin: 15px 10px 0 10px;
    color: #444;
    font-size: 15px;
    line-height: 1.4;
    word-break: break-word;
}

.aArt_abst > p {
    margin: 25px 10px 0 10px;
    text-align: justify;
    color: #666;
    font-size: 15px;
    line-height: 1.4;
    /* text-indent: 2.6rem; */
    word-break: break-word;
}

.aArt_abst .titHtml .MaxPicture {
    text-align: center;
}

.aArt_abst .titHtml .MaxPicture > img {
    margin-bottom: 10px;
}

.aArt_abst .titHtml .MaxPicture > font {
    display: block;
    margin: 0 auto;
    font-size: 13px;
}

.refTable th {
    background: red !important;
    color: #666;
}

.topBtnBox.btns {
    margin-bottom: 20px;
}

.bottomBtnBox.btns {
    margin-top: 20px;
}

.repeat-warning-row {
    background: red !important;
}

.liter_ture {
    height: calc(100% - 100px);
    /* display: flex;
    justify-content: space-between; */
    /* display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: minmax(100%, auto);
    gap: 20px; */
}

::v-deep .chanFerAll {
    width: 100% !important;

    border-top: 1px solid #d6e5ec;
    box-sizing: border-box;
}

::v-deep .chanFerAll > div {
    height: 100%;
}

::v-deep .chanFerAll > div > .el-textarea {
    /* height: 100%; */
    height: 100%;
}

::v-deep .chanFerAll > div > .el-textarea .el-textarea__inner {
    /* height: 100%; */
    height: 100% !important;
}

::v-deep .el-table-column--selection .cell {
    padding: 0 !important;
}

::v-deep .el-table--small {
    font-size: 13px !important;
}

.reference-item {
    line-height: 18px;
}

::v-deep .el-table .cell {
    padding: 0 !important;
}

.automatic-parsing-box {
    position: relative;
    padding-bottom: 24px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    color: #006699;
}

.automatic-parsing-box span {
    position: absolute;
    right: 14px;
    bottom: 1px;
    cursor: pointer;
}

::v-deep .automatic-parsing-box .automaticParsing .el-textarea__inner {
    border: none !important;
}

::v-deep.el-table--small .el-table__cell {
    padding-top: 4px;
    padding-bottom: 4px;
}

.operation {
    zoom: 0.9;
}

::v-deep .operation .el-button--mini {
    font-size: 14px !important;
    padding: 6px 10px !important;
}

.duplicateRefBox {
    color: #606266;
    margin-top: 0px;
    margin-bottom: 20px;

    background: #fef0f0;
    border: 1px solid #fbc4c4;
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 3px;
    display: flex;
    align-items: center;
}
.wrongLine {
    color: #f15f44;
}
.Duplicate-item {
    position: absolute;

    left: 1px;
    top: calc((100% - 24px) / 2);
}
.beautiful-gradient {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.01);

    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border-radius: 30px;
}
.text-highlight {
    background-color: rgb(252, 98, 93);
    background-color: rgb(252 98 93 / 68%);
    color: #333;
}
.template-info {
    margin-top: 20px;
    margin-bottom: 20px;
    background: rgb(244, 244, 245);
    border: 1px solid rgb(211, 212, 214);
    font-size: 14px;
    color: #606266;
    padding-left: 15px;
    border-radius: 4px;
    padding: 14px;
    box-sizing: border-box;
}
.template-title {
    /* font-size: 16px; */
    font-weight: bold;

    margin-bottom: 10px;
    color: #333;
    display: inline-block;
}
.ref-list-wrapper {
    background: #fff;
}

.ref-item-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 0px 0px 10px;

    transition: all 0.2s ease;
    position: relative;
}

.ref-item-row:hover {
    background-color: #f9fbff;
}

/* 序号与状态 */
.ref-index-area {
    width: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}
.index-num {
    font-size: 13px;
    color: #909399;
    font-weight: bold;
}
.status-ok {
    color: #67c23a;
    margin-top: 5px;
}
.status-warn {
    color: #e6a23c;
    margin-top: 5px;
}

/* 内容区 */
.ref-content-area {
    line-height: 22px;
    flex: 1;
    min-width: 0;
    color: #333;
    text-align: justify;
    display: flex;
    align-items: flex-start;
    word-wrap: break-word;
    font: 14px Helvetica Neue, Helvetica, PingFang SC, Tahoma, Arial, sans-serif;
}

.doi-link-text {
    font-size: 12px;
    color: #006699;
    text-decoration: none;
}

/* 操作区 */
.ref-actions-area {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;

    flex-shrink: 0;
    margin-left: auto;
    min-width: 100px;
}
.action-icon {
    font-size: 15px;
    cursor: pointer;
    color: #909399;
    transition: color 0.2s;
}
.action-icon:hover {
    color: #006699;
}
.action-icon.success:hover {
    color: #67c23a;
}
.action-icon.danger:hover {
    color: #f56c6c;
}
.action-icon.disabled {
    color: #e4e7ed;
    cursor: not-allowed;
}

.order-icons {
    display: flex;
    flex-direction: column;
    gap: 0;
}
.order-icons .action-icon {
    font-size: 12px;
    line-height: 1;
}

.ai-mini-tag {
    width: 18px;
    height: 18px;
    margin-left: 5px;
}

.ref-number-prefix {
    margin-right: 6px;
    color: #006699;
}
</style>
