<template>
    <div class="RequestAccess-all" v-loading.fullscreen.lock="RequestAccessLoading" :element-loading-text="loadingtext">
        <el-dialog :close-on-click-modal="false" top="28vh" width="450px" title="添加公务出访（无团组）" :visible.sync="AddRequestAccessVisible">
                <div class="RequestAccess-li">
                    <label>公务名称：</label>
                    <el-input style="width:312px" size="small" v-model="invName" placeholder="请输入公务名称"></el-input>
                </div>
                <div class="RequestAccess-btn">
                    <el-button type="primary" @click="InvitationAI_NoGroupAdd" size="small">确 定</el-button>
                    <el-button size="small" @click="AddRequestAccessVisible=false">取消</el-button>
                </div>
        </el-dialog>
        <el-dialog :close-on-click-modal="false" top="18vh" width="450px" title="AI访问关键字设置" :visible.sync="RequestAccessVisible">
            <div class="RequestAccess-ul">
                <!-- <div class="RequestAccess-li">
                    <label>公务名称：</label>
                    <el-input style="width:312px" size="small" v-model="invName" placeholder="请输入公务名称"></el-input>
                </div> -->
                <div class="RequestAccess-li">
                    <label>拜访单位：</label>
                    <el-select style="width:312px" size="small" filterable remote :filter-method="InvAIClientKeywordSearch" :loading="selectLoadings" v-model="unitName" clearable placeholder="请选择">
                        <el-option v-for="item in unitNamess" :key="item" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </div>
                <div class="RequestAccess-li">
                    <label>拜访国家：</label>
                    <el-select style="width:312px" size="small" multiple filterable remote :filter-method="InvAICountryKeywordSearch" :loading="selectLoadingss" v-model="countrie" clearable placeholder="请选择">
                        <el-option v-for="item in countriess" :key="item" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </div>
                <div class="RequestAccess-li">
                    <label>拜访时间：</label>
                    <el-date-picker  style="width:312px" size="small"  v-model="visitDate" type="date" placeholder="选择日期">
                    </el-date-picker>
                </div>
                <div class="RequestAccess-li">
                    <label>拜访目的：</label>
                    <el-input style="width:312px" size="small" v-model="objective" placeholder="请输入拜访目的"></el-input>
                </div>
                <div class="RequestAccess-li">
                    <label>规模类型：</label>
                    <el-select style="width:312px" size="small" multiple filterable v-model="orgScale" clearable placeholder="请选择">
                        <el-option v-for="item in orgScales" :key="item" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </div>
                <div class="RequestAccess-li">
                    <label>行业：</label>
                    <el-select style="width:312px" size="small" multiple filterable v-model="industryNode" clearable placeholder="请选择">
                        <el-option v-for="item in industryNodes" :key="item" :label="item" :value="item">
                        </el-option>
                    </el-select>
                </div>
                <div class="RequestAccess-li">
                    <label>华人单位筛选：</label>
                    <el-radio-group v-model="isBackground">
                        <el-radio :label="true">筛选</el-radio>
                        <el-radio :label="false">不筛选</el-radio>
                    </el-radio-group>
                </div>
                <div class="RequestAccess-li">
                    <label>公司层级：</label>
                    <el-radio-group v-model="orgLevel">
                        <el-radio v-for="(item,index) in orgLevels" :key="index" :label="item">{{item}}</el-radio>
                    </el-radio-group>
                </div>
                <div class="RequestAccess-li" style="align-items: flex-start;">
                    <label>其他信息：</label>
                    <el-input style="width:312px" type="textarea" rows="3" size="small" v-model="otherConstraints"></el-input>
                </div>
                <div class="RequestAccess-btn">
                    <el-button type="primary" @click="InvitationAI_NoGroupSetPrompt" size="small">确 定</el-button>
                    <el-button size="small" @click="RequestAccessVisible=false">取消</el-button>
                </div>
            </div>
        </el-dialog>
        <el-dialog :close-on-click-modal="false" top="5vh" width="900px" title="邮件预览" :visible.sync="RequestAccessEmailVisible">
            <div style="margin-bottom: 15px;">
                <div class="quill-title" style="font-weight: 600;margin-bottom: 5px;">邮件标题：</div>
                <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="contenttitle"></el-input>
            </div>
            <!-- 新增：附件上传区域 -->
            <div style="margin-bottom: 15px;">
                <div class="quill-title" style="font-weight: 600;margin-bottom: 5px;">邮件附件：</div>
                <div class="attachment-section">
                    <el-upload 
                    class="pop-upload"
                    ref="upload"
                    action="#"
                    :file-list="fileList"
                    :auto-upload="false"
                    :multiple="true"
                    :on-change="handleChange"
                    :on-remove="handleremove"
                    name="files"
                    accept=".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.jpg,.jpeg,.png,.zip,.rar">
                        <el-button size="small" slot="trigger" type="primary" icon="el-icon-upload">选择文件（可多选）</el-button>
                        <el-button style="margin-left:15px ;" @click="handleEmailAttachmentUpload" size="small" type="primary">上传</el-button>
                        <div slot="tip" class="el-upload__tip">支持多文件上传</div>
                    </el-upload>

                    <!-- 上传进度 -->
                    <div class="upload-progress" v-if="uploadProgress.visible">
                        <el-progress :percentage="uploadProgress.percent" :status="uploadProgress.status"></el-progress>
                        <div class="upload-progress-text">{{ uploadProgress.text }}</div>
                    </div>

                    <!-- 已上传附件列表 -->
                    <div class="email-attachment-list" v-if="emailAttachments.length > 0">
                        <div class="attachment-header">
                            <span>已上传附件（{{ emailAttachments.length }}个）</span>
                            <el-button type="text" size="small" @click="clearAllAttachments"
                                style="color: #F56C6C;">清空全部</el-button>
                        </div>
                        <div v-for="(file, index) in emailAttachments" :key="index" class="attachment-item">
                            <i class="el-icon-document"></i>
                            <span class="attachment-name">{{ file.split('/').pop() }}</span>
                            <!-- <span class="attachment-size">{{ formatFileSize(file.fileSize) }}</span> -->
                            <el-button type="text" size="small" @click="previewAttachment(file)"
                                v-if="canPreview(file)">预览</el-button>
                            <el-button v-if="canDownload(file)" type="text" size="small" @click="downloadAttachment(file)">下载</el-button>
                            <el-button type="text" size="small" style="color: #F56C6C;"
                                @click="removeEmailAttachment(index,file.split('/').pop())">删除</el-button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="quill-title" style="font-weight: 600;margin-bottom: 5px;">邮件内容：</div>
            <div class="quill-box">
                <quill-editor class="editor" ref="myTextEditor" v-model="content" :options="editorOption"
                    @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @ready="onEditorReady($event)"
                    @change="onEditorChange($event)">
                    <button id="custom-button">defineAsyncComponent</button>
                </quill-editor>
            </div>
            <div class="quill-btn">
                <el-button type="primary" @click="InvitationAI_NoGroupEmailSave" size="small">保 存</el-button>
                <el-button size="small" @click="RequestAccessEmailVisible=false">取 消</el-button>
            </div>
        </el-dialog>
        <div class="RequestAccess-hader">
            <div class="RequestAccess-hader-top">
                <div>
                    <el-select style="width:250px" @change="InvitationAI_NoGroupItemByName" size="small" filterable remote :filter-method="InvAIKeywordSearch" :loading="selectLoading" v-model="itemNameid" placeholder="请选择">
                        <el-option v-for="item in itemNamess" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                </div>
                <div>
                    <el-button type="primary" size="small" @click="openaddbox">新增</el-button>
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupInsertResource">添加入资料库</el-button>
                    <!-- <el-button type="primary" size="small" @click="BusinessSynchronizationWrite" >行程单位传递</el-button> -->
                    <el-button type="primary" size="small" @click="AIKeyWords">AI关键字设置</el-button>
                    <!-- <el-button type="primary" size="small" @click="InvitationAICompleteText" >AI续查</el-button> -->
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupSearchStreamProgress">AI重新搜索公务方/机构（覆盖）</el-button>
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupCompleteTextStream" >AI续查</el-button>
                    <!-- <el-button type="primary" size="small" @click="InvitationAISearch">AI重新搜索公务方/机构（覆盖）</el-button> -->
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupFileGenerator">下载文件</el-button>
                    <!-- <el-button type="primary" size="small" @click="InvitationAIGenerateEmail">AI生成邮件</el-button> -->
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupGenerateEmailStream">AI生成邮件</el-button>
                    <!-- <el-button type="primary" size="small" @click="InvitationAISeedEmail">发送邮件</el-button> -->
                    <el-button type="primary" size="small" @click="InvitationAI_NoGroupSeedEmailStream">发送邮件</el-button>
                </div>
            </div>
        </div>
        <div class="RequestAccess-table">
            <el-table  height="700" ref="multipleTable" :data="tableData" border style="width: 100%" @select="tableselect" @select-all="handleSelectAll" @selection-change="handleSelectionChange" :row-class-name="tableRowClassName">
                <el-table-column type="selection" prop="isChecked" width="55">
                </el-table-column>
                <el-table-column type="index" label="序号" width="50">
                </el-table-column>
                <el-table-column prop="region" label="国家" width="80">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.region">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column prop="nameCn" label="名称">
                     <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.nameCn">
                        </el-input>
                     </template>
                </el-table-column> 
                <el-table-column prop="address" label="地址">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.address">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column prop="scope" label="经营范围">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.scope">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column prop="contact" label="联系人">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.contact">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column prop="phone" label="联系电话" width="140">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.phone">
                        </el-input>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="官方网址">
                    <template slot-scope="scope">
                        <el-link type="primary" :href="scope.row.siteUrl" target="_blank">{{scope.row.siteUrl}}</el-link>
                    </template>
                </el-table-column> -->
                <el-table-column prop="email" label="联系邮箱">
                    <template slot-scope="scope">
                        <el-input type="textarea" autosize placeholder="请输入内容" size="small" v-model="scope.row.email">
                        </el-input>
                    </template>
                </el-table-column>
                <el-table-column label="相关信息" width="80">
                    <template slot-scope="scope">
                        <el-popover v-if="scope.row.postUrl.length>0" placement="right" width="400" trigger="hover">
                            <div style="margin-bottom: 15px;" v-for="(item,index) in scope.row.postUrl" :key="index">
                                <div>时间：{{ item.date }}</div>
                                <div>内容：{{ item.description }}</div>
                                <div>
                                    <div>链接：</div>
                                    <el-link type="primary" :href="item.url" target="_blank">{{ item.url }}</el-link>
                                </div>
                            </div>
                            <el-button slot="reference" type="primary" size="mini">查看</el-button>
                        </el-popover>
                        <div v-else>
                            暂无信息
                        </div>

                        
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="操作" width="100">
                    <template slot-scope="scope">
                        <div style="display: flex;flex-direction: column;align-items: center;">
                            <el-button style="width:85px" type="primary" @click="EmailPreview(scope.row)" size="mini">{{scope.row.emailInfo.status===4?'已发送':'邮件预览'}}</el-button>
                            <el-button style="margin: 10px 0;width:85px" type="primary" @click="InvitationAI_NoGroupSave(scope.row)" size="mini">保 存</el-button>
                            <el-button style="margin:0;width:85px" type="danger" @click="InvitationAI_NoGroupSingleDel(scope.row)" size="mini" >删 除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="RAaddline">
                <el-button size="small" @click="addlineclick" type="primary">添加一行</el-button>
            </div>
        </div>
    </div>
</template>
<script>
import { streamRequestGET, streamRequestPOST } from '@/store/streamRequest';
import { co } from '@fullcalendar/core/internal-common';
export default {
    data () {
        return {
            RequestAccessLoading:false,
            userid: '',
            value:'',
            options: [],
            tableData:[],
            RequestAccessVisible:false,
            AddRequestAccessVisible:false,
            RequestAccessEmailVisible:false,
            itemNameid:'',
            itemNames:[],
            itemNamess:[],
            invName:'',
            objective:'',
            unitName:'',
            unitNames:[],
            unitNamess:[],
            countrie:[],
            countries:[],
            countriess:[],
            otherConstraints:'',
            selectLoading:false,
            selectLoadings:false,
            selectLoadingss:false,
            multipleSelection: [],
            entry:{},
            Id:0,
            contenttitle:'',
            singleguid:'',
            industryNode:[],
            industryNodes:[],
            orgScale:[],
            orgScales:[],
            isBackground:'',
            //富文本
            content: '',
            contents:'',
            editorOption: {
                modules: {
                    toolbar: [
                        ["bold", "italic", "underline", "strike"], // 加粗 斜体 下划线 删除线
                        ["blockquote", "code-block"], // 引用  代码块
                        [{ header: 1 }, { header: 2 }], // 1、2 级标题
                        [{ list: "ordered" }, { list: "bullet" }], // 有序、无序列表
                        [{ script: "sub" }, { script: "super" }], // 上标/下标
                        [{ indent: "-1" }, { indent: "+1" }], // 缩进
                        // [{'direction': 'rtl'}],                         // 文本方向
                        [{ size: ["small", false, "large", "huge"] }], // 字体大小
                        [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
                        [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
                        [{ font: [] }], // 字体种类
                        [{ align: [] }], // 对齐方式
                        ["clean"], // 清除文本格式
                        ["link", "image", "video"], // 链接、图片、视频
                        ["sourceEditor"]
                    ], //工具菜单栏配置
                },
                placeholder: '编写邮件内容', //提示
                readyOnly: false, //是否只读
                theme: 'snow', //主题 snow/bubble
                syntax: true, //语法检测
            },
            cs:`<p><span class="ql-font-monospace" style="color: rgb(220, 54, 46);">&lt;h3&gt;Official Study Visit Inquiry – Chengdu Yimin Group &amp;amp; Washington State Premium Apple Cooperative&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Dear Leaders at the Washington State Premium Apple Cooperative,&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;On behalf of Chengdu Yimin Group—responsible for securing Chengdu’s food security and elevating access to premium agricultural products—I am pleased to formally request a strategic study visit to your cooperative in June 2025.&lt;/p&gt;&lt;p&gt;As a vital player in Chengdu’s push for sustainable, traceable food systems, we recognize that &lt;strong&gt;integrating global horticultural standards with premium market access&lt;/strong&gt; is key to meeting urban consumers’ growing demand for high-quality produce. Your Cooperative, with 50,000 mu of orchards, 20,000 tons of annual exports, and certifications in HACCP and GlobalGAP, leads Washington’s apple industry by merging sustainable farming with success in China and European premium markets. We aim to draw on your expertise to strengthen our own premium agricultural sourcing and export capabilities.&lt;/p&gt;&lt;p&gt;We are particularly interested in:&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Integration of GlobalGAP and HACCP standards across apple cultivation, harvesting, and post-harvest handling;&lt;/li&gt;&lt;li&gt;Sustainable farming techniques for producing high-yield, nutrient-dense premium apple varieties;&lt;/li&gt;&lt;li&gt;Branding and distribution strategies for premium apples in China and Europe—including regulatory alignment and consumer trust-building.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;We propose a 2–3 day visit during the week of June 1, 2025, including orchard and processing facility tours, discussions with your agronomists and market leads, and insights into export compliance. This visit will allow us to learn from your end-to-end model while exploring synergies in premium produce trade.&lt;/p&gt;&lt;p&gt;Enclosed please find the &lt;em&gt;StrategicInquiryBrief&lt;/em&gt; detailing our priorities and logistics. We are confident this engagement will foster a partnership aligned with global trends in sustainable agriculture and high-value food trade. Please advise on your availability for next steps.&lt;/p&gt;&lt;p&gt;— Sincerely,&lt;/p&gt;&lt;p&gt;Chengdu Yimin Group11&lt;/p&gt;</span></p>`,
            abortController:null,
            loadingtext:'正在加载',

            fileList:[],
            emailAttachments: [], // 邮件附件列表（仅用于展示，不影响保存）
            uploadProgress: {
                visible: false,
                percent: 0,
                status: null,
                text: ''
            },
            isUploading: false, // 添加上传锁标识，防止重复上传
            visitDate:'',
            orgLevels:[],
            orgLevel:'',
        }
    },
    methods:{
        //处理时间
        disposeTime(val){
            var date = new Date(val);
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            let time = y + '-' + m + '-' + d;
            return time
        },
        // 失去焦点
        onEditorBlur(editor) {
            // this.content=this.contents
            // this.$refs.myTextEditor.quill.enable(false);
            // setTimeout(()=>{
            //     this.$refs.myTextEditor.quill.enable(true);
            // },1000)
        },
        // 获得焦点
        onEditorFocus(editor) {},
        // 开始
        onEditorReady(editor) {},
        // 值发生变化
        onEditorChange(editor) {
            // this.contents = editor.text;
        },

        initSelection() {
            this.$nextTick(() => {
                this.tableData.forEach(row => {
                    if (row.isChecked) {
                        this.$refs.multipleTable.toggleRowSelection(row, true);
                    }
                });
            });
        },
        //选中
        InvitationAI_NoGroupSetChecked(guids){
            var url = "/api/Resource/InvitationAI_NoGroupSetChecked"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data: {
                    id: that.Id,
                    currUserId: that.userid,
                    guids:guids
                }
            }).then(function (res) {
                
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            
            // this.InvitationAISetChecked(guids);
        },
        tableselect(val){
            this.multipleSelection = val;
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            this.InvitationAI_NoGroupSetChecked(guids);
        },
        handleSelectAll(val){
            this.multipleSelection = val;
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            this.InvitationAI_NoGroupSetChecked(guids);
        },
        AIKeyWords(){
            this.otherConstraints = this.entry!={}?this.entry.otherConstraints:'';
            this.countrie = this.entry!={}?this.entry.targetCountry:[];
            this.unitName = this.entry!={}?this.entry.originUnit:'';
            this.invName = this.entry!={}?this.entry.invName:'';
            this.visitDate = this.entry!={}?this.entry.visitDate:'';
            this.objective = this.entry!={}?this.entry.objective:'';
            this.orgScale = this.entry!={}?this.entry.scaleTypes:[];
            this.industryNode = this.entry!={}?this.entry.industries:[];
            this.isBackground = this.entry!={}?this.entry.isBackground:'';
            this.orgLevel = this.entry!={}?this.entry.orgLevel:'';
            this.RequestAccessVisible=true;
            
        },
        //获取基础数据
        InvitationAI_NoGroupInit() {
            var url = "/api/Resource/InvitationAI_NoGroupInit"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'get',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.itemNames = res.data.data.itemNames;
                        that.itemNamess = that.itemNames;
                        if (that.itemNameid=='') {
                            that.itemNameid = that.itemNames[0].id;
                        }
                        that.unitNames = res.data.data.unitNames;
                        that.unitNamess = that.unitNames;
                        that.countries = res.data.data.countries;
                        that.countriess = that.countries;
                        that.orgScales = res.data.data.orgScales;
                        that.industryNodes = res.data.data.industryNodes;
                        that.orgLevels = res.data.data.orgLevels;
                        resolve();
                    } else {
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                this.InvitationAI_NoGroupItemByName();
            });

        },
        //添加一行
        addlineclick() {
            // 生成唯一标识
            const newGuid = this.generateGuid();

            // 新行数据模板
            const newRow = {
                guid: newGuid,
                region: '',           // 国家
                nameCn: '',           // 名称
                address: '',          // 地址
                scope: '',            // 经营范围
                contact: '',          // 联系人
                phone: '',            // 联系电话
                email: '',            // 联系邮箱
                postUrl: [
                    {
                        date:"",
                        description:"",
                        url:"",
                    }
                ],          // 相关信息链接
                isChecked: false,     // 是否选中
                source: 2,            // 来源：2-手动添加，1-AI生成
                emailInfo: {          // 邮件信息
                    status: 0,        // 0-未生成，1-已生成，4-已发送
                    emailTitle: '',
                    emailContent: ''
                },
                intgAdvice:'',
                recLevel:'',
                industry:'',
                nameEn:'',
                siteUrl:'',
                remark: '',
            };

            // 添加到表格数据最前面
            this.tableData.unshift(newRow);

            // 可选：滚动到顶部
            this.$nextTick(() => {
                const table = this.$refs.multipleTable;
                if (table && table.$el) {
                    table.$el.scrollIntoView({ behavior: 'smooth' });
                }
            });

            this.$message({
                message: '已添加新行，请填写信息后保存',
                type: 'success',
                duration: 2000
            });
            
        },
         /**
        * 生成唯一标识
        */
        generateGuid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                const r = Math.random() * 16 | 0;
                const v = c === 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        },
        //邮件预览
        EmailPreview(val){
            this.RequestAccessEmailVisible = true;
            var contents = '';
            this.contenttitle = '';
            this.singleguid = '';
            this.emailAttachments = []; // 清空附件列表
            this.uploadProgress = {
                visible: false,
                percent: 0,
                status: null,
                text: ''
            };
            
            if (this.$marked && typeof this.$marked === 'function') {
                contents = this.$marked(val.emailInfo.emailContent);
            } else {
                contents = val.emailInfo.emailContent;
            }
            
            console.log(this.content);
            
            this.content = contents;
            this.contenttitle = val.emailInfo.emailTitle;
            this.singleguid = val.guid;
            
            // 加载已有附件（仅用于展示）
            if (val.emailInfo.attachmentPaths && val.emailInfo.attachmentPaths.length > 0) {
                for (let i = 0; i < val.emailInfo.attachmentPaths.length; i++) {
                    console.log(val.emailInfo.attachmentPaths[i]);
                    
                    this.emailAttachments.push(val.emailInfo.attachmentPaths[i])
                    console.log(this.emailAttachments);
                    
                }
                // this.emailAttachments = [...val.emailInfo.attachmentPaths];
            }
        },
        // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用,function(file, fileList)
        handleChange(file, fileList) {
            this.fileList=fileList;
            
        },
        //未上传时移除文件
        handleremove(file, fileList) {
            this.fileList=fileList;
            
        },
        /**
        * 文件上传前校验
        */
        beforeEmailAttachmentUpload(file) {
            // const isLt10M = file.size / 1024 / 1024 < 10;
            // if (!isLt10M) {
            //     this.$message.error(`文件 ${file.name} 大小不能超过 10MB!`);
            //     return false;
            // }

            const allowedExts = ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'jpg', 'jpeg', 'png', 'zip', 'rar'];
            const ext = file.name.split('.').pop().toLowerCase();

            const isAllowedType = allowedExts.includes(ext);
            if (!isAllowedType) {
                this.$message.error(`文件 ${file.name} 格式不支持！`);
                return false;
            }

            return true;
        },

        /**
         * 处理邮件附件上传（支持多文件）
         */
        handleEmailAttachmentUpload() {
            if (this.isUploading) {
                this.$message.warning('正在上传中，请稍后...');
                return;
            }
            // 设置上传锁
            this.isUploading = true;
            const formData = new FormData();
            this.fileList.forEach(file => {
                formData.append('Attachments', file.raw);
            });
            formData.append('Guid', this.singleguid);
            formData.append('Id', this.Id);
            formData.append('CurrUserId', this.userid);
            // 显示上传进度
            this.uploadProgress.visible = true;
            this.uploadProgress.percent = 0;
            this.uploadProgress.status = null;
            this.uploadProgress.text = '上传中...';
            var that = this
            new Promise(function (resolve, reject) {
                that.RequestAccessLoading=true;
                that.$axios({
                    method: 'post',
                    url: '/api/Resource/InvitationAI_NoGroupFileSave', // 多文件上传接口
                    headers: {
                        'Authorization': 'Bearer ',
                        'Content-Type': 'multipart/form-data'
                    },
                    data: formData,
                    onUploadProgress: (progressEvent) => {
                        const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
                        that.uploadProgress.percent = percent;
                        if (percent === 100) {
                            that.uploadProgress.text = '上传完成，处理中...';
                        } else {
                            that.uploadProgress.text = `上传中 ${percent}%`;
                        }
                    }
                }).then(response => {
                    that.uploadProgress.visible = false;
                    that.emailAttachments = []
                    if (response.data.code === 200) {
                        const uploadedFiles = response.data.data;
                        if (uploadedFiles && uploadedFiles.length > 0) {
                            uploadedFiles.forEach(file => {
                                that.emailAttachments.push(file);
                            });
                            that.$message.success(`成功上传 ${uploadedFiles.length} 个文件`);
                        } else {
                            that.$message.success('文件上传成功');
                        }
                        that.fileList = []
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message.error(response.data.msg || '上传失败');
                    }
                }).catch(error => {
                    that.RequestAccessLoading=false;
                    that.uploadProgress.visible = false;
                    that.$message.error('上传失败：' + (error.message || '网络错误'));
                }).finally(() => {
                    // 无论成功或失败，都释放上传锁
                    that.isUploading = false;
                });
            }).then(() => {
                this.InvitationAI_NoGroupItemByName();
            });
        },

        /**
         * 删除附件
         */
        removeEmailAttachment(index,val) {
            this.$confirm('确定要删除该附件吗？', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.RequestAccessLoading=true;
                var that = this
                new Promise(function (resolve, reject) {
                    // 调用删除接口
                    that.$axios({
                        method: 'post',
                        url: '/api/Resource/InvitationAI_NoGroupFileDel',
                        headers: {
                            'Authorization': 'Bearer '
                        },
                        data: {
                            id: that.Id,
                            currUserId: that.userid,
                            guid: that.singleguid,
                            attachmentNames: [val],
                        }
                    }).then(res => {
                        if (res.data.code === 200) {
                            that.emailAttachments = [];
                            // this.emailAttachments.splice(index, 1);
                            const uploadedFiles = res.data.data;
                            uploadedFiles.forEach(file => {
                                that.emailAttachments.push(file);
                            });
                            that.$message.success(res.data.msg);
                            resolve();
                        } else {
                            that.RequestAccessLoading=false;
                            that.$message.error(res.data.msg || '删除失败');
                        }
                    }).catch(error => {
                        that.RequestAccessLoading=false;
                        that.$message.error('删除失败：' + (error.message || '网络错误'));
                    });
                }).then(() => {
                    this.InvitationAI_NoGroupItemByName();
                });
                
            }).catch(() => { });
        },

        /**
        * 清空所有附件
        */
        clearAllAttachments() {
            if (this.emailAttachments.length === 0) {
                this.$message.info('没有可清空的附件');
                return;
            }

            this.$confirm(`确定要清空全部 ${this.emailAttachments.length} 个附件吗？`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.RequestAccessLoading=true;
                const attachmentIds = this.emailAttachments.map(a => a.split('/').pop());
                var that = this
                new Promise(function (resolve, reject) {
                    // 调用删除接口
                    that.$axios({
                        method: 'post',
                        url: '/api/Resource/InvitationAI_NoGroupFileDel',
                        headers: {
                            'Authorization': 'Bearer '
                        },
                        data: {
                            id: that.Id,
                            currUserId: that.userid,
                            guid: that.singleguid,
                            attachmentNames: attachmentIds,
                        }
                    }).then(res => {
                        if (res.data.code === 200) {
                            that.emailAttachments = [];
                            const uploadedFiles = res.data.data;
                            uploadedFiles.forEach(file => {
                                that.emailAttachments.push(file);
                            });
                            that.$message.success(res.data.msg);
                            resolve();
                        } else {
                            that.RequestAccessLoading=false;
                            that.$message.error(res.data.msg || '删除失败');
                        }
                    }).catch(error => {
                        that.RequestAccessLoading=false;
                        that.$message.error('删除失败：' + (error.message || '网络错误'));
                    });
                }).then(() => {
                    this.InvitationAI_NoGroupItemByName();
                });
            }).catch(() => { });
        },

        /**
         * 预览附件
         */
        previewAttachment(file) {
            if (file) {
                const previewableExts = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'txt'];
                const ext = file.split('.').pop().toLowerCase();

                if (previewableExts.includes(ext)) {
                    window.open(file, '_blank');
                } else {
                    this.$message.info('该文件类型不支持在线预览，请下载后查看');
                    this.downloadAttachment(file);
                }
            } else {
                this.$message.warning('文件地址不存在');
            }
        },

        /**
         * 下载附件
         */
        downloadAttachment(file) {
            if (file) {
                window.open(file);
                // const link = document.createElement('a');
                // link.href = file;
                // link.download = file;
                // document.body.appendChild(link);
                // link.click();
                // document.body.removeChild(link);
            } else {
                this.$message.warning('文件地址不存在');
            }
        },

        /**
         * 判断是否可以预览
         */
        canPreview(file) {
            const previewableExts = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'txt'];
            const ext = file.split('.').pop().toLowerCase();
            return previewableExts.includes(ext) && file;
        },
        //判断是否可以下载
        canDownload(file) {
            const previewableExts = ['pdf', 'jpg', 'jpeg', 'png', 'gif', 'txt'];
            const ext = file.split('.').pop().toLowerCase();
            return !previewableExts.includes(ext) && file;
        },
        /**
         * 格式化文件大小
         */
        formatFileSize(bytes) {
            if (bytes === 0) return '0 B';
            const k = 1024;
            const sizes = ['B', 'KB', 'MB', 'GB'];
            const i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
        },
        //dakaixinzeng
        openaddbox(){
            this.invName='',
            this.AddRequestAccessVisible=true
        },
        //添加公务出访（无团组）
        InvitationAI_NoGroupAdd() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupAdd"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        invName: that.invName,
                        currUserId: that.userid,
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        that.AddRequestAccessVisible=false;
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupInit();
            });
        },


        //邮件修改保存
        InvitationAI_NoGroupEmailSave() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupEmailSave"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                        guid:that.singleguid,
                        emailTitle:that.contenttitle,
                        emailContent:that.content,
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        that.RequestAccessEmailVisible=false;
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //查询资料
        InvitationAISearch() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAISearch"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //资料续查
        InvitationAICompleteText() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAICompleteText"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //根据id获取团名称
        reasonidgetname(id) {
            var name = '';
            for (let i = 0; i < this.itemNames.length; i++) {
                if (this.itemNames[i].id == id) {
                    name = this.itemNames[i].name;
                    break;
                }
            }
            return name;
        },
        //下载文件
        InvitationAI_NoGroupFileGenerator() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupFileGenerator/"+this.Id
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.RequestAccessLoading=false;
                    window.open(res.data.data.url);
                } else {
                    that.RequestAccessLoading=false;
                    that.$message({
                        type: 'error',
                        message: res.data.msg
                    });
                }
            })
        },
        //流式(生成邮件)
        InvitationAI_NoGroupGenerateEmailStream() {
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            if (guids.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要生成的邮件！'
                });
                return;
            }
            this.RequestAccessLoading = true;
            var url = "http://132.232.92.186:8888/api/Resource/InvitationAI_NoGroupGenerateEmailStream"
            this.loadingtext = '';
            var that = this
            this.abortController = streamRequestPOST(
                url,
                {
                    id: that.Id,
                    currUserId: that.userid,
                    guids:guids
                },
                (data) => {
                    that.loadingtext = data.message;
                    if (data.progress != -1) {
                        if (data.progress === 100) {
                            // that.RequestAccessLoading=false;
                            that.$message({
                                message: data.message,
                                type: 'success',
                            });
                            that.loadingtext='正在加载';
                            that.InvitationAI_NoGroupItemByName();
                        }
                    } else {
                        that.RequestAccessLoading = false;
                        that.$message({
                            type: 'error',
                            message: data.message
                        });
                    }
                }
            );
        },
        //流式(发送邮件)
        InvitationAI_NoGroupSeedEmailStream() {
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            if (guids.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要发送的邮件！'
                });
                return;
            }
            this.RequestAccessLoading = true;
            var url = "http://132.232.92.186:8888/api/Resource/InvitationAI_NoGroupSeedEmailStream"
            this.loadingtext = '';
            var that = this
            this.abortController = streamRequestPOST(
                url,
                {
                    id: that.Id,
                    currUserId: that.userid,
                    guids:guids
                },
                (data) => {
                    that.loadingtext = data.message;
                    if (data.progress != -1) {
                        if (data.progress === 100) {
                            // that.RequestAccessLoading=false;
                            that.$message({
                                message: data.message,
                                type: 'success',
                            });
                            that.loadingtext='正在加载';
                            that.InvitationAI_NoGroupItemByName();
                        }
                    } else {
                        that.RequestAccessLoading = false;
                        that.$message({
                            type: 'error',
                            message: data.message
                        });
                    }
                }
            );
        },
        //流式(AI重新搜索公务方/机构（续写）)
        InvitationAI_NoGroupCompleteTextStream() {
            this.RequestAccessLoading=true;
            var url = "http://132.232.92.186:8888/api/Resource/InvitationAI_NoGroupCompleteTextStream"
            this.loadingtext='';
            var that = this
            streamRequestPOST(
                url,
                {
                    id:that.Id,
                    currUserId:that.userid,
                },
                (data) => { 
                    that.loadingtext=data.message;
                    if (data.progress!=-1) {
                        if (data.progress===100) {
                            // that.RequestAccessLoading=false;
                            that.$message({
                                message: data.message,
                                type: 'success',
                            });
                            that.loadingtext='正在加载';
                            that.InvitationAI_NoGroupItemByName();
                        }
                    }else{
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message:data.message
                        });
                    }
                 });
        },
        //AI重新搜索公务方/机构（覆盖）
        InvitationAI_NoGroupSearchStreamProgress() {
            this.RequestAccessLoading = true;
            var url = "http://132.232.92.186:8888/api/Resource/InvitationAI_NoGroupSearchStreamProgress"
            this.loadingtext = '';
            var that = this
            this.abortController = streamRequestPOST(
                url,
                {
                    id: that.Id,
                    currUserId: that.userid,
                },
                (data) => {
                    that.loadingtext = data.message;
                    if (data.progress != -1) {
                        if (data.progress === 100) {
                            // that.RequestAccessLoading=false;
                            that.loadingtext='正在加载';
                            that.$message({
                                message: data.message,
                                type: 'success',
                            });
                            that.InvitationAI_NoGroupItemByName();
                        }
                    } else {
                        that.RequestAccessLoading = false;
                        that.$message({
                            type: 'error',
                            message: data.message
                        });
                    }
                }
            );
        },
        //资料列表、
        InvitationAI_NoGroupItemByName() {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupItemByName/"+this.reasonidgetname(this.itemNameid)
            var that = this
            this.$axios({
                method: 'get',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
            }).then(function (res) {
                that.tableData=[];
                that.otherConstraints='';
                that.countrie=[];
                that.unitName='';
                that.invName='';
                that.objective='';
                that.Id=0;
                if (res.data.code == 200) {
                    that.tableData = res.data.data.aiCrawledDetails;
                    that.Id = res.data.data.id;
                    that.entry = res.data.data.entry;
                    that.entry.invName=res.data.data.invName;
                    that.initSelection();
                    that.RequestAccessLoading=false;
                    // that.otherConstraints = res.data.data.id!=0?res.data.data.entry.otherConstraints:'';
                    // that.countrie = res.data.data.id!=0?res.data.data.entry.targetCountry:'';
                    // that.unitName = res.data.data.id!=0?res.data.data.entry.originUnit:'';
                } else {
                    that.RequestAccessLoading=false;
                    that.$message({
                        type: 'error',
                        message: res.data.msg
                    });
                }
            })
        },
        //保存
        InvitationAI_NoGroupSave(val) {
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupSave"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                        aiCrawledDetail:val
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //生成邮件
        InvitationAIGenerateEmail() {
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            if (guids.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要生成的邮件！'
                });
                return;
            }
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAIGenerateEmail"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                        guids:guids
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //添加资料库
        InvitationAI_NoGroupInsertResource() {
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            if (guids.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要添加的资料！'
                });
                return;
            }
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAI_NoGroupInsertResource"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                        guids:guids
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //发送邮件
        InvitationAISeedEmail() {
            var guids=[];
            for (let i = 0; i < this.multipleSelection.length; i++) {
                guids.push(this.multipleSelection[i].guid);
            }
            if (guids.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要发送邮件的单位！'
                });
                return;
            }
            this.RequestAccessLoading=true;
            var url = "/api/Resource/InvitationAISeedEmail"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {

                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.Id,
                        currUserId: that.userid,
                        guids:guids
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        resolve();
                        // that.RequestAccessLoading=false;
                    } else {
                        that.RequestAccessLoading=false;
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(() => {
                that.InvitationAI_NoGroupItemByName();
            });
        },
        //单行删除
        InvitationAI_NoGroupSingleDel(row){
            this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                if(this.Id===0){
                    this.tableData.splice(this.tableData.findIndex(item=>item.guid===row.guid),1);
                    this.$message({
                        message: '删除成功',
                        type: 'success',
                    });
                    return;
                }
                var url = "/api/Resource/InvitationAI_NoGroupSingleDel"
                var that = this
                new Promise(function (resolve, reject) {
                    that.$axios({
                        method: 'post',
                        url: url,
                        headers: {
                            Authorization: 'Bearer '
                        },
                        data: {
                            id: that.Id,
                            guid: row.guid,
                        }
                    }).then(function (res) {
                        if (res.data.code == 200) {
                            that.$message({
                                message: res.data.msg,
                                type: 'success',
                            });
                            resolve();
                        } else {
                            that.$message({
                                type: 'error',
                                message: res.data.msg
                            });
                        }
                    })
                }).then(() => {
                    that.InvitationAI_NoGroupItemByName();
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '操作已取消！'
                });
            });
            
            
        },
        //关键字设置
        InvitationAI_NoGroupSetPrompt(){
            var url = "/api/Resource/InvitationAI_NoGroupSetPrompt"
            var that = this
            new Promise(function (resolve, reject) {
                that.$axios({
                    method: 'post',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                    data: {
                        id: that.itemNameid,
                        originUnit: that.unitName,
                        visitDate: that.disposeTime(that.visitDate),
                        objective: that.objective,
                        targetCountry: that.countrie,
                        industries: that.industryNode,
                        scaleTypes: that.orgScale,
                        isBackground: that.isBackground,
                        otherConstraints: that.otherConstraints,
                        orgLevel: that.orgLevel,
                        currUserId: that.userid
                    }
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.$message({
                            message: res.data.msg,
                            type: 'success',
                        });
                        that.RequestAccessVisible = false;
                        resolve();
                    } else {
                        that.$message({
                            type: 'error',
                            message: res.data.msg
                        });
                    }
                })
            }).then(()=>{
                that.InvitationAI_NoGroupInit();
            });
            
        },
        //联想搜索提示
        InvAIKeywordSearch(query) {
            if (query !== '') {
                this.selectLoading=true;
                var url = "/api/search/InvAIKeywordSearch/" + query
                var that = this
                this.$axios({
                    method: 'get',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.itemNamess = res.data.data;
                    }else{
                        that.itemNamess=[];
                    }
                }).finally(()=>{
                    that.selectLoading=false;
                })
            }else{
                this.itemNamess = this.itemNames;
            }
        },
        //联想搜索提示
        InvAIClientKeywordSearch(query) {
            if (query !== '') {
                this.selectLoadings=true;
                var url = "/api/search/InvAIClientKeywordSearch/" + query
                var that = this
                this.$axios({
                    method: 'get',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.unitNamess = res.data.data;
                    }else{
                        that.unitNamess=[];
                    }
                }).finally(()=>{
                    that.selectLoadings=false;
                })
            }else{
                this.unitNamess = this.unitNames;
            }
        },
        //联想搜索提示
        InvAICountryKeywordSearch(query) {
            if (query !== '') {
                this.selectLoadingss=true;
                var url = "/api/search/InvAICountryKeywordSearch/" + query
                var that = this
                this.$axios({
                    method: 'get',
                    url: url,
                    headers: {
                        Authorization: 'Bearer '
                    },
                }).then(function (res) {
                    if (res.data.code == 200) {
                        that.countriess = res.data.data;
                    }else{
                        that.countriess=[];
                    }
                }).finally(()=>{
                    that.selectLoadingss=false;
                })
            }else{
                this.countriess = this.countries;
            }
        },
        //单位传递
        BusinessSynchronizationWrite() {
            var enterpriseNames=[];
            
            for (let i = 0; i < this.multipleSelection.length; i++) {
                enterpriseNames.push(this.multipleSelection[i].nameCn);
            }
            if (enterpriseNames.length==0) {
                this.$message({
                    type: 'error',
                    message: '请选择需要传递的单位！'
                });
                return;
            }
            this.RequestAccessLoading=true;
            var url = "/api/Groups/BusinessSynchronizationWrite"
            var that = this
            this.$axios({
                method: 'post',
                url: url,
                headers: {
                    Authorization: 'Bearer '
                },
                data:{
                    diid:that. itemNameid,
                    enterpriseNames:enterpriseNames,
                }
            }).then(function (res) {
                if (res.data.code == 200) {
                    that.RequestAccessLoading=false;
                    that.$message({
                        message: res.data.msg,
                        type: 'success',
                    });
                }else{
                    that.RequestAccessLoading=false;
                    that.$message({
                        message: res.data.msg,
                        type: 'error',
                    });
                }
            })
        },
        tableRowClassName({ row }) {
            if (row.source===1) {
                return 'error-row';
            }
            // if (row.status === 'error') {
            //     return 'error-row';
            // } else if (row.status === 'success') {
            //     return 'success-row';
            // }
            return '';
        }
    },
    mounted() {
        this.userid = JSON.parse(localStorage.getItem('userinif')).userInfo.userId;
        this.InvitationAI_NoGroupInit();
    }
}
</script>
<style>
.error-row {
    color: green  !important;
}
.error-row .el-textarea__inner{
    color: green  !important;
}

.RequestAccess-all {
    background-color: #fff;
    padding: 10px;
    box-shadow: 0 0 5px #0005;
    border-radius: 10px;
    min-height: 768px;
}
.RequestAccess-hader-top{
    display: flex;
    justify-content: space-between;
}
.RequestAccess-table{
    margin-top: 20px;
}
.RequestAccess-li{
    display: flex;
    align-items: center;
    margin-bottom: 20px;
}
.RequestAccess-li>label{
    width: 98px;
    text-align: right;
}
.RequestAccess-li .el-radio{
    margin-top: 4px;
}
.RequestAccess-btn{
    text-align: right;
}
.quill-btn{
    text-align: right;
}
.RAaddline {
    margin-top: 10px;
    text-align: center;
}


/*富文本样式*/
.quill-box{
    display: flex;
    align-items: baseline;
    margin-bottom: 22px;
}
.quill-box .ql-container{
    height: 86%;
}
.quill-title{
    font-size: 14px;
    color: #606266;
    width: 70px;
    text-align: right;
    padding: 0 12px 0 0;
}
.quill-box .editor {
    line-height: normal !important;
    height: 500px;
    width: 100%;
}
.quill-box .ql-snow .ql-tooltip[data-mode=link]::before {
content: "请输入链接地址:";
}
.quill-box .ql-snow .ql-tooltip.ql-editing a.ql-action::after {
    border-right: 0px;
    content: '保存';
    padding-right: 0px;
}

.quill-box .ql-snow .ql-tooltip[data-mode=video]::before {
    content: "请输入视频地址:";
}

.quill-box .ql-snow .ql-picker.ql-size .ql-picker-label::before,
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-item::before {
content: '14px';
}
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-label[data-value=small]::before,
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-item[data-value=small]::before {
content: '10px';
}
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-label[data-value=large]::before,
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-item[data-value=large]::before {
content: '18px';
}
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-label[data-value=huge]::before,
.quill-box .ql-snow .ql-picker.ql-size .ql-picker-item[data-value=huge]::before {
content: '32px';
}

.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item::before {
content: '文本';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {
content: '标题1';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {
content: '标题2';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before {
content: '标题3';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="4"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="4"]::before {
content: '标题4';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="5"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="5"]::before {
content: '标题5';
}
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="6"]::before,
.quill-box .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="6"]::before {
content: '标题6';
}

.quill-box .ql-snow .ql-picker.ql-font .ql-picker-label::before,
.quill-box .ql-snow .ql-picker.ql-font .ql-picker-item::before {
content: '标准字体';
}
.quill-box .ql-snow .ql-picker.ql-font .ql-picker-label[data-value=serif]::before,
.quill-box .ql-snow .ql-picker.ql-font .ql-picker-item[data-value=serif]::before {
content: '衬线字体';
}
.quill-box .ql-snow .ql-picker.ql-font .ql-picker-label[data-value=monospace]::before,
.quill-box .ql-snow .ql-picker.ql-font .ql-picker-item[data-value=monospace]::before {
content: '等宽字体';
}


/* 多文件上传样式 */
.attachment-section {
    border: 1px solid #EBEEF5;
    border-radius: 4px;
    padding: 15px;
    background-color: #FAFAFA;
}

.attachment-uploader {
    margin-bottom: 15px;
}

.upload-progress-list {
    margin: 10px 0;
    padding: 10px;
    background-color: #F5F7FA;
    border-radius: 4px;
}

.upload-progress-item {
    margin-bottom: 10px;
}

.upload-progress-item:last-child {
    margin-bottom: 0;
}

.progress-name {
    font-size: 12px;
    color: #606266;
    margin-bottom: 5px;
    display: block;
}

.email-attachment-list {
    max-height: 250px;
    overflow-y: auto;
    border-top: 1px solid #EBEEF5;
    padding-top: 10px;
}

.attachment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0 10px 0;
    font-size: 14px;
    font-weight: 600;
    color: #606266;
}

.attachment-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background-color: #FFFFFF;
    margin-bottom: 8px;
    border-radius: 4px;
    border: 1px solid #EBEEF5;
    transition: all 0.3s;
}

.attachment-item:hover {
    background-color: #F5F7FA;
    border-color: #409EFF;
}

.attachment-item i {
    margin-right: 8px;
    color: #409EFF;
}

.attachment-item .attachment-name {
    flex: 1;
    font-size: 14px;
    color: #606266;
    word-break: break-all;
}

.attachment-item .attachment-size {
    margin: 0 10px;
    font-size: 12px;
    color: #909399;
}

.attachment-item .el-button--text {
    margin: 0 5px;
    padding: 0;
}

.el-upload__tip {
    font-size: 12px;
    color: #909399;
    margin-top: 5px;
}
</style> 