<template>
        <div :style="'padding:20px 30px;background:#f7f7f7;min-height:'+tableHeight+'px;'">
        <div style="margin: 0 auto;width:1000px;">
            <el-row :gutter="20">
            <el-col :span="17" >
                <div class="box info">
                    <label>基本信息<el-link v-if="user.id == project.creatorId || user.id == project.inchargerId" @click="showEdit" style="float:right;"><i class="el-icon-edit"  ></i></el-link></label>
                    <el-row :gutter="10" >
                        <el-col :span="5" ><span class="gray_label">项目名称:</span></el-col><el-col :span="7" ><span >{{project.projectName}}</span></el-col>
                        <el-col :span="5" ><span class="gray_label">项目分类:</span></el-col><el-col :span="7" ><span >{{project.categoryName}}</span></el-col>
                    </el-row>
                    <el-row :gutter="10" >
                        <el-col :span="5" ><span class="gray_label">项目描述:</span></el-col><el-col :span="7" ></el-col>
                        <el-col :span="18" ><span>{{project.projectDesc}}</span></el-col>
                    </el-row>
                    <el-row :gutter="10">
                        <el-col :span="5" ><span class="gray_label">状态:</span></el-col><el-col :span="7" ><span >{{project.status==null?'-':statusTxt[project.status]}}</span></el-col>
                        <el-col :span="5" ><span class="gray_label">完成度: </span></el-col><el-col :span="7" ><span>
                            <el-progress  :percentage="project.progress == null?0:project.progress"></el-progress></span></el-col>
                    </el-row>
                    <el-row :gutter="10">
                        <el-col :span="5" ><span class="gray_label">项目编号: </span></el-col><el-col :span="7" ><span >{{project.projectCode}}&nbsp;</span></el-col>
                        <el-col :span="5" v-if="permissions.projectContract"><span class="gray_label">合同金额：</span></el-col>
                        <el-col :span="7" >
                        <span v-if="permissions.projectContract">{{project.contractAmount == null?'-':project.contractAmount | numberToCurrency}} 元</span></el-col>
                    </el-row>
                    <el-row :gutter="10">
                        <el-col :span="5" ><span class="gray_label">项目级别: </span></el-col><el-col :span="7" ><span >{{levelTxt[project.level]}}</span></el-col>
                        <el-col :span="5" ><span class="gray_label">创建日期:</span></el-col><el-col :span="7" ><span>{{project.createDate}}</span></el-col>
                    </el-row>
                    <el-row :gutter="10">
                        <el-col :span="5" ><span class="gray_label">计划开始日期：</span></el-col><el-col :span="7" >
                            <span >{{project.planStartDate==null?'-':project.planStartDate}}</span></el-col>
                        <el-col :span="5" ><span class="gray_label">计划结束日期:</span></el-col><el-col :span="7" ><span>
                            {{project.planEndDate == null?'-':project.planEndDate}}</span></el-col>
                    </el-row>
                    <el-row :gutter="10">
                        <el-col :span="5" ><span class="gray_label">实际完成日期:</span></el-col>
                        <el-col :span="7" ><span>{{project.finishDate==null?'-':project.finishDate}}</span></el-col>
                    </el-row>
                    <el-row :gutter="10" v-if="yonghuUser.customDegreeActive == 1">
                        <el-col :span="5" ><span class="gray_label">{{yonghuUser.customDegreeName}}:</span></el-col>
                        <el-col :span="18" ><span>{{project.associateDegreeNames}}</span></el-col>
                    </el-row>
                </div>
                <div class="box" style="margin-top:10px;">
                    <div><label>相关人员</label>
                    <el-link v-if="user.id == project.creatorId || user.id == project.inchargerId" @click="showEditPar" style="float:right;"><i class="el-icon-edit"  ></i></el-link>
                    </div>
                    <div style="margin-top:10px;color:#999;">负责人</div>
                    <div><el-link style="margin:10px" @click="showUser(project.inchargerId)">{{project.inchargerName}}</el-link></div>
                    <div style="margin-top:10px;color:#999;">日报审核人</div>
                    <div>
                        <span v-if="project.auditorList.length == 0" style="margin:10px;">-</span>
                        <el-link v-for="item in project.auditorList" :key="item.id" style="margin:10px;" @click="showUser(item.auditorId)">{{item.auditorName}}</el-link>
                    </div>
                   
                    <div v-show="project.isPublic == 0" style="color:#999;">参与人</div>
                    <div v-show="project.isPublic == 0" >
                        <el-link v-for="item in project.participationList" :key="item.id" style="margin:10px;" @click="showUser(item.id)">{{item.name}}</el-link>
                        <el-button class="el-icon-plus" @click="addMembVisible=true" size="mini"></el-button>
                    </div>
                </div>
                <!-- <div class="box info" style="margin-top:10px;" v-if="permissions.projectBaseline">
                    <div><label>成本基线<el-link v-if="permissions.projectCorrection" @click="showEditBase" style="float:right;"><i class="el-icon-edit"  ></i></el-link></label>
                    <el-row :gutter="10">
                        <div v-for="item in projectBaseCostData" :key="item.id">
                        <el-col :span="5" ><span class="gray_label">{{item.baseName}}:</span></el-col>
                        <el-col :span="7" align="right" ><span style="padding-right:20px;">
                            ￥{{item.baseAmount==null?'-':item.baseAmount | numberToCurrency}}</span></el-col>
                        </div>
                    </el-row>
                    </div>
                </div> -->
                <!--项目相关工程专业 -->
                <div class="box info" style="margin-top:10px;" v-if="user.company.packageEngineering == 1">
                    <div><label>相关工程专业<el-link v-if="user.id == project.creatorId || user.id == project.inchargerId" @click="showEditProfession" style="float:right;"><i class="el-icon-edit"  ></i></el-link></label>
                    <el-row :gutter="10" v-for="item in projectProfessionListOnPage" :key="item.id">
                        <el-col :span="5" ><span >{{item.professionName}}</span></el-col>
                        <el-col :span="2" ><span >{{item.percentage}}%</span></el-col>
                        <el-col :span="14" ><span style="margin: 0 5px;font-size:13px;" v-for="memb in item.membList" :key="memb">{{memb.membName}}({{memb.percentage}}%)</span></el-col>
                        <el-col :span="3" ><span >{{item.inchargerName}}</span></el-col>
                    </el-row>
                    </div>
                </div>

                <!--项目相关领导 -->
                <div class="box info" style="margin-top:10px;" >
                    <div><label>相关领导<el-link v-if="user.id == project.creatorId || user.id == project.inchargerId" @click="showChooseLeaderTree" style="float:right;"><i class="el-icon-edit"  ></i></el-link></label>
                    
                    </div>
                    <el-row :gutter="10">
                        <el-col :span="24" ><span v-for="item in chosenLeaders" :key="item.userId" style="margin-right:10px;">
                            <el-link @click="showUser(item.userId)">{{item.userName}}</el-link>
                        </span>
                        </el-col>
                    </el-row>
                    
                </div>

                <div class="box" style="margin-top:10px;">
                    <label>项目统计</label>
                    <div>
                        <el-row :gutter="10">
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">已完成</p>
                            <p style="font-size:20px;font-weight:bold;color:green;">{{taskSum.finishCount}}</p>
                        </el-col>
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">未完成</p>
                            <p style="font-size:20px;color:blue;font-weight:bold;">{{taskSum.unfinishCount}}</p>
                        </el-col>
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">已逾期</p>
                            <p style="font-size:20px;color:red;font-weight:bold;">{{taskSum.timeupCount}}</p>
                        </el-col>
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">待认领</p>
                            <p style="font-size:20px;color:#orange;font-weight:bold;">{{taskSum.unassignCount}}</p>
                        </el-col>
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">今日到期</p>
                            <p style="font-size:20px;font-weight:bold;color:pink;">{{taskSum.todayTimeupCount}}</p>
                        </el-col>
                        <el-col :span="4" style="text-align:center;">
                            <p style="color:#666;font-size:12px;">逾期完成</p>
                            <p style="font-size:20px;font-weight:bold;color:gray;">{{taskSum.timeupFinishCount}}</p>
                        </el-col>
                        </el-row>
                    </div>
                </div>
            </el-col>
            <el-col :span="7">
                <!--进度显示 -->
                <div v-if="user.company.packageEngineering == 1" style="margin-bottom:10px;background:#fff;border: 1px solid #eeeeee;border-radius:5px;min-height:305px;padding-left:5px;padding-right:5px;">
                    <p><i class="el-icon-odometer"></i><span style="margin-left:5px;">完成情况</span></p>
                    <el-divider></el-divider>
                    <el-row><el-col :span="12"><span>项目总进度</span></el-col>
                        <el-col :span="12"><el-progress :percentage="progressData.totalProjectProgress" ></el-progress></el-col></el-row>
                    <p style="font-size:12px;color:#666;">各专业进度</p>
                    <el-table :show-header="false" :data="progressData.professionList" row-key="id" size="small"  :tree-props="{children: 'membList', hasChildren: 'hasChildren'}">
                        <el-table-column
                        prop="professionName">
                        </el-table-column>
                        <el-table-column
                        prop="progress"
                        width="100">
                        <template slot-scope="scope">
                            <el-progress :percentage="scope.row.progress" ></el-progress>
                        </template>
                        </el-table-column>
                    </el-table>
                </div>
                
                <div style="background:#fff;border: 1px solid #eeeeee;border-radius:5px;min-height:547px;padding-left:5px;padding-right:5px;">
                    <div>
                    <p><i class="el-icon-trophy"></i><span style="margin-left:5px;">里程碑</span></p>
                    </div>
                    <el-timeline :reverse="reverse" style="padding-left: 3px;">
                        <el-timeline-item
                        v-for="(task, index) in mileStoneList"
                        :key="index"
                        :color="task.taskStatus==0?'#ddd':'#830BE2'"
                        size="large"
                        :timestamp="task.taskTex">
                        {{task.name}}
                        </el-timeline-item>
                    </el-timeline>
                </div>
            </el-col>
            </el-row>
        </div>
        <!--用户详细信息弹出框-->
        <el-dialog title="查看详情" v-if="userDetailVisible" :visible.sync="userDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
            <div class="line"><span>姓名</span><span>{{userDetail.name}}</span></div>
            <div class="line"><span>手机号码</span><span>{{userDetail.phone}}</span></div>
            <div class="line"><span>角色</span><span>{{roleArray[userDetail.role]}}</span></div>
            <div class="line"><span>部门</span><span>{{userDetail.departmentName}}</span></div>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="userDetailVisible = false" >确定</el-button>
            </div>
        </el-dialog>

        
        <!--编辑基本信息界面-->
        <el-dialog title="项目基本信息" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
            <el-form ref="basicInfoForm" :model="addForm" :rules="rules" label-width="120px">
                <el-form-item label="项目编号" >
                    <el-input v-model="addForm.code"  placeholder="请输入项目编号" clearable></el-input>
                </el-form-item>
                <el-form-item label="项目名称" prop="name">
                    <el-input v-model="addForm.name"  placeholder="请输入项目名称" clearable></el-input>
                </el-form-item>
                <el-form-item label="项目描述" prop="name">
                    <el-input type="textarea" :rows="2" v-model="addForm.projectDesc" maxlength="50" show-word-limit  placeholder="请输入项目描述" clearable></el-input>
                </el-form-item>
                <el-form-item label="级别" >
                    <el-select v-model="addForm.level"  placeholder="请选择级别" style="width:32%;" >
                        <el-option v-for="item in importanceList" :key="item.id" :label="item.label" :value="item.id"></el-option>
                    </el-select>
                    <span style="margin-left:50px;margin-right:10px;">合同金额</span>
                    <el-input v-model="addForm.contractAmount"  id="contractAmount"  style="width:32%;"
                    placeholder="整数" clearable @keyup.native="restrictNumber('contractAmount')"></el-input><span style="margin-left:10px;">元</span>
                </el-form-item>
                <el-form-item label="开始日期" prop="planStartDate">
                    <el-date-picker v-model="addForm.planStartDate" 
                     :editable="false" 
                     format="yyyy-MM-dd" 
                     value-format="yyyy-MM-dd"
                     :clearable="false" type="date" 
                     placeholder="选择日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="截止日期" prop="planEndDate">
                    <el-date-picker v-model="addForm.planEndDate" 
                     :editable="false" 
                     format="yyyy-MM-dd" 
                     value-format="yyyy-MM-dd"
                     :clearable="false" type="date" 
                     placeholder="选择日期"></el-date-picker>
                </el-form-item>

                <!-- 研究中心 -->
                <el-form-item :label="yonghuUser.customDegreeName" v-if="user.timeType.customDegreeActive != 0">
                    <el-select v-model="auseList" multiple placeholder="请选择" filterable="true" style="width: 100%">
                        <span v-for="(item, index) in ause" :key="index">
                        <el-option :label="item.name" :value="item.id"></el-option>
                        </span> 
                    </el-select>
                </el-form-item>
               
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addFormVisible = false">取消</el-button>
                <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <el-dialog title="校正成本基线" v-if="addBaseFormVisible" :visible.sync="addBaseFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
            <el-form ref="basicInfoForm" label-width="120px">
                <el-form-item v-for="(item, index) in modBaseCostData" :label="item.baseName" :key="item.id">
                    <el-input :id="'baseCost'+index" v-model="item.baseAmount"  placeholder="请输入" clearable  @keyup.native="restrictNumber('baseCost'+index)"></el-input>
                </el-form-item>
                <el-form-item label="备注" >
                    <el-input v-model="remark"  placeholder="请输入校正原因" ></el-input>
                </el-form-item>
            </el-form>
            
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addBaseFormVisible = false">取消</el-button>
                <el-button type="primary" @click="adjustBase" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--编辑参与人界面-->
        <el-dialog title="编辑参与人员" v-if="pVisible" :visible.sync="pVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
            <el-form ref="participForm" :model="addForm" :rules="rules" label-width="120px">
                <el-form-item label="全部参与者">
                    <el-select v-model="addForm.userId" multiple filterable placeholder="请选择参与者" style="width:100%;" @change="changeParticipator">
                        <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="主要负责人" >
                    <el-select v-model="addForm.inchargerId"  filterable placeholder="请选择负责人" style="width:100%;" >
                        <el-option v-for="item in project.participationList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="pVisible = false">取消</el-button>
                <el-button type="primary" @click="submitParticip" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--添加参与人界面-->
        <el-dialog title="添加参与人" v-if="addMembVisible" :visible.sync="addMembVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
            <el-form ref="addMembForm" :model="addMembForm"  label-width="120px">
                <el-form-item label="新增参与者">
                    <el-select v-model="addMembForm.userId" multiple filterable placeholder="请选择参与者" style="width:100%;" >
                        <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="addMembVisible = false">取消</el-button>
                <el-button type="primary" @click="submitAddMemb" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <!--修改工程专业界面-->
        <el-dialog title="工程专业" v-if="editProfessionDialog" :visible.sync="editProfessionDialog" 
        :close-on-click-modal="false" customClass="customWidth" width="1000px">
            <el-table :data="projectProfessionList" size="small" max-height="400" :key="Math.random()">
                <el-table-column prop="professionId" width="200">
                                   <template slot-scope="scope">
                                       <el-select v-model="scope.row.professionId" >
                                           <el-option v-for="item in professionList" :key="item.id" :label="item.name" :value="item.id"/>
                                       </el-select>
                                   </template>
                                   <template slot="header" >
                                       <span style="font-size:14px;font-weight:normal;">专业名称</span>
                                   </template>
                               </el-table-column>
                               <el-table-column prop="percentage" width="100" label="占比">
                                   <template slot-scope="scope">
                                       <el-input type="number" v-model="scope.row.percentage"></el-input>
                                   </template>
                               </el-table-column>
                               
                               <el-table-column prop="membNames" label="相关人员及占比">
                                   <template slot-scope="scope">
                                       <span style="margin:0 5px;" v-for="item in scope.row.membList" :key="item.membId">{{item.membName}}({{item.percentage}}%)</span>
                                       <el-link @click="showEditPpMembs(scope.row)">{{(scope.row.membList == null || scope.row.membList.length == 0)?'设置专业参与人员':'设置'}}</el-link>
                                   </template>
                               </el-table-column>
                               <el-table-column prop="inchargerName" width="120" label="负责人">
                                   <template slot-scope="scope">
                                       <el-select v-model="scope.row.inchargerId" >
                                           <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id">
                                               
                                           </el-option>
                                       </el-select>
                                   </template>
                               </el-table-column>
                               <el-table-column  width="80">
                                   <template slot-scope="scope">
                                       <el-button icon="el-icon-delete" size="mini" style="margin-left:10px;" @click.stop.native="deleteItem(scope.$index)"></el-button>
                                   </template>
                                   <template slot="header" >
                                       <el-link type="primary" :underline="false" @click="addItem">添加</el-link>
                                   </template>
                               </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editProfessionDialog = false">取消</el-button>
                <el-button type="primary" @click="saveProjectProfessions" :loading="addLoading">提交</el-button>
            </div>
        </el-dialog>

        <!-- 项目专业人员的设置 -->
        <el-dialog title="设置项目专业人员"  v-if="editPpMembDialog" :visible.sync="editPpMembDialog" :close-on-click-modal="false" customClass="customWidth" width="600px">
            <el-table :data="curProfessionRow.membList" height="400">
                <el-table-column prop="name" label="专业人员">
                    <template slot-scope="scope">
                        <el-select v-model="scope.row.membId"  filterable placeholder="请选择专业参与人" style="width:100%;" >
                            <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column prop="percentage" width="120" label="占比(%)">
                    <template slot-scope="scope">
                        <el-input type="number" v-model="scope.row.percentage"></el-input>
                    </template>
                </el-table-column>
                <el-table-column  width="80">
                    <template slot-scope="scope">
                        <el-button icon="el-icon-delete" size="mini" style="margin-left:10px;" @click.stop.native="deleteMembItem(scope.$index)"></el-button>
                    </template>
                    <template slot="header" >
                        <el-link @click="addMembItem">添加</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
                <el-button  @click="editPpMembDialog = false" >取消</el-button>
                <el-button type="primary" @click="addPpMemb" >确定</el-button>
            </div>
        </el-dialog>

        
        <!-- 按部门选择相关领导 -->
        <el-dialog title="选择相关领导"  v-if="chooseLeaderVisible" :visible.sync="chooseLeaderVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
            <!-- <el-input style="width:100%" v-model="filterName" placeholder="请输入姓名搜索" @change="findUserInTree"></el-input> -->
            <div class="tree" style="height:400px">
                <el-scrollbar style="height:100%">
                <el-tree :data="deptMembData" show-checkbox :props="defaultProps" node-key="id"
                    ref="chooseLeaderTree" @check-change="onLeaderTreeItemChange" :default-checked-keys="addForm.notifyUserIds"
                    highlight-current ></el-tree>
                </el-scrollbar>
            </div>
            <div>已选中&nbsp;{{chosenMembCount}}&nbsp;人</div>
            <div slot="footer" class="dialog-footer">
                <el-button  @click="chooseLeaderVisible = false" >取消</el-button>
                <el-button type="primary" @click="chooseLeader()" >确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style scoped>
.fileTypeIcon {
    color:#20a0ff;font-size:20px;

}
.box {
    background:#fff;border: 1px solid #eeeeee;border-radius:5px;padding:10px;
}
.info span {
    color:#303133;
}
.gray_label {
    color:#999 !important;
}

.el-row {
    margin-top:10px;
}
.line {
    padding:10px;
}
.line span{
    font-size:15px;
}
.line span:nth-child(even){
    float:right;
}
</style>
<script>
    import util from "../../common/js/util";
    export default {
        data() {
            return {
                permissions: JSON.parse(sessionStorage.getItem("permissions")),
                remark:null,
                progressData:{},
                deptMembData: [
                    {
                        id: 0,
                        label: '未分配',
                    }
                ],
                chosenMembCount:0,
                chosenLeaders:[],
                chooseLeaderVisible:false,
                projectProfessionItem:null,
                curProfessionRow:null,
                editPpMembDialog:false,
                professionList:[],
                editProfessionDialog: false,
                projectProfessionList:[],
                modBaseCostData:[],
                projectBaseCostData:[],
                roleArray:["普通员工","超级管理员", "系统管理员", "公司高层","财务管理员", "项目管理员"],
                addBaseFormVisible:false,
                addMembVisible:false,
                addMembForm:{},
                pVisible:false,
                taskSum:{},
                participator:[],
                users:[],
                addForm:{},
                addFormVisible:false,
                userDetail:{},
                userDetailVisible: false,
                importanceList:[{id:1,label:'正常'},{id:2,label:'紧急'},{id:3,label:'重要'},{id:4,label:'重要且紧急'}],
                //1-一般,2-紧急,3-重要,4-重要且紧急
                levelTxt:["全部","正常","紧急","重要","重要且紧急"],
                //1-进行中,2-已完成,3-已撤销
                statusTxt: ["全部","进行中","已完成","已撤销"],
                mileStoneList:[],
                reverse:false,
                project:{},
                addFolderDialog: false,
                upLoading:false,
                keyword:null,
                user: JSON.parse(sessionStorage.getItem("user")),
                recentFiles: [],
                addLoading: false,
                curProjectId:null,
                title: "",
                rules: {
                    name: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
                },
                yonghuUser: [],
                ause: [], // 研究中心总数据
                auseList: [], // 选中的研究中心
            };
        },
        filters: {
            numberToCurrency(value) {
                console.log('info numberToCurrency='+value);
                if (!value || value=='-') return '0.00'
                value = value.toFixed(2)
                const intPart = Math.trunc(value)
                const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
                let floatPart = '.00'
                const valueArray = value.toString().split('.')
                if (valueArray.length === 2) { // 有小数部分
                floatPart = valueArray[1].toString() // 取得小数部分
                return intPartFormat + '.' + floatPart
                }
                return intPartFormat + floatPart
            }
        },
        methods: {
            yanjiuzx() {
                this.http.post('/report-extra-degree/getAll ',{},
                res => {
                    if (res.code == "ok") {
                        this.ause = res.data
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            userssHu() {
                this.http.post('/time-type/getCompanyTimeSetting',{ 
                    companyId: this.user.companyId
                },
                res => {
                    if (res.code == "ok") {
                        this.yonghuUser = res.data
                        console.log(this.yonghuUser)
                    } 
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
            },
            getProgressData() {
                this.http.post("/project-profession/getProgressData", {projectId: this.curProjectId},
                    res => {
                        if (res.code == "ok") {
                            this.progressData = res.data;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },
            setUserToDept(list) {
                for (var i in list) {
                    if (list[i].children != null) {
                        this.setUserToDept(list[i].children);
                    }
                    
                    if (list[i].userList != null) {
                        if (list[i].children == null) {
                            list[i].children = [];
                        }
                        list[i].userList.forEach(element => {
                            var obj = {id: element.id, label:element.name, parentId:element.departmentId, isUser:1};
                            list[i].children.push(obj);
                        });
                    }
                }
            },
            
            // 获取部门列表
            getDepartment() {
                this.http.post("/department/listAllMemb", {},
                res => {
                    if (res.code == "ok") {
                        var list = res.data;
                        //设置员工到部门下面
                        this.setUserToDept(list);
                        this.deptMembData = list;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            getProjectNotifyUserList(projectId) {
                this.http.post("/project-notify-user/get", {projectId: projectId},
                    res => {
                        if (res.code == "ok") {
                            var chosenLeaderIds = [];
                            var chosenLeaderNames = '';
                            var leaderList = res.data;
                            this.chosenLeaders = leaderList;
                            for(var j in leaderList) {
                                chosenLeaderIds.push(leaderList[j].userId)
                                chosenLeaderNames += leaderList[j].userName+',';
                            }
                            if (chosenLeaderNames.length > 0) {
                                chosenLeaderNames = chosenLeaderNames.substring(0, chosenLeaderNames.length -1);
                            }
                            this.addForm.notifyUserIds = chosenLeaderIds;
                            this.addForm.notifyUserNames = chosenLeaderNames;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },
            showChooseLeaderTree() {
                this.chosenMembCount = this.chosenLeaders.length;
                this.chooseLeaderVisible = true;
            },
            onLeaderTreeItemChange() {
                var chosenList = this.$refs.chooseLeaderTree.getCheckedNodes();
                var list = chosenList.filter(item=>item.isUser == 1);
                this.chosenMembCount = list.length;
            },
            //选中相关领导
            chooseLeader() {
                this.chooseLeaderVisible = false;
                var chosenList = this.$refs.chooseLeaderTree.getCheckedNodes();
                var chosenMembList = chosenList.filter(item=>item.isUser == 1);
                this.addForm.notifyUserNames = '';
                this.addForm.notifyUserIds = [];
                this.chosenLeaders = [];
                for (var i=0;i<chosenMembList.length; i++) {
                    this.addForm.notifyUserIds.push(chosenMembList[i].id);
                    this.addForm.notifyUserNames += chosenMembList[i].label+',';
                    var item = {userId:chosenMembList[i].id, userName:chosenMembList[i].label};
                    this.chosenLeaders.push(item);
                }
                if (this.addForm.notifyUserNames.length > 0) {
                    this.addForm.notifyUserNames = this.addForm.notifyUserNames.substring(0, this.addForm.notifyUserNames.length-1);
                }
                //提交数据修改
                this.http.post("/project-notify-user/modify", {projectId: this.curProjectId, chosenLeaders: JSON.stringify(this.chosenLeaders)},
                res => {
                    if (res.code == "ok") {
                        
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },

            restrictNumber(targetId) {
                let inpu = document.getElementById(targetId);
                inpu.value = inpu.value.replace(/[^\d.]/g, "");  //仅保留数字和"."
                inpu.value = inpu.value.replace(/\.{2,}/g, "."); //两个连续的"."仅保留第一个"."
                inpu.value = inpu.value.replace(".", "$#*").replace(/\./g,'').replace('$#*','.');//去除其他"."
                inpu.value = inpu.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');;//限制只能输入两个小数
                if (inpu.value.indexOf(".") < 0 && inpu.value != "") { //首位是0的话去掉
                    inpu.value = parseFloat(inpu.value);
                }
            },
            addPpMemb() {
                //检查合计比例是否到达100%
                let p = 0;
                let hasNoMemb = false;

                this.curProfessionRow.membList.forEach(m=>{
                    p += parseInt(m.percentage);
                    //检查人员是否选择
                    if (m.membId == null) {
                        hasNoMemb = true;
                    }
                });
                if (hasNoMemb) {
                    this.$message({
                            message: '专业人员不能为空',
                            type: "error"
                        });
                    return;
                }
                //检查人员不能重复
                let hasDuplicate = false;
                this.curProfessionRow.membList.forEach(m=>{
                    if (this.curProfessionRow.membList.filter(innerM=>innerM.membId == m.membId).length>1) {
                        hasDuplicate = true;
                    }
                });
                if (hasDuplicate) {
                    this.$message({
                            message: '专业人员不能重复',
                            type: "error"
                        });
                    return;
                }
                if (p != 100) {
                    this.$message({
                            message: '占比合计必须是100%',
                            type: "error"
                        });
                    return;
                }
                

                this.editPpMembDialog = false;
                this.curProfessionRow.membList.forEach(m=>{
                    m.membName = this.participator.filter(p=>p.id == m.membId)[0].name;
                });
                this.projectProfessionItem.membList = JSON.parse(JSON.stringify(this.curProfessionRow.membList));
            },
            //删除专业人员
            deleteMembItem(index) {
                this.curProfessionRow.membList.splice(index,1);
            },
            //添加专业人员
            addMembItem() {
                if (this.curProfessionRow.membList == null) {
                    this.curProfessionRow.membList = [{membId:null, percentage:100}];
                } else {
                    let p = 0;
                    this.curProfessionRow.membList.forEach(m=>{
                        p += parseInt(m.percentage);
                    });
                    this.curProfessionRow.membList.push({membId:null, percentage:100-p});
                }
                this.$forceUpdate();
            },
            showEditPpMembs(row) {
                this.projectProfessionItem = row;
                this.curProfessionRow = JSON.parse(JSON.stringify(row));
                if (this.curProfessionRow.membList == null || this.curProfessionRow.membList.length == 0) {
                    this.curProfessionRow.membList = [{membId:null, percentage:100}];
                } 
                this.editPpMembDialog = true;
            },
            checkProjectProfession() {
                //检查合计比例是否到达100%
                let p = 0;
                let hasNoMemb = false;
                let hasNoProfession = false;
                let hasNoMembList = false;
                this.projectProfessionList.forEach(m=>{
                    p += parseInt(m.percentage);
                    //检查人员是否选择
                    if (m.inchargerId == null) {
                        hasNoMemb = true;
                    }
                    if (m.professionId == null) {
                        hasNoProfession = true;
                    }
                    if (m.membList == null) {
                        hasNoMembList = true;
                    }
                });
                
                if (hasNoProfession) {
                    this.$message({
                            message: '专业不能为空',
                            type: "error"
                        });
                    return false;
                }
                if (hasNoMembList) {
                    this.$message({
                            message: '专业相关人员不能为空',
                            type: "error"
                        });
                    return false;
                }
                
                if (hasNoMemb) {
                    this.$message({
                            message: '专业负责人不能为空',
                            type: "error"
                        });
                    return false;
                }
                //检查专业不能重复
                let hasDuplicate = false;
                this.projectProfessionList.forEach(m=>{
                    if (this.projectProfessionList.filter(innerM=>innerM.professionId == m.professionId).length>1) {
                        hasDuplicate = true;
                    }
                });
                if (hasDuplicate) {
                    this.$message({
                            message: '专业不能重复',
                            type: "error"
                        });
                    return false;
                }
                if (p != 100) {
                    this.$message({
                            message: '专业占比合计必须是100%',
                            type: "error"
                        });
                    return false;
                }
                return true;
            },
            showEditProfession() {
                if (this.professionList.length == 0) {
                    this.getProfessionList();
                }
                this.projectProfessionList = JSON.parse(JSON.stringify(this.projectProfessionListOnPage));
                this.editProfessionDialog = true;
            },
            getProjectProfessionList() {
                this.http.post("/project-profession/get", {projectId: this.curProjectId},
                    res => {
                        if (res.code == "ok") {
                            this.projectProfessionListOnPage = res.data;
                        } else {
                            this.$message({
                                message: res.msg,
                                type: "error"
                            });
                        }
                    },
                    error => {
                        this.$message({
                            message: error,
                            type: "error"
                        });
                    });
            },
            //保存项目专业
            saveProjectProfessions() {
                if (!this.checkProjectProfession()) {//检查不通过，直接返回
                    return;
                }
                let projectId = this.curProjectId;
                var list = this.projectProfessionList.filter(p=>p.professionId != null);
                list.forEach(p=>p.inchargerName = this.participator.filter(m=>m.id == p.inchargerId)[0].name);
                list.forEach(p=>p.professionName = this.professionList.filter(m=>m.id == p.professionId)[0].name);
                this.http.post("/project-profession/modify", {projectId: projectId, json: JSON.stringify(list)},
                res => {
                    if (res.code == "ok") {
                        this.editProfessionDialog = false;
                        this.projectProfessionListOnPage = res.data;
                        this.$message({
                            message: '修改成功',
                            type: "success"
                        });
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            //删除项目专业
            deleteItem(index) {
                this.projectProfessionList.splice(index,1);
            },
            //添加项目专业
            addItem() {
                let p = 0;
                this.projectProfessionList.forEach(m=>{
                    p += parseInt(m.percentage);
                });
                this.projectProfessionList.push( { professionId:null, inchargerId:null,membIds:[], percentage: 100-p});
            },
            getProfessionList() {
                this.http.post("/profession/getAll", {},
                res => {
                    if (res.code == "ok") {
                        var list = res.data;
                        this.professionList = list;
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getProjectBaseData(projectId) {
                this.http.post('/project-basecost/get',{projectId: projectId},
                        res => {
                            if (res.code == "ok") {
                               this.projectBaseCostData = res.data;
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.$message({
                                message: error,
                                type: "error"
                            });
                            }
                        );
            },
            adjustBase() {
                //如果没有做修改，不提交数据
                var hasChangeData = false;
                for (var i=0;i<this.modBaseCostData.length; i++) {
                    var item = this.modBaseCostData[i];
                    var oldAmount = this.projectBaseCostData.filter(p=>p.id == item.id)[0].baseAmount;
                    if (item.baseAmount != oldAmount) {
                        hasChangeData = true;
                        break;
                    }
                }
                if (!hasChangeData) {
                    this.addBaseFormVisible = false;
                    return;
                }
                this.http.post('/project/adjustBase', {
                    id: this.addForm.id,
                    contractAmount: this.addForm.contractAmount,
                    baseCostData:JSON.stringify(this.modBaseCostData),
                    remark: this.remark
                },
                res => {
                    if (res.code == "ok") {
                        this.getProjectBaseData(this.curProjectId);
                        this.addBaseFormVisible = false;
                        this.$message({
                            message: '校正成功',
                            type: "success"
                        });
                        this.$emit("basecost-change", null);
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            //提交添加参与人的请求
            submitAddMemb() {
                this.addLoading = true;
                let formData = new FormData();
                formData.append("id", this.curProjectId);
                console.log(this.addMembForm.userId, '要传过去的数据')
                if(this.addMembForm.userId.length != 0) {
                    for(var j in this.addMembForm.userId) {
                        formData.append("userId", this.addMembForm.userId[j]);
                    }
                } else {
                    this.addLoading = false;
                    this.$message({
                        message: '请选择参与者',
                        type: 'warning'
                    });
                    return
                }
                // return
                this.http.uploadFile('/project/addMemb',formData,
                res => {
                    this.addLoading = false;
                    if (res.code == "ok") {
                        this.$message({
                            message: "添加成功",
                            type: "success"
                        });
                        this.addMembForm.userId = []
                        this.addMembVisible = false;
                        this.getProjectInfo();
                        this.$parent.$parent.$parent.getDetail(); // 调用父级页面的方法
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.addLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getProjectTaskSum() {
                this.http.post('/project/taskSum', {
                    id: this.curProjectId
                },
                res => {
                    if (res.code == "ok") {
                        this.taskSum = res.data;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            number(){　　
        　　　  this.addForm.contractAmount = this.addForm.contractAmount.replace(/[^\.\d]/g,'');
                this.addForm.contractAmount = this.addForm.contractAmount.replace('.','');
        　　},
            //选择参与人
            changeParticipator() {
                //检查是否在参与人中，如果没有需要加入到参与人中
                console.log(this.addForm.userId);
                var find = false;
                this.project.participationList = [];
                this.addForm.userId.forEach(u=>{
                    var findUser = this.users.filter(au=>au.id == u)[0];
                    this.project.participationList.push(findUser);
                })
                
            },
            getUsers() {
                this.http.post(this.port.manage.list, {
                    departmentId: -1,
                    pageIndex: 1,
                    pageSize: -1
                    // pageSize: 99999
                },
                res => {
                    if (res.code == "ok") {
                        this.users = res.data.records;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            submitParticip() {
                this.addLoading = true;
                let formData = new FormData();
                if(this.addForm.id != null) {
                    formData.append("id", this.addForm.id);
                }
                formData.append("name", this.addForm.name);
                if(this.addForm.userId.length != 0) {
                    for(var j in this.addForm.userId) {
                        formData.append("userId", this.addForm.userId[j]);
                    }
                }
                if(this.addForm.inchargerId != null) {
                    formData.append("inchargerId", this.addForm.inchargerId);
                }
                
                this.http.uploadFile(this.port.project.add,formData,
                res => {
                    this.addLoading = false;
                    if (res.code == "ok") {
                        this.$message({
                            message: '修改成功',
                            type: "success"
                        });
                        this.pVisible = false;
                        this.getProjectInfo();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.addLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            submitInsert() {
                this.$refs.basicInfoForm.validate(valid => {
                    if (valid) {
                        this.addLoading = true;
                        let formData = new FormData();
                        formData.append("name", this.addForm.name);
                        if(this.addForm.id != null) {
                            formData.append("id", this.addForm.id);
                        }
                        if(this.addForm.userId.length != 0) {
                            for(var j in this.addForm.userId) {
                                formData.append("userId", this.addForm.userId[j]);
                            }
                        }
                        if(this.addForm.inchargerId != null) {
                            formData.append("inchargerId", this.addForm.inchargerId);
                        }
                        if(this.addForm.code != null) {
                            formData.append("code", this.addForm.code);
                        }
                        if(this.addForm.planStartDate != null) {
                            formData.append("planStartDate", this.addForm.planStartDate);
                        }
                        if(this.addForm.planEndDate != null) {
                            formData.append("planEndDate", this.addForm.planEndDate);
                        }
                        if(this.addForm.level != null) {
                            formData.append("level", this.addForm.level);
                        }
                        if(this.addForm.contractAmount != null) {
                            formData.append("contractAmount", this.addForm.contractAmount);
                        }
                        if(this.addForm.projectDesc != null) {
                            formData.append("projectDesc", this.addForm.projectDesc);
                        }
                        var listId = []
                        var listName = []
                        if(this.auseList.length > 0) {
                            for(var l in this.auseList) {
                                for(var o in this.ause) {
                                    if(this.auseList[l] == this.ause[o].id) {
                                        listId.push(this.ause[o].id)
                                        listName.push(this.ause[o].name)
                                        break;
                                    }
                                }
                            }
                        }
                        listId.toString()
                        listName.toString()
                        console.log(listId, listName)
                        formData.append("associateDegrees", listId)
                        formData.append("associateDegreeNames", listName)
                        // return
                        this.http.uploadFile(this.port.project.add,formData,
                        res => {
                            this.addLoading = false;
                            if (res.code == "ok") {
                                this.$message({
                                    message: (this.addForm.id!=null?'修改':'创建')+"成功",
                                    type: "success"
                                });
                                this.addFormVisible = false;
                                this.getProjectInfo();
                            } else {
                                this.$message({
                                    message: res.msg,
                                    type: "error"
                                });
                            }
                        },
                        error => {
                            this.addLoading = false;
                            this.$message({
                                message: error,
                                type: "error"
                            });
                        });
                        }
                });
            },
            
            showEdit() {
                this.addForm = JSON.parse(JSON.stringify(this.project));
                console.log('---'+this.project);
                console.log(this.addForm.projectCode);
                
                var list = this.project.participationList , arr = [];
                for(var j in list) {
                    arr.push(list[j].id)
                }
                this.$set(this.addForm,'code',this.addForm.projectCode)
                this.$set(this.addForm,'name',this.addForm.projectName)
                this.addForm.userId = arr
                this.addFormVisible = true;
                console.log(this.addForm, 123)
                var arr = []
                if(this.addForm.associateDegrees.length > 0) {
                    if(this.addForm.associateDegrees.length == 1) {
                        var sl = +this.addForm.associateDegrees + 0
                        arr.push(sl)              
                    } else {
                        var spl =  this.addForm.associateDegrees.split(',')
                        for(var i in spl) {
                            var ss  = +spl[i] + 0
                            arr.push(ss)
                        }
                    }
                } else {
                    arr = []
                }
                this.auseList = arr
            },
            showEditPar() {
                this.addForm = JSON.parse(JSON.stringify(this.project));
                this.addForm.code = this.addForm.projectCode;
                this.addForm.name = this.addForm.projectName;
                //设置参与人
                var list = this.project.participationList , arr = [];
                for(var j in list) {
                    arr.push(list[j].id)
                }
                this.addForm.userId = arr;
                console.log(this.addForm.userId );

                this.pVisible = true;
                
            },
            //显示用户详情
            showUser(userId) {
                this.userDetailVisible = true;
                this.http.post(this.port.manage.userDetail, {
                    userId: userId
                },
                res => {
                    if (res.code == "ok") {
                        this.userDetail = res.data;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            cursorOver(row, column, cell, event) {
                this.currentDataId = row.id;
            },
            viewOnline(row) {
                this.http.post('/pdf-file/getProjectFile', {fileId: row.id},
                res => {
                    if (res.code == "ok") {
                        console.log(res.data+'----'+row.documentName);
                        let routeUrl = this.$router.resolve({
                            path: "/viewonline",
                            params: {serverFname:res.data, fileName:row.documentName}
                        });
                        sessionStorage.setItem("serverFname",res.data);
                        sessionStorage.setItem("fileName",row.documentName);
                        console.log(routeUrl.href);
                        window.open(routeUrl.href, '_blank');
                    } else {
                        this.$message({
                            message: res.msg,
                            type: 'error'
                        });
                    }
                }, error => {
                    this.$message({
                        message: error,
                        type: 'error'
                    });
                })
            },
            

            openWin(url) {
                var el = document.createElement("a");
                document.body.appendChild(el);
                el.href = encodeURI(url); 
                el.target = '_blank'; 
                el.click();
                document.body.removeChild(el);
            },

            //获取里程碑文件
            getMileStoneList() {
                this.http.post('/task/getMileStoneList', {
                    projectId: this.curProjectId,
                },
                res => {
                    if (res.code == "ok") { 
                        console.log(res.data, '里程碑数据')
                        for(var i in res.data) {
                            // if(res.data[i].taskStatus == 1) {
                            //     res.data[i].taskTex = '完成于 ' + res.data[i].finishDate
                            // } else {
                            //     res.data[i].taskTex = '截止于 ' + res.data[i].endDate
                            // }
                            if(res.data[i].finishDate) {
                                res.data[i].taskTex = '完成于 ' + res.data[i].finishDate
                            } else if(res.data[i].endDate) {
                                res.data[i].taskTex = '截止于 ' + res.data[i].endDate
                            } else {
                                res.data[i].taskTex = ''
                            }

                        }
                        this.mileStoneList = res.data;
                        this.mileStoneList.unshift( {id:-1, name:'开始', taskStatus:1});
                        
                        
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },
            getUsers() {
                this.http.post(this.port.manage.list, {
                    departmentId: -1,
                    pageIndex: 1,
                    // pageSize: 99999
                    pageSize: -1
                },
                res => {
                    if (res.code == "ok") {
                        this.users = res.data.records;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            },


            //获取列表
            getProjectInfo() {
                this.listLoading = true;
                this.http.post('/project/detail', {
                    id: this.curProjectId
                },
                res => {
                    this.listLoading = false;
                    if (res.code == "ok") {
                        this.project = res.data;
                        console.log('test123',this.project);
                        this.participator = this.project.participationList;
                    } else {
                        this.$message({
                        message: res.msg,
                        type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
                this.getProjectProfessionList();
            },
            refreshPage() {
                this.curProjectId = parseInt(this.$route.params.id);
                this.getMileStoneList();
                this.getProjectInfo();
                this.getProjectTaskSum();
                this.getProjectBaseData(this.curProjectId);
                this.getProjectNotifyUserList(this.curProjectId);
                this.getProgressData();
            }
        },
        created() {
            console.log('created===');
            let height = window.innerHeight;
            this.tableHeight = height - 160;
            const that = this;
            window.onresize = function temp() {
                that.tableHeight = window.innerHeight - 160;
            };
        },
        mounted() {
            console.log('mounted===');
            this.curProjectId = parseInt(this.$route.params.id);
            this.getDepartment();
            this.getUsers();

            this.getMileStoneList();
            this.getProjectInfo();
            this.getProjectTaskSum();
            this.getProjectBaseData(this.curProjectId);
            this.getProjectNotifyUserList(this.curProjectId);
            this.getProgressData();
            this.userssHu()
            this.yanjiuzx()
        }
    };
</script>