<template>
    <section>
        <!--工具条 top-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true">
                <el-form-item >
                    <!-- <div style="display: flex;align-items: center;height: 40px;"> -->
                    <div v-if="true" style="display: flex;align-items: center;height: 40px;">
                    <el-input v-model="keyword" class="input-with-select" @keyup.enter.native="searchList" :placeholder="searchField == '1' ? $t('peaseenterthe') : $t('peaseenterthe')" clearable="true" size="small">
                        <el-select v-model="searchField" style="width:120px;"  slot="prepend" :placeholder="$t('defaultText.pleaseChoose')">
                            <el-option :label="$t('headerTop.projectName')" value=1 ></el-option>
                            <el-option :label="user.companyId == '7030' ? '项目令号' : $t('Itemno')" value=2 ></el-option>
                        </el-select>
                        <el-button slot="append" @click="searchList" icon="el-icon-search"></el-button>
                    </el-input>
                    </div>
                </el-form-item>
                <!-- 分类筛选 -->
                <el-form-item >
                    <span style="margin-left:5px;margin-right:5px;color:#606266;">{{ $t('fen-lei') }}</span>
                    <el-select v-model="statusClf" style="width:140px;"  :placeholder="$t('defaultText.pleaseChoose')" clearable @change="searchClfList" size="small">
                        <el-option v-for="item in baseClfList" :key="item.id" :label="item.name" :value="item.id" ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item style="float:right;">
                    <el-link type="primary" :underline="false" @click="handleAdd(-1,null)">{{'新增'}}</el-link>
                    <el-link type="primary" v-if="permissions.projectApprovalEdit||permissions.projectApprocalImport" style="margin-right:10px;" :underline="false" @click="importDialog=true">{{'导入'}}</el-link>
                    <el-link type="primary" v-if="permissions.projectApprovalEdit||permissions.projectApprocalExport" style="margin-right:10px;" :underline="false" @click="exportData()">{{'导出'}}</el-link>
                </el-form-item>
            </el-form>
        </el-col>
        <div style="display: flex;width: 100%;">
                <div class="classification">
                    <div>
                        <p :class="idx == 0 ? 'on' : ''" @click="switchs(0)" v-if="permissions.projectApprovalEdit">{{'全部项目'}}</p>
                        <p :class="idx == 1 ? 'on' : ''" @click="switchs(1)">{{'我发起的'}}</p>
                        <!-- <p :class="idx == 2 ? 'on' : ''" @click="switchs(2)">{{'我审核的'}}</p> -->
                    </div>
                </div>
                <div style="max-width: 94%;min-width: 90%">
                    <el-table ref="projectlistOfWudulist" border @cell-mouse-enter="hoverCall" @cell-mouse-leave="handCall" :cell-class-name="tableCellClassName" :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;" @selection-change="checkedWudulist">
                        <el-table-column type="selection" width="60" :selectable="isSelectable">
                        </el-table-column>
                        <el-table-column prop="projectCode" :label="user.companyId == '7030' ? '项目令号' : $t('Itemno')"  width="150"></el-table-column>
                        <el-table-column prop="projectName" :label="$t('headerTop.projectName')" min-width="250" sortable="custom">
                        <template slot-scope="scope">
                            <div> 
                                <el-button type="text" v-if="user.company.packageProject==1 && (user.company.nonProjectSimple==0 || (user.company.nonProjectSimple==1&&scope.row.isPublic==0))" @click="showProjectApprovalDeatil(scope.row)">{{scope.row.projectName}}</el-button>
                                <span v-else>{{scope.row.projectName}}</span>
                            </div>
                        </template>
                    </el-table-column>
                        <el-table-column prop="categoryName" :label="$t('projectclassification')"  width="140"></el-table-column>
                        <el-table-column prop="isPublic" :label="$t('projecttype')"  width="140">
                            <template slot-scope="scope">{{scope.row.isPublic==0?$t('zheng-shi-xiang-mu'):$t('fei-xiang-mu')}}</template>
                        </el-table-column>
                        <el-table-column prop="inchargerName" :label="$t('projectmanager')"  min-width="150">
                            <template slot-scope="scope">
                                <el-link type="primary" :underline="false" @click="showUser(scope.row.inchargerId)">
                                    <span v-if="user.userNameNeedTranslate != 1">
                                        {{scope.row.inchargerName}}
                                    </span>
                                    <span v-if="user.userNameNeedTranslate == 1">
                                        <TranslationOpenDataText type='userName' :openid='scope.row.inchargerName'></TranslationOpenDataText>
                                    </span>
                                </el-link>
                            </template>
                        </el-table-column>
                        <!-- 级别 -->
                        <el-table-column :prop="user.timeType.projectLevelState == 1 ? 'levelName' : 'level'" :label="$t('ji-bie')" min-width="190"   v-if="user.company.packageProject == 1">
                            <template slot-scope="scope">
                                <span v-if="user.timeType.projectLevelState == 1">{{scope.row.levelName}}</span>
                                <span v-else>{{importanceListLable[scope.row.level - 1]}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="status" :label="$t('other.approvalStatus')" min-width="100" >
                            <template slot-scope="scope">
                                {{scope.row.status == null?"-":approvalStatusStr[scope.row.status]}}
                            </template>
                        </el-table-column>
                        <el-table-column :label="$t('operation')" :width="300" align="left" fixed="right">
                            <template slot-scope="scope">
                                <el-button size="mini" type="primary" v-if="(permissions.projectApprovalEdit||permissions.projectApprovalCheck)&&scope.row.status!=1" @click="handleAdd(scope.$index, scope.row)">{{'编辑'}}</el-button>
                                <!-- <el-button size="mini" v-if="(permissions.projectApprovalEdit||permissions.projectApprovalCheck) && scope.row.status==0"  @click="check(scope.row,1)">{{'通过'}}</el-button>
                                <el-button size="mini" v-if="(permissions.projectApprovalEdit||permissions.projectApprovalCheck) && scope.row.status==0" @click="check(scope.row,2)">{{'驳回'}}</el-button> -->
                                <el-button size="mini" v-if="(permissions.projectApprovalEdit ||permissions.projectApprovalCheck) && scope.row.status==1" @click="check(scope.row,3)">{{'撤销'}}</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <!--工具条 footer-->
                    <el-col :span="24" class="toolbar">
                        <el-pagination :key="projectListPageComponentKey"
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :page-sizes="[20 , 50 , 80 , 100]"
                            :page-size="size"
                            :current-page.sync="page"
                            layout="total, sizes, prev, pager, next"
                            :total="total"
                            style="float:right;"
                        ></el-pagination>
                    </el-col>

                    <!--新增界面-->
                    <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="960px" :top="'6vh'">
                        <div style="height: 72vh;overflow-y: auto;overflow-x: hidden;">
                            <el-form ref="form1" :model="addForm" :rules="rules" label-width="120px">
                                <el-form-item :label="user.companyId == '7030' ? '项目令号' : $t('Itemno')" :class="title == $t('newproject')" v-if="user.companyId!=936">
                                    <!-- <el-input v-model="addForm.code" :disabled="!permissions.projectManagement && addForm.creatorId != user.id" placeholder="请输入项目编号" clearable></el-input> -->
                                    <el-input v-model="addForm.code" :placeholder="$t('peaseenterthe')" clearable :disabled="canOnlyModParticipator || (!permissions.projectManagement && addForm.creatorId != user.id && !permissions.projectCodeAndName)" maxlength="50" show-word-limit="true"></el-input>
                                </el-form-item>
                                <el-form-item :label="$t('headerTop.projectName')" prop="name">
                                    <!-- <el-input v-model="addForm.name" :disabled="!permissions.projectManagement && addForm.creatorId != user.id" placeholder="请输入项目名称" clearable></el-input> -->
                                    <el-input v-model="addForm.name" :placeholder="$t('peaseenterthe')" clearable :disabled="canOnlyModParticipator || (!permissions.projectManagement && addForm.creatorId != user.id && !permissions.projectCodeAndName) || isShowProjectName" maxlength="255" show-word-limit="true"></el-input>
                                </el-form-item>
                                <el-form-item :label="$t('projectclassification')" v-if="user.timeType.mainProjectState != '1'">
                                    <!-- <el-select v-model="addForm.category"  style="width:32%;" clearable :disabled="!permissions.projectManagement && addForm.creatorId != user.id"> -->
                                    <el-select v-model="addForm.category"  style="width:32%;" clearable filterable :disabled="canOnlyModParticipator">
                                        <el-option v-for="(item) in baseClfList" :key="item.id" :value="item.id" :label="item.name"></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item :label="$t('projecttype')" :class="title == $t('newproject') && user.companyId == 936 ? 'wpgCssClass' : ''" prop="isPublic">
                                    <el-select v-model="addForm.isPublic" style="width:32%;" @change="selectPublic" :disabled="canOnlyModParticipator">
                                        <el-option :value="0" :label="$t('zheng-shi-xiang-mu')"></el-option>
                                        <el-option :value="1" :label="$t('fei-xiang-mu')"></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item :label="$t('other.projectDescription')" prop="projectDesc">
                                    <!-- <el-input v-model="addForm.projectDesc" :disabled="!permissions.projectManagement && addForm.creatorId != user.id" placeholder="请输入项目描述" clearable maxlength="4000"></el-input> -->
                                    <el-input v-model="addForm.projectDesc" :placeholder="$t('peaseenterthe')" clearable maxlength="4000" :disabled="canOnlyModParticipator" show-word-limit></el-input>
                                </el-form-item>
                                <el-form-item :label="$t('Allparticipants')" v-show="addForm.isPublic == 0" :class="title == $t('newproject') && user.companyId == 936 ? 'wpgCssClass' : ''">
                                    <el-tooltip placement="top" effect="light" v-if="user.userNameNeedTranslate != 1">

                                        <div slot="content" style="width:780px">{{addForm.userNames}}</div>
                                        <el-input  @focus="showChooseMembTree" v-model="addForm.userNames"></el-input>
                                    </el-tooltip>

                                    <el-tooltip placement="top" effect="light" v-if="user.userNameNeedTranslate == 1">
                                        <div slot="content" style="width:780px">
                                            <span v-for="(item, index) in addFormUserNames" :key="index">
                                                <!-- {{item}} -->
                                                <TranslationOpenDataText type='userName' :openid='item'></TranslationOpenDataText>
                                                <span v-if="index < addFormUserNames.length - 1">,</span>
                                            </span>
                                        </div>
                                        <div @click="showChooseMembTree" style="width: 800px;overflow:hidden;white-space:nowrap;height:40px;border: 1px solid #DCDFE6;border-radius: 4px;box-sizing: border-box;padding: 0 10px">
                                            <span v-for="(item, index) in addFormUserNames" :key="index">
                                                <!-- {{item}} -->
                                                <TranslationOpenDataText type='userName' :openid='item'></TranslationOpenDataText>
                                                <span v-if="index < addFormUserNames.length - 1">,</span>
                                            </span>
                                        </div>
                                    </el-tooltip>
                                </el-form-item>
                                <el-form-item :label="$t('projectmanager')" :class="title == $t('newproject') && user.companyId == 936 ? 'wpgCssClass' : ''" v-if="user.company.nonProjectSimple == 0 || (user.company.nonProjectSimple == 1 && addForm.isPublic == 0)">
                                <el-select v-if="user.userNameNeedTranslate != 1" v-model="addForm.inchargerId" filterable :placeholder="$t('defaultText.pleaseChoose')" style="width:32%;" :disabled="canOnlyModParticipator || projectManagerEdit">
                                        <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id">
                                            <span style="float: left">{{ item.name }}</span>
                                        </el-option>
                                    </el-select>
                                    <selectCat v-if="user.userNameNeedTranslate == 1" :size="'medium'" :subject="participator" :subjectId="addForm.inchargerId" :distinction="'3'" @selectCal="selectCal" :disabled="canOnlyModParticipator || projectManagerEdit || isShowProjectName"></selectCat>
                                </el-form-item>

                                <el-form-item :label="$t('newspaperauditor')">
                                    <el-select v-if="user.userNameNeedTranslate != '1'" @change="$forceUpdate()" v-model="addForm.auditUserIds"  :disabled="!(permissions.projectManagement|| user.id == addForm.inchargerId || user.id == addForm.creatorId)" filterable :placeholder="$t('defaultistheprojectleader')" style="width:100%;" :multiple="user.timeType.reportAuditType != 6" >
                                        <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id"></el-option>
                                    </el-select>
                                    <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :tile="true" :widthStr="'800'" :disabled="!(permissions.projectManagement|| user.id == addForm.inchargerId || user.id == addForm.creatorId)" :subjectId="addForm.auditUserIds" :subject="participator" :clearable="false" :distinction="'10'"  :multiSelect="user.timeType.reportAuditType != 6" @selectCal="selectCal"></selectCat>
                                </el-form-item>
                                <!--专业项目协作版本功能 -->
                                <el-form-item :label="$t('ji-bie')" :class="title == $t('newproject') && user.companyId == 936 ? 'wpgCssClass' : ''" v-if="user.company.packageProject==1 && (user.company.nonProjectSimple == 0 || (user.company.nonProjectSimple == 1 && addForm.isPublic == 0))">
                                    <el-select v-model="addForm.level"  :placeholder="$t('defaultText.pleaseChoose')" style="width:32%;" v-if="user.timeType.projectLevelState == 1" :disabled="canOnlyModParticipator || isShowProjectName">
                                        <el-option v-for="item in levelList" :key="item.id" :label="item.projectLevelName" :value="item.id"></el-option>
                                    </el-select>
                                    <el-select v-model="addForm.level"  :placeholder="this.$t('defaultText.pleaseChoose')" style="width:32%;" :disabled="canOnlyModParticipator" v-else>
                                        <el-option v-for="item in importanceList" :key="item.id" :label="item.label" :value="item.id"></el-option>
                                    </el-select>
                                </el-form-item>
                                <!-- 增加合同金额字段 -->
                                <el-form-item  :label="$t('contractamount')" v-if="user.company.packageProject==1 && (user.company.nonProjectSimple == 0 || (user.company.nonProjectSimple == 1 && addForm.isPublic == 0))">
                                    <el-input id="contractAmount" v-model="addForm.contractAmount" :disabled="canOnlyModParticipator" style="width:32%;" @input="contractAmountChange(addForm.contractAmount)" :placeholder="$t('zheng-shu')" clearable  @keyup.native="restrictNumber('contractAmount')"></el-input><span style="margin-left:10px;position:absolute;">{{ $t('yuan') }}</span>
                                    <template v-if="title == $t('modifytheproject') && contractAmountReasonShow">
                                        <span style="margin-left:63px;margin-right:10px;">{{ $t('modifythereason') }}</span>
                                        <el-input v-model="addForm.changeContractReason" style="width:33%" clearable :placeholder="$t('contractamountasd')"></el-input>
                                    </template>
                                </el-form-item>
                                <el-form-item :label="$t('ommencementDate')" prop="planStartDate"  v-if="(user.company.nonProjectSimple == 0 || (user.company.nonProjectSimple == 1 && addForm.isPublic == 0))">
                                    <el-date-picker v-model="addForm.planStartDate" :disabled="canOnlyModParticipator"
                                    :editable="false" style="width:32%;" 
                                    format="yyyy-MM-dd" 
                                    value-format="yyyy-MM-dd"
                                    :clearable="false" type="date" 
                                    :placeholder="$t('optiondate')"></el-date-picker>

                                    <span style="margin-left:63px;margin-right:10px;" >{{ $t('ji-hua-jie-shu-ri-qi') }}</span>
                                    <el-date-picker v-model="addForm.planEndDate" style="width:33%;"
                                    :editable="false" :disabled="canOnlyModParticipator"
                                    format="yyyy-MM-dd" 
                                    value-format="yyyy-MM-dd"
                                    :clearable="false" type="date" 
                                    :placeholder="$t('optiondate')"></el-date-picker>
                                </el-form-item>
                                <!-- 项目基线 -->
                                <div style="margin: 10px 0 30px 0;min-height:200px;" v-if="user.company.packageProject == 1 && !canOnlyModParticipator && (user.company.nonProjectSimple == 0 || (user.company.nonProjectSimple == 1 && addForm.isPublic == 0))">
                                    <el-tabs v-model="activeName" @tab-click="handleClick">
                                    <el-tab-pane :label="$t('costbaseline')" name="baseCostPanel"  >
                                        <div style="padding-top:10px;">
                                            <!--新版 -->
                                            <span class="rg_span" v-for="(item, index) in projectBaseCostData" :key="item.id">
                                                <span style="width:120px;display: inline-block;" v-if="user.company.packageProject==1">{{item.baseName}}</span>
                                                <el-input :id="'baseCost'+index" @input="addUpfun()" v-model="item.baseAmount" style="width:200px; margin-bottom: 20px"
                                                :placeholder="$t('zheng-shu')" clearable  @keyup.native="restrictNumber('baseCost'+index)"></el-input><span style="margin-left:10px;">{{ $t('yuan') }}</span>
                                            </span>    

                                            <!-- 合计 -->
                                            <div style="margin-top: 10px;float:right;">
                                                <span style="margin-right:50px;margin-right:10px;" v-if="user.company.packageProject==1">{{ $t('other.totals') }}</span>
                                                <span v-if="addForm.budget <= 0 || addForm.budget == undefined">0</span>
                                                <span v-else>{{addForm.budget | numberToCurrency}}</span>
                                                <span style="margin-right:50px;margin-left:10px;">{{ $t('yuan') }}</span>
                                            </div>
                                        </div>
                                    </el-tab-pane>
                                    </el-tabs>
                                </div>
                                <el-divider></el-divider>
                                <!-- <template>
                                    <div><span>{{'审核人'}}</span></div>
                                    <div>
                                        <div v-for="(item, index) in pointList" :key="index" >
                                        第{{index+1}}审核人:
                                        <el-select  v-if="user.userNameNeedTranslate != 1" :disabled="item.status!=0" v-model="item.userId" style="width:140px;" :placeholder="$t('defaultText.pleaseChoose')" clearable @change="manageSelect" size="small" filterable popper-class="managePopperClass">
                                            <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id">
                                                <span style="float: left">{{ item.name }}</span>
                                            </el-option>
                                        </el-select> 
                                        <selectCat v-if="user.userNameNeedTranslate == 1" :size="'medium'" :subject="participator" :subjectId="item.userId" :distinction="'12'" @selectCal="selectCal" :disabled="canOnlyModParticipator || projectManagerEdit || isShowProjectName"></selectCat>
                                        <i class="el-icon-circle-plus-outline" @click="addInput(index)" v-if="index==pointList.length-1"></i>
                                        <i class="el-icon-remove-outline" v-if="pointList.length>1 && item.status==0"  @click="deleteInput(index)"></i>
                                        <span>{{item.status==0?'待审核':item.status==1?"已审核":"已驳回"}}</span>
                                        </div>
                                    </div>
                                </template> -->
                            </el-form>  
                        </div>
                        <div slot="footer" class="dialog-footer;">
                            <el-button @click.native="deletePro(1, addForm)" v-if="(permissions.projectApprovalEdit) && addForm.id" style="float:left">{{ $t('btn.delete') }}</el-button>
                            <el-button @click.native="addFormVisible = false">{{ $t('btn.cancel') }}</el-button>
                            <el-button type="primary" @click="submitInsert" :loading="addLoading">{{ $t('btn.submit') }}</el-button>
                        </div>
                    </el-dialog>
                    <!-- 按部门选择人员 -->
                    <el-dialog :title="$t('selectingParticipants')"  :visible.sync="chooseParticipVisible" :close-on-click-modal="false" customClass="customWidth" width="500px">
                        <!-- <el-input style="width:100%" v-model="filterName" placeholder="请输入姓名搜索" @change="findUserInTree"></el-input> -->
                        <div v-if="user.userNameNeedTranslate == '1'">
                            <el-input :placeholder="$t('pleaseentercontent')" v-model.trim="filterText" class="input-with-select" @keyup.enter.native="echartDepartment()">
                                <el-button slot="append" icon="el-icon-search" @click="echartDepartment()"></el-button>
                            </el-input>
                        </div>
                        
                        <div class="tree" style="height:400px">
                            <el-scrollbar style="height:100%">
                                <el-input
                                :placeholder="$t('keywordfiltering')"
                                v-model="filterText" v-if="user.userNameNeedTranslate != '1'">
                                </el-input>
                                <el-tree :data="deptMembData" :key="searchPersonnelFlgnum" show-checkbox :default-expand-all="searchPersonnelFlg" :props="defaultProps" node-key="id"
                                    ref="chooseMembTree" @check-change="onTreeItemChange" :default-checked-keys="addForm.userId"
                                    highlight-current  :filter-node-method="filterNode">
                                    <span class="custom-tree-node" slot-scope="{ node, data }">
                                        <span v-if="user.userNameNeedTranslate == '1'">
                                            <span v-if="node.data.children">
                                                <TranslationOpenDataText type='departmentName' :openid='node.label'></TranslationOpenDataText>
                                            </span>
                                            <span v-else>
                                                <TranslationOpenDataText type='userName' :openid='node.label'></TranslationOpenDataText>
                                            </span>
                                        </span>
                                        <span v-if="user.userNameNeedTranslate != '1'">
                                            {{ node.label }}
                                        </span>
                                        <!-- {{ node.label }} -->
                                    </span>
                                </el-tree>
                            </el-scrollbar>
                        </div>
                        <div>{{ $t('btn.choose') }}&nbsp;{{chosenMembCount}}&nbsp;{{ $t('other.people') }}</div>
                        <div slot="footer" class="dialog-footer">
                            <el-button  @click="chooseParticipVisible = false" >{{ $t('btn.cancel') }}</el-button>
                            <el-button type="primary" @click="chooseParticip()" >{{ $t('btn.determine') }}</el-button>
                        </div>
                    </el-dialog>
                    <!--用户详细信息弹出框-->
                    <el-dialog :title="$t('Checkthedetails')" v-if="userDetailVisible" :visible.sync="userDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="400px">
                        <div class="line"><span>{{ $t('lable.name') +"："}}</span>
                            <span v-if="user.userNameNeedTranslate != 1">{{userDetail.name}}</span>
                            <span v-if="user.userNameNeedTranslate == 1"><TranslationOpenDataText type='userName' :openid='userDetail.name'></TranslationOpenDataText></span>
                        </div>
                        <div class="line"><span>{{ $t('Worknumber') +"："}}</span><span>{{userDetail.jobNumber}}</span></div>
                        <div class="line"><span>{{ $t('lable.phone') +"："}}</span><span>{{userDetail.phone}}</span></div>
                        <div class="line"><span>{{ $t('jiao-se') +"："}}</span><span>{{userDetail.roleName}}</span></div>
                        <div class="line"><span>{{ $t('lable.department') +"："}}</span>

                            <span v-if="user.userNameNeedTranslate != 1">{{userDetail.departmentName}}</span>
                            <span v-if="user.userNameNeedTranslate == 1"><TranslationOpenDataText type='departmentName' :openid='userDetail.departmentName'></TranslationOpenDataText></span>
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="userDetailVisible = false" >{{ $t('btn.determine') }}</el-button>
                        </div>
                    </el-dialog>

                    <!--查看立项-->
                    <el-dialog :title="$t('Checkthedetails')" v-if="projectApprovalDetailVisible" :visible.sync="projectApprovalDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="400px">
                        <div class="line"><span>{{user.companyId='7030' ? '项目令号:' : '项目编号：'}}</span><span>{{projectApprocalDetail.projectCode}}</span></div>
                        <div class="line"><span>{{'项目名称：'}}</span><span>{{projectApprocalDetail.projectName}}</span></div>
                        <div class="line"><span>{{'项目分类：'}}</span><span>{{projectApprocalDetail.categoryName}}</span></div>
                        <div class="line"><span>{{'项目类型：'}}</span><span>{{projectApprocalDetail.isPublic==0?"正式项目":"非项目"}}</span></div>
                        <div class="line"><span>{{'项目描述：'}}</span><span>{{projectApprocalDetail.projectDesc}}</span></div>
                        <div class="line"><span>{{'全部参与人：'}}</span>
                            <span v-for="(par, index) in projectApprocalDetail.participationApprovalList" :key="par.userId">
                                <span v-if="user.userNameNeedTranslate != 1">
                                    {{par.userName}}
                                </span>
                                <span v-if="user.userNameNeedTranslate == 1">
                                    <TranslationOpenDataText type='userName' :openid='par.userName'></TranslationOpenDataText>
                                </span>
                                <span v-if="index < projectApprocalDetail.participationApprovalList.length-1">,</span>
                            </span>
                        </div>
                        <div class="line"><span>{{'项目经理：'}}</span>
                            <span v-if="user.userNameNeedTranslate != 1">{{projectApprocalDetail.inchargerName}}</span>
                            <span v-if="user.userNameNeedTranslate == 1&&projectApprocalDetail.inchargerName"><TranslationOpenDataText type='userName' :openid='projectApprocalDetail.inchargerName'></TranslationOpenDataText></span>
                        </div>
                        <div class="line"><span>{{'日报审核人：'}}</span>
                            <span v-for="(par,index) in projectApprocalDetail.projectApprovalAuditorList" :key="par.auditorId">
                                <span v-if="user.userNameNeedTranslate != 1">
                                    {{par.auditorName}}
                                </span>
                                <span v-if="user.userNameNeedTranslate == 1">
                                    <TranslationOpenDataText type='userName' :openid='par.auditorName'></TranslationOpenDataText>
                                </span>
                                <span v-if="index < projectApprocalDetail.projectApprovalAuditorList.length-1">,</span>
                            </span>
                        </div>
                        <div class="line"><span>{{'级别：'}}</span><span>{{importanceListLable[projectApprocalDetail.level-1]}}</span></div>
                        <div class="line"><span>{{'合同金额：'}}</span><span>{{projectApprocalDetail.contractAmount}}</span></div>
                        <div class="line">
                            <span>{{'计划开始日期：'}}</span><span>{{projectApprocalDetail.planStartDate}}</span>
                            <span>{{'计划结束日期：'}}</span><span>{{projectApprocalDetail.planEndDate}}</span>
                        </div>
                        <el-divider></el-divider>
                        <div class="line">
                            <span>{{ $t('costbaseline') }}</span>
                        </div>
                        <div class="line" v-for="(item,index) in projectApprocalDetail.projectApprovalBasecostList">
                            <span>{{item.baseName+"："}}</span><span>{{item.baseAmount}}</span>
                        </div>
                        <el-divider></el-divider>
                        <div class="line">
                            <span>{{ $t('caoZuoJiLu') }}</span>
                        </div>
                        <div class="line" v-for="(item,index) in approvalLogData">
                            <span v-if="user.userNameNeedTranslate != 1">{{item.userName}} {{item.createTime}} {{approvalTypeStr[item.type]}}{{ $t('leRiBao') }}</span>
                            <span v-if="user.userNameNeedTranslate == 1"><TranslationOpenDataText type='userName' :openid='item.userName'></TranslationOpenDataText> {{item.createTime}}{{approvalTypeStr[item.type]}}{{ $t('leRiBao') }}</span>
                        </div>
                        <div slot="footer" class="dialog-footer">
                            <el-button type="primary" @click="projectApprovalDetailVisible = false" >{{'关闭'}}</el-button>
                        </div>
                    </el-dialog>
                    <el-dialog :title="$t('liXiangDaoRu')" v-if="importDialog" :visible.sync="importDialog" customClass="customWidth" width="500px">
                    <p>1. {{$t('other.download')}}
                    <el-link type="primary" style="margin-left:5px;" :underline="false" :href="'./upload/立项导入模板.xlsx'" :download="'立项导入模板.xlsx'">{{ $t('liXiangDaoRuMoBanXlsx') }}</el-link>
                    </p>
                    <p>2. {{$t('other.projectsAndPeopleInThetemplate')}}。</p>
                    <p style="display: flex;justify-content: center;">
                        <el-upload ref="upload"  action="#" :limit="1" :http-request="batchImportData" :show-file-list="false">
                        <el-button type="primary" :underline="false" :loading="importingData">{{$t("other.startImporting")}}</el-button>
                    </el-upload>
                    </p>
                    </el-dialog>
                    <el-dialog append-to-body :title="$t('liXiangDaoRuJieGuo')" v-if="showImportResult" :visible.sync="showImportResult" width="40%">
                            <div >
                                {{importResultMsg}}
                            </div>
                    </el-dialog>
            </div>
        </div>
    </section>
</template>

<script>
import selectCat from "@/components/select.vue"
export default {
name: '',
components: {
    selectCat
},
props: { },
data() { 
return {
    keyword:"",
    searchField:"1",
    user: JSON.parse(sessionStorage.getItem("user")),
    total: 0,
    page: 1,
    size: localStorage.getItem("projectPageSize")==null?20:parseInt(localStorage.getItem("projectPageSize")),
    listLoading:false,
    approvalStatusStr:[this.$t('state.WaitingAudit'),this.$t('state.alreadyPassed'),this.$t('state.rejected'),this.$t('state.undone')],
    importanceList:[{id:1,label:this.$t('zheng-chang')},{id:2,label:this.$t('jin-ji')},{id:3,label:this.$t('zhong-yao')},{id:4,label:this.$t('zhong-yao-qie-jin-ji')}],
    importanceListLable:[this.$t('zheng-chang'), this.$t('jin-ji'), this.$t('zhong-yao'), this.$t('zhong-yao-qie-jin-ji'), this.$t('di-feng-xian'), this.$t('zhong-feng-xian'), this.$t('gao-feng-xian')],
    addFormVisible:false,
    baseCostItemList:[],
    permissions: JSON.parse(sessionStorage.getItem("permissions")),
    addForm: {
        name: '',
        userId: [],
        level:1,
        bu:'',
        id: '',
        code: '',
        projectDesc: '',
        alarmType: 0
    },
    projectBaseCostData:[],
    activeName:"baseCostPanel",
    baseClfList:[],
    addFormUserNames: [],
    deptMembData: [
        {
            id: 0,
            label: this.$t('lable.unassigned'),
        }
    ],
    allMembData:[],
    participator:[],
    chosenListBackup: [], 
    chooseParticipVisible:false,
    rules: {
        name: [{ required: true, message: this.$t('pleaseentername'), trigger: "blur" }],
        code: [{ required: true, message: this.$t('qing-shu-ru-bian-hao'), trigger: "blur" }],
        projectStageName: [{ required: true, message: this.$t('pleaseentername'), trigger: "blur" }],
        projectLevelName: [{ required: true, message: this.$t('pleaseentername'), trigger: "blur" }],
        deptId: [{ required: true, message: this.$t('qingXuanZeSuoShuBuMen'), trigger: "blur" }]
    },
    chosenMembCount:0,
    dataDetail:{},
    userDetailVisible:false,
    userDetail:{},
    pointList:[{
        userId:"",
        seq:1,
        status:0
    }],
    idx: 1,
    tableHeight: 0,
    projectApprovalDetailVisible:false,
    projectApprocalDetail:{},
    importDialog:false,
    approvalLogData:[],
    approvalTypeStr:[this.$t('btn.submit'),this.$t('bian-ji'),this.$t('btn.through'),this.$t('btn.rejected'),this.$t('btn.undo')],
    addLoading:false,
    importingData:false,
    showImportResult:false,
    importResultMsg:null,
    filterText:'',
    wxFilterText:''
}
},
computed: {},
watch: {},
created () {
    let height = window.innerHeight;
    this.tableHeight = height - 195;
    const that = this;
    window.onresize = function temp() {
        that.tableHeight = window.innerHeight - 195;
    };
},
mounted () {
    this.getList();
    this.getProjectBaseConfigList();
    this.getClfConfigList();
    this.getDepartment();
    this.getUsers();
},
methods: {
    isSelectable(row,index){
        if(row.creatorId == this.user.id || row.inchargerId == this.user.id || this.permissions.projectApprovalEdit){
            return true
        }else{
            return false
        }
    },
    submitInsert() {
        this.$refs.form1.validate(valid => {
            if (valid) {
                this.addLoading = true;
                let targetData = {};
                targetData.projectName= this.addForm.name
                if(this.addForm.projectDesc != null) {
                    targetData.projectDesc=this.addForm.projectDesc
                }
                if(this.addForm.id != null) {
                    targetData.id=this.addForm.id
                }
                if(this.addForm.isPublic != null) {
                    targetData.isPublic=this.addForm.isPublic
                }
                if(this.addForm.userId.length != 0 && this.addForm.isPublic == 0) {
                    let userArray=[]
                    for(let i in this.addForm.userId){
                        userArray.push({
                            "userId":this.addForm.userId[i]
                        })
                    }
                    targetData.participationApprovalList=userArray
                }
                if(this.addForm.inchargerId != null) {
                    targetData.inchargerId=this.addForm.inchargerId
                }
                if(this.addForm.code != null) {
                    targetData.projectCode=this.addForm.code
                }
                if(this.addForm.planStartDate != null) {
                    targetData.planStartDate=this.addForm.planStartDate
                }
                if(this.addForm.planEndDate != null) {
                    targetData.planEndDate=this.addForm.planEndDate
                }
                if(this.addForm.level != null) {
                    targetData.level=this.addForm.level
                }
                if(this.addForm.contractAmount != null) {
                    targetData.contractAmount=this.addForm.contractAmount
                }
                if (this.projectBaseCostData != null) {
                    targetData.projectApprovalBasecostList=this.projectBaseCostData
                    //计算总预算成本
                    if (this.addForm.budget == null) {
                        this.addForm.budget = 0;
                    }
                    targetData.budget=this.addForm.budget
                }
                if (this.addForm.contractAmount) {
                    targetData.contractAmount=this.addForm.contractAmount
                } else {
                    targetData.contractAmount=0
                }
                if (this.user.timeType.outputValueStatus == 1){
                    targetData.outputValue=this.addForm.outputValue ? this.addForm.outputValue : 0
                }
                //日报审核人
                if (this.addForm.auditUserIds) {
                    targetData.auditUserIds=this.addForm.auditUserIds
                }
                if(this.addForm.auditUserIds&&this.addForm.auditUserIds.length != 0) {
                    let userArray=[]
                    for(let i in this.addForm.auditUserIds){
                        userArray.push({
                            "auditorId":this.addForm.auditUserIds[i]
                        })
                    }
                    targetData.projectApprovalAuditorList=userArray
                }
                if(this.addForm.category != null) {
                    targetData.category=this.addForm.category
                }
                if(this.addForm.status != null) {
                    targetData.status=this.addForm.status
                }
                //审核人
                if (this.pointList) {
                    targetData.projectApprovalCheckList=this.pointList
                }
                this.http.JSONPost("/project-approval/editProjectApproval",targetData,
                res => {
                    this.addLoading = false;
                    if (res.code == "ok") {
                        this.$message({
                            message: (this.addForm.id!=null?this.$t('xiu-gai'):this.$t('create'))+this.$t('other.successful'),
                            type: "success"
                        });
                        this.addFormVisible = false;
                        this.getList();
                        if (this.user.company.packageEngineering == 1) {
                            this.saveProjectProfessions(res.data);
                        }
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.addLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                });
            }
        });
    },
    // 获取分类条目
    getClfConfigList() {
        this.http.get('/project-category/list',
            res => {
                if (res.code == "ok") {
                    this.baseClfList = res.data;
                //    console.log("获取分类条目",res.data);
                    this.$forceUpdate();
                } else {
                    this.$message({
                        message: res.msg,
                        type: "error"
                    });
                }
            },
            error => {
                this.$message({
                    message: error,
                    type: "error"
                });
                }
            );
        
    },
    //分页
    handleCurrentChange(val) {
        this.page = val;
        this.getList();
    },

    handleSizeChange(val) {
        this.size = val;
        localStorage.projectPageSize = this.size;
        this.page = 1
        this.getList();
    },
    getProjectBaseConfigList() {
        this.http.post('/project-basecost-setting/list',{},
            res => {
                if (res.code == "ok") {
                    this.baseCostItemList = res.data;
                    this.$forceUpdate();
                } else {
                    this.$message({
                        message: res.msg,
                        type: "error"
                    });
                }
            },
            error => {
                this.$message({
                    message: error,
                    type: "error"
                });
            }
        );
    },
    //显示新增界面
    handleAdd(i, item) {
        if(i == -1) {
            this.title = this.$t('newproject');
            this.addForm = {
                name: '',
                isPublic:0,
                userId: [],
                userNames:'',
                code:'',
                inchargerId:null,
                level: this.user.timeType.projectLevelState == 1 ? (this.levelList.length > 0 ? this.levelList[0].id : null) : 1,
                customerId:null,
                notifyUserNames:'',
                chosenLeaders:[],
                category:null,
                creatorId: this.user.id,
                projectMainId: '',
                outputValue: '',
                bu: [],
                manDay:0,
                fromOutside: 0,
                status:0,
            }
            this.projectBaseCostData = [];
            this.addFormUserNames = [];
            this.auseList = [];
            for (var m=0;m<this.baseCostItemList.length; m++) {
                this.projectBaseCostData.push({baseId: this.baseCostItemList[m].id, baseName:this.baseCostItemList[m].name, baseAmount:0});
            }
            this.pointList=[{
                "userId":"",
                "status":0
            }]
        } else {
            this.http.post('/project-approval/getDetail', {id: item.id},
            res => {
                let theData=[];
            if (res.code == "ok") {
                theData=res.data
            }
            var list = theData.participationApprovalList;
            if (item.isPublic == 1) {
                list = this.users;
            }
            var arr=[]
            var names=""
            let namesLiss = [] // 企业微信用到的参与者
            if (names.length > 0) {
                names = names.substring(0, names.length -1);
            }
            var auditorArr=[]
            if(theData.participationApprovalList){
                for(let i in theData.participationApprovalList){
                    arr.push(theData.participationApprovalList[i].userId);
                    names+=theData.participationApprovalList[i].userName+",";
                    namesLiss.push(theData.participationApprovalList[i].userName)
                }
            }
            this.addFormUserNames = namesLiss
            if(theData.projectApprovalAuditorList){
                for(let i in theData.projectApprovalAuditorList){
                    auditorArr.push(theData.projectApprovalAuditorList[i].auditorId)
                }
            }
            if (names.length > 0) {
                names = names.substring(0, names.length -1);
            }
            this.addForm = {
                id: item.id,
                name: item.projectName,
                userId: arr,
                auditUserIds:auditorArr,
                userNames:names,
                isPublic: item.isPublic,
                code:item.projectCode,
                inchargerId: item.inchargerId,
                level: item.level,
                planStartDate: item.planStartDate,
                planEndDate: item.planEndDate,
                budget: item.budget,
                baseMan: item.baseMan,
                contractAmount: item.contractAmount,
                baseFee: item.baseFee,
                baseRisk1: item.baseRisk1,
                baseRisk2: item.baseRisk2,
                baseOutsourcing: item.baseOutsourcing,
                customerId:item.customerId==0?null:item.customerId,
                category:item.category,
                projectDesc: item.projectDesc,
                creatorId: item.creatorId,
                outputValue: item.outputValue,
                status: item.status,
            }
            this.participator=theData.participationApprovalList
            this.changeParticipator();
            this.getProjectBaseData(item.id);
            console.log("===========",this.projectBaseCostData)
            this.getProjectCheckerData(item.id);
            });
        }
        this.addFormVisible = true;
    },
    //获取项目列表
    getList() {
        localStorage.projectPageIndex = this.page;
        this.listLoading = true;
        let parameter = {
            pageIndex: this.page,
            pageSize: this.size,
            keyword:this.keyword,
            searchField: this.searchField,
            category:this.statusClf,
            status: this.status,
            viewId:this.idx
        }
        this.http.post("/project-approval/listByPage", parameter,
        res => {
            this.listLoading = false;
            if (res.code == "ok") {
                var list = res.data.records;
                this.list = list;
                this.total = res.data.total;
            } else {
                this.$message({
                message: res.msg,
                type: "error"
                });
            }
        },
        error => {
            this.listLoading = false;
            this.$message({
                message: error,
                type: "error"
            });
        });
    },
    // 项目基线合计
    addUpfun() {
        var total = 0;
        for (var i=0;i<this.projectBaseCostData.length; i++) {
            if (this.projectBaseCostData[i].baseAmount) {
                total += parseFloat(this.projectBaseCostData[i].baseAmount);
            }
        }
        this.addForm.budget = total;
    },
    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);
        }
    },
    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;
    },

    showChooseMembTree() {
        this.deptMembData = JSON.parse(JSON.stringify(this.allMembData))
        this.chosenMembCount = this.participator.length;
        this.chooseParticipVisible = true;
        this.filterText = ''
        this.wxFilterText = ''
        if(this.user.userNameNeedTranslate == 1) {
            this.getDepartment()
        }
        let that = this
        setTimeout(()=>{    
            that.chosenListBackup = that.$refs.chooseMembTree.getCheckedNodes();
        }, 500)
    },
    onTreeItemChange() {
        var chosenList = this.$refs.chooseMembTree.getCheckedNodes();
        var list = chosenList.filter(item=>item.isUser == 1);
        this.chosenMembCount = list.length;
    },
    findUserInTree() {
        if (this.filterName == '') {
            this.deptMembData = this.allMembData;
        } else {
            var list = this.findRecursively(this.filterName, this.allMembData);
            this.deptMembData = list;
        }
    },

    findRecursively(username, list) {
        var filterList = [];
        for (var i=0;i<list.length; i++) {
            if (list[i].isUser == 1) {
                if (list[i].label.indexOf(username) >= 0) {
                    //匹配上了
                    filterList.push(list[i]);
                }
            } else if (list[i].children != null && list[i].children.length > 0) {
                var subList = this.findRecursively(username, list[i].children);
                if (subList.length > 0) {
                    subList.forEach(s=>filterList.push(s));
                }
            }
        }
        return filterList;
    },

    //确定选择参与人
    chooseParticip() {
        this.chooseParticipVisible = false;
        var chosenList = this.$refs.chooseMembTree.getCheckedNodes();
        if(this.searchPersonnelFlg) {
            chosenList = [...chosenList, ...this.chosenListBackup]
        }
        this.chosenMembList = chosenList.filter(item=>item.isUser == 1);
        this.addForm.userNames = '';
        this.addFormUserNames = []
        this.addForm.userId = [];
        this.participator = [];
        for (var i=0;i<this.chosenMembList.length; i++) {
            this.addForm.userId.push(this.chosenMembList[i].id);
            this.addForm.userNames += this.chosenMembList[i].label+',';
            this.addFormUserNames.push(this.chosenMembList[i].label)
            var item = {id:this.chosenMembList[i].id, name:this.chosenMembList[i].label};
            this.participator.push(item);
        }
        if (this.addForm.userNames.length > 0) {
            this.addForm.userNames = this.addForm.userNames.substring(0, this.addForm.userNames.length-1);
        }
    },
    // 获取部门列表
    getDepartment() {
        this.http.post("/department/listAllMemb", {},
        res => {
            if (res.code == "ok") {
                var list = res.data;
                //设置员工到部门下面
                this.setUserToDept(list);
                this.deptMembData = list;
                console.log(this.deptMembData, '看看数据')
                
                //用于筛选过滤
                this.allMembData = JSON.parse(JSON.stringify(this.deptMembData));
            } else {
                this.$message({
                    message: res.msg,
                    type: "error"
                });
            }
        },
        error => {
            this.$message({
                message: error,
                type: "error"
            });
        });
    },
    onTreeItemChange() {
        var chosenList = this.$refs.chooseMembTree.getCheckedNodes();
        var list = chosenList.filter(item=>item.isUser == 1);
        this.chosenMembCount = list.length;
    },
    findUserInTree() {
        if (this.filterName == '') {
            this.deptMembData = this.allMembData;
        } else {
            var list = this.findRecursively(this.filterName, this.allMembData);
            this.deptMembData = list;
        }
    },
    addPersonCheck(){
        var chosenList = this.$refs.chooseMembTree2.getCheckedNodes();
        var list = chosenList.filter(item=>item.isUser == 1);
        this.chosenMembCount = list.length;
        // console.log(list);
    },
    addPersonSure(){
        this.addGroupPersonPdialog = false
        let chosenList = this.$refs.chooseMembTree2.getCheckedNodes();
        let list = chosenList.filter(item=>item.isUser == 1);
        let listIDs = []
        let listNames = ''
        let listNamesList = []
        for(let i=0;i<list.length;i++){
            listIDs.push(list[i].id)
            listNames += list[i].label + ','
            listNamesList.push(list[i].label)
        }
        this.addGroupPersonData.person = listIDs
        this.addGroupPersonData.personNames = listNames
        this.addGroupPersonDataPersonNames = listNamesList
        console.log('触发', this.addGroupPersonDataPersonNames)
    },
    // 企业微信搜索
    echartDepartment() {
        console.log('我点击了搜索')
        if(this.filterText != '') {
            this.http.post("/user/getEmployeeList", {
                keyword: this.filterText,
                cursor: '',
                departmentId: -1,
                pageIndex: 1,
                pageSize: 1000
            },
            res => {
                if (res.code == "ok") {
                    this.filterNodePersonnel = res.data.records.map(item => item.name)
                    this.$refs.chooseMembTree.filter(this.filterText);
                } else {
                    this.$message({
                        message: res.msg,
                        type: "error"
                    });
                }
            },
            error => {
                this.$message({
                    message: error,
                    type: "error"
                });
            });
        } else {
            this.searchPersonnelFlgnum = +this.searchPersonnelFlgnum +1
            this.searchPersonnelFlg = false
            this.getDepartment()
        }
    },
    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);
                });
            }
        }
    },
    formDataToObject(formData) {
        const object = {};
        for (const [key, value] of formData.entries()) {
            if (key in object) {
            object[key] = [].concat(object[key], value);
            } else {
            object[key] = value;
            }
        }
        return object;
    },
    searchList() {
        this.page = 1;
        this.getList();
    },
    // 分类筛选
    searchClfList(){
        this.page = 1;
        this.getList();
    },
    getUsers() {
        // this.http.post(this.port.manage.list, {
        //     departmentId: -1,
        //     pageIndex: 1,
        //     // pageSize: 99999
        //     pageSize: -1
        // },
        this.http.post('/user/getSimpleActiveUserList', {},
        res => {
            if (res.code == "ok") {
                this.users = res.data;
            } else {
                this.$message({
                message: res.msg,
                type: "error"
                });
            }
        },
        error => {
            this.$message({
                message: error,
                type: "error"
            });
        });
    },
    // 自定义组件事件
    selectCal(obj) {
        if(obj.distinction == '1') {
            this.inchagerId = obj.id
            this.manageSelect()
        } else if(obj.distinction == '2') {
            this.participationId = obj.id
            this.participationSelect()
        } else if(obj.distinction == '3') {
            this.addForm.inchargerId = obj.id
            // console.log(this.participator)
            this.participator = JSON.parse(JSON.stringify(this.participator))
        } else if(obj.distinction =='4') {
            this.projectProfessionList[obj.other].inchargerId = obj.id
        } else if(obj.distinction =='5') {
            this.paramInchargerId = obj.id
        }else if(obj.distinction =='6') {
            this.hasSetGroupInchargerId = obj.id
        } else if(obj.distinction == '10') {
            let userList = obj.arrUserList
            let arr = []
            for(var i in userList) {
                arr.push(userList[i].id)
            }
            this.participator = JSON.parse(JSON.stringify(this.participator))
            this.addForm.auditUserIds = arr
        } else if(obj.distinction == '11') {
            let userList = obj.id
            console.log(obj)
            this.curProfessionRow.membList[obj.other].membId = userList
        } else if(obj.distinction == '12') {
            this.pointList.push({
                "userId":obj.id,
                "status":0
            })
            this.pointList=this.pointList.filter(i=>i.userId!="")
        }
    },
    getProjectBaseData(projectId) {
        this.http.post('/project-approval-basecost/get',{projectId: projectId},
                res => {
                    if (res.code == "ok") {
                        if(res.data.length>0){
                            this.projectBaseCostData = res.data;
                        }else{
                            this.projectBaseCostData = [];
                            for (var m=0;m<this.baseCostItemList.length; m++) {
                                this.projectBaseCostData.push({baseId: this.baseCostItemList[m].id, baseName:this.baseCostItemList[m].name, baseAmount:0});
                            }
                        }
                        
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
    },
    getProjectCheckerData(projectId) {
        this.http.post('//project-approval-check/get',{projectId: projectId},
                res => {
                    if (res.code == "ok") {
                        if(res.data.length>0){
                            this.pointList = res.data;
                        }else{
                            this.pointList=[{
                                "userId":"",
                                "status":0
                            }]
                        }
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        });
                    }
                },
                error => {
                    this.listLoading = false;
                    this.$message({
                        message: error,
                        type: "error"
                    });
                    }
                );
    },
    selectPublic() {
        if (this.addForm.isPublic == 1) {
            this.participator = this.users;
        } else {
            this.participator = [];
        }
    },
    //选择参与人
    changeParticipator() {
        //检查是否在参与人中，如果没有需要加入到参与人中
        // console.log('addform',this.addForm.userId,this.users);
        this.participator = [];
        this.addForm.userId.forEach(u=>{
            var list = this.users.filter(au=>au.id == u);
            if (list.length > 0) {
                var findUser = list[0];    
                this.participator.push(findUser);
            } else {
                console.log('未找到用户: '+u);
            }
            
        })
    },
    //显示用户详情
    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"
            });
        });
    },
    addInput(index){
        this.pointList.push({
            userId:"",
            seq:index+2,
            status:0
        })
    },
    deleteInput(index){
        this.pointList.splice(index,1)
        // if(this.pointList.length<=0){
        //     this.pointList.push({
        //     checkerId:""
        //     })
        // }
    },
    // 切换当前选项的索引
    switchs(e) {
        this.idx = e
        this.page = 1
        // console.log(this.searchField)
        this.getList()
    },
    deletePro(i, item) {
        this.$confirm(this.$t('queDingYaoShanChuLiXiang')+'[' + item.name +this.$t('ma')+']',this.$t('shanChuLiXiang'), {
            confirmButtonText: this.$t('btn.determine'),
            cancelButtonText: this.$t('btn.cancel'),
            type: "warning"
        })
        .then(() => {
            this.listLoading = true;
            this.http.post('/project-approval/delete',{ 
                id: item.id 
            },
            res => {
                this.listLoading = false;
                if (res.code == "ok") {
                    this.$message({
                        message: this.$t('message.successfullyDeleted'),
                        type: "success"
                    });
                    this.addFormVisible=false
                    this.getList();
                } else {
                    this.$message({
                        message: res.msg,
                        type: "error"
                    });
                }
            },
            error => {
                this.listLoading = false;
                this.$message({
                    message: error,
                    type: "error"
                });
                }
            );
        })
        .catch(() => {});
    },
    check(item,checkType,revokeType){
        this.listLoading = true;
        this.http.post('/project-approval/check',{ 
            id:item.id ,
            checkType:checkType,
            revokeType:revokeType
        },
        res => {
            this.listLoading = false;
            if (res.code == "ok") {
                this.$message({
                    message: this.$t('operationissuccessful'),
                    type: "success"
                });
                this.addFormVisible=false
                this.getList();
            } else {
                this.$message({
                    message: res.msg,
                    type: "error"
                });
            }
        },
        error => {
            this.listLoading = false;
            this.$message({
                message: error,
                type: "error"
            });
            }
        );
    },
    showProjectApprovalDeatil(item){
        this.projectApprovalDetailVisible=true
        this.http.post('/project-approval/getDetail', {id: item.id},
        res => {
        if (res.code == "ok") {
            this.projectApprocalDetail=res.data
        }
        });
        this.getApprovalEditLog(item)
    },
    getApprovalEditLog(item){
        this.http.post('/project-approval-log/listById', {id: item.id},
        res => {
        if (res.code == "ok") {
            this.approvalLogData=res.data
        }
        });
    },
    batchImportData(item) {
    //首先判断文件类型
    let str = item.file.name.split(".");
    let format = str[str.length - 1];
    if (format != "xls" && format != "xlsx") {
        this.$message({
            message: this.$t('other.PleaseselecttheXLSorXLSXfile'),
            type: "error"
        });
    } else {
        this.importingData = true;
        let formData = new FormData();
        formData.append("multipartFile", item.file);
        formData.append("companyId", this.user.companyId)
        this.http.uploadFile('/project-approval/importData', formData,
        res => {
            this.$refs.upload.clearFiles();
            this.importingData = false;
            if (res.code == "ok") {
                //换成弹出框，以免有人等了半天回来啥也没看到
                this.importResultMsg = res.data+this.$t('liXiangShuJu')+(res.msg?res.msg:"");;
                this.showImportResult=true
                this.getList();
                this.importDialog = false;
            } else {
                this.importResultMsg = this.$t('export.Importfailure')+"："+res.msg;
                this.showImportResult=true
            }
        },
        error => {
            this.$refs.upload.clearFiles();
            this.importingData = false;
            this.$message({
                message: error,
                type: "error"
            });
        });
    }
    },
    exportData(){
        let parameter = {
            keyword:this.keyword,
            searchField: this.searchField,
            category:this.statusClf,
            status: this.status,
            viewId:this.idx
        }
        this.http.post("/project-approval/exportData", parameter,
        res => {
            if (res.code == "ok") {
                const a = document.createElement("a"); // 创建a标签
                a.setAttribute("download", this.$t('liXiangDaoChuXlsx')); // download属性
                a.setAttribute("href", res.data); // href链接
                a.click(); // 自执行点击事件
                a.remove();
            } else {
                this.$message({
                message: res.msg,
                type: "error"
                });
            }
        },
        error => {
            this.$message({
                message: error,
                type: "error"
            });
        });
    },
},
}
</script>
<style scoped>
.toolbar_formitem_n1{
    margin-right: 0 !important;
}
.rg_span{
    display: inline-block;
}
.classification {
    width: 120px;
    border-right: 1px solid #f2f2f2;
    display: flex;
    flex-wrap: wrap;
    padding-top: 20px;
}
.classification p{
    width: 120px;
    text-align: center;
    line-height: 50px;
    margin: 0;
    cursor: pointer;
}
.classification p:hover {
    background: #dddddd;
}
.on {
    color: #409EFF;
}
</style>
