<template>
  <div class="box" style="position: relative">
    <!-- <el-page-header @back="$router.go(-1)" :content="dataList.employee_name" class="header"> -->
    <el-page-header @back="$router.go(-1)" class="header">
    </el-page-header>
    <div style="position:absolute;top:23px;left:126px;color:#303133;font-size: 17px;"><WWOpenData type="userName" :openid="dataList.employee_name"></WWOpenData>{{date}}绩效</div>
    <div class="search">
      <el-button type="primary" @click="drawer=true" style="width: 100px;margin-right: 10px;" v-if="deptManagerRouters">+绩效工作</el-button>
      <!-- <el-date-picker :clearable="false" v-model="date" type="month" placeholder="选择月" value-format="yyyy-MM"></el-date-picker> -->
    </div>
    <div class="flex-box">
      <div class="flex-1 flex-box flex-v-ce">
        <div class="point" v-if="dataList.base_point">
          <div>{{dataList.base_point}}</div>
          <div>月平衡分</div>
        </div>
        <div class="point" v-if="dataList.status==3">
          <div>{{dataList.review_point}}</div>
          <div>最终得分</div>
        </div>
      </div>

      <div class="flex-box" style="height: 20px;">
        <el-dropdown>
          <span class="el-dropdown-link">终审人</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-if="dataList.reviewer_name"><WWOpenData type="userName" :openid="dataList.reviewer_name"></WWOpenData></el-dropdown-item>
            <el-dropdown-item class="fontColorF" v-else>无数据</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

        <el-dropdown style="margin-left: 20px;">
          <span class="el-dropdown-link">
            <el-tooltip placement="top" style="margin-right: 5px;">
              <div slot="content">发布人可修改/删除绩效</div>
              <span class="tips">?</span>
            </el-tooltip>发布人<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item v-if="dataList.publisher_name"><WWOpenData type="userName" :openid="dataList.publisher_name"></WWOpenData></el-dropdown-item>
            <el-dropdown-item class="fontColorF" v-else>无数据</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>

        <el-dropdown style="margin-left: 20px;">
          <span class="el-dropdown-link">
            <el-tooltip placement="top" style="margin-right: 5px;">
              <div slot="content">监察员可查看次员工的月绩效，参与月终的绩效评审。</div>
              <span class="tips">?</span>
            </el-tooltip>监察员<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <template v-if="dataList.notice_info.length>0">
              <el-dropdown-item  v-for="(item, index) in dataList.notice_info" :key="index"><WWOpenData type="userName" :openid="item.name"></WWOpenData></el-dropdown-item>
            </template>
            <el-dropdown-item class="fontColorF" v-else>无数据</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div> 
    <div class="table_page">
      <!-- <el-table :data="dataList.work_list" style="width:100%" ref="dataList" tooltip-effect="dark" v-loading="loading"  @row-click="openDetail" @cell-mouse-enter="v_show_hover_D" @cell-mouse-leave="v_show_hover_T"> -->
      <el-table :data="dataList.work_list" style="width:100%" ref="dataList" tooltip-effect="dark" v-loading="loading"  @row-click="openDetail">
        <el-table-column prop="task_name" label="绩效工作" align="center" width="400px">
          <template slot-scope="scope">
            <div class="flex-box flex-v-ce" >
              <el-progress type="circle" :percentage="scope.row.progress" :width="width"></el-progress>
              <span style="margin-left: 10px;">{{ scope.row.task_name }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="expire_time" label="截止时间" align="center"></el-table-column>
        <el-table-column prop="orderNo" label="权重" align="center">
          <template slot-scope="scope">
            <span>{{ ((scope.row.base_point / dataList.base_point) * 100).toFixed(0) }}%</span>
          </template>
        </el-table-column>
        <el-table-column prop="base_point" label="工作绩效分" align="center"></el-table-column>
        <el-table-column prop="base_point" label="操作" align="center" v-if="operation_if && deptManagerRouters">
          <template slot-scope="scope">
            <el-dropdown placement="bottom" :show-timeout="150" :hide-timeout="150" >
            <!-- <span class="el-dropdown-links" style="display:none" @click.stop="''" ref="v_show_hover">···</span> -->
            <span class="el-dropdown-links" @click.stop="">···</span>
            <el-dropdown-menu  slot="dropdown" >
              <el-dropdown-item v-if="scope.row.status == 1"><el-button type="text" class="color-red" v-loading.fullscreen.lock="bodyLoad" @click.stop="modifications(scope.row)">修改</el-button></el-dropdown-item>
              <el-dropdown-item :disabled="false"><el-button type="text" class="color-red" v-loading.fullscreen.lock="bodyLoad" @click.stop="deletes(scope.row,0)">删除</el-button></el-dropdown-item>
              <!-- <el-dropdown-item ><el-button type="text" class="color-red" v-loading.fullscreen.lock="bodyLoad" @click.stop="deletes(scope.row,1)">撤销</el-button></el-dropdown-item> -->
            </el-dropdown-menu>
          </el-dropdown>
          </template>
        </el-table-column>
        <template slot="empty">
          <noData :isSolt="true">
              <template v-slot:default>
                <div class="fontColorF"> 还没有绩效工作 <span class="blue" @click="drawer=true"  v-if="deptManagerRouters">【创建绩效工作】</span></div>
              </template>
          </noData>
        </template>
      </el-table>
    </div>
    
    <!-- 修改-->
    <el-drawer :visible.sync="drawerAmend" :with-header="false" :before-close="handleCloses">
      <div class="drawer_title">绩效工作编辑</div>
      <div style="overflow: auto; height: calc(100vh - 81px);" v-loading="drawerAmendLoad">
        <!-- <div class="fontColorF" style="text-align: right;margin:0 20px 20px 0;">使用之前的绩效工作,<span class="blue" @click="openJx">去引用 >></span></div> -->
        <el-form :model="drawerAmends" ref="examineItem" label-width="100px" class="demo-ruleForm">
          <el-form-item label="任务内容" prop="task_name" :rules="[{ required: true, message: '请输入任务内容', trigger: 'blur' }]">
            <el-input type="textarea" rows="3" v-model="drawerAmends.task_name"  maxlength="20" show-word-limit></el-input>
          </el-form-item>
          <!--  v-if="((surplus / base_point) * 100).toFixed(0) >= 0" -->
          <div class="fontColorF input_text">
            <div v-if="surplus_mark1 == 0">权重还剩余{{ ((surplus / base_point) * 100).toFixed(0) }}%可以分配</div>
            <div v-if="surplus_mark1 > 0">权重分配已超出100%，当前额外分配
              <span style="color:#26A2FF;">{{ surplus_mark1 }}%</span>
            </div>
          </div>
          <!-- {{surplus_mark}}
          {{((surplus / base_point) * 100).toFixed(0) >= 0}} -->
          <el-form-item label="权重" prop="weight" :rules="[{ required: true, message: '请输入权重', trigger: 'blur' },{ type: 'number', message: '权重必须为数字值'}]">
            <span slot="label">权重
              <el-tooltip placement="top" style="margin-right: 5px;">
                <div slot="content">本条任务占月绩效的比重，权重越高越重要。</div>
                <span class="tips">?</span>
              </el-tooltip>
            </span>
            <el-input v-model.number="drawerAmends.weight" placeholder="请输入权重"><template slot="append">%</template></el-input>
          </el-form-item>
          <el-form-item label="绩效分" prop="base_point" v-if="drawerAmends.weight>0">
            <el-input disabled="disabled" v-model="drawerAmends.base_point"></el-input>
          </el-form-item>
          <div class="fontColorF input_text">工作绩效分=月平衡分*权重，权重填写后将自动计算</div>
          
          <!-- <el-form-item label="截止时间" prop="expire_time" :rules="[{required: true, message: '请选择截止时间', trigger: 'blur' }]">
              <el-date-picker v-model="examineItem.expire_time" :default-value="examineItem_expire_time" type="date" placeholder="选择截止时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" style="width: 100%;"/>
          </el-form-item> -->
          
          <el-form-item label="截止时间" prop="expire_time" :rules="[{required: true, message: '请选择截止时间', trigger: 'blur' }]">
            <el-date-picker
             style="width: 100%;"
              v-model="drawerAmends.expire_time"
              type="datetime"
              format="yyyy-MM-dd HH:mm"
              value-format="yyyy-MM-dd HH:mm"
              placeholder="选择日期时间"
              default-time="18:00:00">
            </el-date-picker>
           </el-form-item>

          <el-form-item label="审批人" prop="reviewer_id" :rules="[{required: true, message: '请选择审批人', trigger: 'blur' }]">
              <div class="border flex-box flex-v-ce" @click="add_reviewer_show = true">
                <div class="flex-1 fontColorF" v-if="!selectReviewer.name">请选择</div>
                <div class="flex-1" v-else><WWOpenData type="userName" :openid="selectReviewer.name"></WWOpenData></div>
                <i class="el-icon-arrow-down"></i>
              </div>
          </el-form-item>
          <el-form-item label="任务备注" prop="task_remark" :rules="[{ required: true, message: '请输入任务备注', trigger: 'blur' }]">
            <el-input rows="5" type="textarea" v-model="drawerAmends.task_remark" maxlength="300" show-word-limit></el-input>
          </el-form-item>
          <el-form-item style="text-align: right;">
              <el-button @click="handleCloses()">取消</el-button>
              <el-button :loading="btnLoad" type="primary" @click="submitForme('examineItem')">确认修改</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer> 

    <!-- 抽屉 -->
    <el-drawer :visible.sync="drawer" :with-header="false" :before-close="handleClose">
      <div class="drawer_title">创建绩效工作</div>
      <div style="overflow: auto; height: calc(100vh - 81px);">
        <div class="fontColorF" style="text-align: right;margin:0 20px 20px 0;">使用之前的绩效工作,<span class="blue" @click="openJx">去引用 >></span></div>
        <el-form :model="examineItem" ref="examineItem" label-width="100px" class="demo-ruleForm">
          <el-form-item label="任务内容" prop="task_name" :rules="[{ required: true, message: '请输入任务内容', trigger: 'blur' }]">
            <el-input type="textarea" rows="3" v-model="examineItem.task_name"  maxlength="20" show-word-limit></el-input>
          </el-form-item>
          <!--  v-if="((surplus / base_point) * 100).toFixed(0) >= 0" -->
          <div class="fontColorF input_text">
            <div v-if="surplus_mark2 == 0">权重还剩余{{ ((surplus / base_point) * 100).toFixed(0) }}%可以分配</div>
            <div v-if="surplus_mark2 > 0">权重分配已超出100%，当前额外分配
              <span style="color:#26A2FF;">{{ surplus_mark2 }}%</span>
            </div>
          </div>
          <!-- {{surplus_mark}}
          {{((surplus / base_point) * 100).toFixed(0) >= 0}} -->
          <el-form-item label="权重" prop="weight" :rules="[{ required: true, message: '请输入权重', trigger: 'blur' },{ type: 'number', message: '权重必须为数字值'}]">
            <span slot="label">权重
              <el-tooltip placement="top" style="margin-right: 5px;">
                <div slot="content">本条任务占月绩效的比重，权重越高越重要。</div>
                <span class="tips">?</span>
              </el-tooltip>
            </span>
            <el-input v-model.number="examineItem.weight" placeholder="请输入权重"><template slot="append">%</template></el-input>
          </el-form-item>
          <el-form-item label="绩效分" prop="base_point" v-if="examineItem.weight>0">
            <el-input disabled="disabled" v-model="examineItem.base_point"></el-input>
          </el-form-item>
          <div class="fontColorF input_text">工作绩效分=月平衡分*权重，权重填写后将自动计算</div>
          
          <!-- <el-form-item label="截止时间" prop="expire_time" :rules="[{required: true, message: '请选择截止时间', trigger: 'blur' }]">
              <el-date-picker v-model="examineItem.expire_time" :default-value="examineItem_expire_time" type="date" placeholder="选择截止时间" format="yyyy-MM-dd HH:mm" value-format="yyyy-MM-dd HH:mm" style="width: 100%;"/>
          </el-form-item> -->
          
          <el-form-item label="截止时间" prop="expire_time" :rules="[{required: true, message: '请选择截止时间', trigger: 'blur' }]">
            <el-date-picker
             style="width: 100%;"
              v-model="examineItem.expire_time"
              type="datetime"
              format="yyyy-MM-dd HH:mm"
              value-format="yyyy-MM-dd HH:mm"
              placeholder="选择日期时间"
              default-time="18:00:00">
            </el-date-picker>
           </el-form-item>

          <el-form-item label="审批人" prop="reviewer_id" :rules="[{required: true, message: '请选择审批人', trigger: 'blur' }]">
              <div class="border flex-box flex-v-ce" @click="add_reviewer_show = true">
                <div class="flex-1 fontColorF" v-if="!selectReviewer.name">请选择</div>
                <div class="flex-1" v-else><WWOpenData type="userName" :openid="selectReviewer.name"></WWOpenData></div>
                <i class="el-icon-arrow-down"></i>
              </div>
          </el-form-item>
          <el-form-item label="任务备注" prop="task_remark" :rules="[{ required: true, message: '请输入任务备注', trigger: 'blur' }]">
            <el-input rows="5" type="textarea" v-model="examineItem.task_remark" maxlength="300" show-word-limit></el-input>
          </el-form-item>
          <el-form-item style="text-align: right;">
              <el-button @click="handleClose()">取消</el-button>
              <el-button :loading="btnLoad" type="primary" @click="submitForm('examineItem')">确定</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer> 

    <!-- 添加人员 -->
      <EmployeeSelector
        title="选择审批人"
        :visible.sync="add_reviewer_show"
        :is_filtration_creator="false"
        :isChecKedAll="false"
        :multi="false"
        :employee_list="superior_list"
        :user_employee_list="true"
        :selected="amendList"
        @confirm="sub_add_employee"
      />
    <!-- <el-dialog title="选择审批人" :visible.sync="add_reviewer_show" :before-close="publicClose" width="700px">
        <EmployeeSelector1 :isChecKedAll="false" v-if="add_reviewer_show" :selected="amendList" ref="Employee" :can_select_dept="false" :multi="false"  @confirms="add_employee_confirms" @confirm="add_employee_confirm"></EmployeeSelector1>
         <span slot="footer">
           <el-button @click="publicClose()">取消</el-button>
           <el-button type="primary" @click="sub_add_employee">完成</el-button> 
         </span>
    </el-dialog> -->
    <!-- 更新进度 -->
    <el-dialog title="引入绩效" :visible.sync="isSlider2" :before-close="publicClose" width="40%">
        <el-date-picker v-model="dialogDate" type="month" placeholder="选择月" value-format="yyyy-MM"></el-date-picker>
        <el-table highlight-current-row :data="work_list" style="width:100%" ref="dataList" tooltip-effect="dark" v-loading="loading" @current-change="handleSelectionChange">
          <el-table-column prop="task_name" label="绩效工作" align="center" width="300px">
            <template slot-scope="scope">
              <div class="flex-box flex-v-ce">
                <el-progress type="circle" :percentage="scope.row.progress" :width="width"></el-progress>
                <span style="margin-left: 10px;">{{ scope.row.task_name }}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="orderNo" label="权重" align="center">
            <template slot-scope="scope">
              <span>{{ ((scope.row.base_point / scope.row.base_point) * 100).toFixed(0) }}%</span>
            </template>
          </el-table-column>
          <el-table-column prop="base_point" label="工作绩效分" align="center"></el-table-column>
        <template slot="empty"><noData></noData></template>
        </el-table>
        <span slot="footer">
          <el-button @click="publicClose">取消</el-button>
          <el-button type="primary" @click="dialogBtn">确定</el-button>
        </span>
    </el-dialog>


  <!-- 抽屉3 -->
  <el-drawer :visible.sync="drawer3"  :with-header="false" :before-close="handleClose">
    <div class="drawer_title">绩效工作详情</div>
    <div class="drawer_box" style="overflow: auto; height: calc(100vh - 81px);" v-if="workDetailData" v-loading="loading">
      <div class="flex-box flex-v-ce">
        <userImage class="user_img person_imghead" width="46px" height="46px" :user_name="workDetailData.employee_name" :img_url="workDetailData.img_url"></userImage>
        <div class="d_userMessage">
          <div><WWOpenData type="userName" :openid="workDetailData.employee_name"></WWOpenData></div>
          <div v-if="workDetailData.dept_list[0]"><WWOpenData type="userName" :openid="workDetailData.dept_list[0].dept_name"></WWOpenData></div>
        </div>
      </div>
      <ul>
        <li class="flex-box">
          <div class="label">任务内容</div>
          <div class="content_text">{{workDetailData.task_name}}</div>
        </li>
        <li class="flex-box">
          <div class="label">任务备注</div>
          <textarea class="flex-1" disabled="disabled" v-model="workDetailData.task_remark"  style="border: none;height:100px">
          </textarea>
          <!-- <div class="content_text">{{workDetailData.task_remark}}</div> -->
        </li>
        <li class="flex-box">
          <div class="label">绩效分</div>
          <div class="content_text yellow">{{workDetailData.point_config.base_point}}</div>
        </li>
        <li class="flex-box" v-if="workDetailData.point_config.review_point">
          <div class="label">最终分</div>
          <div class="content_text yellow">{{workDetailData.point_config.review_point}}</div>
        </li>
        <li class="flex-box">
          <div class="label">创建时间</div>
          <div class="content_text">{{workDetailData.create_time}}</div>
         </li>
        <li class="flex-box">
          <div class="label">截止时间</div>
          <div class="content_text">{{workDetailData.expire_time}}</div>
        </li>
        <li class="flex-box">
          <div class="label">发布人</div>
          <div class="content_text"><WWOpenData type="userName" :openid="workDetailData.publisher_name"></WWOpenData></div>
        </li>
        <!-- <li class="flex-box">
          <div class="label">发布时间</div>
          <div class="content_text">{{workDetailData.expire_time}}</div>
        </li> -->
        <li class="flex-box" v-if="workDetailData.point_config.timeout_deduction_point>0">
          <div class="label">逾期扣分</div>
          <div class="content_text">{{workDetailData.point_config.timeout_deduction_point}}</div>
        </li>
        <li class="flex-box">
          <div class="label">审批人</div>
          <div class="content_text"><WWOpenData type="userName" :openid="workDetailData.reviewer_name"></WWOpenData></div>
        </li>
        <li class="flex-box">
          <div class="label">积分种类</div>
          <div class="content_text">{{workDetailData.pt_name}}</div>
        </li>
      </ul>
      <div class="d_progress">
        <div class="flex-box">
          <div class="flex-1">工作进度（{{workDetailData.progress}}%）</div>
          <div class="fontColorF addJf" @click="isSlider=true" v-if="workDetailData.employee_id==userId&& workDetailData.status==1">+更新进度</div>
        </div>
        <el-progress :percentage="workDetailData.progress"></el-progress>
      </div>
      <el-tabs v-model="activeName" >
        <el-tab-pane label="工作记录" name="work">
          <div class="flex-box">
            <div class="flex-1"></div>
            <div class="fontColorF addJf" @click="isOne=true" v-if="workDetailData.employee_id==userId&&workDetailData.status==1 || workDetailData.employee_id==userId&&workDetailData.status==2">+记一条工作记录</div>
          </div>
          <div class="work_box" style="padding-top:10px" v-if="workDetailData.process !== null && workDetailData.process.list !== null">
            <div class="flex-box work_item" v-for="(item,index) in workDetailData.process.list" :key="index" v-show="item.point == 0">
              <userImage class="user_img person_imghead" width="40px" height="40px" :user_name="item.recorder" :img_url="item.img_url"></userImage>
              <div class="work_right flex-1">
                <div class="flex-box">
                  <div class="d_name flex-1"><WWOpenData type="userName" :openid="item.recorder"></WWOpenData></div>
                  <div class="d_date">{{item.time}}</div>
                </div>
                <div class="d_content">{{item.remark}}</div>
                <div>
                  <i class="el-icon-delete delicon color-red" @click="delItem(index,'work')"></i>
                </div>
              </div>
            </div>
            <div v-if="!text_list[0]" class="fontColorF" style="text-align: center;">暂无工作记录</div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="记分记录" name="participation">
          <div class="flex-box" style="padding-bottom: 10px;border-bottom: 1px solid #f1f1f1;">
            <div class="flex-1 fontColorF"><span v-if="point_total!=0">合计：{{point_total}}</span> </div>
            <div class="fontColorF addJf" @click="isIntegral=true" v-if="workDetailData.reviewer_id==userId&&workDetailData.status==1 || workDetailData.reviewer_id==userId&&workDetailData.status==2">+记分</div>
          </div>
          <div class="work_box" style="padding-top:10px" v-if="workDetailData.process !== null && workDetailData.process.list !== null">
            <div class="flex-box work_item" v-for="(item,index) in workDetailData.process.list" :key="index" v-show="item.point != 0">
              <userImage class="user_img person_imghead" width="40px" height="40px" :user_name="item.recorder" :img_url="item.img_url"></userImage>
              <div class="work_right flex-1">
                <div class="flex-box">
                  <div class="d_name flex-1"><WWOpenData type="userName" :openid="item.recorder"></WWOpenData>
                  <span class="blue" v-if="item.point>0">+{{item.point}}</span>
                  <span class="green" v-if="item.point<0">{{item.point}}</span>
                  </div>
                  <div class="d_date">{{item.time}}</div>
                </div>
                <div class="d_content">{{item.remark}}</div>
                <div>
                  <i class="el-icon-delete delicon color-red" @click="delItem(index,'point')"></i>
                </div>
              </div>
            </div>
            <div v-if="!point_list[0]" class="fontColorF" style="text-align: center;">暂无记分记录</div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-drawer>

  <!-- 更新进度 -->
  <el-dialog title="更新进度" :visible.sync="isSlider" :before-close="publicClose" width="40%">
    <div v-loading="jobSchedule">
      <div class="slider">
         <div class="fontColorF">拖动滑杆更新进度</div>
         <el-slider v-model="progress" :marks="{0:'0%'}"></el-slider>
      </div>
       <span slot="footer" style="display:flex;justify-content: flex-end;margin-top:25px">
         <el-button @click="publicClose()">取消</el-button>
         <el-button type="primary" @click="sliderSend">完成</el-button>
       </span>
    </div>
  </el-dialog>
  <!-- 记一条 -->
  <el-dialog title="记一条" :visible.sync="isOne" :before-close="publicClose" width="40%">
    <div v-loading="remembera">
       <div class="flex-box">
         <div style="width: 80px;">工作记录</div>
         <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="textarea"></el-input>
       </div>
       <span slot="footer" style="display:flex;justify-content: flex-end;margin-top:25px">
         <el-button @click="publicClose()">取消</el-button>
         <el-button type="primary" @click="one">完成</el-button>
       </span>
    </div>
  </el-dialog>
  <!-- 记分记录 -->
  <el-dialog title="记分" :visible.sync="isIntegral" :before-close="publicClose" width="40%">
    <el-form :model="integral" ref="integral" :rules="formRules" label-width="80px" v-loading="scoringRecord">
      <el-form-item label="记录"  prop="text" :rules="[{ required: true, message: '记录不能为空'}]">
        <el-input type="textarea" :rows="3" v-model="integral.text"></el-input>
      </el-form-item>
      <el-form-item label="记分"  prop="num" >
        <div class="num" :class="[integral.type=='1'?'add':'jian']"></div>
          <el-input placeholder="请输入内容" v-model.number="integral.num">
            <el-select v-model="integral.type" slot="prepend" placeholder="请选择" style="width: 80px;">
              <el-option label="奖分" value="1"></el-option>
              <el-option label="扣分" value="2"></el-option>
            </el-select>
          </el-input>
      </el-form-item>
      <el-form-item style="display:flex;justify-content: flex-end;">
          <el-button @click="publicClose()">取消</el-button>
          <el-button type="primary" @click="integralSend('integral')">完成</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>

  </div>

</template>

<script>
import EmployeeSelector from '@/views/common/EmployeeSelector';
  import EmployeeSelector1 from '@/views/common/EmployeeSelector1'
  import noData from '@/components/noData'
  const validatorNoZero = (rule, value, callback) => {
    if (value === 0) {
      return callback(new Error("记分不能为0"));
    } else if (value === '') {
      return callback(new Error("记分不能为空"));
    }else if (isNaN(value)){
      return callback(new Error("积分必须为数字值"));
    }else{
      callback();
    }
  };

  export default {
  name: 'team_detail',
  components: {EmployeeSelector1, EmployeeSelector, noData},
  data() {
    return {
      amendList:{employee:[], dept: []},
      drawerAmends:{//发布工作
        targets: [],//工作执行者列表,以逗号分割的字符串或直接传入数组
        pt_id: 0,//积分种类id
        task_name: "",//任务名
        task_remark: "",//任务详细描述
        base_point: 0,//任务参考积分
        expire_time: "",//截至时间
        package_id: "",//绩效工作包id
        weight: "",//绩效权重 绩效工作包发布工作时必须大于0，其余工作发布为0
        reviewer_id: "",//终审人id
        timeout_deduction_point: 0,//逾期扣分/月
        cate_id: 0,//共组分类id
      },
      drawerAmends_weight:'',
      drawerAmend:false,//修改弹窗
      drawerAmendLoad:false,//修改弹窗loading
      jobSchedule:false,//更新进度loading
      remembera:false,//加一条loading
      scoringRecord:false,//记分loading
      deptManagerRouters: !this.$authoritys('dept_manager'),
      // drawer_variate:0,//进入绩效包是否打开抽屉、(若要启用此功能请打开)
      operation_if:false,//操作列显示隐藏
      // v_show_hover_Ds:false,
      add_employee_confirmss:'',
      the_pop_up:'',
      width: 46,
      page: 1,
      perPage: 10,
      total: 0,
      loading: false,
      btnLoad:false,
      bodyLoad: false,
      userId:this.$store.getters.user_info.id,
      package_id:'',//绩效包id
      employee_id:'',//用户id
      getData_2:'',
      date: this.$moment().format('YYYY-MM'),
      dialogDate:this.$moment().format('YYYY-MM'),
      dataList: {
        notice_info:[]
      },

      drawer: false,//控制刚进入页面抽屉是否启用
      examineItem_expire_time:'',
      examineItem:{//发布工作
        targets: [],//工作执行者列表,以逗号分割的字符串或直接传入数组
        pt_id: 0,//积分种类id
        task_name: "",//任务名
        task_remark: "",//任务详细描述
        base_point: 0,//任务参考积分
        expire_time: "",//截至时间
        package_id: "",//绩效工作包id
        weight: "",//绩效权重 绩效工作包发布工作时必须大于0，其余工作发布为0
        reviewer_id: "",//终审人id
        timeout_deduction_point: 0,//逾期扣分/月
        cate_id: 0,//共组分类id
      },
      //终审人
      superior_list:[],
      add_reviewer_show:false,
      selectReviewer:{},
      isSlider2:false,
      point_total:0,//不知道什么分
      surplus:0,
      base_point:0,
      work_list:[],
      selectItem:{},


      //工作详情相关
      workDetail:'',
      workDetailData:'',
      drawer3: false,
      activeName: '',
      isSlider:false,
      isOne:false,
      isIntegral:false,
      textarea:'',//记录一条内容
      integral:{
        text:'',
        num:0,
        type:"1",
      },
      text_list:[],
      point_list:[],
      point_total:0,
      progress:0,

      formRules:{
        num: [
          {
            required: true,
            validator: validatorNoZero,
            trigger: "blur"
          }
        ],
      }
    };
  },
  watch: {
    "dialogDate"(){
       this.getData(true);
    },
    "examineItem.weight"(val, old) {
      this.examineItem.base_point = ((val / 100) * this.base_point).toFixed(0)
    },
    "drawerAmends.weight"(val, old) {
      this.drawerAmends.base_point = ((val / 100) * this.base_point).toFixed(0)
    },
    "examineItem.expire_time"(val){
      // console.log(val);
    },
    "date"(){
      this.getData();
    },
    "ticket_count"(val){
      if(val){
        this.examineItem2.ticket_count=1;
      }else{
        this.examineItem2.ticket_count=0;
      }
    }
  },
  computed: {
    usedWeight () {
      return ((this.base_point - this.surplus) / (this.base_point || 1)) * 100
    },
    surplus_mark1 () {
      //this.surplus  所以任务的   剩余分数
      //this.base_point 总分
      if (((this.surplus / this.base_point) * 100).toFixed(0) - this.drawerAmends.weight < 0) {
        return Math.abs(((this.surplus / this.base_point) * 100).toFixed(0) - this.drawerAmends.weight)
      }
      return 0
    },
    surplus_mark2 () {
      //this.surplus  所以任务的   剩余分数
      //this.base_point 总分
      if (((this.surplus / this.base_point) * 100).toFixed(0) - this.examineItem.weight < 0) {
        return Math.abs(((this.surplus / this.base_point) * 100).toFixed(0) - this.examineItem.weight)
      }
      return 0
    }
  },
  created () {
    let point_types = JSON.parse(localStorage.getItem('SET_POINT_TYPES'))
    for (let i in point_types) {
      if (point_types[i].code == 'JX') {
        this.examineItem.pt_id = point_types[i].id
        this.drawerAmends.pt_id = point_types[i].id
      }
    }
  },
  mounted() {
// setTimeout(()=>{//判断有无数据、，有就不弹出，无就弹出侧边栏
    //   if(this.the_pop_up.length == 0){
    //         this.drawer = true
    //   }else{
    //     this.drawer = false
    //   }
    // },1000)
    if(this.$route.query.date&&this.$route.query.package_id){//这是路由传入绩效包id的判断
        setTimeout(()=>{
          this.drawer = this.$route.query.cT
        },500)
       this.package_id=this.$route.query.package_id;
       this.date=this.$route.query.date;
       this.getData_2=true;//给一个标识，判断是 绩效包id / 用户id
      //  this.examineItem.expire_time = this.$route.query.date
       this.examineItem_expire_time = this.$route.query.date//当前页的时间等于上级的时间
       this.getData();
    }
    if(this.$route.query.date&&this.$route.query.employee_id){//这是路由传入用户id的判断，，（上级页面无绩效包id）
       this.employee_id=this.$route.query.employee_id;
       this.date=this.$route.query.date;
       this.examineItem_expire_time = this.$route.query.date
       this.getData_2=false;
       this.getData();
    }
  },
  methods: {
    handleCloses(){
      this.drawerAmend = false
      this.selectReviewer = {}
      setTimeout(()=>{
        this.drawerAmendLoad = false
        this.getData();
      },200)
    },
    submitForme(formName) {
      var self=this;
      this.drawerAmendLoad = true
      self.drawerAmends.targets=[self.dataList.employee_id];
      self.drawerAmends.package_id=self.dataList.id;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(self.drawerAmends.weight==0){self.$message.error("权重不能为0"); return false}
            self.$http('post','/api/integral/work/update',self.drawerAmends).then(res => {
              if (res.data.code == 1) {
                self.$message.success(res.data.msg);
                self.handleCloses();
              } else {
                self.$message.error(res.data.msg);
              }
            }).finally(()=>{
                self.handleClose();
            })
          }
      });
    },
    //修改绩效工作
    modifications(item){
      this.drawerAmend = true
      this.drawerAmendLoad = true
      this.$http('get',`/api/integral/work?work_id=${item.id}`)
      .then(res => {
          if (res.data.code == 1) {
            let datas = res.data.data
            this.drawerAmends.targets = [datas.employee_id]
            this.drawerAmends.id = datas.id
            this.drawerAmends.task_name = datas.task_name
            if(datas.performance_data){
              this.drawerAmends.weight = +datas.performance_data.weight
            }
            this.drawerAmends.expire_time = datas.expire_time
            this.drawerAmends.task_remark = datas.task_remark
            this.amendList.employee = [{id:datas.reviewer_id,name:datas.reviewer_name,img_url:datas.img_url}]
            this.selectReviewer = {id:datas.reviewer_id,name:datas.reviewer_name,img_url:datas.img_url}
            // this.drawerAmends.package_id = datas.task_remark
            this.drawerAmends.reviewer_id = datas.reviewer_id
            this.drawerAmendLoad = false
          }else{

          }
      }).finally(()=>{
          this.drawerAmendLoad = false
      })
    },
    // v_show_hover_T(row, column, cell, event){
    //   this.$refs.v_show_hover.style.display = 'none'
    // },
    // v_show_hover_D(row, column, cell, event){
    //   for(let i=0;i<this.$refs.v_show_hover.length;i++){
        
    //     console.log(this.$refs.v_show_hover[i])
    //   }
    //   this.$refs.v_show_hover.style.display = 'block'
      
    // },
    // 删除工作记分 与 工作记录
    delItem(index,type){
      let self = this
      self.$confirm('确定永久删除此项?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let data = {
          work_id: this.workDetailData.id,
          process: JSON.parse(JSON.stringify(this.workDetailData.process.list))
        }
        data.process.splice(index,1)
        self.$http('post','/api/integral/work',data).then(res => {
          if(res.data.code == 1){
            self.workDetailData.process.list.splice(index,1)
          }else{
            self.$message.error(res.data.msg)
          }
        }).catch(e => {self.$message.close()})
      })
    },
    //删除 //撤销
    deletes(item,e){
      let self = this
      this.$message.closeAll()
      if(e == 1){
        if(item.status != 1){
          this.$message({
            showClose: true,
            message: '已完成工作不能撤销',
            type: 'error'
          });
          return false
        }
      }
      self.$confirm(e==0?'删除此任务将会删除其相关记录和积分数据，确认删除吗？':'任务撤销后将不可恢复，确定撤销吗？', e==0?'删除任务':'撤销任务', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self.bodyLoad = true
        self.$http(e==0?'DELETE':'post','/api/integral/work',e==0?{work_id: item.id}:{work_id: item.id,status: 'refuse'}).then(res => {
          if (res.data.code == 1) {
            self.$message.success(res.data.msg);
            self.dataList.work_list.forEach((element,index) => {
              element.id == item.id?self.dataList.work_list.splice(index, 1):''
            });
          } else {
            self.$message.error(res.data.msg);
          }
        }).finally(() => {
            self.bodyLoad = false;
        })
      })
    },

    integralSend(formName){
       var self=this;
       var items=this.workDetailData.process.list||[];
       var process={
            img_url: this.$store.getters.user_info.img_url,
            point:this.integral.type=="1" ?this.integral.num:'-'+this.integral.num,
            recorder_id: this.$store.getters.user_info.id,
            recorder: this.$store.getters.user_info.name,
            remark: this.integral.text,
            time: this.$moment().format('YYYY-MM-DD HH:mm')
          }
      var data={
          work_id:this.workDetail.id,
          process:[],
        }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          items.unshift(process);
          data.process=items;
          // debugger
          this.scoringRecord = true
          self.$http('post','/api/integral/work',data).then(res => {
              if (res.data.code == 1) {
                self.publicClose();
                self.openDetail();
              } else {
               self.$message.error(res.data.msg);
              }
          }).finally(() => {
            setTimeout(()=>{
              this.scoringRecord = false
            },300)
          });
        }
        })
    },
    one(){
        if(!this.textarea){
           this.$message.error("请输入备注内容");
           return
        }
        var self=this;
        var items=this.workDetailData.process.list||[];
        var process={
            img_url: this.$store.getters.user_info.img_url,
            point: 0,
            recorder_id: this.$store.getters.user_info.id,
            recorder: this.$store.getters.user_info.name,
            remark: this.textarea,
            time: this.$moment().format('YYYY-MM-DD HH:mm')
          }
        var data={
          work_id:this.workDetail.id,
          process:[],
        }
       items.unshift(process);
       data.process=items;
       this.remembera = true
       self.$http('post','/api/integral/work',data).then(res => {
           if (res.data.code == 1) {
              self.publicClose();
               self.openDetail();
           } else {
            self.$message.error(res.data.msg);
           }
       }).finally(()=>{
         setTimeout(()=>{
            this.remembera = false
         },300)
       })
    },
    //更新进度
    sliderSend(){
        var self=this;
        let data = {
          work_id: self.workDetailData.id,
          progress: self.progress,
        }
        this.jobSchedule = true
        self.$http('post','/api/integral/work',data).then(res => {
             if (res.data.code == 1) {
               self.openDetail();
               self.isSlider=false;
             }else{
               self.$message.error(res.data.msg);
             }
        }).finally(()=>{
          setTimeout(()=>{
            this.jobSchedule = false
          },300)
        })
    },
    //打开工作详情
    openDetail(item){
      var self=this;
      self.drawer3=true;
      self.loading = true;
      if(item){this.workDetail=item;}
      self.$http('get',`/api/integral/work?work_id=${this.workDetail.id}`).then(res => {
          if (res.data.code == 1) {
            self.loading = false;
            self.workDetailData=res.data.data;
            self.progress=self.workDetailData.progress;
            self.text_list = []
            self.point_list = []
            self.point_total = 0
            if (self.workDetailData.process.list && self.workDetailData.process.list.length > 0) {
              for (let i in self.workDetailData.process.list) {

                self.point_total += self.workDetailData.process.list[i].point * 1

                if (self.workDetailData.process.list[i].point != 0) {

                  self.point_list.push(self.workDetailData.process.list[i])
                } else {

                  self.text_list.push(self.workDetailData.process.list[i])
                }
              }
            }
           setTimeout(function(){
              self.activeName="work"
           },400)
          }else{
            self.loading = false;
            self.$message.error(res.data.msg);
          }
      })
    },
    dialogBtn(){
        if(!this.selectItem){ this.$message.error("请选择绩效工作"); return; }
        var selectItem=this.selectItem;
        let point = ((selectItem.base_point / this.base_point) * 100).toFixed(0)
        this.examineItem.task_name= selectItem.task_name;//任务名
        this.examineItem.task_remark=selectItem.task_remark//任务详细描述
        this.examineItem.weight=Number(point);//绩效权重 绩效工作包发布工作时必须大于0，其余工作发布为0
        this.publicClose();
    },
    handleSelectionChange(val) {
      this.selectItem = val;
    },
    openJx(){
      this.isSlider2=true;
      this.getData(true);
    },
    //人员确定
    // sub_add_employee(item){
    //   if(this.add_employee_confirmss !== '' ){
    //       this.$refs.Employee.confirm();//调用组件的confirm（）；
    //   }
    //   this.publicClose();
    //   this.add_employee_confirmss = ''
    // },
    add_employee_confirms(val){
      this.add_employee_confirmss = val
    },
    //执行人选择
    sub_add_employee(val){
      this.amendList.employee = val.employee;
      this.selectReviewer=val.employee[0];
      this.examineItem.reviewer_id=val.employee[0].id;
      this.drawerAmends.reviewer_id=val.employee[0].id;
    },
    //公共弹窗关闭
    publicClose(){
      this.add_reviewer_show=false;
      this.isSlider2=false;
      this.selectItem="";

      //工作详情
      this.isIntegral=false;
      this.isOne=false;
      this.isSlider=false;
      this.textarea='',//记录一条内容
      this.integral={
        text:'',
        num:0,
        type:"1",
      }
      this.add_employee_show=false;
    },

    //绩效包工作任务审批
    submitForm(formName) {
      var self=this;
      self.examineItem.targets=[self.dataList.employee_id];
      self.examineItem.package_id=self.dataList.id;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(self.examineItem.weight==0){self.$message.error("权重不能为0"); return false}
            self.$http('post','/api/integral/work/publish',self.examineItem).then(res => {
             if (res.data.code == 1) {
               self.$message.success(res.data.msg);
               self.handleClose();
             } else {
               self.$message.error(res.data.msg);
             }
         })
        }
      });
    },
    handleClose() {
      this.examineItem.task_name= "";//任务名
      this.examineItem.task_remark="";//任务详细描述
      this.examineItem.expire_time="";//截至时间
      this.examineItem.weight="";//绩效权重 绩效工作包发布工作时必须大于0，其余工作发布为0
      this.examineItem.reviewer_id="";//终审人id
      this.selectReviewer={};
      this.drawer=false;
      this.activeName="";
      this.drawer3=false;
      this.getData();
    },
    //此函数判断当前账号与发布者是否一致
    operation_none_fei(publisher_id){
      if(publisher_id == this.$store.getters.user_info.id){
        this.operation_if = true  
      }else{
        this.operation_if = false
      }
    },

    getData(is) {
      let self = this;
      self.loading = true;
      if(is){
        self.$http('get','/api/integral/performance/info',{employee_id:self.dataList.employee_id, month: self.dialogDate }).then(res => {
          if (res.data.code == 1) {
            self.work_list = res.data.data.work_list||[]
          } else {
            self.$message.error(res.data.msg);
          }
        }).finally(() => {
          self.loading = false;
        });
      }else{
        self.$http('get','/api/integral/performance/info',this.getData_2==true?{ package_id: self.package_id, month: self.date }:{ employee_id: self.employee_id, month: self.date }).then(res => {
          if (res.data.code == 1) {
            // this.drawer_variate = 0；//删除最后一个后弹出，在删除后调用并归零（没有此需求不要打开这句）
            //当绩效包无任务，自动弹出创建绩效工作抽屉，只在进入弹出一次；(若要启用此功能请打开)
            // if(res.data.data.work_list.length == 0){
            //   this.drawer_variate++;
            //   if(this.drawer_variate == 1){
            //     this.drawer = true
            //   }
            // }
            this.superior_list = this.$getEmployeeMap()[res.data.data.employee_id].superior_list
            this.operation_none_fei(res.data.data.publisher_id)//传入发布者ID

            this.the_pop_up = res.data.data.work_list
            self.dataList = res.data.data||[]
            // self.dataList.employee_name=self.dataList.employee_name+" "+self.date+"绩效"
            self.dataList.employee_name=self.dataList.employee_name
            self.total = res.data.data.work_count;
            self.base_point=res.data.data.base_point;
            self.point_total = 0//重新请求数据，清空原先数据
            for(let i in res.data.data.work_list){
              self.point_total += res.data.data.work_list[i].base_point*1
            }
            self.surplus= self.base_point - self.point_total;
          } else {
            self.$message.error(res.data.msg);
          }
        }).finally(() => {
          self.loading = false;
        });
        }
    },
    //页码变更
    handleCurrentChange: function(val) {
      this.page = val;
      this.getData(this.page, this.perPage);
    }
  }
}
</script>

<style lang="scss" scoped="scoped">
  $blue: #26a2ff;
  $red: #f56c6c;
  $yellow: #e6a23c;
  $green: #67c23a;
  $fontColorZ: #303133;
  $fontColorF: #909399;
  $fontColorT: #c0c4cc;
  .green{
   color: #67c23a;
  }
  .blue{
    color:#26a2ff;
    cursor: pointer;
  }
  .fontColorF{
    color:#909399;
  }
  .yellow{color: #e6a23c;}
  .input_text{
    margin-bottom: 20px;
    padding-left: 100px;
  }
  .drawer_box{
    padding:0 20px;
    .d_userMessage{
      margin-left: 10px;
    }
    .d_userMessage div:nth-child(1){
      font-size: 16px;
      margin-bottom: 8px;
    }
    .d_userMessage div:nth-child(2){
      font-size: 12px;
      color: $fontColorF;
    }
    ul{
      padding: 12px 0;
      border-bottom: 1px solid #f1f1f1;
    }
    li{
      padding: 6px 0;
    }
    li .label{
      width: 80px;
      text-align: left;
      color: $fontColorF;
    }
    .content_text{
      flex:1
    }
    .d_progress{
      padding: 12px 0;
      border-bottom: 1px solid #f1f1f1;
      margin-bottom: 10px;
    }
    .work_box{}
    .d_footer{
      position: fixed;
      bottom: 20px;
      right: 20px;
    }
    .work_right{
      margin-top: 10px;
      margin-left: 10px;
      padding-bottom: 10px;
      border-bottom: 1px solid #f1f1f1;
    }
    .d_name{
      color: $fontColorZ;
      margin-bottom: 10px;
    }
    .d_date{
      color: $fontColorF;
    }
    .work_item{
       margin-bottom: 10px;
    }
    .addJf{
      font-size: 13px;
      cursor: pointer;
      margin-bottom: 5px;
      padding: 5px;
    }
    .addJf:hover{
      color: $blue;
    }
  }
  .slider{
    padding: 30px 20px;
  }
  .num{
    position: absolute;
    height: 20px;
    width: 20px;
    z-index: 999;
    left: 85px;
  }
  .add:before{
    position: absolute;
    content: "+";
    color: $red;
  }
  .jian:before{
    position: absolute;
    content: "-";
    color: $green;
  }

  .border{
    -webkit-appearance: none;
    background-color: #FFF;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #DCDFE6;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    color: #606266;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    width: 100%;
    cursor: pointer;
  }
	.drawer_title{
		font-size: 18px;
		padding: 20px;
    border-bottom:1px #efefef solid;
    margin-bottom: 20px;
  }
  .box {
  overflow: hidden;
  padding: 20px;
  .header {
    padding-bottom: 20px;
    border-bottom: 1px solid #f1f1f1;
  }
  .search {
    padding: 20px 0;
  }
  .point{
    margin-right: 20px;
  }
  .point div:nth-child(1) {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
  }
  .point div:nth-child(2) {
   color: $fontColorF;
  }
  .page {
    text-align: center;
    padding: 20px 0;
  }
  .tips {
    background: $fontColorT;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    color: #fff;
    display: inline-block;
    font-size: 12px;
    line-height: 14px;
    text-align: center;
  }
  .demo-ruleForm{
    padding: 0 20px;
  }
}
.color-red{
  color: $red;
  &:hover{
    color: #f14141;
  }
}
.delicon{
  font-size: 20px;
  float: right;
}

.el-dropdown-links {
    font-size: 20px;
    cursor: pointer;
    color: #686a6d;
  }

   /deep/ .el-table tr:hover{
  cursor:pointer
}
</style>
