<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div style="margin-top: 10px;">
                <el-button v-if="sts == 0||sts==3" type="primary" @click="checkexa = true" size="medium">发起</el-button>
                <el-button v-if="sts == 0||sts==3" type="primary" @click="chexiao" size="medium">撤销</el-button>
                <el-button v-if="sts == 2" type="primary" @click="tongguo" size="medium">通过</el-button>
                <el-button v-if="sts == 2" type="primary" @click="dahui" size="medium">打回</el-button>
                <el-button v-if="sts != 0" type="primary" @click="guiji" size="medium">轨迹</el-button>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
                    tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="opType" label="类型">
                    </el-table-column>
                    <el-table-column prop="oaNo" label="员工工号">
                    </el-table-column>
                    <el-table-column prop="cityCompName" label="省/地市公司">
                    </el-table-column>
                    <el-table-column prop="areaCompName" label="区县">
                    </el-table-column>
                    <el-table-column prop="roleName" label="岗位角色">
                    </el-table-column>
                    <el-table-column prop="userName" label="姓名">
                    </el-table-column>
                    <el-table-column prop="phoneNo" label="手机号">
                    </el-table-column>
                    <el-table-column label="操作" width="120px" align="center" v-if="sts == 0||sts == 3">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(scope.row)">撤销</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination>
            </div>
        </div>

        <el-dialog title="轨迹" :visible.sync="gjsts" width="50%" :destroy-on-close="true"
        	:modal-append-to-body="false" :close-on-click-modal="false">
        	<div style="padding-bottom: 30px;">

        		<el-table class="com-table" ref="multipleTable" :data="rovaList" tooltip-effect="dark"
        				size="small" border style="width: 100%">
        				<el-table-column prop="stepName" label="节点">
        				</el-table-column>
        				<el-table-column prop="actName" label="动作">
        				</el-table-column>
        				<el-table-column prop="dealName" label="处理人">
        				</el-table-column>
        				<el-table-column prop="dealTime" label="处理时间">
        				</el-table-column>
        			</el-table>

        	</div>
        </el-dialog>

        <el-dialog title="选择审批人" :visible.sync="checkexa" width="50%" :destroy-on-close="true"
        	:modal-append-to-body="false" :close-on-click-modal="false">
        	<div>

        		<el-form :model="infolist" ref="infolist">
        			<el-form-item prop="visiblec" class="info-line online">
        				<span>审批人员</span>
        				<deptTreeOnly class="tree" @treeCheck="treeCheckonly" :defaultList="defaultList"
        					:type="depttype" :closeList="closeList"></deptTreeOnly>
        				<div class="tree treeUser">
        					<p>{{treeListonly.leaderAuditName}}
        						<i v-if="treeListonly.leaderAuditName" @click="deletes()"
        							class="el-icon-error"></i>
        					</p>
        				</div>
        			</el-form-item>
        		</el-form>

        		<div slot="footer" style="text-align: right;padding-bottom: 20px;">
        			<el-button type="primary" @click="faqi">确 定</el-button>
        			<el-button @click="checkexa = false">取 消</el-button>
        		</div>
        	</div>
        </el-dialog>

    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'
    import myUpload from '../../../components/upload'
    import uploadDown from '../../../components/uploadDown.vue'
    import deptTreeOnly from "../../../components/deptTreeOnly.vue"

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            myUpload,
            uploadDown,
            deptTreeOnly
        },
        data() {
            return {

                tooltit: '操作审批',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {},
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                docType: [],
                contentType: [],
                sts: '',
                checkexa: false,
                treeListonly: {},
                defaultList: [],
                closeList: false,
                visionchonly: false,
                depttype: 0,
                companyFlag: 0,
                checkexasts: 0,
                gjsts:false,
                rovaList:[]
            }
        },
        methods: {
            guiji(){
                this.gjsts=true;
                let woNo = this.$route.query.id.split(",")[0]
                this.$http({
                    url: "/market/cMkOrgWo/queryMkOrgWoTraceList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: woNo,
                    },
                }).then((res) => {
                    console.log(res.data.taskList)
                    this.rovaList = res.data;
                });
            },
            deletes() {
            	this.treeListonly = {};
            	this.closeList = !this.closeList;
            },
            treeCheckonly(v) {
            	this.treeListonly = v;
            },
            faqi() {
                if(this.checkexasts == 1){
                    let woNo = this.$route.query.id.split(",")[0]
                    this.$http({
                        url: "/market/cMkOrgWo/leaderApproval",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woNo: woNo,
                            provMgrNo : this.treeListonly.leaderAuditNo,
                            provMgrName : this.treeListonly.leaderAuditName,
                            remark:''
                        },
                    }).then((res) => {
                        this.checkexasts = 0;
                        this.jumpup();
                    });
                }else{
                    let woNo = this.$route.query.id.split(",")[0]
                    this.$http({
                        url: "/market/cMkOrgWo/dispatchWo",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woNo: woNo,
                            deptLeaderNo : this.treeListonly.leaderAuditNo,
                            deptLeaderName : this.treeListonly.leaderAuditName
                        },
                    }).then((res) => {
                        this.jumpup();
                    });
                }
            },
            chexiao() {
                let woNo = this.$route.query.id.split(",")[0]
                this.$http({
                    url: "/market/cMkOrgWo/backoutWo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: woNo
                    },
                }).then((res) => {
                    this.jumpup();
                });
            },
            tongguo() {
                if(this.companyFlag == 0){
                    let woNo = this.$route.query.id.split(",")[0]
                    this.$http({
                        url: "/market/cMkOrgWo/inForceWo",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: {
                            woNo: woNo
                        },
                    }).then((res) => {
                        this.jumpup();
                    });
                }else{
                    this.checkexa = true;
                    this.checkexasts = 1;
                }
            },
            dahui() {
                let woNo = this.$route.query.id.split(",")[0]
                this.$http({
                    url: "/market/cMkOrgWo/rejectWo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        woNo: woNo
                    },
                }).then((res) => {
                    this.jumpup();
                });
            },
            jumpup() {
                this.$router.push({
                    path: "/personnelApproval",
                });
                this.setabList("审批管理", "/personnelApproval");
            },
            setabList(n, p) {
                let params = {
                    children: "",
                    name: n,
                    rountPath: p,
                    target: "_self",
                };
                for (let i = 0; i < this.$store.state.tabList.length; i++) {
                    if (this.$store.state.tabList[i].name === params.name) {
                        this.$store.state.tabList[i] = params;
                    }
                }
                let set = new Set([...this.$store.state.tabList, params]);
                set.add(params);
                this.$store.commit("setDefaultActive", params.rountPath);
                this.$store.commit("setTabList", Array.from(set));
            },
            dialogCheck(v) {
                this.$http({
                    url: "/market/cMkOrgWo/backoutWoDetail",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        id: v.id
                    },
                }).then((res) => {
                    this.getList({}, 1)
                });
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                v.woNo = this.$route.query.id.split(",")[0]
                this.$http({
                    url: "/market/cMkOrgWo/queryWoDetailPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data.data;
                    this.total = res.data.totalRecord;
                    this.loading = false;
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },

            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.sts = this.$route.query.id.split(",")[1];
                this.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag
                });
            },
        },
        mounted() {
            this.getList({}, 1);
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 100px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 120px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 120px);
        }

        .tree {
            width: calc(50% - 60px);
            display: inline-block;
            margin-right: 20px;
            height: 300px;
            overflow-y: scroll;

            .el-icon-error {
                float: right;
                font-size: 20px;
                margin-top: 9px;
                cursor: pointer;
            }
        }

        .treeUser {
            margin: 0;
            border: 1px solid #ddd;

            p {
                background: #f4f4f4;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }

        .treeUserb {
            width: calc(100% - 100px);
            border: 1px solid #ddd;
            background: #f4f4f4;
            border-radius: 3px;
            height: auto;
            overflow: hidden;

            p {
                display: inline-block;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }
    }

    .adv-type {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        // border: 1px solid #ddd;
        border-radius: 5px;
        padding: 20px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

        div {
            width: 33%;
            text-align: center;
            height: 80px;
            overflow: hidden;
            min-width: 100px;
            cursor: pointer;
            padding-top: 10px;
            margin: 10px 0;
        }

        div:hover {
            background: #CFE8FC;
            border-radius: 5px;
        }

        span {
            width: 100%;
            display: inline-block;
            height: 40px;

            // line-height: 40px;
            i {
                color: #0074D9;
                font-size: 36px;
            }
        }
    }
</style>
