<template>
    <el-table v-loading="loading" ref="dataTableRef" highlight-current-row class="sample-table" v-load-more="tableScrollHandler" :data="dataList" style="width: 100%"
        @sort-change="sortHandler" :default-sort="{ prop: 'CreateTime', order: 'descending' }"
        @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="20" v-if="currentMenu==3||currentMenu==4"/>
            <el-table-column className="indentLeft">
                <template #header>
                    <div class="row items-center" @click="OffEdit()">
                        <span>文档名称</span>
                        <el-popover :width="200" trigger="click" @before-enter="()=>filterFileNameStatus=true" @before-leave="()=>filterFileNameStatus=false">
                            <template #reference>
                                <el-icon size="14px" class="q-ml-md cusor-pointer" :class="{'text-el-primary':queryObj.FileName}">
                                    <ArrowDown v-if="!filterFileNameStatus"/>
                                    <ArrowUp v-else/>
                                </el-icon>
                            </template>
                            <el-input v-model="queryObj.FileName" placeholder="请输入文档关键字" size="mini" class="full-width" />
                            <div class="q-mt-md text-right">
                                <el-button link class="q-mr-sm">
                                    <span class="text-bolder pingfangr" @click="setFilterNameHandler(0)">重置</span>
                                </el-button>
                                <el-button link type="primary">
                                    <span class="text-bolder pingfangr" @click="setFilterNameHandler(1)">确认</span>
                                </el-button>
                            </div>
                        </el-popover>
                    </div>
                </template>
                <template #default="scope">
                    <div class="row items-center full-width" style="padding-left: 12px;">
                        <div :class="{'share-icon-box':scope.row.IsShare}" style="display: inline-block;">
                            <img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1708337830000_43.png" height="25" v-if="scope.row.FileType==1" @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)"/>
                            <img src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1708250377000_777.png" height="25" v-else-if="scope.row.FileType==2" @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)"/>
                            <img src="@/assets/img/file.png" height="25" v-else @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)"/>
                        </div>
                        <div class="temp-tr col q-ml-md file-name" :class="{'cusor-pointer':scope.row.FileType==0}">
                            <el-tooltip v-if="!scope.row.editTitle" effect="dark" :content="scope.row.FileName">
                                <!-- <template v-if="scope.row.Highlight">
                                    <span class='text-waring' @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)">{{scope.row.FileName}}</span>
                                </template> -->
                                <div class="file-name" v-html="queryObj.FileName!=''?(scope.row.FileName.replaceAll(queryObj.FileName,`<span class='text-waring'>${queryObj.FileName}</span>`)):scope.row.FileName"
                                    @click.stop="scope.row.FileType>0?OffEdit():editDelete(scope.row,2)"></div>
                            </el-tooltip>
                            <el-input
                            class="journeyAds-Input"
                            v-model="scope.row.FileName"
                            autosize
                            type="textarea"
                            placeholder="请输入文档名称"
                            maxlength="500"
                            size="small"
                            v-if="scope.row.editTitle"
                            @blur="handleUpdateTitle(scope.row)"/>
                        </div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="" width="25" prop="">
                <template #default="scope">
                    <span class="q-pr-sm q-pt-xs pointer" v-if="scope.row.FileType&&datas.loggedder==scope.row.CreateName&&currentMenu!=-1"
                    >
                        <el-tooltip effect="dark" v-if="scope.row.UpdateStatus">
                            <template #content>
                                <span v-if="scope.row.UpdateStatus==1||scope.row.UpdateStatus==2" @click.stop="OffEdit()">
                                    {{scope.row.UpdateStatus==1?'同步中':scope.row.UpdateStatus==2?'同步成功':'同步失败'}}
                                </span>
                                <div v-if="scope.row.UpdateStatus==3" class="row flex-end">
                                    <el-button type="primary" icon="Refresh" size="small" 
                                    @click.stop="OffEdit(),SynchronousUpdate(scope.row)">更新</el-button>
                                </div>
                            </template>
                            <el-icon @click.stop="OffEdit()">
                                <Clock :class="[scope.row.UpdateStatus==1?'text-info':'']" v-if="scope.row.UpdateStatus==1" />
                                <CircleCheck :class="[scope.row.UpdateStatus==2?'text-el-primary':'']" v-if="scope.row.UpdateStatus==2" />
                                <CircleClose :class="[scope.row.UpdateStatus==3?'text-waring':'']" v-if="scope.row.UpdateStatus==3" />
                            </el-icon>
                        </el-tooltip>
                    </span>
                </template>
            </el-table-column>
            <el-table-column :label="datas.Title" width="150" sortable="custom" prop="CreateTime">
                <template #default="scope">
                    <span @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)">
                        {{ scope.row.FileType==0?'':formatDateTimeToRead(scope.row.UpdateTime&&scope.row.UpdateTime!=''?scope.row.UpdateTime:scope.row.CreateTime) }}
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="创建人" prop="" width="180" >
                <template #default="scope">
                    <span class="row items-center" @click.stop="scope.row.FileType?OffEdit():editDelete(scope.row,2)">
                        <span>{{scope.row.CreateName}}</span>
                        <span class="text-info q-pl-sm" v-if="datas.loggedder!=scope.row.CreateName"> 分享的</span>
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="120">
                <template #default="scope">
                    <div class="row items-center" :class="{'hover':showItemId!=scope.row.FileId}">
                        <el-button v-if="(datas.loggedder==scope.row.CreateName&&currentMenu!=-1)||scope.row.IsEdit" type="primary" :icon="Edit" size="small" @click.stop="editDelete(scope.row)">编辑</el-button>
                        <el-button v-if="currentMenu==-1" type="primary" icon="Position" size="small" @click.stop="recover(scope.row)">恢复</el-button>
                        <el-dropdown class="q-pl-md" trigger="click" @visible-change="(val:boolean)=>dropdownChange(val,scope.row.FileId)" 
                            v-if="(datas.loggedder==scope.row.CreateName&&(scope.row.FileType||currentMenu!=-1))||scope.row.IsDownload||scope.row.IsView">
                            <el-icon size="16" color="#b1b7cf"><MoreFilled /></el-icon>
                            <template #dropdown>
                                <el-dropdown-menu class="q-pa-md" @click.stop="OffEdit">
                                    <el-dropdown-item v-if="(datas.loggedder==scope.row.CreateName&&scope.row.FileType>0)||scope.row.IsView" icon="View" @click="viewTemplate(scope.row)">查看</el-dropdown-item>
                                    <template v-if="currentMenu!=-1&&datas.loggedder==scope.row.CreateName">
                                        <el-dropdown-item v-if="scope.row.FileType" icon="EditPen" @click.stop="startEditTitle(scope.row)">重命名</el-dropdown-item>
                                        <el-dropdown-item v-if="scope.row.FileType && (userInfo.iv || userInfo.it)" icon="Clock" @click.stop="history(scope.row)">历史版本</el-dropdown-item>
                                        <el-dropdown-item icon="Position" @click.stop="()=>setFileShareHandler(scope.row)" v-if="userInfo.it">分享</el-dropdown-item>
                                        <el-dropdown-item v-if="scope.row.IsShare  && userInfo.it" icon="Hide" @click.stop="removeShareHandler(scope.row)">取消分享</el-dropdown-item>
                                        <el-dropdown-item v-if="currentMenu==3||currentMenu==4" icon="Expand" @click.stop="MoveFile(scope.row)">移动至</el-dropdown-item>
                                        <el-dropdown-item v-if="scope.row.FileType && (userInfo.iv || userInfo.it)" @click.stop="CollectHandler(scope.row)">
                                            <span class="row items-center">
                                                <el-icon :color="scope.row.IsCollect?'#FCC525':'#65676B'" size="14">
                                                    <Star /></el-icon>
                                                    <span>{{scope.row.IsCollect?'取消收藏':'收藏'}}</span>
                                            </span>
                                        </el-dropdown-item>
                                        <el-dropdown-item icon="Delete" @click="editDelete(scope.row,1)">删除</el-dropdown-item>
                                    </template>
                                    <el-dropdown-item v-if="(datas.loggedder==scope.row.CreateName&&scope.row.FileType&&currentMenu!=-1)||scope.row.IsDownLoad" icon="Download" @click="exportDocument(scope.row)">导出PDF</el-dropdown-item>
                                    <el-dropdown-item v-if="(datas.loggedder==scope.row.CreateName&&scope.row.FileType&&currentMenu!=-1)||scope.row.IsDownLoad" icon="Download" @click="exportOnlineImage(scope.row)">导出IMG</el-dropdown-item>
                                    <el-dropdown-item v-if="(datas.loggedder==scope.row.CreateName&&scope.row.FileType&&currentMenu!=-1)||scope.row.IsView" icon="CopyDocument" @click.stop="CopyTo(scope.row)">复制到</el-dropdown-item>
                                    
                            </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                </template>
            </el-table-column>
            <template #empty>
                <el-empty :image-size="150" v-if="(!dataList || dataList.length==0) && !loading" 
                :description="datas.emptyTitle" />
            </template>
    </el-table>
    <ShareForm
    :id="shareId"
    :file-type="shareFileType"
    v-if="shareId > 0"
    @close="() => (shareId = 0,emit('refreshHandler'))"
  ></ShareForm>
  <Folder
    :folder-id="folderObj?.id"
    :folder-name="folderObj?.name"
    :parent-id="folderObj.parentId"
    :folder-type="folderObj?.type"
    v-if="folderObj.id > -1"
    @close="() => (folderObj.id = -1)"
    @success="emit('refreshHandler')"
  ></Folder>

  <HistoricalVersion
    :details="journeyAdsDetails"
    v-if="isHistoricalVersion"
    @close="() => {journeyAdsDetails = '';isHistoricalVersion=false}"
    @refreshHandler="emit('refreshHandler')"
  ></HistoricalVersion>

  <TreeFile v-if="isTreeFile" 
  :details="journeyAdsDetails"
  :file-type="journeyAdsDetails.FileType"
  :file-id="queryObj.FileId"
  @close="() => {journeyAdsDetails = '';isTreeFile=false}" 
  @success="() => {
    journeyAdsDetails = '';
    isTreeFile=false;
    emit('success')}"></TreeFile>
  
  <CopyFile v-if="isCopyTo" 
  :details="journeyAdsDetails"
  @close="() => {journeyAdsDetails = '';isCopyTo=false}"></CopyFile>

  <TreeFileRecover v-if="isTreeFileRecover" 
  :details="journeyAdsDetails"
  :file-type="queryObj.FileType"
  @close="() => {journeyAdsDetails = '';isTreeFileRecover=false}" 
  @success="() => {
    journeyAdsDetails = '';
    isTreeFileRecover=false;
    emit('success')}"></TreeFileRecover>

    <a ref="downloadLink" target="_blank" :href="fileUrl" style="display:none"></a>
</template>
<script setup lang="ts">
import { useUserStore } from '@/store/user';
import { storeToRefs } from 'pinia';
import { ApiResult } from '@/configs/axios';
import OrgService from '@/services/OrgService';
import { ref,reactive,watch,inject,nextTick, PropType } from 'vue';
import { Edit,View,Download,EditPen,Delete,Star,Clock,CircleCheck,CircleClose } from '@element-plus/icons-vue';
import { ElMessage,ElTree,ElLoading, ElMessageBox } from 'element-plus';

import ConfigService from "@/services/ConfigService";
import FolderService from "@/services/FolderService";
import { injectKeyTemplate } from "@/types/injectKey";
import { createPlayLink, createSaleEditorLink, formatDateTimeToRead } from "@/utils/common";
import { useSellTemplateStore, useScreenStore, useSlidesStore } from "@/store";
import { isPC, query } from '@/utils/common'

import ShareForm from "./ShareForm.vue";
import Folder from "./Folder.vue";
import HistoricalVersion from "./HistoricalVersion.vue";
import TreeFile from "./TreeFile.vue";
import TreeFileRecover from "./TreeFileRecover.vue";
import breadPeeling from "./breadPeeling.vue";
import CopyFile from "./CopyFile.vue";
import { useRouter } from 'vue-router';

    const props = defineProps({
        currentMenu:{
            type: Number,
            default: 3,
        },
        position:{
            type:Object as PropType<{FileId:number,FileType:1|2,Position:{FileId:number,FileName:string}[]}|null>,
            default:null
        },
        list:{
            type:Array,
            required:[]
        },
        msg:{
            type:Object,
            required:{}
        },
        setFileList:{
            type:Array,
            required:[]
        },
        navigations:{
            type:Array,
            required:[]
        },
    })
    const emit = defineEmits<{
        (event: 'close'): void,
        (event: 'success'): void,
        (event:'refreshHandler'): void,
        (event:'UpdateData'): void,
    }>()
    const folderObj = ref<{
        id: number;
        name: string;
        parentId: number;
        type: number;
    }>({ id: -1, name: "", parentId: 0, number: 1 });
    const datas = reactive({
        loggedder: '',
        emptyTitle: '',
        Title: '',
        selectAll: false as any,
        journeyAds: { RefreshLoading: false } as any,
        fileList: [] as any,
        setFileList: [] as any,
        pdfImg:
            "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1708337830000_43.png",
        adsImg:
            "https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1708250377000_777.png",
    });
    const SalesEditorStore = useSellTemplateStore();
    const marketStore = useScreenStore();
    const { userInfo } = storeToRefs(useUserStore())
    datas.loggedder = userInfo.value.nickname
    const router = useRouter()
    const dataList = ref([] as Array<any>);
    dataList.value = props.list
    const queryObj = ref({} as any);
    queryObj.value = props.msg
    const loading = ref(false) as Boolean

    const shareId = ref(0);
    const shareFileType = ref(0)
    const journeyAdsDetails = ref('');
    const isHistoricalVersion = ref(false);
    const isCopyTo = ref(false);
    const isIndeterminate = ref(false);
    const isTreeFile = ref(false)
    const isTreeFileRecover = ref(false)
    const Navigations = ref([] as Array<any>);
    const searchData = ref({} as any);
    searchData.value = inject(injectKeyTemplate);
    const deleteLoading = ref<any>(null);
    const removeShareLoading = ref<any>(null);
    const editObj = reactive({});
    const filterFileNameStatus = ref(false)
    const showItemId = ref(0)
    const dataTableRef = ref()
    if(props.currentMenu==0){
        datas.Title = '最近浏览'
        datas.emptyTitle = '没有最近浏览文档'
    } 
    else if(props.currentMenu==1) {
        datas.Title = '收藏时间'
        datas.emptyTitle = '没有收藏文档'
    }
    else if(props.currentMenu==3||props.currentMenu==4) {
        datas.Title = '最近修改'
        if(queryObj.value.FileId){
            datas.emptyTitle = '没有文档'
        }else datas.emptyTitle = '文件夹里没有文档'
    }
    else if(props.currentMenu==-1) {
        datas.Title = '删除时间'
        datas.emptyTitle = '没有删除文档'
    }
    const downloadLink= ref()
    const fileUrl = ref("")

    // 导出img
    const exportOnlineImage=(row: any)=>{
        let rangeArray:number[] = []
        rangeArray.push(0)
        fileUrl.value =  `https://fileservice.oytour.com/api/img/${row.FileId}/${rangeArray.join(',')}/png/1/${row.HashInfo}`
        nextTick(()=>{
            downloadLink.value.click()
        })
    }

    const SynchronousUpdate = async (row: any) => {
        ElMessageBox.confirm(`此操作将更新行程${row.FileName}，是否确定?`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
        })
            .then(async () => {
                try {
                    let queryMsg = {
                        FileId: row.FileId,
                    };
                    deleteLoading.value = ElLoading.service({
                        lock: true,
                        text: "正在处理",
                    });
                    let pageRes = await ConfigService.CreateTripFile(queryMsg);
                    if (pageRes.data.resultCode == ApiResult.SUCCESS) {
                        ElMessage({
                            showClose: true,
                            message: `更新操作成功`,
                            type: "success",
                        });
                        emit('refreshHandler');
                    } else {
                        ElMessage({
                            showClose: true,
                            message: `更新操作失败`,
                            type: "warning",
                        });
                    }
                    deleteLoading.value.close();
                    deleteLoading.value = null;
                } catch (error) {}
            })
            .catch(() => {});
        
    }

    const exportDocument = (item:any) => {
        let url = `https://fileservice.oytour.com/api/img/${item.FileId}/1/png/1/${item.HashInfo}`
        if(item.FileType==1) url = `https://fileservice.oytour.com/api/pdf/${item.FileId}/${item.HashInfo}`
        window.open(url);
    }
    const viewTemplate = (row:any) => {
        let param = query()
        const url = createPlayLink(row.FileId,0,props.currentMenu==-1?1:2)//`${location.origin}?uid=${param.uid}&sellId=${row.FileId}&ViewSlideshow=${props.currentMenu==-1?1:2}`
        window.open(url);
    }
    const handleSelectionChange = (val: []) =>{
        let obj = {
            selectedDatas: val.map(x=>{return x.FileId}),
        }
        emit('UpdateData',obj)
    }
    const dropdownChange = (val:boolean,id:number) => {
        showItemId.value = val?id:0
    }
    const setFilterNameHandler = (t:0|1)=>{
        filterFileNameStatus.value = false
        if(!t) queryObj.value.FileName=''
        let obj = {
            FileName: queryObj.value.FileName
        }
        emit('refreshHandler',obj)
    }
    const sortHandler = (val:any)=>{
        queryObj.value.OrderByType = val.order=='descending'?2:1
        let obj = {
            OrderByType: queryObj.value.OrderByType
        }
        emit('refreshHandler',obj)
    }
    // 恢复文件
    const recover = async (row:any) => {
        journeyAdsDetails.value = row
        isTreeFileRecover.value = true
        return
        // try {
        //     let queryMsg = {
        //         Ids: row.FileId
        //     }
        //     deleteLoading.value = ElLoading.service({
        //         lock: true,
        //         text: "正在处理",
        //     });
        //     let dataRes = await FolderService.UpdateTripOtherStatus(queryMsg);
        //     deleteLoading.value.close();
        //     deleteLoading.value = null;
        //     if (dataRes.data.resultCode == ApiResult.SUCCESS) {
        //         ElMessage({
        //             showClose: true,
        //             message: `恢复${row.FileName}成功`,
        //             type: "success",
        //         });
        //         emit('refreshHandler')
        //     }else{
        //         ElMessage({
        //             showClose: true,
        //             message: `恢复${row.FileName}失败`,
        //             type: "warning",
        //         });
        //     }
        // } catch (error) {}
        
    }
    // 收藏文件
    const CollectHandler = async (row:any) => {
        try {
            let queryMsg = {
                FileId: row.FileId,
                FileType: row.FileType,
                IsCollect: row.IsCollect?0:1,
            }
            deleteLoading.value = ElLoading.service({
                lock: true,
                text: "正在处理",
            });
            let dataRes = await FolderService.SetFileCollect(queryMsg);
            deleteLoading.value.close();
            deleteLoading.value = null;
            if (dataRes.data.resultCode == ApiResult.SUCCESS) {
                ElMessage({
                    showClose: true,
                    message: `${queryMsg.IsCollect?'收藏':'取消收藏'}${row.FileName}成功`,
                    type: "success",
                });
                emit('refreshHandler')
            }else{
                ElMessage({
                    showClose: true,
                    message: `收藏${row.FileName}失败`,
                    type: "warning",
                });
            }
        } catch (error) {}
        
    }
    // 复制文件
    const CopyTo = (row:any) => {
        isCopyTo.value = true
        journeyAdsDetails.value = row
    }
    // 移动到文件夹
    const MoveFile = (item:any) => {
        journeyAdsDetails.value = item
        isTreeFile.value = true
    }
    
    // 历史版本
    const history = (row: any) => {
        journeyAdsDetails.value = row;
        isHistoricalVersion.value = true
    };
    // 重命名
    const OffEdit = () => {
        for (let i = 0; i < dataList.value.length; i++) {
            dataList.value[i].editTitle = false;
            if (
                editObj.value &&
                editObj.value.FileId &&
                dataList.value[i].FileId == editObj.value.FileId
            ) {
             dataList.value[i].FileName = editObj.value.FileName;
            }
        }
    };
    const handleUpdateTitle = async (row: any) => {
        if (!row.FileName) row.FileName = editObj.value.FileName;
        row.editTitle = false;
        if (row.FileName != editObj.value.FileName) {
            editObj.value.FileName = row.FileName;
            try {
            let queryMsg = {
                FileId: row.FileId,
                Title: editObj.value.FileName,
            };
            let TemplateRes = await ConfigService.ReNameTripOther(queryMsg);
            if (TemplateRes.data.resultCode == ApiResult.SUCCESS) {
                ElMessage({
                    showClose: true,
                    message: "重命名成功",
                    type: "success",
                });
            } else {
                ElMessage({
                    showClose: true,
                    message: "重命名失败",
                    type: "warning",
                });
            }
            } catch (error) {}
        }
    };
    const startEditTitle = (row: any) => {
        row.editTitle = true;
        editObj.value = JSON.parse(JSON.stringify(row));
    };
    const removeShareHandler= async (item:any) =>{
        if(removeShareLoading.value) return
        removeShareLoading.value=ElLoading.service({
            lock: true,
            text: "正在处理",
        })
        let errmsg=''
        try {
            let response = await ConfigService.RemoveFileShareAsync([item.FileId])
            if(response.data.resultCode==ApiResult.SUCCESS){
                ElMessage.success({
                    message:'设置成功'
                })
                item.IsShare=false
            } else errmsg='取消分享失败，请刷新重试'
        } catch (error) {
            errmsg = '取消分享失败，请刷新重试'
        }
        if(errmsg!='') {
            ElMessage.error({
                message:errmsg
            })
        }
        removeShareLoading.value.close();
        removeShareLoading.value = null;
    }

    const DeleteFile = async (item: any) => {
        ElMessageBox.confirm("此操作将删除该文件夹及其下的文件，是否确定?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
        })
            .then(async () => {
            try {
                let queryMsg = {
                    FolderId: item.FileId,
                };
                deleteLoading.value = ElLoading.service({
                    lock: true,
                    text: "正在处理",
                });
                let pageRes = await FolderService.RemoveTripFolder(queryMsg);
                if (pageRes.data.resultCode == ApiResult.SUCCESS) {
                    ElMessage({
                        showClose: true,
                        message: `删除${
                            queryObj.value.FileType == 2 ? "广告" : "行程"
                        }文件夹成功`,
                        type: "success",
                    });
                    emit('refreshHandler');
                } else {
                    ElMessage({
                        showClose: true,
                        message: `删除${
                            queryObj.value.FileType == 2 ? "广告" : "行程"
                        }文件夹失败`,
                        type: "warning",
                    });
                }
                deleteLoading.value.close();
                deleteLoading.value = null;
            } catch (error) {}
            })
            .catch(() => {});
        };

    const DeleteTemplate = async (item: any) => {
            ElMessageBox.confirm("此操作将删除该模版，是否确定?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(async () => {
                    try {
                        let queryMsg = {
                            Id: item.FileId,
                        };
                        deleteLoading.value = ElLoading.service({
                            lock: true,
                            text: "正在处理",
                        });
                        let pageRes = await ConfigService.sellSetRemoveTemplate(queryMsg);
                        if (pageRes.data.resultCode == ApiResult.SUCCESS) {
                            ElMessage({
                                showClose: true,
                                message: `删除${item.FileType == 2 ? "广告" : "行程"}成功`,
                                type: "success",
                            });
                            emit('refreshHandler');
                        } else {
                            ElMessage({
                                showClose: true,
                                message: `删除${item.FileType == 2 ? "广告" : "行程"}失败`,
                                type: "warning",
                            });
                        }
                    deleteLoading.value.close();
                    deleteLoading.value = null;
                } catch (error) {}
            })
            .catch(() => {});
        };
    const editDelete = async (row: any, type: Number) => {
            if (type == 1) {
                if (row.FileType) DeleteTemplate(row);
                else DeleteFile(row);
            } else {
                if (row.FileType) {
                    const cp =userInfo.value.nickname!=row.CreateName&&row.IsView==0?0:1
                    const ep =userInfo.value.nickname!=row.CreateName&&row.IsDownLoad==0?0:1
                    //@TODO:返回字段中缺少CreateBy,
                    const url = createSaleEditorLink(row.FileId,row.TempId,row.FileType,row.ParentFileId,ep,cp)
                    router.push({
                        path:url
                    })
                } else {
                    // 2文件夹详情
                    if (type == 2) {
                        Navigations.value.push(
                            {
                                FileId: row.FileId,
                                FileName: row.FileName,
                                ParentFileId: row.ParentFileId
                            }
                        );
                        let obj = {
                            FileId: row.FileId,
                            Navigations: Navigations.value
                        }
                        emit('refreshHandler',obj);
                    } else {
                        folderObj.value.id = row.FileId;
                        folderObj.value.name = row.FileName;
                        folderObj.value.type = row.FileType;
                    }
                }
            }
        };
    
    const operaFolder = (id: number, name: string) => {
        folderObj.value.id = id;
        folderObj.value.name = name;
        folderObj.value.type = queryObj.value.FileType;
    };

    const setFileShareHandler=(item:any)=>{
        shareFileType.value=item.FileType
        shareId.value =item.FileId
    }
    const tableScrollHandler = ()=>{
        if(queryObj.value.pageCount>queryObj.value.pageIndex){
            queryObj.value.pageIndex++
            let obj = {
                pageIndex: queryObj.value.pageIndex
            }
            emit('refreshHandler',obj)
        }
    }
    const setCurrentRow = ()=>{
        setTimeout(()=>{
            let tempRow = dataList.value.find(x=>x.Highlight)
            if(tempRow){
                dataTableRef.value.setCurrentRow(tempRow)
            }
        },500)
    }
    loading.value = true
    setTimeout(()=>{
        loading.value = false 
    },300)
    watch(() => props.list, (n,o) => {
        loading.value = true
        if (props.list) {
            nextTick(() => {
                dataList.value = props.list
                setCurrentRow()
            })
        }
        setTimeout(()=>{
            loading.value = false 
        },300)
    })

    watch(() => props.navigations, (n,o) => {
        Navigations.value = n
    })

    setCurrentRow()
</script>
<style lang="scss">
    .sample-table .el-table .el-table__cell{
        padding: 0;
    }
     .journeyAds-Input {
        padding-right: 20px;
        position: relative;
        margin-bottom: 2px;
        ::v-deep(.el-textarea__inner) {
        padding: 5px;
        background: #f5f5f5;
        }
    }
    .el-table{
        height: 100% !important;
    }
    
    .sample-table{
        font-size: 12px !important;
        font-family: microsoft yahei !important;
        
    }
    .sample-table::v-deep(.el-table--fit){
        height: 100%;
    }
    .sample-table .el-table-column--selection{
        border: none !important;
    }
    .sample-table .el-table-column--selection .cell{
        padding: 0 !important;
        padding-right: 5px !important;
        padding-left: 5px !important;
    }
    .sample-table th .cell{
        font-weight: normal !important;
    }
    .sample-table td, .sample-table th {
        border-bottom: 1px solid #f6f6f6 !important;
    }
    .sample-table td{
        /* color:#000; */
    }
    .sample-table tr td .el-checkbox,
    .sample-table tr td .hover{
        visibility: hidden !important;
    }
    .sample-table tr:hover td .el-checkbox,
    .sample-table tr td .is-checked,
    .sample-table tr:hover td .hover{
        visibility: visible !important;
    }
    .sample-table .indentLeft{
        border:none !important;
        padding: 0 !important;
    }
    .sample-table .indentLeft .cell{
        padding: 0 !important;
    }
    .sample-table .temp-tr,
    .sample-table th.indentLeft{
        border-bottom: 1px solid #f6f6f6 !important;
        padding: 8px 0 !important;
    }
    .sample-table th.indentLeft .cell{
        padding: 0 12px !important;
    }
    .sample-table .file-name{
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
        width: 0;
    }
    
    /* .sample-table th:nth-child(2) .cell{
        padding-left: 0 !important;
    } */
    .share-icon-box{
        position: relative;
    }
    .share-icon-box::after{
        display: block;
        position: absolute;
        bottom: -4px;
        right: 0px;
        content: " ";
        background: url('@/assets/img/share.png');
        width: 14px;
        height: 14px;
        z-index: 2;
    }
</style>