<template>
  <div>
    <el-drawer :title="title" :visible.sync="show" :with-header="false" :size="'600px'" :before-close="closeDetail" direction="rtl">
<!--      <div class="drawer_title">审批详情</div>-->
      <div v-loading="detail_loading">
        <div class="detail_popup" v-if="detail_info !== null">
          <el-row :gutter="10" style="padding-bottom:20px;border-bottom:1px #f8f8f8 solid;position: relative;">
            <el-col :span="24">
              <template>
                <userImage
                :id="detail_info.employee_id"
                :user_name="detail_info.employee_info.name"
                :img_url="detail_info.employee_info.img_url"
                class="fl" width="50px" height="50px" fontSize="15"></userImage>
              </template>
              <template>
                <span style="line-height:50px; margin-left:10px;margin-right:4px;">{{ $getEmployeeMapItem(detail_info.employee_id).name }}</span>
                <span class="color_red point" v-show="detail_info.point >= 0 && detail_info.point">
                  <span v-if="(detail_info.review_point == 0 ? detail_info.point : detail_info.review_point) >= 0">+</span>
                  {{ detail_info.review_point == 0 ? detail_info.point : detail_info.review_point }} {{ $getTypsName(detail_info.pt_id) }}
                </span>
                <span class="color_green point" v-show="detail_info.point < 0 && detail_info.point">{{ detail_info.point }} {{ $getTypsName(detail_info.pt_id) }}</span>
              </template>
<!--              <br />-->
<!--              <template>-->
<!--                <b style="font-size:13px;position: absolute;left:65px;top:45px">-->
<!--                  <span v-if="detail_info.status == 1" class="green">审批通过</span>-->
<!--                  <span v-else-if="detail_info.status == 2" class="red">拒绝</span>-->
<!--                  <span v-else-if="detail_info.status == 0" class="orange">待审批</span>-->
<!--                  <span v-else></span>-->
<!--                </b>-->
<!--              </template>-->
              <el-tag :type="reviewStatusType(detail_info.review_status)" >{{reviewStatusMap[detail_info.review_status] || '--'}}</el-tag>
            </el-col>
          </el-row>
          <el-descriptions direction="vertical" :column="2" border title="审批信息" >
            <el-descriptions-item
              v-for="(item,index) in detail_info.detail"
              :key="index"
              :label="item.key"
              :label-style="{textAlign:'center',maxWidth:'200px'}"
              :content-style="{textAlign:'center',maxWidth: '200px'}"
            >
              <template v-if="item.key === '附件'">
                <el-image v-for="(items, indexs) in item.value" :key="indexs" style="width: 50px; height: 50px;margin:2px;" :src="items" :preview-src-list="item.value"></el-image>
              </template>
              <template v-else-if="item.key === '工作留存'">
                <el-image v-for="(items, indexs) in item.value" :key="indexs" style="width: 100px; height: 100px;margin:2px;" :src="items" :preview-src-list="item.value"></el-image>
              </template>
              <template v-else>
                <el-popover
                  placement="bottom"
                  :title="item.key"
                  width="500"
                  trigger="click"
                  :content="item.value.toString()"
                >
                  <div slot="reference" style="cursor: pointer" class="desc-content">{{item.value}}</div>
                </el-popover>
              </template>
              <template v-else-if="item.key === '工作备注'">
                <el-popover
                  placement="bottom"
                  title="工作备注"
                  width="500"
                  trigger="click"
                  :content="item.value"
                >
                  <div slot="reference" style="cursor: pointer" class="desc-content">{{item.value}}</div>
                </el-popover>
              </template>
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions
            direction="vertical"
            :column="1"
            border
            v-if="detail_info.item_name"
            :label-style="{textAlign:'center',width:'100px'}"
            :content-style="{textAlign:'center',maxWidth:'200px'}"
          >
            <template slot="title">
              <p class="row_title">规则依据</p>
              <span class="row_tips" style="font-size:12px;color:#909399">此事件打分参考以下积分规则</span>
            </template>
            <el-descriptions-item label="规则分类">
              <el-popover
                placement="bottom"
                title="规则分类"
                trigger="click"
                :content="detail_info.rule_name"
              >
                <div slot="reference" style="cursor: pointer" class="desc-content">{{detail_info.rule_name}}</div>
              </el-popover>
            </el-descriptions-item>
            <el-descriptions-item label="积分规则">
              <el-popover
                placement="bottom"
                title="事件分类"
                trigger="click"
                :content="detail_info.item_name"
              >
                <div slot="reference" style="cursor: pointer" class="desc-content">{{detail_info.item_name}}</div>
              </el-popover>
            </el-descriptions-item>
            <el-descriptions-item label="规则积分">
              <template v-if="detail_info.item_range_type === 1">
                <span v-if="detail_info.item_max_point > 0">+</span>
                {{ detail_info.item_max_point }}{{ detail_info.pt_id === 3 ? 'B分' : detail_info.pt_id === 2 ? 'A分' : detail_info.pt_id === 1 ? '绩效分' : '' }}
              </template>
              <template v-else>
                {{ detail_info.item_min_point }}~{{ detail_info.item_max_point
                }}{{ detail_info.pt_id === 3 ? 'B分' : detail_info.pt_id === 2 ? 'A分' : detail_info.pt_id === 1 ? '绩效分' : '' }}
              </template>
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions
            direction="vertical"
            :column="1"
            border
            v-else-if="detail_info.rule_name"
            :label-style="{textAlign:'center'}"
            :content-style="{textAlign:'center'}"
          >
            <template slot="title">
              <p class="row_title">规则依据</p>
              <span class="row_tips" style="font-size:12px;color:#909399">此事件打分参考以下积分规则</span>
            </template>
            <el-descriptions-item label="规则分类">
              <el-popover
                placement="bottom"
                title="规则分类"
                width="500"
                trigger="click"
                :content="detail_info.rule_name"
              >
                <div slot="reference" style="cursor: pointer" class="desc-content">{{detail_info.rule_name}}</div>
              </el-popover>
            </el-descriptions-item>
          </el-descriptions>

          <div v-show="detail_info.process">
            <Steps :process="detail_info.process"></Steps>
          </div>
          <el-collapse v-if="detail_info && detail_info.logs" v-model="infoActiveNames">
            <el-collapse-item :disabled="detail_info.logs.length === 0" :title="detail_info.logs.length + '条操作日志'" name="logs">
              <el-alert
                v-for="(item,index) in detail_info.logs"
                :key="index"
                type="info"
                show-icon
                :title="item.create_time + ' ' + item.msg"
                :closable="false"
              />
            </el-collapse-item>
          </el-collapse>
        </div>
        <footer class="drawer-footer flex-box-end flex-v-ce">
<!--          <div v-if="detail_info.status == 0&&detail_info.reviewer_id==$userInfo().id">-->

          <div v-if="canComplete">
            <el-button v-if="canRejectRewrite" type="warning" @click="showRejectRewrite = true" >
              <el-tooltip content="驳回申请,任务执行者重新处理任务再重新提交" placement="top-start"><span>驳回重做</span></el-tooltip>
            </el-button>


            <el-button v-if="detail_info.pt_id === 1" @click="closeDetail">取消</el-button>

            <el-button v-else @click="rejectBtn">
              <el-tooltip content="拒绝并终止审批" placement="top"><span>拒绝</span></el-tooltip>
            </el-button>

            <el-button type="primary" @click="adoptBtn">
              <el-tooltip content="第一阶段审批节点可指定分数值是否发放奖票等,并可以继续提交到下个审批人" placement="top-end"><span>通过</span></el-tooltip>
            </el-button>
          </div>

          <div v-if="canRefuse">
            <span style="color:#909399;font-size:12px;padding-right:20px">撤回后需重新审批</span>
            <el-button type="primary" @click="revokeApproval">撤回审批</el-button>
          </div>
        </footer>
      </div>
    </el-drawer>

    <el-dialog :close-on-click-modal="false" title="拒绝审批" :visible.sync="rejectShow" :before-close="rejectClose" width="520px" center>
      <el-form :model="rejectForm" ref="rejectForm" label-width="80px" v-loading="rejectLoading">
        <el-form-item
          label="审批意见"
          prop="remark"
          :rules="[
            { required: true, message: '请输入审批意见'},
            {
              min: 3,
              max: 50,
              message: '长度在 3 到 50 个字符',
              trigger: 'blur'
            }
          ]"
        >
          <el-input type="textarea" :rows="4" v-model="rejectForm.remark" placeholder="请输入审批意见(限50字)" maxlength="50" show-word-limit @input="onRejectRemarkInput"></el-input>
        </el-form-item>

        <div class="flex-box-end">
          <el-button @click="cancelReject('rejectForm')">取消</el-button>
          <el-button type="primary" @click="confirmReject('rejectForm')">确认</el-button>
        </div>
      </el-form>
    </el-dialog>

    <el-dialog title="通过审批" :close-on-click-modal="false" :visible.sync="adoptShow" width="571px" :before-close="adoptClose" center>
      <el-form :model="adoptForm" ref="adoptForm" label-width="80px" v-loading="determinedBy" class="form">
        <el-form-item label="指定规则" v-if="!detail_info.rule_id && !detail_info.item_id && detail_info.source_type != 4">
          <el-switch v-model="adoptForm.ruleOrItem" active-color="#13ce66"></el-switch>
        </el-form-item>
        <el-form-item
          label="分类"
          v-if="detail_info.source_type != 4"
          v-show="(detail_info.rule_id && !detail_info.item_id) || !adoptForm.ruleOrItem"
          prop="rule_id"
          :rules="[{ required: true, message: '请选择规则分类'}]"
        >
          <el-cascader
            :disabled="!!detail_info.rule_id || !!detail_info.item_id"
            class="date-picker-width"
            v-model="adoptForm.rule_id"
            :options="ruleTrees"
            :props="{ value: 'id', label: 'name', children: 'child' }"
            @change="ruleChange"
            ref="rule"
            filterable
            clearable
            change-on-select
            placeholder="请选择规则分类"
          ></el-cascader>
        </el-form-item>

        <el-form-item label="规则内容" v-if="(!!detail_info.rule_id && detail_info.item_name) || (!!detail_info.item_id && detail_info.item_name)">
          <span>{{ detail_info.item_name }}</span>
        </el-form-item>
        <el-form-item
          label="规则"
          v-if="detail_info.source_type != 4"
          v-show="(detail_info.rule_id && detail_info.item_id) || adoptForm.ruleOrItem"
          prop="item_id"
          :rules="[{ required: true, message: '请选择规则'}]"
        >
          <el-cascader
            :disabled="!!detail_info.rule_id || !!detail_info.item_id"
            class="date-picker-width"
            :popper-class="'itemClass'"
            v-model="adoptForm.item_id"
            :options="item_list"
            filterable
            clearable
            :props="{
              value: 'id',
              label: 'name',
              children: 'child',
              emitPath: 'false'
            }"
            :show-all-levels="false"
            ref="ruleItem"
            @change="cascaderItemIdChange"
            placeholder="请选择规则"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="规则积分" v-show="detail_info.item_id">
          {{
            detail_info.item_range_type == 1
              ? detail_info.item_min_point
              : detail_info.item_range_type == -1
              ? detail_info.item_min_point
              : detail_info.item_min_point + '～' + detail_info.item_max_point
          }}{{ detail_info.pt_id == 3 ? 'B分' : detail_info.pt_id == 2 ? 'A分' : detail_info.pt_id == 1 ? '绩效分' : '' }}
        </el-form-item>

        <el-form-item label="" v-if="rangeType.rule_rangeType_pt_id == 2 || rangeType.rule_rangeType_pt_id == 3">
          <span>
            {{ rangeType.rule_min_point == rangeType.rule_max_point ? rangeType.rule_min_point : rangeType.rule_min_point + '~' + rangeType.rule_max_point
            }}{{ rangeType.rule_rangeType_pt_id == 3 ? 'B分' : 'A分' }}
          </span>
        </el-form-item>

        <el-form-item label="" v-if="rangeType.rule_rangeType_name != ''">
          <span>{{ rangeType.rule_rangeType_name }}</span>
        </el-form-item>

        <el-form-item label="审批积分">
          <el-col :span="10">
            <el-input-number
              v-if="detail_info.item_range_type == 2"
              :min="detail_info.item_min_point"
              :max="detail_info.item_max_point"
              v-model="adoptForm.point"
              :disabled="!isFirstStep"
              type="number"
            ></el-input-number>
            <el-input-number
              v-else-if="detail_info.item_range_type == 1"
              :disabled="detail_info.item_range_type == 1"
              :min="1"
              v-model="adoptForm.point"
              placeholder="请输入分值"
            ></el-input-number>

            <div v-else>
              <el-input-number
                v-if="rangeType.rule_range_type == 2"
                :disabled="forbiddenInputNum"
                :min="rangeType.rule_min_point"
                :max="rangeType.rule_max_point"
                v-model="adoptForm.point"
                placeholder="请输入分值"
              ></el-input-number>
              <el-input-number v-else :disabled="returnIs" v-model="adoptForm.point" placeholder="请输入分值"></el-input-number>
            </div>

          </el-col>
        </el-form-item>
        <el-form-item
          v-if="detail_info.source_type == 4"
          label="审批意见"
          prop="remark"
          :rules="[{ required: true, message: '请输入审批意见'}, { max: 100, message: '长度不能超过 100 个字符'}]"
        >
          <el-input :rows="4" type="textarea" v-model="adoptForm.remark" placeholder="说点什么(限100字)" @input="onApprovalRemarkInput"></el-input>
        </el-form-item>
        <div style="padding-left: 80px">奖票用于优秀表现和重要事项的表彰</div>
        <el-form-item label="发放奖票"><el-switch :disabled="!isFirstStep" v-model="adoptForm.switch" active-color="#13ce66"></el-switch></el-form-item>

        <el-form-item label="发生时间" v-if="(detail_info.source_type === 2 || detail_info.source_type === 3) && isFirstStep">
          <el-row>
            <el-col :span="18">
              <el-date-picker
                v-model="adoptForm.event_time"
                :picker-options="pickerBeginDateBefore"
                type="date"
                placeholder="请选择时间"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="递交审批" v-if="detail_info.source_type != 4&&!isCreator">
          <el-row>
            <el-col :span="18">
              <el-input auto-complete="off" v-model="manager" placeholder="请选择上级递交审批"></el-input>
              <div @click="show_employee_selector = true" style=" position: absolute; top: 0; right: 0; left: 0; bottom: 0; z-index: 9;"></div>
            </el-col>
          </el-row>
          <EmployeeSelector
            :is_filtration_creator="false"
            :user_employee_list="true"
            :employee_list="employee_lists"
            :multi="false"
            :isChecKedAll="false"
            :include_self="false"
            :selected="manager_selected"
            :visible.sync="show_employee_selector"
            @confirm="employee_confirm"
          />
        </el-form-item>
        <el-form-item v-if="detail_info.source_type != 4" label="审批意见" prop="remark" :rules="[{ max: 100, message: '长度不能超过 100 个字符'}]">
          <el-input :rows="4" type="textarea" v-model="adoptForm.remark" placeholder="说点什么(限100字)" @input="onApprovalRemarkInput"></el-input>
        </el-form-item>

        <center>
          <el-button @click="adoptClose">取 消</el-button>
          <el-button type="primary" @click="submitAdopt('adoptForm')">确定</el-button>
        </center>
      </el-form>
    </el-dialog>

    <el-dialog
      title="驳回重做"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :modal="false"
      :show-close="false"
      :visible.sync="showRejectRewrite"
      width="571px"
      center
    >
      <template>
        <el-form v-model="formRejectRewrite">
          <el-form-item>
            <el-input
              type="textarea"
              :rows="3"
              :clearable="true"
              :maxlength="100"
              :show-word-limit="true"
              placeholder="原因说明"
              v-model="formRejectRewrite.remark"
              @input="onRewriteRemarkInput"
            />
          </el-form-item>
        </el-form>
      </template>
      <template slot="footer">
        <div class="flex-box-end flex-v-ce">
          <el-button @click="formRejectRewrite.remark = '',showRejectRewrite = false">关闭</el-button>
          <el-button type="primary" :disabled="!canRejectRewrite" :loading="submitting" @click="rejectRewrite">确认</el-button>
        </div>
      </template>

    </el-dialog>


  </div>
</template>

<script>
import EmployeeSelector from '@/components/EmployeeSelector';
import Steps from '@/components/Steps.vue';
import moment from 'moment';
import Template from "../../../examine/components/Template.vue";
import {specialFilter} from "../../../utils";
export default {
  name: 'examinePopup',
  data() {
    return {
      pickerBeginDateBefore: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      },
      employee_lists: [],
      itemParticulars: false,
      rangeType: {
        rule_range_type: 0,
        rule_min_point: 0,
        rule_max_point: 0,
        rule_rangeType_pt_id: 0,
        rule_rangeType_name: ''
      },
      itemMaxPoint: 1,
      forbiddenInputNum: false,
      determinedBy: false, //确定通过loading
      rejectLoading: false, //驳回loading
      detail_id: null,
      detail_loading: false,
      detailShow: false,
      detail_info: {
        rule_id: '',
        employee_info:{}
      },
      employee_map: this.$getEmployeeMap(),
      rejectShow: false,
      adoptShow: false,
      rejectForm: {
        remark: ''
      },
      adoptForm: {
        ruleOrItem: false,
        rule_id: null,
        item_id: 0,
        showPoint: null,
        point: null,
        switch: false,
        remark: '',
        event_time: ''
      },
      // 规则 or 细则
      ruleTrees: null,
      item_list: null,
      // 奖扣积分数组
      awardPointsArray: [{ name: '奖分', value: 1 }, { name: '扣分', value: 2 }],
      awardPoints: 1,

      // 下一个审批人
      manager: '',
      manager_selected: { dept: [], employee: [] },
      show_employee_selector: false,
      isCreator:false,//是否创始人
      flatteningIntegralRules:[],
      showRejectRewrite:false,
      formRejectRewrite:{
        remark:''
      },
      submitting:false,
      infoActiveNames:[],
      reviewStatusMap:{
        0:'待审批',
        1:'已通过',
        2:'拒绝',
        3:'驳回重做',
      }
    };

  },
  props: {
    id: {
      type: Number,
      default: 0
    },
    show: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    },
    refreshParentList:{
      type: Boolean,
      default: true
    }
  },
  watch: {
    id(val) {
      this.detail_id = val;
    },
    show(val) {
      if (val) {
        this.getDetail();
      }
    },
    'adoptForm.ruleOrItem'(val) {
      if (val) {
        this.adoptForm.rule_id = 0;
      } else {
        this.rangeType = {
          rule_range_type: 0,
          rule_min_point: 0,
          rule_max_point: 0,
          rule_rangeType_pt_id: 0,
          rule_rangeType_name: ''
        };
        this.forbiddenInputNum = false;
        this.adoptForm.item_id = 0;
      }
    }
  },
  components: {Template, EmployeeSelector, Steps, moment },
  computed: {
    isFirstStep(){
      return this.detail_info && ((this.detail_info.pid === 0 && this.detail_info.step === 0) || this.detail_info.step === 1)
    },
    canComplete(){
      return this.detail_info && this.detail_info.can_complete === 1
    },
    canRefuse(){
      return this.detail_info && this.detail_info.can_refuse === 1
    },
    canRejectRewrite(){
      return this.canComplete && this.detail_info.source_type === 1
    },
    returnIs() {
      let is=false
      is=this.forbiddenInputNum;
      // if(this.detail_info.pid){
      if(!this.isFirstStep){
        is=true
      }
      return is
    },

  },
  mounted() {
    this.isCreator=this.$supremeAuthority('creator');
    this.getRuleItem();
    this.getRuleItemTree();
    this.employee_lists = this.$store.getters.user_info.employee_detail.superior_list;
  },
  methods: {
    cascaderItemIdChange(val) {
       if(val.length>0){
         let datas = null;
         this.flatteningIntegralRules.forEach(element => {
         	if (element.id == val[val.length - 1]) {
         		datas = { ...element };
         	}
         });
         if (datas.range_type == 1) {
           this.forbiddenInputNum = true;
         } else {
           this.forbiddenInputNum = false;
         }
         this.rangeType.rule_range_type = datas.range_type;
         this.rangeType.rule_min_point = datas.min_point;
         this.rangeType.rule_max_point = datas.max_point;
         this.rangeType.rule_rangeType_pt_id = datas.pt_id;
         this.rangeType.rule_rangeType_name = datas.name;
         this.adoptForm.point = datas.min_point;
         this.adoptForm.rule_id = datas.rule_id;
       }else{
         this.rangeType = {
           rule_range_type: 0,
           rule_min_point: 0,
           rule_max_point: 0,
           rule_rangeType_pt_id: 0,
           rule_rangeType_name: ''
         };
         this.forbiddenInputNum = false;
         this.adoptForm.item_id = 0;
         this.adoptForm.point = null;
         this.adoptForm.rule_id = null;
       }
    },
    //审批撤销
    revokeApproval() {
      this.$confirm('确定要撤回此项吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.detail_loading = true;
          this.$axiosUser('DELETE', '/api/pro/integral/review', { review_id: this.detail_id })
            .then(res => {
              if (res.data.code == 1) {
                this.$message.success("已撤回");
                this.closeDetail(); //关闭抽屉
                setTimeout(() => {
                  this.detail_loading = false;
                }, 200);
                if (this.refreshParentList) this.$parent.get_list(); //刷新列表
                this.$emit('hasSubmit')
              }
            })
            .finally(() => {
              this.detail_loading = false;
            });
        })
        .catch(() => {});
    },
    // 选择规则分类关闭down
    ruleChange(val) {
      if (val.length == 0) {
        this.adoptForm.rule_id = 0;
      } else {
        this.adoptForm.rule_id = val[val.length - 1];
      }
      this.$nextTick(() => {
        this.$refs.rule.dropDownVisible = false;
      });
    },
    // 选择规则细则
    itemChange(val) {
      if (val.length == 0) {
        this.adoptForm.item_id = 0;
      } else {
        this.adoptForm.item_id = val[val.length - 1];
      }
      this.$nextTick(() => {
        this.$refs.ruleItem.dropDownVisible = false;
      });
    },
    getItemDetail(arr) {
      //此递归暂不用，规则多的情况下会出问题
      let result = [];
      for (const item of arr) {
        var res = JSON.parse(JSON.stringify(item)); // 先克隆一份数据作为第一层级的填充
        delete res['child'];
        result.push(res);
        if (item.child instanceof Array && item.child.length > 0) {
          // 如果当前child为数组并且长度大于0，才可进入getItemDetail()方法
          result = result.concat(this.getItemDetail(item.child));
        }
      }
      return result;
    },
    // 获取规则细则树
    getRuleItemTree() {
      let self = this;
      let params = {
        pt_id: this.detail_info.pt_id,
        cycle_type: '1'
      };
      this.$axiosUser('get', '/api/pro/integral/rule/trees', params, 'v2').then(res => {
        if (res.data.code == 1) {
          self.item_list = res.data.data.tree;
          self.flatteningIntegralRules = self.getItemDetail(res.data.data.tree);
        } else {
          self.$message.error(res.data.data.msg);
        }
      });
    },
    // 获取规则分类规则细则信息
    getRuleItem() {
      let self = this;
      let params = {
        cycle_type: 1
      };
      this.$axiosUser('get', '/api/pro/integral/rule/trees', params).then(res => {
        if (res.data.code == 1) {
          self.ruleTrees = this.getTreeData(res.data.data.rule_tree);
        } else {
          self.$message.error(res.data.data.msg);
        }
      });
    },
    // 打开详情
    getDetail() {
      let self = this;
      let params = {
        review_id: self.detail_id
      };
      self.detailShow = true;
      self.detail_loading = true;
      this.$axiosUser('get', '/api/pro/integral/review', params)
        .then(res => {
          if (res.data.code === 1) {
            self.detail_info = res.data.data;

            self.detail_info.rule_id ? (self.adoptForm.rule_id = self.detail_info.rule_id) : '';
            self.adoptForm.switch = self.detail_info.ticket_count > 0;
            if (res.data.data.item_id) {
              self.adoptForm.item_id = self.detail_info.item_id;
              self.adoptForm.showPoint = self.detail_info.point;
              self.detail_info.point > 0 ? (self.awardPoints = 1) : (self.awardPoints = 2);
              self.adoptForm.point = Math.abs(self.detail_info.point);
              self.adoptForm.event_time = moment.unix(res.data.data.event_time).format('YYYY-MM-DD');
            }
          }
          self.detail_loading = false;
        })
        .finally(e => {
          self.detail_loading = false;
        });
    },
    getEmployeeName(id) {
      for (const key in this.employee_map) {
        if (this.employee_map[key].id == id) {
          return this.employee_map[key].name;
        }
      }
    },
    // 关闭抽屉
    closeDetail() {
      this.infoActiveNames = []
      this.rejectShow = false
      this.adoptShow = false
      this.showRejectRewrite = false
      this.$emit('update:show', false);
    },
    // 驳回按钮
    rejectBtn() {
      this.rejectShow = true;
    },
    // 关闭驳回弹窗
    rejectClose() {
      this.rejectShow = false;
      this.$refs['rejectForm'].resetFields();
    },
    // 确定驳回
    confirmReject(formName) {
      let self = this;
      self.$refs[formName].validate(valid => {
        if (valid) {
          let data = {
            review_id: self.detail_id,
            action: 'refuse',
            ticket_count: '0',
            remark: self.rejectForm.remark
          };

          this.rejectLoading = true;
          this.$axiosUser('post', '/api/pro/integral/review', data)
            .then(res => {
              if (res.data.code == 1) {
                self.rejectShow = false;
                self.detail_info.status = 2;
                self.$message.success(res.data.msg);
                this.rejectClose(); //关闭驳回弹窗
                setTimeout(() => {
                  //延迟关闭，防止重复点击
                  this.rejectLoading = false;
                }, 200);
                this.closeDetail(); //关闭抽屉
                if (this.refreshParentList) this.$parent.get_list(); //刷新列表
                this.$emit('hasSubmit')
              } else {
                self.$message.error(res.data.msg);
                this.rejectLoading = false;
              }
            }).finally(e => {
              this.rejectLoading = false;
            });
        }
      });
    },
    // 取消驳回
    cancelReject(formName) {
      this.rejectShow = false;
      this.$refs[formName].resetFields();
    },
    // 通过按钮
    adoptBtn() {
      if (this.detail_info.item_range_type == 1) {
        this.adoptForm.point = Math.abs(this.detail_info.point);
      } else {
        this.adoptForm.point = this.detail_info.point;
      }
      this.detail_info.point > 0 ? (this.awardPoints = 1) : (this.awardPoints = 2);
      this.adoptForm.rule_id = this.detail_info.rule_id;
      this.adoptForm.item_id = this.detail_info.item_id;
      if (this.detail_info.rule_id == 0 && this.detail_info.item_id == 0 && this.detail_info.pt_id != 1) {
        //没有  规则分类 与 规则细则 与 不是绩效任务时，才请求规则细则（减少请求）
        this.getRuleItemTree();
      }
      this.adoptShow = true;

      this.rangeType = {
        rule_range_type: 0,
        rule_min_point: 0,
        rule_max_point: 0,
        rule_rangeType_pt_id: 0,
        rule_rangeType_name: ''
      };
    },
    // 递归判断列表，把最后的child设为undefined
    getTreeData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].child.length < 1) {
          // child若为空数组，则将child设为undefined
          data[i].child = undefined;
        } else {
          // child若不为空数组，则继续 递归调用 本方法
          this.getTreeData(data[i].child);
        }
      }
      return data;
    },
    // 下一个审批人
    employee_confirm(data) {
      this.manager_selected = { dept: [], employee: [] };
      this.adoptForm.reviewer_id = '';
      this.manager = '';
      if (data.employee !== null && data.employee.length != 0) {
        this.manager_selected.employee = data.employee;
        this.adoptForm.reviewer_id = data.employee[0].id;
        this.manager = data.employee[0].name;
      }
    },
    // 关闭通过弹窗
    adoptClose() {
      this.adoptForm.rule_id = 0;
      this.adoptForm.reviewer_id = 0;
      this.adoptForm.item_id = 0;
      this.adoptForm.reviewer_id = 0;
      this.forbiddenInputNum = false;
      this.adoptShow = false;
      this.manager = ''; //清空递交审批
      this.manager_selected = { dept: [], employee: [] }; //清空递交审批
      this.adoptForm.remark = '';
      this.adoptForm.switch = false;
      // this.$refs["adoptForm"].resetFields();
    },
    // 确定通过
    submitAdopt(formName) {
      let self = this;
      // console.log(self.adoptForm.point)
      if(this.adoptForm.point===''||this.adoptForm.point===undefined){
        this.$message.error("请填写积分分值")
        return false
      }
      self.$refs[formName].validate(valid => {
        if (valid) {
          let data = {
            review_id: self.detail_id,
            action: 'complete',
            rule_id: self.adoptForm.rule_id,
            item_id: 0,
            point: self.adoptForm.point,
            reviewer_id: '',
            remark: self.adoptForm.remark,
            ticket_count: 0,
            event_time: self.adoptForm.event_time
          };
          self.adoptForm.item_id ? (data.item_id = self.adoptForm.item_id) : (data.item_id = 0);
          self.adoptForm.reviewer_id ? (data.reviewer_id = self.adoptForm.reviewer_id) : (data.reviewer_id = 0);
          self.adoptForm.switch ? (data.ticket_count = 1) : (data.ticket_count = 0);
          if (this.detail_info.item_range_type == 1) {
            if (self.awardPoints === 1) {
              data.point = self.adoptForm.point;
            } else {
              data.point = self.adoptForm.point * -1;
            }
          }
          if (data.rule_id == '' || data.rule_id == null) {
            data.rule_id = 0;
          }
          if (this.detail_info.item_range_type == -1) {
            let itemID = '';
            for (let i in data.item_id) {
              itemID = data.item_id[i];
            }
            data.item_id = itemID;
          }
          if (data.item_id == '' || data.item_id == null) {
            data.item_id = 0;
          }
          this.determinedBy = true;
          this.$axiosUser('post', '/api/pro/integral/review', data)
            .then(res => {
              if (res.data.code == 1) {
                self.adoptShow = false;
                self.detail_info.status = 2;
                self.$message.success(res.data.msg);
                this.adoptClose(); //关闭通过弹窗
                this.closeDetail(); //关闭抽屉
                if (this.refreshParentList) this.$parent.get_list(); //刷新列表
                this.$emit('hasSubmit')
              }
            })
            .finally(e => {
              this.determinedBy = false;
            });
        }
      });
    },
    rejectRewrite(){
      let self = this
      self.submitting = true
      let params = {
        review_id:self.detail_info.id,
        remark:self.formRejectRewrite.remark || ''
      }

      self.$axiosUser('post','/api/pro/integral/review/reject/rewrite',params)
        .then((res) => {
          if(res.data.code === 1){
            self.formRejectRewrite.remark = ''
            self.showRejectRewrite = false
            self.closeDetail()
            if (self.refreshParentList) self.$parent.get_list()
            self.$emit('hasSubmit')
          } else {
            self.$message.error(res.data.msg)
          }
        })
        .finally(() => {
          self.submitting = false
        })



    },
    reviewStatusType(status){
      switch (status) {
        case 0:
          return 'info'
        case 1:
          return 'success'
        case 2:
        case 3:
        default:
          return 'warning'
      }
    },
    onApprovalRemarkInput(val){
      this.adoptForm.remark = specialFilter(val)
    },
    onRejectRemarkInput(val){
      this.rejectForm.remark = specialFilter(val)
    },
    onRewriteRemarkInput(val){
      this.formRejectRewrite.remark = specialFilter(val)
    }
  }
};
</script>

<style lang="scss" scoped="scoped">
  .form {
    /deep/ .el-form-item {
      margin-bottom: 15px;
    }
  }
  /deep/ .el-dialog__body {
      padding:20px;
      color: #606266;
      font-size: 14px;
      word-break: break-all;
  }
.drawer-footer {
  background-color: #fff;
  border-top: 1px solid #ebebeb;
  padding: 10px 20px;
  font-size: 14px;
}
 .itemClass .el-cascader-menu .el-cascader-menu__wrap li.el-cascader-node {
  height: auto;
  max-width: 500px;
  .el-cascader-node__label {
    // white-space: initial;
    overflow: initial;
    text-overflow: initial;
  }
}

.detail_popup {
  padding: 20px;
  overflow-y: auto;
  overflow-x: hidden !important;
  height: calc(100vh - 60px);
  .row_title {
    position: relative;
    margin: 0 0 20px 0;
    padding-top: 12px;
    font-size: 16px;
    color: #303133;
    line-height: 22px;
  }
  .row_title:before {
    position: absolute;
    top: 0;
    content: ' ';
    width: 100%;
    border-top: 1px #f8f8f8 solid;
  }
  .el-row {
    margin-bottom: 10px;
    font-size: 14px;
    .el-col-4 {
      color: #606266;
    }
  }
}
.drawer_title {
  font-size: 18px;
  padding: 20px;
  border-bottom: 1px #efefef solid;
  height: 60px;
  box-sizing: border-box;
}
.detail_row{
  padding-bottom: 10px;
  line-height: 50px;
}
.desc-content{
  display: block;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
