<template>
    <div>
        <el-container>
            <!-- 行政组织及岗位级 -->
            <el-aside width="220px">
                <el-row>
                    <el-col :span="24">
                        <el-row>
                            <el-col :span="20">
                                <el-link v-if="isAllClick" type="primary" :underline="false" icon="el-icon-folder-checked" @click="setAllClickPost">全部选择({{ jibuqi }})</el-link>
                                <el-link v-if="!isAllClick" type="danger" :underline="false" icon="el-icon-delete" @click="clearAllClickPost">取消全部({{ jibuqi }})</el-link>
                            </el-col>
                            <!-- <el-col :span="12">
                                <el-link type="warning" :underline="false">已选择岗位<i class="el-icon-view el-icon--right"></i> </el-link>
                            </el-col> -->
                        </el-row>
                    </el-col>
                    <el-col :span="24">
                        <el-tree
                            :data="orgPostThree"
                            show-checkbox
                            :default-expand-all="false"
                            node-key="number"
                            ref="orgAndPostTree"
                            highlight-current
                            @check="changeOrgPostTree"
                            :props="orgProps">
                        </el-tree>
                    </el-col>
                </el-row>
                
            </el-aside>

            <el-main>

                <!--主信息列表-->
                <el-row>
                    <el-col :span="24">
                        <el-form ref="shearchPostTarget" :model="searchPostData" label-width="80px" :inline="true">
                            <el-form-item label="考核指标"  >
                                <el-input v-model="searchPostData.name" placeholder="请输入指标名称"></el-input>
                            </el-form-item>
                            <el-form-item label="指标维度"  >
                                <el-select clearable  v-model="searchPostData.dimension" placeholder="请选择指标维度">
                                    <el-option v-for="item in dutyclasslist"
                                    :key="item.outId"
                                    :label="item.title"
                                    :value="item.outId"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="指标性质">
                                <el-select clearable  v-model="searchPostData.nature" placeholder="请选择指标维度">
                                    <el-option label="定性指标" value="1"></el-option>
                                    <el-option label="定量指标" value="2"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item>
                                <el-button
                                  type="primary"
                                  icon="el-icon-search"
                                  @click="onSubmitPostSearch"
                                  >查询</el-button>
                            </el-form-item>
                            <el-form-item>
                                <el-button
                                  type="warning"
                                  icon="el-icon-plus"
                                  @click="addNewPostTarget"
                                  >新增</el-button>
                            </el-form-item>
                        </el-form>
                    </el-col>
                    <el-col :span="24">
                        <el-table :data="postTargetList">
                            <el-table-column fixed align="left" label="考核指标" width="150">
                                <template #default="scope">
                                    <el-link :underline="false" type="primary" v-if="scope.row.type==1" @click="showPostTargetContList(scope.row)">{{ scope.row.title }}</el-link>
                                    <el-link :underline="false" v-if="scope.row.type==2" disabled style="color:#000000">{{ scope.row.title }}</el-link>
                                </template>
                            </el-table-column>
                            <el-table-column
                                align="left"
                                label="考核维度"
                                prop="dimensionname"
                            />
                            <el-table-column align="center" label="指标性质">
                                <template #default="scope">
                                  <div v-if="scope.row.type == 1">定性指标</div>
                                  <div v-if="scope.row.type == 2">定量指标</div>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" label="单位" prop="unit" />
                            <el-table-column align="center" label="考核周期" prop="outId">
                                <template #default="scope">
                                <el-tag v-if="scope.row.cycle == 1">班</el-tag>
                                <el-tag v-if="scope.row.cycle == 2">天</el-tag>
                                <el-tag v-if="scope.row.cycle == 3">周</el-tag>
                                <el-tag v-if="scope.row.cycle == 4">月</el-tag>
                                <el-tag v-if="scope.row.cycle == 5">季度</el-tag>
                                <el-tag v-if="scope.row.cycle == 6">年</el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" label="计分方式" prop="outId">
                                <template #default="scope">
                                  <el-tag v-if="scope.row.scoringmethod == 1">自动计分</el-tag>
                                  <el-tag v-if="scope.row.scoringmethod == 2">手动计分</el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column align="left" label="数据提交">
                                <template #default="scope">
                                  <div v-for="item in scope.row.reportary" :key="item.key">
                                    {{ item.name }}
                                  </div>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" label="辅助计数" prop="cycleattr" />
                            <el-table-column align="center" label="状态">
                                <template #default="scope">
                                  <el-switch
                                    inline-prompt
                                    v-model="scope.row.state"
                                    active-color="#13ce66"
                                    inactive-color="#ff4949"
                                    :active-value="1"
                                    :inactive-value="2"
                                    @change="changeVal($event, scope.row.id)"
                                  />
                                </template>
                            </el-table-column>
                            <el-table-column label="操作" align="center" fixed="right" width="130">
                                <template #default="scope">
                                    <el-button
                                        icon="el-icon-edit"
                                        size="small"
                                        type="text"
                                        @click="showEdit(scope.row)"
                                        >编辑</el-button
                                    >
                                    <el-button
                                        icon="el-icon-delete"
                                        size="small"
                                        type="text"
                                        @click="delPostTargetCont(scope.row)"
                                        >删除</el-button
                                    >
                                </template>
                            </el-table-column>









                        </el-table>

                    </el-col>
                    <el-col :span="24">
                        <div class="gva-pagination">
                            <el-pagination
                              @current-change="handleCurrentChange"
                              :page-sizes="[searchPostData.pagesize, 30, 50, 100]"
                              :page-size="searchPostData.pagesize"
                              layout="total, sizes, prev, pager, next, jumper"
                              :total="searchPostData.total"
                              :current-page="currentPage"
                            >
                            </el-pagination>
                            
                        </div>
                    </el-col>
                </el-row>
                <!--添加指标-->
                <el-dialog :close-on-click-modal="false" :visible.sync="addPostTargetBox" :before-close="closePostTargetBoxDialog" title="添加岗位指标" width="50%">
                    <el-form ref="addPostTagetForm" :model="addPostTargetCont" label-width="100px" :rules="addRules">
                        <el-form-item label="指标名称" prop="title">
                            <el-input v-model="addPostTargetCont.title" autocomplete="off" />
                        </el-form-item>
                        <el-form-item label="岗位/人员" >

                            <el-row>
                                <el-col :span="14">
                                    <el-input
                                        placeholder="请输入岗位名称"
                                        prefix-icon="el-icon-search"
                                        v-model="searchPostName">
                                    </el-input>
                                </el-col>
                                <el-col :span="1" style="height:1px"></el-col>
                                <el-col :span="8">
                                    <el-button type="primary" @click="searchpostlist" :loading="searchLoading">搜索岗位</el-button>
                                </el-col>
                            </el-row>
                            <el-table :data="otherOrgList" style="width: 100%">
                                <el-table-column label="行政组织">
                                    <template slot-scope="scope">
                                        {{ scope.row.orgId }}
                                        <el-cascader v-model="scope.row.orgId" :options="orgThree"  :props="orgListProps" @change="getOrgPost(scope)"></el-cascader>
                                    </template>
                                </el-table-column>
                                <el-table-column label="相关岗位">
                                    <template slot-scope="scope">
                                        <el-select
                                            clearable
                                            v-model="scope.row.postId"
                                            filterable
                                            placeholder="请选择"
                                        >
                                            <el-option
                                            v-for="item in scope.row.postList"
                                            :key="item.id"
                                            :label="item.name"
                                            :value="item.id"
                                            >
                                            </el-option>
                                        </el-select>          
                                    </template>
                                </el-table-column>
                                <el-table-column label="提报人">
                                    <template slot-scope="scope">
                                        <el-cascader
                                          filterable
                                          clearable
                                          v-model="scope.row.operator"
                                          :options="grouplistBackup"
                                          :show-all-levels="false"
                                          :props="userProps"
                                          collapse-tags
                                        ></el-cascader>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作" width="120">

                                    <template slot-scope="scope">
                                      <el-button
                                          icon="el-icon-delete"
                                          size="small"
                                          type="text"
                                          @click="deleteOrgPostRulesList(scope)"
                                        >删除</el-button>
                                        <el-button v-if="scope.$index == otherOrgList.length-1" @click="jiaOrgPostArr" type="primary" icon="el-icon-plus" circle size="mini"></el-button>
                                    </template>
                      
                                </el-table-column>

                                
                            </el-table>


                            
                        </el-form-item>
                        <el-form-item label="指标维度" prop="dimension">
                            <el-select
                              v-model="addPostTargetCont.dimension"
                              clearable
                              placeholder="请选择考核维度"
                              @change="shuaxinSelect"
                            >
                                <el-option
                                    v-for="item in dutyclasslist"
                                    :key="item.outId"
                                    :label="item.title"
                                    :value="item.outId"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="指标性质" prop="type">
                            <el-select v-model="addPostTargetCont.type" placeholder="请选择指标性质">
                                <el-option label="定性指标" :value="1"></el-option>
                                <el-option label="定量指标" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="计量单位" prop="unit">
                            <el-input v-model="addPostTargetCont.unit" autocomplete="off" />
                        </el-form-item>
                        <el-form-item label="计分方式" prop="scoringmethod">
                            <el-select v-model="addPostTargetCont.scoringmethod" placeholder="请选择指标性质">
                                <el-option label="自动计分" :value="1"></el-option>
                                <el-option label="手动计分" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="考核周期" prop="cycle">
                            <el-select v-model="addPostTargetCont.cycle" placeholder="请选择考核周期">
                                <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="辅助计数" prop="cycleattr">
                            <el-input-number v-model="addPostTargetCont.cycleattr" controls-position="right" :min="1" :max="12" value="1" placeholder="请输入辅助计数" ></el-input-number>
                        </el-form-item>
                        
                    </el-form>
                    <template #footer>
                        <div class="dialog-footer">
                            <el-button size="small" @click="closePostTargetBoxDialog">取 消</el-button>
                            <el-button size="small" type="primary" @click="addPostTargetDialog"
                                >确 定</el-button
                          >
                        </div>
                    </template>
                </el-dialog>
                <!--编辑指标弹窗-->
                <el-dialog :close-on-click-modal="false" :visible.sync="editPostTargetBox" :before-close="closeEtitPostTargetBox" title="添加岗位指标" width="50%">
                    <el-form ref="editPostTagetForm" :model="editPostTargetCont" label-width="100px" :rules="addRules">
                        <el-form-item label="指标名称" prop="title">
                            <el-input v-model="editPostTargetCont.title" autocomplete="off" />
                        </el-form-item>
                        <el-form-item label="岗位/人员" >
                            <el-row>
                                <el-col :span="14">
                                    <el-input
                                        placeholder="请输入岗位名称"
                                        prefix-icon="el-icon-search"
                                        v-model="searchPostName">
                                    </el-input>
                                </el-col>
                                <el-col :span="1" style="height:1px"></el-col>
                                <el-col :span="8">
                                    <el-button type="primary" @click="searchpostlist" :loading="searchLoading">搜索岗位</el-button>
                                </el-col>
                            </el-row>
                            <el-table :data="otherOrgList" style="width: 100%">
                                <el-table-column label="行政组织">
                                    <template slot-scope="scope">
                                        <el-cascader v-model="scope.row.orgId" :options="orgThree"  :props="orgListProps" @change="getOrgPost(scope)"></el-cascader>
                                    </template>
                                </el-table-column>
                                <el-table-column label="相关岗位">
                                    <template slot-scope="scope">
                                        <el-select
                                            clearable
                                            v-model="scope.row.postId"
                                            filterable
                                            placeholder="请选择"
                                        >
                                            <el-option
                                            v-for="item in scope.row.postList"
                                            :key="item.id"
                                            :label="item.name"
                                            :value="item.id"
                                            >
                                            </el-option>
                                        </el-select>          
                                    </template>
                                </el-table-column>
                                <el-table-column label="提报人">
                                    <template slot-scope="scope">
                                        <el-cascader
                                          filterable
                                          clearable
                                          v-model="scope.row.operator"
                                          :options="grouplistBackup"
                                          :show-all-levels="false"
                                          :props="userProps"
                                          collapse-tags
                                        ></el-cascader>
                                    </template>
                                </el-table-column>
                                <el-table-column label="操作" width="120">

                                    <template slot-scope="scope">
                                      <el-button
                                          icon="el-icon-delete"
                                          size="small"
                                          type="text"
                                          @click="deleteOrgPostRulesList(scope)"
                                        >删除</el-button>
                                        <el-button v-if="scope.$index == otherOrgList.length-1" @click="jiaOrgPostArr" type="primary" icon="el-icon-plus" circle size="mini"></el-button>
                                    </template>
                      
                                </el-table-column>

                                
                            </el-table>
                        </el-form-item>
                        <el-form-item label="指标维度" prop="dimension">
                            <el-select
                              v-model="editPostTargetCont.dimension"
                              clearable
                              placeholder="请选择考核维度"
                              @change="shuaxinSelect"
                            >
                                <el-option
                                    v-for="item in dutyclasslist"
                                    :key="item.outId"
                                    :label="item.title"
                                    :value="item.outId"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="指标性质" prop="type">
                            <el-select v-model="editPostTargetCont.type" placeholder="请选择指标性质">
                                <el-option label="定性指标" :value="1"></el-option>
                                <el-option label="定量指标" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="计量单位" prop="unit">
                            <el-input v-model="editPostTargetCont.unit" autocomplete="off" />
                        </el-form-item>
                        <el-form-item label="计分方式" prop="scoringmethod">
                            <el-select v-model="editPostTargetCont.scoringmethod" placeholder="请选择指标性质">
                                <el-option label="自动计分" :value="1"></el-option>
                                <el-option label="手动计分" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="考核周期" prop="cycle">
                            <el-select v-model="editPostTargetCont.cycle" placeholder="请选择考核周期">
                                <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="辅助计数" prop="cycleattr">
                            <el-input-number v-model="editPostTargetCont.cycleattr" controls-position="right" :min="1" :max="12" value="1" placeholder="请输入辅助计数" ></el-input-number>
                        </el-form-item>
                        
                    </el-form>
                    <template #footer>
                        <div class="dialog-footer">
                            <el-button size="small" @click="closeEtitPostTargetBox">取 消</el-button>
                            <el-button size="small" type="primary" @click="editPostTargetDialog"
                                >确 定</el-button
                          >
                        </div>
                    </template>
                </el-dialog>
                <!--弹出已经选择的岗位-->
                <el-dialog :close-on-click-modal="false" :visible.sync="xuanZePostBox" :before-close="closeXuanZeDialog" title="已选择岗位" custom-class="dialogBox">
                    <el-table
                        :data="selectedPost"
                        style="width: 100%">
                        <el-table-column
                            prop="orgname"
                            label="行政组织"
                            >
                        </el-table-column>
                        <el-table-column
                            prop="postname"
                            label="岗位"
                            >
                        </el-table-column>
                        <el-table-column
                            fixed="right"
                            label="操作"
                            width="120"
                            align="center">
                            <template slot-scope="scope">
                                <el-button
                                @click.native.prevent="deletePostRow(scope.$index, selectedPost)"
                                type="text"
                                size="small">
                                移除
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-dialog>

                <!--指标细则弹出层-->
                <el-dialog :close-on-click-modal="false" :visible.sync="detailsBox" :before-close="closeDetailsBox" :title="'指标《'+this.postTargetInfo.title + '》考核方法明细'"  width="85%" top="5vh" custom-class="dialogMyClass">
                    <posttargetdetails ref="targetDearilsList" v-if="detailsBox" :postTargetInfo="postTargetInfo"></posttargetdetails>
                </el-dialog>


            </el-main>



        </el-container>
    </div>
</template>
<script>
import { govthree,positionlist,orgThreeList,getOrgAndPostThree } from "@/api/personnel/post";
import { dutyclasslist } from "@/api/duty/dimension";
import { get_posttarget_list,setPosttargetState,getorgary,searchPostListCont,getOrgAndPostAry,addPostTargetCont,get_post_target,newEditPostTarget } from "@/api/systemaccredit/systemapi";
import { getgroupdepartmap, getgroupuser } from "@/api/duty/group";

import posttargetdetails from "@/views/basicCont/targettabslayout/posttargetdetails.vue";

export default {
    components: {
        posttargetdetails
    },
    data() {
        return {
            orgPostThree:[],
            isAll:false,
            addRules:{
                title: [{ required: true, message: '必填', trigger: 'blur' }],
                departmentsPostOther: [{ required: true, message: '必填', trigger: 'blur' }],
                dimension: [{ required: true, message: '必填', trigger: 'blur' }],
                type: [{ required: true, message: '必填', trigger: 'blur' }],
                unit: [{ required: true, message: '必填', trigger: 'blur' }],
                cycleattr: [{ required: true, message: '必填', trigger: 'blur' }],
                scoringmethod: [{ required: true, message: '必填', trigger: 'blur' }],
                cycle: [{ required: true, message: '必填', trigger: 'blur' }],
            }, //新增表单规则
            options: [
                {
                value: 4,
                label: "月",
                },
                {
                value: 5,
                label: "季度",
                },
                {
                value: 6,
                label: "年",
                },
            ],
            searchLoading:false,
            grouplistBackup: [],    //操作人
            userProps: {
                value: "key",
                label: "name",
                children: "govlist",
                emitPath: false,
                multiple: true,
            },
            searchPostName:"",  //岗位名称
            //额外行政组织
            orgThree: {},
            otherOrgList:[
                {
                    orgId:[],
                    postId:"",
                    postList:[],
                    // 多人员列表
                    operator:[]
                }
            ],
            dutyclasslist: {}, //考核维度
            searchPostData:{
                total:0,
                page:1,
                pagesize:10,
                name:"",
                dimension:"",
                nature:""
            },   //搜索条件
            currentPage:1,
            countPostNumber:0,  //已选择岗位个数
            //行政组织树配置数据
            orgList:[],
            orgProps: {
                children: "child",
                label: "name",
            },
            orgListProps: {
                value: "id",
                label: "name",
                children: "child",
                checkStrictly: true
            },
            postList: [],           //岗位
            orgId:0,    //行政组织ID
            orgName:0,    //行政组织名称
            selectedPost:[],    //已选择岗位
            xuanZePostBox:false, //已选择岗位弹出
            postTargetList:[], //岗位指标列表
            addPostTargetBox:false, //添加岗位指标
            addPostTargetCont:{
                title:"",
                dimension:"",
                unit:"",
                type:1,
                scoringmethod:1,
                cycle:4,
                cycleattr:1
            }, //添加岗位指标数据
            guoduOrg:[], //过度使用Org
            editPostTargetBox:false, //编辑指标弹窗
            editPostTargetCont:{
                title:"",
                dimension:"",
                unit:"",
                type:1,
                scoringmethod:1,
                cycle:4,
                cycleattr:1
            }, //编辑弹窗内容
            detailsBox:false, //细则弹窗
            postTargetInfo:{}, //指标
            allNodeKey:[],
            isAllClick:true, //
            jibuqi:0,
        }
    },
    created(){
        this.getOrgPostThreeCont();
        this.getOrgList();
        this.getDutyclasslist();
        this.getPosttargetList();
        this.getOrgListOther();
        this.getSystemadminlist();
    },
    methods:{
        //获取行政组织与岗位树
        async getOrgPostThreeCont(){
            const sendData = {
                id:"309",
                levelL:0,
                all:0
            }
            // console.log("获取行政组织树--------------------->",sendData)
            const orgList = await getOrgAndPostThree(sendData)
            this.orgPostThree = orgList.data.list
            this.allNodeKey = orgList.data.allnumber
        },
        //全部选中
        setAllClickPost(){
            this.$refs.orgAndPostTree.setCheckedKeys(this.allNodeKey);
            this.isAllClick = false;
        },
        //取消全部选择
        clearAllClickPost(){
            this.isAllClick = true;
            this.$refs.orgAndPostTree.setCheckedKeys([]);
            this.jibuqi = 0;
            this.selectedPost=[];
        },
        //树节点状态变化是
        changeOrgPostTree(val,checkList){
            this.selectedPost=[];
            this.jibuqi=0;
            if(checkList.checkedNodes != null && checkList.checkedNodes.length > 0){
                checkList.checkedNodes.forEach(item => {
                    if(item.attribute == 2){
                        let orgNameStr = item.orgname
                        if(item.superior != item.departid*1){
                            orgNameStr = item.departname+" / "+item.orgname
                        }
                        this.selectedPost.push({orgid: item.superior,orgname:orgNameStr,manorg:item.superior,postid:item.id*1,postname:item.name});
                        this.jibuqi++
                    }
                });
            }
            console.log("树节点状态变化是--------------------->",val,checkList)
        },
        //获取行政组织列表
        async getOrgListOther(){
            const sendData = {
                id:309,
                all:1
            }
            // console.log("获取行政组织树--------------------->",sendData)
            const orgList = await orgThreeList(sendData)
            this.orgThree = orgList.data
            console.log("获取行政组织树--------------------->",orgList)
        },
         // 改变page
         handleCurrentChange(val) {
            this.searchPostData.page=val
            this.currentPage = val
            this.getPosttargetList()
        },
        // 获取考核纬度列表
        async getDutyclasslist() {
            const res = await dutyclasslist(this.searchList);
            this.dutyclasslist = res.data.list;
            // console.log("获取考核纬度列表",this.dutyclasslist)
        },
        //获取行政组织列表
        async getOrgList(){
            let sendData ={
                // page:309,
                // level:4,
                // all:1
            }
            const res = await govthree(sendData);
            this.orgList = res.data
            this.orgList.forEach((item,index)=>{
                // console.log("获取行政组织列表===>",item,index)
                if(index === 0){
                    this.orgId = item.id
                    this.orgName = item.name
                    this.getPost(item.id)
                }
            })
        },
         // 点击行政组织树
         handleNodeClick(val) {
            this.orgId = val.id
            this.orgName = val.name
            this.getPost(val.id);
            // console.log(val)
            let setKey = new Array
            if(this.selectedPost.length > 0){
                this.selectedPost.forEach(item=>{
                    if(item.orgid == val.id){
                        setKey.push(item.postid)
                    }
                });
            }
            if(setKey.length > 0){
                this.$refs.postTree.setCheckedKeys(setKey);
            }
        },
        // 获取岗位
        async getPost(val) {
            const from = {
                organization: val.toString(),
                page: 1,
                pagesize: 10,
            };
            const res = await positionlist(from);
            this.postList = res.data.list; 
        },
        // 点击岗位列表
        NodePostClick(val,checked) {
            console.log('岗位',val,checked.checkedNodes)
            if(this.selectedPost != null && this.selectedPost.length <= 0){
                checked.checkedNodes.forEach(item => {
                    console.log("点击岗位列表----1----->",item)
                    let orgNameStr = item.departmentname+" / "+item.aoname
                    if(item.department == 309){
                        orgNameStr = item.aoname
                    }
                    this.selectedPost.push({orgid: this.orgId,orgname:orgNameStr,manorg:item.administrativeorganization,postid:item.id,postname:item.name})
                });
            }else{
                let postAry = new Array
                if(this.selectedPost != null){
                    
                    this.selectedPost.forEach(item => {
                        console.log("点击岗位列表----2----->",item)
                        if(item.orgid != this.orgId){
                            postAry.push({orgid: item.orgid,orgname: item.orgname,manorg:item.manorg,postid: item.postid,postname: item.postname})
                        }
                    });
                }
                
                this.selectedPost = [];
                if(checked.checkedNodes != null){
                    checked.checkedNodes.forEach(item => {
                        console.log("点击岗位列表----3----->",item)
                        let orgNameStr = item.departmentname+" / "+item.aoname
                        if(item.department == 309){
                            orgNameStr = item.aoname
                        }
                        this.selectedPost.push({orgid: this.orgId,orgname:orgNameStr,manorg:item.administrativeorganization,postid:item.id,postname:item.name})
                    });
                }
                
                if(postAry.length > 0){
                    postAry.forEach(item=>{
                        console.log("点击岗位列表----4----->",item)
                        this.selectedPost.push({orgid: item.orgid,orgname: item.orgname,manorg:item.manorg,postid: item.postid,postname: item.postname})
                    })
                }
            }
            if(this.selectedPost != null){
                this.countPostNumber = this.selectedPost.length
            }
            
            // console.log("点击岗位列表",this.selectedPost)
            this.getPosttargetList()
        },
        //查看已经选择的列表
        lookPostList(){
            // console.log("查看已经选择的列表",this.selectedPost)
            this.xuanZePostBox = true;
        },
        //关闭选择弹窗
        closeXuanZeDialog(){
            this.xuanZePostBox = false;
        },
        //移除已选择得岗位
        deletePostRow(index, rows) {
            rows.splice(index, 1);
            let setKey = new Array
            if(this.selectedPost.length > 0){
                this.selectedPost.forEach(item=>{
                    if(item.orgid == this.orgId){
                        setKey.push(item.postid)
                    }
                });
            }
            if(setKey.length >= 0){
                this.$refs.postTree.setCheckedKeys(setKey);
            }
            this.countPostNumber = this.selectedPost.length
            this.getPosttargetList()
        },
        // 获取岗位指标列表
        async getPosttargetList() {
            let postId = new Array
            // console.log("获取岗位指标列表--->",this.selectedPost)
            if(this.selectedPost != null && this.selectedPost.length > 0){
                this.selectedPost.forEach(item=>{
                    postId.push(item.postid)
                });
            }
            this.postTargetList = [];
            let sendData ={
                page:this.searchPostData.page,
                pagesize:this.searchPostData.pagesize,
                title:this.searchPostData.name,
                dimension:this.searchPostData.dimension,
                attribute:this.searchPostData.nature*1,
                postidlist:postId
            }
            const res = await get_posttarget_list(sendData);
            if(res.code == 0){
                this.postTargetList = res.data.list
                // console.log("获取指标列表-->",res.data)
                this.searchPostData.total = res.data.total
                this.searchPostData.page = res.data.page
                this.searchPostData.pagesize = res.data.pageSize
                this.searchPostData.count = res.data.count
            }
            
        },
        //搜索信息
        async onSubmitPostSearch(){
            this.searchPostData.page = 1
            this.searchPostData.pagesize=10
            this.getPosttargetList()
        },
        //删除指标
        async delPostTargetCont(val){
            this.$confirm('此操作将永久删除相关资料！是否继续执行此操作?', '是否删除此项资料？', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async() => {
                let sendData = {
                    id:val.id.toString(),
                    state:3,
                    istrue:2
                }
                console.log("此操作将永久删除相关资料",val)
                const respon = await setPosttargetState(sendData)
                if (respon.code === 0) {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    })
                    if(this.searchPostData.count -1 <= 0){
                        this.searchPostData.page=this.searchPostData.page -1
                        if(this.searchPostData.page < 1){
                            this.searchPostData.page = 1
                        }
                    }
                    this.getPosttargetList();
                }
                    
            })
        },
        //修改状态
        async changeVal(val,id){
            console.log("修改状态------------------>",val,id)
            let sendData = {
                    id:id.toString(),
                    state:val,
                    istrue:2
            }
            const respon = await setPosttargetState(sendData)
            if (respon.code === 0) {
                this.getPosttargetList();
            }
        },
        //初始化数据
        initPosttargetCont(){
            this.addPostTargetCont = {};
        },
        //关闭新增弹窗
        closePostTargetBoxDialog(){
            // this.addPostTargetCont.departmentsPostOther = ""
            this.addPostTargetBox = false;
            // this.$refs.addPostTagetForm.resetFields();
            // this.$forceUpdate();
            this.initAddPostTarget();
        },
        //初始化添加数据
        initAddPostTarget(){
            this.$refs.addPostTagetForm.resetFields()  // 这里可以换做移除样式的方法clearValidate
        },
        //新增按钮
        async addNewPostTarget(){
            this.addPostTargetBox = true;
            this.otherOrgList = [];
            if(this.selectedPost != null && this.selectedPost.length >0) {
                // console.log("新增按钮->",this.selectedPost)
                this.selectedPost.forEach(async items=>{
                    this.searchPostName = items.postname
                    let sendCont = {
                        id:items.manorg.toString()
                    }
                    const res = await getOrgAndPostAry(sendCont)
                    // console.log("获取行政组织--------11212313---》》》",res);
                    this.otherOrgList.push({
                        orgId:res.data.orglist,
                        postId:items.postid,
                        postList:res.data.postlist,
                        operator:[]
                    })
                })
            }else{
                this.otherOrgList = [{
                    orgId:[],
                    postId:"",
                    postList:[],
                    // 多人员列表
                    operator:[]
                }];
            }
            console.log("获取行政组织--------1---》》》",this.selectedPost);
            console.log("获取行政组织--------2---》》》",this.otherOrgList);
            console.log("获取行政组织--------3---》》》",this.orgThree);
            // console.log("获取行政组织--------4---》》》",this.selectedPost,this.otherOrgList,this.orgThree);
            // console.log("获取行政组织--------5---》》》",this.selectedPost,this.otherOrgList,this.orgThree);
            
        },
        // 添加行政组织岗位人员数据
        jiaOrgPostArr(){
            this.otherOrgList.push({
                orgId:[],
                postId:"",
                postList:[],
                // 多人员列表
                operator:[]
            })
        },
        // 删除行政组织岗位人员数据
        deleteOrgPostRulesList(row){
            this.otherOrgList.splice(row.$index,1);
        },
        //搜索全部岗位
        async searchpostlist(){
            this.searchLoading = true;
            if(this.searchPostName == ""){
                this.$notify.error({
                title: '错误',
                message: '请输入岗位名称'
                });
            }else{
                this.otherOrgList = [];
                const sendData = {
                orgid:"309",
                name:this.searchPostName
                }
                const res = await searchPostListCont(sendData)
                // this.otherOrgList=[];
                if(res.data != null && res.data.length > 0){
                    res.data.forEach(item=>{
                        this.otherOrgList.push({
                            orgId:item.orgid,
                            postId:item.postid,
                            postList:item.postlist,
                            // 多人员列表
                            operator:[]
                        })
                    })
                }

                
                // console.log("搜索全部岗位------1232--->",res)
            }
            if(this.otherOrgList.length < 1){
                this.otherOrgList = [{
                    orgId:[],
                    postId:"",
                    postList:[],
                    // 多人员列表
                    operator:[]
                }]
            }
            this.searchLoading = false;
            // console.log("搜索全部岗位--------->",this.searchPostName)
        },
        //获取行政组织岗位
        async getOrgPost(val){
            // console.log("获取行政组织岗位--------------------->",val.row,val.row.orgId)
            let orgId = 0
            if(val.row.orgId){
                if(val.row.orgId.length > 0){
                orgId = val.row.orgId[val.row.orgId.length -1]
                }
            }
            // console.log("获取行政组织岗位---------------12213------>",orgId)
            const from = {
                organization: orgId.toString(),
                page: 1,
                pagesize: 1000000,
            };
            const res = await positionlist(from);
            val.row.postList = res.data.list
            this.addPostTargetCont.departmentsPostOther =  res.data.list
        },
        // 获取员工列表
        async getSystemadminlist() {
            const from = {
                id:309,
                level: 4,
            };
            const res = await getgroupuser(from);
            this.grouplistBackup = res.data;
            this.grouplistBackup.forEach((item) => {
                if (item.govlist != null) {
                // 即：this.digui(item);在这地方添加的
                item.govlist.forEach((items) => {
                    // 下面的就是执行递归的方法，因为我是从第二层才开始需要往下挖的，所以这里多了个forEach,如果从第一层起，从item就好了，即：this.digui(item);在上面添加
                    this.digui(items); // 这里是源头，把一个对象开始递归，开始循环
                    // 如果想看完整数据，那么是在这里打印数据哦
                    // console.log(items, "看我查看完整的数据哦");
                    // 因为上一步递归时，就已经把循环children的动作做完了，这里是验收递归方法的地方。
                });
                } else {
                item.govlist = item.child;
                // 如果第一层没有子项做的操作。。。。。
                }
            });
            console.log("第一层没有子项做的操作",this.grouplistBackup);
        },
        //提交新增岗位指标数据
        async addPostTargetDialog(){
            
            this.$refs.addPostTagetForm.validate(async (valid) => {
                if (valid) {
                    //组装岗位与提报人员
                    let postAndMan = new Array
                    if(this.otherOrgList != null && this.otherOrgList.length > 0) {
                        this.otherOrgList.forEach((item,i)=>{
                            console.log("提交新增岗位指标数据-"+i+"->",item)
                            if(item.orgId.length > 0 && item.orgId != 0 && item.postId != ""){
                                postAndMan.push({
                                    orgid:item.orgId[item.orgId.length -1],
                                    postid:item.postId,
                                    operator:item.operator.map(String)
                                })
                            }

                        });
                    }
                    console.log("提交新增岗位指标数据-&&&&->",postAndMan)
                    this.addPostTargetCont.cycleattr = parseInt(this.addPostTargetCont.cycleattr);
                    this.addPostTargetCont.otherposttarget= postAndMan
                    const res = await addPostTargetCont(this.addPostTargetCont)
                    console.log("提交新增岗位指标数据-返回值->",res,this.addPostTargetCont)
                    if(res.code == 0){
                        this.getPosttargetList()
                        this.$confirm('添加成功，是否继续添加？', '添加成功？', {
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type: 'warning'
                        }).then(async() => {
                            this.initAddPostTarget();
                        }).catch(() => {
                            this.closePostTargetBoxDialog()
                        })
                        
                    }
                    

                }
            })
        },
        //刷新下拉框
        shuaxinSelect(){
            this.$forceUpdate()
        },
        //编辑岗位指标
        async showEdit(val){
            // console.log("编辑岗位指标---------------12213------>",val)
            let sendContent ={
                id:val.id.toString(),
            }
            const res = await get_post_target(sendContent);
            // console.log("编辑岗位指标---------=------>",res)
            if(res.code == 0){
                this.searchPostName = res.data.postname
                this.editPostTargetCont = {
                    id:res.data.id.toString(),
                    title:res.data.title,
                    dimension:res.data.dimensionstr,
                    unit:res.data.unit,
                    type:res.data.type,
                    scoringmethod:res.data.scoringmethod,
                    cycle:res.data.cycle,
                    cycleattr:res.data.cycleattr
                }


                this.otherOrgList = [];
                if(res.data.otherposttarget != null && res.data.otherposttarget.length >0) {
                    // console.log("新增按钮->",res.data.)
                    res.data.otherposttarget.forEach(async items=>{
                        // this.searchPostName = items.postname
                        let sendCont = {
                            id:items.orgid.toString()
                        }
                        const resIng = await getOrgAndPostAry(sendCont)
                        // console.log("获取行政组织--------11212313---》》》",resIng);
                        this.otherOrgList.push({
                            orgId:resIng.data.orglist,
                            postId:items.postid,
                            postList:resIng.data.postlist,
                            operator:items.operator
                        })
                    })
                }else{
                    this.otherOrgList = [{
                        orgId:[],
                        postId:"",
                        postList:[],
                        // 多人员列表
                        operator:[]
                    }];
                }
            }
            this.editPostTargetBox = true
        },
        //关闭编辑指标弹窗
        closeEtitPostTargetBox(){
            this.editPostTargetBox = false
        },
        //提交岗位指标编辑数据
        async editPostTargetDialog(){
            this.$refs.editPostTagetForm.validate(async (valid) => {
                if (valid) {
                    //组装岗位与提报人员
                    let postAndMan = new Array
                    if(this.otherOrgList != null && this.otherOrgList.length > 0) {
                        this.otherOrgList.forEach((item,i)=>{
                            // console.log("提交新增岗位指标数据-"+i+"->",item)
                            if(item.orgId.length > 0 && item.orgId != 0 && item.postId != ""){
                                postAndMan.push({
                                    orgid:item.orgId[item.orgId.length -1],
                                    postid:item.postId,
                                    operator:item.operator.map(String)
                                })
                            }

                        });
                    }
                    console.log("提交新增岗位指标数据-&&&&->",postAndMan)
                    this.editPostTargetCont.cycleattr = parseInt(this.editPostTargetCont.cycleattr);
                    this.editPostTargetCont.otherposttarget= postAndMan
                    console.log("提交新增岗位指标数据-&&&&->",this.editPostTargetCont)
                    const res = await newEditPostTarget(this.editPostTargetCont)
                    if(res.code == 0){
                        this.getPosttargetList()
                    }
                    this.closeEtitPostTargetBox()

                }
            })
        },
        //获取岗位指标细则
        showPostTargetContList(val){
            console.log("获取岗位指标细则--->",val)
            this.postTargetInfo = val;
            this.detailsBox = true;
        },
        //关闭岗位指标细则弹出层
        closeDetailsBox(){
            this.detailsBox = false;
        },
    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-tree-node.is-current>.el-tree-node__content {
    color:#2E89DE!important
}
.el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
.allButton{
    width: 100%;
}
.el-container {
    height:calc(100% - 50px);
    overflow: hidden;
}
.el-aside {
    text-align: center;
    height: calc(100vh - 125px);
    overflow: hidden;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid rgb(220, 223, 230);
    padding: 0 5px 0 0px;
}
/*滚动条样式*/
.el-aside::-webkit-scrollbar {
    width: 4px;    
}
.el-aside::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    background: rgba(0,0,0,0.2);
}
.el-aside::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    border-radius: 0;
    background: rgba(0,0,0,0.1);
}
.el-main{
    height: calc(100vh - 125px);
    overflow: hidden;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 5px;
}
/*滚动条样式*/
.el-main::-webkit-scrollbar {
    width: 4px;    
}
.el-main::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    background: rgba(0,0,0,0.2);
}
.el-main::-webkit-scrollbar-track {
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
    border-radius: 0;
    background: rgba(0,0,0,0.1);
}
.gva-pagination{
    margin: 10px 0 0 0;
    text-align: center;
}
.tableContBox{
    //background-color: #000;
    height: calc(100vh - 240px);
    overflow: hidden;
    overflow-y: auto;
    overflow-x: hidden;
}
.el-button{
    min-width: 0px;

}
.dialogBox{
    
    min-width: 30%;
    max-width: 90%;
}
.perButtClass{
    margin-left: 10px;
}
.orgLink{
    font-size: 18px;
    
}
.orgTableLink{
    margin-top: 10px;
    margin-bottom: 10px;
}

.postGiveLink{
    width: 100%;
    border-bottom: 1px solid #DCDFE6;
    padding:0 0 5px 0;
}
</style>