
<script lang="ts">
import { Component  } from 'vue-property-decorator';
import template from "./common.component.html"
import BaseRecordComponent from "hbt-common/components/common/baseRecord.component.vue"
import FormComponent from "hbt-common/components/common/form.component.vue"
import TableComponent from "hbt-common/components/common/table.component.vue"
import WorkFlowService from "@/service/workFlow.service"
import FormOption from "hbt-common/models/formOptions"
import BtnOption from "hbt-common/models/btnOptions"
import MapComponent from "@/components/map.component.vue"
import ManagerService from '@/service/manager.service';
import mapboxgl from "mapbox-gl";
import moment from 'moment';
@Component({
    template,
    components:{
        FormComponent,
        TableComponent,
        MapComponent
    },
} as any)
export default class HiddenDangerManagerComponent extends BaseRecordComponent<any> {
    public tableService = new ManagerService();
    public workFlowService = new WorkFlowService()
    // 是否显示删改查按钮
    public isBase = true;
    // 显示治理列表按钮
    public isManager = true;

    public tableActionWidth="370";

    public isReadonly = false;
    public account = JSON.parse(localStorage.getItem("account") as string);

    public params = {
        type:1
    } as any;

    public formActions = [{
        name:"查询",
        value:"search",
        icon:"el-icon-search",
        type:"primary"
    },{
        name:"清空",
        icon:"el-icon-tickets",
        value:"reset"
    }];
    public tableActions = [] as any;
    public footerActions = [] as any;

    public isSure = [{
        name:"确认",
        value:1
    },{
        name:"未确认",
        value:0
    }]
    public isSureMap = ["未确认","确认"];

    public isPass = [{
        name:"通过",
        value:1
    },{
        name:"不通过",
        value:0
    }]
    public isPassMap = ["不通过","通过"];

    public isAccept = [{
        name:"接受",
        value:1
    },{
        name:"不接受",
        value:0
    }]
    public isAcceptMap = ["不接受","接受"];
    public formOptions:FormOption<BtnOption>[] = [];

    public showUpdate = false;
    public currentId = -1;
    public updateParams = {}  as any;
    public updateOptions:FormOption<BtnOption>[] = [];
    public updateOptions2:FormOption<BtnOption>[] = [];
    public updateOptions3:FormOption<BtnOption>[] = [];
    public updateOptions4:FormOption<BtnOption>[] = [];

    public fileList = [] as any;
    public photoList = [] as any;

    public fileList2 = [] as any;
    public photoList2 = [] as any;
    public showFile = false;
    public currentUrl = null;
    public center = [118.751353,31.969568];
    public marker:any = null;
    public map:any = null;
    public showMap = false;

    public statusMap = {0:"草稿",1:"上报",2:"隐患确认",3:"隐患治理",4:"隐患验收",5:"已闭环",6:"流程中断",7:"已作废"};
    public tabs = [{
        name:"草稿",
        value:1
    },{
        name:"待办",
        value:2
    },{
        name:"已办",
        value:3
    },{
        name:"我发起的",
        value:4
    },{name:"作废",value:5}]


    public updateActions = [] as any;

    public selectData = [];

    public levelMap = ["","一般隐患","重大隐患"]
    public reformModeMap = ["","即查即改","限期整改"];
    public executeResultMap = ["","完成","降低标准完成","未完成","延期完成","延期未完成"];
    public executeResultList= [{
        name:"完成",
        value:1
    },{
        name:"降低标准完成",
        value:2
    },{
        name:"未完成",
        value:3
    },{
        name:"延期完成",
        value:4,
    },{
        name:"延期未完成",
        value:5
    }];
    

    created(){

    }
    public tabTableChange(){
        this.params.pageNum=1;
        this.getTableData()
    }
    

    public getTableCallback(){
        this.tableActions = [{
            name:"添加",
            value:"add",
            icon:"el-icon-plus",
            type:"primary"
        },{
            name:"批量删除",
            value:"delete",
            plain:true,
            hide:this.params.type!==1,
            icon:"el-icon-delete",
            type:"danger"
        }] as any
        this.footerActions = [{
            name:"选择全部",
            value:"selectAll",
            hide:this.params.type!==1,
            type:"primary"
        },{
            name:"反向选择",
            hide:this.params.type!==1,
            value:"reverse"
        }];
        this.updateActions = [{
            name:"取消",
            value:"cancel"
        },{
            name:"保存",
            value:"draft",
            hide:this.updateParams.status>1,
            type:"primary"
        },{
            name:"提交",
            value:"submit",
            type:"primary"
        }];
        this.formOptions = [{
            name:"隐患等级",
            key:"level",
            type:"select",
            datas:[{
                name:"一般隐患",
                value:1
            },{
                name:"重大隐患",
                value:2
            }]
        },{
            name:"隐患分类",
            key:"classify",
            type:"select",
            datas:this.$store.state.prevention_dangrous_type
        },{
            name:"整改方式",
            key:"reformMode",
            type:"select",
            datas:[{
                name:"即查即改",
                value:1
            },{
                name:"限期整改",
                value:2
            }]
        }];

        this.updateOptions = [{
            name:"隐患编号",
            key:"number",
            disable:true,
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            type:"text"
        },{
            name:"隐患来源",
            key:"source",
            format:"sourceName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.prevention_danger_resource
        },{
            name:"隐患标题",
            key:"title",
            width:"100%",
            require:true,
            showError:false,
            type:"text"
        },{
            name:"隐患描述",
            width:"100%",
            key:"description",
            require:true,
            showError:false,
            type:"text"
        },{
            name:"隐患级别",
            key:"level",
            format:"levelName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:[{
                name:"一般隐患",
                value:1
            },{
                name:"重大隐患",
                value:2
            }]
        },{
            name:"整改方式",
            key:"reformMode",
            format:"reformModeName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:[{
                name:"即查即改",
                value:1
            },{
                name:"限期整改",
                value:2
            }]
        },{
            name:"隐患位置",
            key:"locationName",
            type:"text",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            unit:{
                type:"btn",
                name:(this.updateParams.status>1 || this.isReadonly)?"查看定位":"点击定位",
                value:"fixed",
                btnType:"primary"
            }
        },{
            name:"隐患分类",
            key:"classify",
            format:"classifyName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.prevention_dangrous_type
        },{
            name:"整改部门",
            key:"reformDeptId",
            format:"reformDeptName",
            type:"treeSelect",
            width:"calc(50% - 20px)",
            require:true,
            expandLevel:Infinity,
            showError:false,
            datas:this.$store.state.deptTreeList
        },{
            name:"整改责任人",
            key:"reformUserId",
            format:"reformUserName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.userList,
        },{
            name:"验证人",
            key:"verifyUserId",
            format:"verifyUserName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.userList,
        },{
            name:"整改时限",
            key:"reformDeadline",
            type:"date",
            subType:"datetime",
            format:"yyyy-MM-dd HH",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
        },{
            name:"隐患照片",
            key:"photo",
            ref:"photo",
            type:"upload",
            width:"calc(50% - 20px)",
            require:true,
            onSucess:this.onSuccess,
            onMove:this.onRemove,
            showError:false,
            autoUpload:true,
            onPreview:this.onPreview,
            accept:"image/png, image/jpeg",
            listType:"picture-card",
            fileList:this.photoList,
            icon:"el-icon-plus",
        },{
            name:"相关附件",
            key:"file",
            ref:"file",
            type:"upload",
            width:"calc(50% - 20px)",
            showError:false,
            onSucess:this.onSuccess2,
            onMove:this.onRemove2,
            onPreview:this.onPreview,
            autoUpload:true,
            accept:"image/png, image/jpeg,.doc,.docx,.xls,.xlsx,.pdf",
            listType:"text",
            tip:this.isReadonly?"":"请上传.pdf,.png,.jpg,.doc.docx,.xls,.xlsx格式文件",
            fileList:this.fileList,
            btn:[{
              name:"上传",
              value:"upload",
              hide:this.isReadonly,
              size:"small",
              type:"primary"
            }]
        },{
            name:"隐患类别",
            key:"dangerType",
            format:"dangerTypeName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.prevention_danger_type,
        },{
            name:"检查类型",
            key:"inspectType",
            format:"inspectTypeName",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            showError:false,
            datas:this.$store.state.prevention_danger_check_type,
        },{
            name:"违章人数",
            key:"violateNumber",
            type:"number",
            width:"calc(50% - 20px)",
            showError:false,
        },{
            name:"专业分类",
            key:"professionClassify",
            format:"professionClassifyName",
            type:"select",
            width:"calc(50% - 20px)",
            showError:false,
            datas:this.$store.state.prevention_major_type,
        },{
            name:"属性分类",
            key:"attributeClassify",
            format:"attributeClassifyName",
            type:"select",
            width:"calc(50% - 20px)",
            showError:false,
            datas:this.$store.state.prevention_safe_reason,
        },{
            name:"发生环节",
            key:"occurNode",
            format:"occurNodeName",
            type:"select",
            width:"calc(50% - 20px)",
            showError:false,
            datas:this.$store.state.prevention_occur_step,
        },{
            name:"违反规定条款",
            key:"violateTerm",
            type:"textarea",
            width:"100%",
            showError:false,
        },{
            name:"隐患整改要求",
            key:"reformDemand",
            type:"textarea",
            width:"100%",
            showError:false,
        }]

        this.updateOptions2 = [{
            name:"隐患确认",
            key:"reformConfirmFlag",
            format:"reformConfirmFlagName",
            type:"radio",
            width:"100%",
            require:true,
            showError:false,
            datas:this.isSure
        },{
            name:"原因说明",
            type:"textarea",
            width:"100%",
            key:"reformReasonDescription",
            require:true,
            hide:this.updateParams.reformConfirmFlag,
            showError:false,
            placeholder:"请输入未确认原因"
        },{
            name:"治理人",
            type:"select",
            width:"calc(50% - 20px)",
            require:true,
            key:"executeUserId",
            format:"executeUserName",
            showError:false,
            hide:this.updateParams.reformConfirmFlag===0,
            datas:this.$store.state.userList
        },{
            name:"治理时限",
            type:"date",
            subType:"datetime",
            width:"calc(50% - 20px)",
            require:true,
            key:"executeDeadline",
            format:"yyyy-MM-dd HH:mm",
            showError:false,
            hide:this.updateParams.reformConfirmFlag===0,
        },{
            name:"治理措施及要求",
            type:"textarea",
            width:"100%",
            key:"executeMeasure",
            require:true,
            hide:this.updateParams.reformConfirmFlag===0,
            showError:false,
            placeholder:"请输入治理措施与要求"
        },{
            name:"治理资金",
            type:"number",
            width:"35%",
            key:"executeMoney",
            require:true,
            hide:this.updateParams.reformConfirmFlag===0,
            showError:false,
            unit:{
                name:"¥",
                type:"text"
            }
        },{
            name:"",
            type:"textarea",
            width:"calc(65% - 40px)",
            key:"executeMoneySource",
            hide:this.updateParams.reformConfirmFlag===0,
            placeholder:"请输入资金来源"
        },{
            name:"确认人",
            type:"text",
            width:"calc(50% - 20px)",
            key:"realConfirmUserName",
            require:true,
            disable:true,
        },{
            name:"确认时间",
            type:"date",
            subType:"datetime",
            width:"calc(50% - 20px)",
            require:true,
            key:"realConfirmTime",
            format:"yyyy-MM-dd HH:mm",
            showError:false,
        }]
        this.updateOptions3 = [{
            name:"接受确认",
            key:"executeConfirmFlag",
            format:"executeConfirmFlagName",
            type:"radio",
            width:"100%",
            require:true,
            showError:false,
            datas:this.isAccept
        },{
            name:"整改结果",
            key:"executeResult",
            format:"executeResultName",
            type:"radio",
            hide:this.updateParams.executeConfirmFlag===0,
            width:"100%",
            require:true,
            showError:false,
            datas:this.executeResultList
        },{
            name:"治理情况汇报",
            type:"textarea",
            width:"100%",
            key:"executeSituation",
            require:true,
            hide:this.updateParams.executeConfirmFlag===0,
            showError:false,
            placeholder:"请输入治理措施与要求"
        },{
            name:"原因说明",
            type:"textarea",
            width:"100%",
            key:"executeReasonDescription",
            require:true,
            hide:this.updateParams.executeConfirmFlag,
            showError:false,
            placeholder:"请输入未确认原因"
        },{
            name:"照片及相关附件",
            key:"file2",
            type:"upload",
            hide:this.updateParams.executeConfirmFlag===0,
            width:"100%",
            showError:false,
            onSucess:this.onSuccess3,
            onMove:this.onRemove3,
            onPreview:this.onPreview,
            autoUpload:true,
            accept:"image/png, image/jpeg,.doc,.docx,.xls,.xlsx,.pdf",
            listType:"text",
            tip:this.isReadonly?"":"请上传.pdf,.png,.jpg,.doc.docx,.xls,.xlsx格式文件",
            fileList:this.fileList2,
            btn:[{
              name:"点击上传附件",
              value:"upload",
              hide:this.isReadonly,
              size:"small",
              type:"primary"
            }]
        },{
            name:"整改人",
            type:"text",
            width:"calc(50% - 20px)",
            key:"realExecuteUserName",
            require:true,
            disable:true,
        },{
            name:"整改时间",
            type:"date",
            subType:"datetime",
            width:"calc(50% - 20px)",
            require:true,
            key:"realExecuteTime",
            format:"yyyy-MM-dd HH:mm",
            showError:false,
        }]
        this.updateOptions4 = [{
            name:"验证结果",
            key:"verifyConfirmFlag",
            format:"verifyConfirmFlagName",
            type:"radio",
            width:"100%",
            require:true,
            showError:false,
            datas:this.isPass
        },{
            name:"验证情况",
            type:"textarea",
            width:"100%",
            key:"verifySituation",
            placeholder:"请输入验证情况"
        },{
            name:"照片",
            key:"photo2",
            type:"upload",
            width:"100%",
            onSucess:this.onSuccess4,
            onMove:this.onRemove4,
            autoUpload:true,
            onPreview:this.onPreview,
            accept:"image/png, image/jpeg",
            listType:"picture-card",
            fileList:this.photoList2,
            icon:"el-icon-plus",
        },{
            name:"验证人",
            type:"text",
            width:"calc(50% - 20px)",
            key:"realVerifyUserName",
            require:true,
            disable:true,
        },{
            name:"验证时间",
            type:"date",
            subType:"datetime",
            width:"calc(50% - 20px)",
            require:true,
            key:"realVerifyTime",
            format:"yyyy-MM-dd HH:mm",
            showError:false,
        }]
    }

    public buildTable(){
        this.tableColumn.push({name:'状态',render:(data)=>this.statusMap[data.status]});
        this.tableColumn.push({name:'当前执行人',width:"100",key:"executor"});
        this.tableColumn.push({name:'最新提交时间',width:"180",key:"updateTime"});
        this.tableColumn.push({name:'隐患来源',width:"150",render:(data)=>this.$store.getters.prevention_danger_resource_map[data.source]});
        this.tableColumn.push({name:'隐患标题',width:"150",render:(data)=>{
            if(this.params.type===2){
                return `<span class="link">${data.title}</span>`
            }else{
                return data.title
            }
        }});
        this.tableColumn.push({name:'隐患描述',key:"description"});
        this.tableColumn.push({name:'隐患等级',render:(data)=>this.levelMap[data.level]});
        this.tableColumn.push({name:'隐患分类',render:(data)=>this.$store.getters.prevention_dangrous_type_map[data.dangerType]});
        this.tableColumn.push({name:'整改方式',render:(data)=>this.reformModeMap[data.reformMode]});
        this.tableColumn.push({name:'隐患位置',width:"150",key:"locationName"});
        this.tableColumn.push({name:'治理责任人',width:"100",key:"executeUserName"});
        this.tableColumn.push({name:'整改结果',render:(data)=>this.executeResultMap[data.executeResult]});
        this.tableColumn.push({name:'整改时限',width:"100",key:"reformDeadline"});
    }

    public rowCallback(el,data){
        const isTarget = el.target.classList.contains("link");
        if(isTarget){
            if(data.status===2){
                data = Object.assign({
                    realConfirmUserId:this.account.userId,
                    realConfirmUserName:this.account.nickName,
                    realConfirmTime:moment().format("YYYY-MM-DD HH:mm")
                },data)
            }
            if(data.status===3){
                data = Object.assign({
                    realExecuteUserId:this.account.userId,
                    realExecuteUserName:this.account.nickName,
                    realExecuteTime:moment().format("YYYY-MM-DD HH:mm")
                },data)
            }
            if(data.status===4){
                data = Object.assign({
                    realVerifyUserId:this.account.userId,
                    realVerifyUserName:this.account.nickName,
                    realVerifyTime:moment().format("YYYY-MM-DD HH:mm")
                },data)
            }
            this.showUpdateModel(data)
        }

    }

    public changeStatus(data,newStatus){
        this.$confirm("确认要"+(newStatus>60?"中断数据？":newStatus===7?"作废数据？":"恢复数据"),"操作确认",{
            type: 'warning'
        }).then(()=>{
            data.status = newStatus;
            this.tableService.addOrUpdate(data,false).then(res=>{
                this.$message.success(newStatus>60?"中断成功":"作废成功");
                this.getTableData()
            })
        })

    }

    public change(data,item){
        this.$forceUpdate()
        if(item && (item.key === "reformConfirmFlag" || item.key==="executeConfirmFlag")){
            this.getTableCallback()
            return
        }
        if(item && item.key === "inspectUserId"){
            this.updateParams.inspectUserName = this.$store.getters.user_map[data]
            return
        }
        if(item && item.key === "executeUserId"){
            this.updateParams.executeUserName = this.$store.getters.user_map[data]
            return
        }
        if(item && item.key === "reformDeptId"){
            this.updateParams.reformDeptName = this.$store.getters.dept_map[data]
            return
        }
        if(item && item.key === "reformUserId"){
            this.updateParams.reformUserName = this.$store.getters.user_map[data]
            return
        }
        if(item && item.key === "verifyUserId"){
            this.updateParams.verifyUserName = this.$store.getters.user_map[data]
            return
        }
        //
    }

    public callback(data){
        // 查询
        if(data.value==="search"){
            this.getTableData()
        // 重置
        }else if(data.value === "reset"){
            this.reset()
        // 反选
        }else if(data.value === "reverse"){
            this.toggleAll()
        // 全选
        }else if(data.value === "selectAll"){
            this.selectAll()
        }else if(data.value === "add"){
            this.showUpdateModel()
        }else if(data.value === "delete"){
            this.deleteData(this.selectData.map((item:any)=>item.id))
        }else if(data.value ==="fixed"){
            this.showMap = true

        }else if(data.value ==="draft" || data.value==="submit"){
           this.doSave(data.value==="submit");

        }
    }
    // 重置数据
    public reset(){
        this.params = {
            pageNum:1,
            pageSize:20,
        } as any;
    }



    public showUpdateModel(row?,isRead?){
        this.isReadonly = !!isRead
        this.updateParams = {status:0} as any;
        if(!row){
            this.tableService.getNumber().then(res=>{
                this.updateParams.number = res.data
                this.getTableCallback();
                this.showUpdate = true
            })
        }else{
            this.updateParams = Object.assign({
                    verifyConfirmFlagName:this.isPassMap[row.verifyConfirmFlag],
                    executeConfirmFlagName:this.isAcceptMap[row.executeConfirmFlag],
                    reformConfirmFlagName:this.isSureMap[row.reformConfirmFlag],
                    executeResultName:this.executeResultMap[row.executeResult],
                    sourceName:this.$store.getters.prevention_danger_resource_map[row.source],
                    attributeClassifyName:this.$store.getters.prevention_safe_reason_map[row.attributeClassify],
                    classifyName:this.$store.getters.prevention_dangrous_type_map[row.classify],
                    dangerTypeName:this.$store.getters.prevention_danger_type_map[row.dangerType],
                    inspectTypeName:this.$store.getters.prevention_danger_check_type_map[row.inspectType],
                    levelName:this.levelMap[row.level],
                    occurNodeName:this.$store.getters.prevention_occur_step_map[row.occurNode],
                    professionClassifyName:this.$store.getters.prevention_major_type_map[row.professionClassify],
                    reformModeName:this.reformModeMap[row.reformMode],
            },row);

            this.getTableCallback()
            // 获取url
            if(row.resourceId){
                    this.tableService.getFileUrls({ids:row.resourceId.split(",")}).then((photos:any)=>{
                        this.photoList = photos.data.map(item=>{
                            return {
                                name:item.originalName,
                                url:item.url,
                                type:item.type,
                                id:item.id
                            }
                        })
                        if(!this.isReadonly && this.updateParams.status<2){
                            this.updateParams.photo = this.photoList.length
                        }

                        this.getTableCallback()
                    })
                }
                if(row.resourceOtherId){
                    this.tableService.getFileUrls({ids:row.resourceOtherId.split(",")}).then((files:any)=>{
                        this.fileList = files.data.map(item=>{
                            return {
                                name:item.originalName,
                                url:item.url,
                                type:item.type,
                                id:item.id
                            }
                        })
                        this.getTableCallback()
                    })
                }
                if(row.executeResourceId){
                    this.tableService.getFileUrls({ids:row.executeResourceId.split(",")}).then((files:any)=>{
                        this.fileList2 = files.data.map(item=>{
                            return {
                                name:item.originalName,
                                url:item.url,
                                type:item.type,
                                id:item.id
                            }
                        })
                        this.getTableCallback()
                    })
                }
                if(row.verifyResourceId){
                    this.tableService.getFileUrls({ids:row.verifyResourceId.split(",")}).then((files:any)=>{
                        this.photoList2 = files.data.map(item=>{
                            return {
                                name:item.originalName,
                                url:item.url,
                                type:item.type,
                                id:item.id
                            }
                        })
                        this.getTableCallback()
                    })
                }
            this.showUpdate = true
        }
    }

    public doSave(isSubmit){
        // 如果是提交 状态直接改成2变成代办  防止隐患确认退回变成草稿
        // 从草稿或者新创建的 要记住 走startWorkFlow
        // 从状态1  上报来不走startWorkFlow
        let preStatus = this.updateParams.status;
        const handleParams = {
            "taskId": this.updateParams.taskId,
            "btnValue": "agree_",
            "message": "",
            "esignature": "",
            "esignature_pwd": null,
            "forwarderList": "[]",
            "formValue": "[]",
            "keyValue": JSON.stringify([{
                F_Id:this.updateParams.id,
                F_FormId:1742822461669376,
                F_Type:2,
                F_UrlAddress:"ceshi1"
            }]),
            "rejectNodeId": null,
            "userJson": "[]",
            "fileValue": []
        }
        let userIds = [] as any;
        if(!preStatus || preStatus===1){
            this.updateParams.status = 2;
            userIds = [this.updateParams.reformUserId]
        }else if(preStatus===2){
            // 确认下一步  退回上一步
            if(this.updateParams.reformConfirmFlag){
                this.updateParams.status+=1;
                userIds = [this.updateParams.executeUserId]
            }else{
                this.updateParams.status-=1;
                handleParams.btnValue = "reject_"
                handleParams.rejectNodeId = "Activity_1r5fgcn" as any;
            }
        }else if(preStatus===3){
            // 确认下一步  退回上一步
            if(this.updateParams.executeConfirmFlag){
                this.updateParams.status+=1
                userIds = [this.updateParams.verifyUserId]
            }else{
                this.updateParams.status-=1
                handleParams.btnValue = "reject_"
                handleParams.rejectNodeId = "Activity_1ue7dkh" as any;
            }
        }else if(preStatus===4){
            // 确认下一步  退回上一步
            if(this.updateParams.verifyConfirmFlag){
                this.updateParams.status+=1
            }else{
                this.updateParams.status-=1
                handleParams.btnValue = "reject_"
                handleParams.rejectNodeId = "Activity_1exiors" as any;
            }
        }
        this.updateParams.resourceId = this.photoList.map(item=>item.id).join(",")
        this.updateParams.resourceName = this.photoList.map(item=>item.name).join(",")
        this.updateParams.resourceOtherId = this.fileList.map(item=>item.id).join(",")
        this.updateParams.resourceOtherName = this.fileList.map(item=>item.name).join(",")
        this.updateParams.executeResourceId = this.fileList2.map(item=>item.id).join(",")
        this.updateParams.executeResourceName = this.fileList2.map(item=>item.name).join(",")
        this.updateParams.verifyResourceId = this.photoList2.map(item=>item.id).join(",")
        this.updateParams.verifyResourceName = this.photoList2.map(item=>item.name).join(",")
        
        this.tableService.addOrUpdate(this.updateParams,!this.updateParams.id).then(res=>{
            this.$message.success(!this.updateParams.id?"新增成功":"编辑成功");
            if(!preStatus){
                this.startWorkFlow([res.data],[this.updateParams.reformUserId])
            }else{
                this.workFlowService.taskHandle(handleParams).then((data)=>{
                    // 验证不需要走下一步
                    if(this.updateParams.status > preStatus && preStatus!==4){
                        this.doAgain(data.data,userIds)
                    }else{

                        this.getTableData()
                    }
                })
            }
            this.handleClose();
        })
    }

    public startWorkFlow(ids,userIds){
        const keyValue = ids.map(id=>{
            return {
                F_Id:id,
                F_FormId:1742822461669376,
                F_Type:2,
                F_UrlAddress:"ceshi1"
            }
        })
        this.workFlowService.startWorkFlow({
            "F_Id": "1743872031226688",
            "relationTaskList": "[]",
            "keyValue": JSON.stringify(keyValue),
            "userJson": "[]",
            "fileValue": [],
            "nextNodeName":"确认",
            "nodeName":"上报",
            "userList": userIds
        }).then((res:any)=>{
            this.getTableData()
            // 发起工作流成功
        })
    }

    public doAgain(data,userIds){
        this.workFlowService.again([{
            "name": "确认",
            "taskId": data.CandidateInfo[0].taskId,
            "userList": userIds
        }]).then(()=>{
            this.getTableData()
        // 发起工作流成功
        })

    }

    public getMap(map){
        this.map = map;
        this.addMarker();
    }
    public addMarker(){
        this.marker = new mapboxgl.Marker({draggable:!this.isReadonly && this.updateParams.status<2})
        .setLngLat(this.center)
        .addTo(this.map);
        this.map.flyTo({center:this.center})
    }

    public onDragEnd() {
        const lngLat = this.marker.getLngLat();
        this.updateParams.locationLng = lngLat.lng;
        this.updateParams.locationLat = lngLat.lat;
        this.center = [lngLat.lng,lngLat.lat]
        // this.updateParams.locationName = lngLat.lng+","+lngLat.lat;
        this.handleClose()
    }


    public onSuccess(res,file,fileList){
        if(res.code===200){
            this.photoList.push({
                name:res.data.originalName,
                url:res.data.url,
                type:res.data.type,
                id:res.data.id
            });
            this.updateParams.photo = this.photoList.length || null
        }
    }
    public onSuccess2(res,file,fileList){
        if(res.code===200){
            this.fileList.push({
                name:res.data.originalName,
                url:res.data.url,
                type:res.data.type,
                id:res.data.id
            })
        }
    }
    public onSuccess3(res,file,fileList){
        if(res.code===200){
            this.fileList2.push({
                name:res.data.originalName,
                url:res.data.url,
                type:res.data.type,
                id:res.data.id
            })
        }
    }
    public onSuccess4(res,file,fileList){
        if(res.code===200){
            this.photoList2.push({
                name:res.data.originalName,
                url:res.data.url,
                type:res.data.type,
                id:res.data.id
            })
        }
    }

    public onRemove(file,fileList){
        this.photoList.splice(this.photoList.findIndex(item=>item.id === file.response.data.id),1)
        this.updateParams.photo = this.photoList.length || null
    }
    public onRemove2(file,fileList){
        this.fileList.splice(this.fileList.findIndex(item=>item.id === file.response.data.id),1)
    }
    public onRemove3(file,fileList){
        this.fileList2.splice(this.fileList2.findIndex(item=>item.id === file.response.data.id),1)
    }
    public onRemove4(file,fileList){
        this.photoList2.splice(this.photoList2.findIndex(item=>item.id === file.response.data.id),1)
    }

    public onPreview(file){
        if(file.type.indexOf("png")>=0 || file.type.indexOf("jp")>=0){
            this.currentUrl = file.url;
            this.showFile = true;
        }else{
            window.open(file.url,"_blank")
        }
    }

    public handleClose(){
        if(this.showMap){
            this.showMap = false;
            this.marker.remove();
            this.marker = null;
            return
        }
        this.photoList = [];
        this.photoList2 = [];
        this.fileList2 = [];
        this.fileList = [];
        this.showUpdate = false;
    }


    public toggleAll() {
        (this.$refs.multipleTable as any).toggleAllSelection();
    }
    public selectAll(){
        if(!this.selectData.length){
            this.toggleAll()
        }else{
            this.tableData.datas.forEach((item,index)=>{
                const find = this.selectData.find((data:any)=>data.userId === item.userId);
                if(!find){
                    (this.$refs.multipleTable as any).toggleRowSelection(item);
                }
            })
        }
    }

    public handleSelectionChange(data){
        this.selectData = data;
    }
}
</script>
<style lang="scss" scoped src="../common.component.scss">

</style>
<style>
.el-radio-button__inner{
    border:none !important;
}
.el-radio-button__orig-radio:checked+.el-radio-button__inner{
    border-bottom: 2px solid #409EFF !important;
}
</style>
