import { downLoad2, getFileName } from "@/utils";
import { cron } from "@/views/workspace/components/common/mixins";
export const common = {
    mixins:[cron],
    props: ['form','projectId','tableHeight','review','productId','reportId'],
    data() {
        return {
            // statusObj: {
            //     0: '等待中',
            //     1: '进行中',
            //     2: '成功',
            //     3: '失败',
            //     4: '等待下一次执行',
            //     5: '已取消',
            //     6: '暂停',
            //     7: '待取消',
            //     8: '待暂停'
            //   },
            statusObj: {
                0: '等待中',
                1: '进行中',
                2: '已完成',
                4: '已暂停',
                5: '已取消',
            },
            taskType:{
                0: '普通任务',
                1: '定时任务',
            },
            taskType2:{
                1: 'Excel导入',
                2: '导出',
                // 3: '欧专局导入',
                4: '接口导入',
                5: '专利号导入',
            },
        }
    },
    watch:{
        projectId(val){
            this.queryParams.projectId = val
            this.getList()
        },
        reportId(val){
            this.queryParams.reportId = val
            this.getList()
        },
        review(val){
            if(val){
                this.getList()
            }
        }
    },
    mounted() {
        if(this.form == 1){
            this.queryParams.taskType2 = '1'
        }else if(this.form == 2){
            this.queryParams.taskType2 = '2'
        }
    },
    methods: {
        handleDownload(row) {
            downLoad2(row.url)
        },
         // 实时进度取消
        cancel(row) {
            let task = {
                taskId: row.id,
            // state:7,//7为待取消
            }
            this.$api.cancelTask(task).then(res => {
            if (res.code==200) {
                this.$message.success('任务已取消')
                if(this.taskData){
                    var index = this.taskData.findIndex(item=>{return item.id == row.id})
                    if(index!=-1){
                        this.taskData.splice(index,1)
                    }
                }else{
                    row.status = 5
                    this.getList()
                }
                // this.getList()
            }
            }).catch(error => {
            // this.$message.error(error.message)
            this.loadingCancel=false
            })
        },
    },
}