<template>
  <div>
    <div class="integral_event_box">
      <el-row :gutter="20" style="margin-bottom: 20px;">

        <el-col :span="3">
          <el-select v-model="newTaskFormType" style="width:110px;" filterable placeholder="请选择">
            <el-option v-for="item in pullrow" :key="item.id" :label="item.value" :value="item.id"></el-option>
          </el-select>
        </el-col>
        <el-col :span="6" class="display_flex" v-show="newTaskFormType==1">
          <el-cascader
            class="date-picker-width"
            v-model="rule"
            :options="rule_trees"
            :props="props"
            @change="rule_null"
            ref="rule"
            clearable
            filterable
            change-on-select
            placeholder="选择规则分类"
          ></el-cascader>
        </el-col>

        <el-col :span="6" class="display_flex"  v-show="newTaskFormType==2">
          <el-cascader
              @change="ruleautomatic"
              class="date-picker-width"
              v-model="automaticIntegration"
              :options="rule_list"
              :props="props"
              ref="rule1"
              filterable
              change-on-select
              placeholder="选择自动积分"
              clearable></el-cascader>
        </el-col>

        <el-col :span="8" class="display_flex">
          <span class="label">积分分类</span>
          <el-select class="date-picker-width" v-model="formData.pt_id" clearable placeholder="请选择积分分类">
            <el-option v-for="item in point_types" :key="item.name" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-col>
        <el-col :span="7" class="display_flex" style="position: relative;">
          <span class="label">部门</span>
          <deptData deptStyle="width:150px;left:50px;" v-if="toPdept && toPdept!=0" :refsName="$refs.dept" :toPdept="toPdept"></deptData>
          <el-cascader class="date-picker-width" v-model="dept_name" :options="dept_tree" :props="{ label: 'name', value: 'id'}" ref="dept" clearable filterable change-on-select placeholder="全公司">
            <template slot-scope="{ node, data }">
                <span>
                  <WWOpenData type="departmentName" :openid="data.name"></WWOpenData>
                </span>
                <!-- <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span> -->
              </template>
          </el-cascader>
        </el-col>
      </el-row>

      <el-row :gutter="20" style="margin-bottom: 20px;">
        <el-col class="time_section display_flex" :span="10">
          <span class="label">时间</span>
          <el-date-picker
            v-model="time_slot"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-col>
        <el-col :span="6" class="display_flex">
          <el-input v-model="formData.keyword" placeholder="输入关键字查找" maxlength="100" @keyup.enter.native="keyWordSelect" class="persons_name">
            <el-button slot="append" icon="el-icon-search" @click="keyWordSelect"></el-button>
          </el-input>
        </el-col>

        <el-col :span="8" style="padding-left:15px;float:right;position: relative;">
          <div v-if="dropOuOfPers.currentLabel && dropOuOfPers.currentLabel != ''" class="dropOuOfPersName" @click="takePartIn">
            <WWOpenData type="userName" :openid="dropOuOfPers.currentLabel"></WWOpenData>
          </div>
          <el-select v-model="select_employee_id" ref="dropOuOfref" clearable placeholder="请选择人员">
            <el-option v-for="item in employee_map" :key="item.id" :label="item.name" :value="item.id">
              <span style="float: left"><WWOpenData type="userName" :openid="item.name"></WWOpenData></span>
            </el-option>
          </el-select>
        </el-col>
      </el-row>

      <el-row :gutter="20" style="margin-bottom: 20px;">
        <el-col :span="4">
          <!-- <el-button type="primary" @click="excelImportShow = true">导入数据</el-button> -->
          <el-button type="primary" @click="exportExcel" :disabled="deriveDis">导出当前数据</el-button>
          <!-- <a :href="aherfUrl" ref="aherfClick" v-if="aherfUrl != ''" v-trigger></a> -->
          <a :href="aherfUrl" ref="aherfClick"></a>
        </el-col>
        <el-col :span="17">
          <!-- <el-button type="primary" plain @click="swiperShowTrue">轮播排名</el-button> -->
          <el-button class="first-element-btn" v-if="noticeRole" :disabled='selectionID.length==0' @click="deleteInBatches" type="danger" >批量删除</el-button>
        </el-col>
      </el-row>

      <el-table :data="list" style="width: 100%" v-loading="loading" @row-click="open_detail" @selection-change="deleteEvents">
        <el-table-column
         v-if="noticeRole"
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column prop="employee_name" label="姓名" align="left">
          <template slot-scope="scope">
            <userImage class="fl" :id="scope.row.employee_id" :user_name="scope.row.employee_name" :img_url="scope.row.employee_img_url" width="50px" height="50px"></userImage>
            <span style="margin-left: 10px; line-height: 50px;"><WWOpenData type="userName" :openid="scope.row.employee_name"></WWOpenData></span>
          </template>
        </el-table-column>
        <el-table-column prop="dept" label="部门" align="left" width="150px">
          <template slot-scope="scope">
            <span v-for="(item,index) in scope.row.dept" :key="index">
              <WWOpenData type="departmentName" :openid="item"></WWOpenData><span v-if="(scope.row.dept.length-index)>1">,</span>
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="point_mark" label="积分" align="left" width="100px">
          <template slot-scope="scope">
            <span :class="scope.row.point < 0 ? 'color_green' : 'color_red'">{{ scope.row.point_mark }} {{ point_name(scope.row.pt_id) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" show-overflow-tooltip label="事件" align="left"></el-table-column>
        <!-- <el-table-column prop="remark_data.rule" show-overflow-tooltip label="分类" align="left">
        </el-table-column> -->
        <el-table-column prop="source_type" label="来源" align="left" width="120px">
          <template slot-scope="scope">
            <span v-show="scope.row.source_type == 1">积分录入</span>
            <span v-show="scope.row.source_type == 2">任务</span>
            <span v-show="scope.row.source_type == 3">积分系统分配</span>
            <span v-show="scope.row.source_type == 4">考勤系统分配</span>
            <span v-show="scope.row.source_type == 5">积分申请</span>
            <span v-show="scope.row.source_type == 6">绩效任务包</span>
            <span v-show="scope.row.source_type > 6">其他</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="录入时间" align="left" width="110px">
          <template slot-scope="scope">
            {{ cuttString(scope.row.create_time) }}
          </template>
        </el-table-column>

        <template slot="empty">
          <noData></noData>
        </template>
      </el-table>
      <center class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formData.page"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next"
          :page-size="pageLimit"
          :total="total"
        ></el-pagination>
      </center>
    </div>
    <el-drawer title="事件详情" :visible.sync="detail_popup" ref="drawer" :with-header="false" :width="'500px'" direction="rtl">
      <div class="drawer_title">事件详情</div>
      <div class="detail_popup" v-loading="detail_loading" v-if="detail_info !== null">
        <el-row style="padding-bottom:10px;border-bottom:1px #f8f8f8 solid;">
          <el-col :span="24">
            <userImage :user_name="detail_info.employee_name" :img_url="detail_info.img_url" class="fl" width="50px" height="50px" fontSize="15"></userImage>
            <span style="line-height:50px; margin-left:10px;margin-right:4px;"><WWOpenData type="userName" :openid="detail_info.employee_name"></WWOpenData></span>
            <span class="color_red point" v-show="detail_info.point >= 0">+{{ detail_info.point }} {{ point_name(detail_info.pt_id) }}</span>
            <span class="color_green point" v-show="detail_info.point < 0">{{ detail_info.point }} {{ point_name(detail_info.pt_id) }}</span>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="4">任务描述</el-col>
          <el-col :span="20" v-if="detail_info.remark">{{ detail_info.remark && (detail_info.remark.customize || detail_info.remark.rule) }}</el-col>
        </el-row>

        <el-row>
          <el-col :span="4">规则分类</el-col>
          <el-col :span="20">{{ detail_info.rule_list }}</el-col>
        </el-row>

        <el-row v-show="detail_info.rule_list">
          <el-col :span="4">事件时间</el-col>
          <el-col :span="20">{{ detail_info.date }}</el-col>
        </el-row>

        <el-row v-show="detail_info.source_type_mark">
          <el-col :span="4">来源类型</el-col>
          <el-col :span="20">{{ detail_info.source_type_mark }}</el-col>
        </el-row>

        <el-row v-show="!detail_info.rule_id">
          <el-col :span="4">记录人</el-col>
          <el-col :span="20"><WWOpenData type="userName" :openid="detail_info.employee_name"></WWOpenData></el-col>
        </el-row>

        <el-row v-show="detail_info.files !== null && detail_info.files.length > 0">
          <el-col :span="4">图片</el-col>
          <el-col :span="20">
            <el-image
              v-for="(item, index) in detail_info.files"
              :key="index"
              style="width: 100px; height: 100px;margin:1px"
              :src="item"
              :preview-src-list="detail_info.files"
            ></el-image>
          </el-col>
        </el-row>

        <div v-show="detail_info.rule_id">
          <p class="row_title">规则依据</p>
          <el-row>
            <el-col :span="4">规则分类</el-col>
            <el-col :span="19">{{ detail_info.rule_list }}</el-col>
          </el-row>
          <el-row v-show="detail_info.rule_item_id!=0">
            <el-col :span="4">积分规则</el-col>
            <el-col :span="19">{{ detail_info.remark.rule }}</el-col>
          </el-row>
          <el-row v-show="detail_info.rule_item.min_point>0">
            <el-col :span="5">积分</el-col>
            <el-col :span="19" v-show="detail_info.rule_item.min_point == detail_info.rule_item.max_point">{{ detail_info.rule_item.min_point }}</el-col>
            <el-col :span="19" v-show="detail_info.rule_item.min_point != detail_info.rule_item.max_point">
              {{ detail_info.rule_item.min_point }} ~ {{ detail_info.rule_item.max_point }}
            </el-col>
          </el-row>
        </div>

        <div v-show="detail_info.process !=undefined&&detail_info.process.length>0">
            <Steps :process="detail_info.process"></Steps>
        </div>
        <!-- <div v-show="detail_info.rule_id">
          <p class="row_title">
            审批
            <span class="row_tips">多人审批时，以最后一人为准</span>
          </p>

          <div class="examine_steps">
            <el-steps direction="vertical" :space="50">
              <el-step v-for="(item, index) in detail_info.process" :key="index">
                <template slot="icon">
                  <userImage width="36px" height="36px" :img_url="item.img_url" :user_name="item.name"></userImage>
                </template>
                <template slot="title">
                  <div style="color: #303133;font-size:14px;margin-top:-2px;">
                    <WWOpenData type="userName" :openid="item.name"></WWOpenData> {{ item.remark }}
                  </div>
                </template>
                <template slot="description" style="">
                  {{ item.time }}
                </template>
              </el-step>
            </el-steps>
          </div>
        </div> -->
        <div style="position: absolute; bottom: 20px; display: block; right: 20px;" v-show="deptManagerRouters">
          <el-button @click="close_integral_event">取消</el-button>
          <el-button type="danger" @click="del_integral_event(detail_info)">删除</el-button>
        </div>
      </div>
    </el-drawer>

    <!-- 导入数据 -->
    <el-dialog title="导入积分事件数据" width="600px" :visible.sync="excelImportShow" :close-on-click-modal="false" :before-close="close_import">
      <div style="padding:0 50px;">
        <div class="align-center" style="margin-bottom:20px;">
          <p>
            1、下载积分事件模版，批量录入积分事件
            <el-button type="primary" @click="downloadTemplate" plain>下载模板</el-button>
          </p>
          <el-upload
            :limit="1"
            :headers="ATOKEN"
            ref="upload1"
            :action="integralUpload"
            :data="{ type: 'integral' }"
            :on-success="handlePictureCardPreview"
            :before-upload="beforeFilesUpload"
          >
            <p>
              2、上传积分事件数据Excel表
              <el-button type="primary" plain>选择文件</el-button>
            </p>
          </el-upload>
          <p>3、选择文件后点击下方【上传】按钮</p>
        </div>

        <div class="align-center" style="margin-bottom:20px; float:left; margin-left:10px;"></div>
        <div class="align-center" style="margin-bottom:20px; float:left; margin-left:10px;"><!-- <el-button type="primary" @click="downloadSheet">Excel导出</el-button> --></div>
        <div style="clear:both;"></div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close_import">取 消</el-button>
        <el-button type="primary" @click="uploadFile(1)" :loading="update_btn" plain>上传</el-button>
      </div>
    </el-dialog>

    <el-dialog title="导入结果" :visible.sync="importErrorInfoShow" width="30%">
      <div>
        <el-table :data="error_list" border stripe>
          <el-table-column prop="name" label="备注信息">
            <template slot-scope="scope">
              {{ scope.row }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer"><el-button type="primary" @click="importErrorInfoShow = false">确 定</el-button></span>
    </el-dialog>

    <el-dialog title="轮播排名" :visible.sync="swiperShow" width="500px">
      <div>
        <el-form :inline="true">
          <div style="color:rgb(122 202 126);font-size: 13px;padding:5px 0 20px 0">设置后，相关排名信息可在各类智能终端屏幕上的网页浏览器滚屏展示</div>
          <el-form-item label="展示标题">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 6 }"
              v-model="titleVals"
              placeholder="请输入标题"
              maxlength="20"
              show-word-limit
              style="width: 341px"
            ></el-input>
          </el-form-item>
        </el-form>
        <el-row>
          <el-col :span="4" style="line-height: 36px;">&nbsp;&nbsp;&nbsp;显示最新</el-col>
          <el-col :span="6">
            <el-select v-model="page_size" placeholder="请选择">
              <el-option v-for="item in swiperPageList" :key="item.value" :label="item.value" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="6" style="line-height: 36px;">条积分事件来轮播</el-col>
        </el-row>
      </div>
      <span slot="footer">
        <el-button @click="swiperShow = false">取 消</el-button>
        <router-link :to="{ path: '/deptRankSwiper?' + '&page=1&page_size=' + this.page_size + '&types=1' }" target="_blank">
          <el-button type="primary" @click="swiperPage">开始轮播</el-button>
        </router-link>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getToken } from '@/utils/auth';
import noData from '@/components/noData';
import Steps from '@/components/Steps.vue';
// import axios from "axios"
export default {
  data() {
    return {
      automaticIntegration:[],
      newTaskFormType:1,
      pullrow: [{
          value: '规则分类',
          id: 1
        },
        {
          value: '自动积分',
          id: 2
        }
      ],
      rule_list:[],//自动积分分类列表

      noticeRole:this.$authoritys('creator') || this.$authoritys('admin') || this.$authoritys('point_manager'),
      select_employee_id: '',
      employee_map: JSON.parse(localStorage.getItem('SET_EMPLOYEE_MAP')),
      deptManagerRouters: !this.$authoritys('dept_manager') && !this.$authoritys('employee'),
      integralUpload: process.env.BASE_API + '/api/upload/excel',
      publicBASE_API: process.env.BASE_API,
      titleVals: '',
      titleVal: {
        titleVal1: '',
        titleVal2: '',
        titleVal3: ''
      },

      ATOKEN: { 'A-TOKEN': getToken() },
      loading: false,
      swiperShow: false,
      swiperPageList: [{ value: '10' }, { value: '30' }, { value: '50' }, { value: '100' }],
      page_size: 10,
      point_types: JSON.parse(localStorage.getItem('SET_POINT_TYPES')),
      dept_name: [],
      dept_tree: [],
      formData: {
        page: 1,
        page_size: 10
      },
      time_slot: null,
      rule_trees: [],
      props: { value: 'id', label: 'name', children: 'child' },
      rule: [],
      list: [],
      total: null,
      detail_info: null,
      detail_popup: false,
      detail_loading: false,
      pageLimit: 10,
      excelImportShow: false,
      update_btn: false,
      error_list: [],
      importErrorInfoShow: false,

      selectionID:[],//删除的事件ID
      toPdept:0,
      dropOuOfPers:[],

      deriveJobId: '',
      deriveJobIf: 0,
      deriveDis: false,
      aherfUrl: '',
    };
  },
  components: { noData, Steps},
  created() {},
  mounted() {
    if (localStorage.getItem('dept_tree')) {
      this.dept_tree = this.getTreeData(JSON.parse(localStorage.getItem('dept_tree')));
    }
    this.get_rule_trees();
    this.get_integral_list(this.formData);
    this.voluntarilyRule_trees()//自动积分列表
  },
  watch: {
    newTaskFormType(val){
      this.formData.rule_id = []
      // this.get_integral_list(this.formData);
    },
    'formData.pt_id'(val, old_val) {
      this.formData.page = 1;
      !val ? delete this.formData.pt_id : '';
      this.get_integral_list(this.formData);
    },
    'formData.page'(val, old_val) {
      this.get_integral_list(this.formData);
    },
    time_slot(val, old_val) {
      this.formData.page = 1;
      if (val !== null) {
        this.formData.start_day = val[0];
        this.formData.end_day = val[1];
      } else {
        delete this.formData.start_day;
        delete this.formData.end_day;
      }
      this.get_integral_list(this.formData);
    },
    dept_name(val, old_val) {
      this.toPdept = val[val.length-1]
      this.formData.page = 1;
      if (val.length != 0) {
        this.formData.dept_id = val[val.length - 1];
      } else {
        this.formData.dept_id = 0;
      }
      this.$nextTick(() => {
        this.$refs.dept.dropDownVisible = false;
        this.get_integral_list(this.formData);
      });
    },
    select_employee_id(val) {
      console.log(val)
      this.formData.employee_ids = val;
      this.get_integral_list(this.formData);
      this.$nextTick(()=>{
        console.log(this.$refs['dropOuOfref'].selected)
        this.dropOuOfPers = this.$refs['dropOuOfref'].selected
      })
    }
  },
  // directives: {
  //   aderivecli:{
  //     inserted(el,binging){
  //       console.log(el)
  //       // el.click()
  //     }
  //   }
  // },
  methods: {
    takePartIn(){
      this.$refs['dropOuOfref'].visible = true
    },
    ruleautomatic(){
      let list = this.automaticIntegration
      this.formData.rule_id = list[0]
      this.get_integral_list(this.formData);
      this.$refs.rule1.dropDownVisible = false;
    },
    voluntarilyRule_trees() {
      let self = this;
      self.$http('get',"/api/integral/rule/trees",{cycle_type: "2",},)
        .then((res) => {
          if (res.data.code == 1) {
            self.rule_list = this.getRuleTreeData(res.data.data.rule_tree);
          }
        })
        .finally(() => {
        });
    },
    //删除事件
    deleteEvents(selection){
      let listId = []
      selection.forEach(item=>{
       listId.push(item.id)
      })
      this.selectionID = listId
    },
    deleteInBatches(){
      if (this.selectionID.length < 1) {
        return false
      }
      this.$confirm('此操作将永久删除选中的积分事件, 确认要删除吗？', '批量删除事件', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        this.$http('DELETE','/api/integral/statistics/integral/many',{event_ids:this.selectionID}).then((res)=>{
          if(res.data.code == 1){
            this.$message({
              message: res.data.msg,
              type: 'success'
            });
            if(this.selectionID.length == this.list.length){
              if(this.formData.page > 1){
                this.formData.page = this.formData.page-1;
              }
            }
            this.get_integral_list(this.formData)
          }else{
            this.$message.error(res.data.msg);
          };
        }).catch(()=>{
          this.loading = false
        }).finally(()=>{
        })
      }).catch(() => {

      })
    },
    
    //轮播
    swiperPage() {
      if (this.titleVals != '') {
        this.titleVal.titleVal1 = this.titleVals;
        localStorage.setItem('titleVal', JSON.stringify(this.titleVal));
      } else {
        this.titleVal.titleVal1 = '';
        localStorage.setItem('titleVal', JSON.stringify(this.titleVal));
      }
    },
    // 轮播弹窗
    swiperShowTrue() {
      if (localStorage.getItem('titleVal')) {
        this.titleVal = JSON.parse(localStorage.getItem('titleVal'));
        this.titleVals = this.titleVal.titleVal1;
      } else {
        this.titleVals = '';
      }
      this.swiperShow = true;
    },
    // keyword
    keyWordSelect() {
      this.formData.page = 1;
      this.get_integral_list(this.formData);
    },
    downloadTemplate() {
      window.open(this.publicBASE_API + '/api/download/integral/template');
    },
    // 文件上传
    close_import() {
      this.excelImportShow = false;
    },
    uploadFile() {
      // this.excelImportShow = false
      let params = {};
      params.file = this.file;
      this.update_btn = true;
      this.$http('post','/api/integral/import', params).then(res => {
          if (res.data.code == 1) {
            if (res.data.data.error.length == 0) {
              this.$message({ type: 'success', message: '导入成功' });
              this.excelImportShow = false;
            } else {
              this.$message({ type: 'error', message: '导入错误' });
              this.error_list = res.data.data.error;
              this.importErrorInfoShow = true;
            }
          } else {
            this.$message({ type: 'error', message: res.data.msg });
          }
        })
        .finally(() => {
          setTimeout(() => {
            this.update_btn = false;
          }, 3000);
        });
    },
    handlePictureCardPreview(response) {
      if (response.code == 1) {
        this.file = response.data;
      }
    },
    beforeFilesUpload(file) {
      const $ext_list = ['xlsx', 'xls'];
      let len = file.name.split('.').length - 1;
      const $ext_name = file.name.split('.')[len];
      if ($ext_list.indexOf($ext_name) != -1) {
      } else {
        this.$message.warning('文件格式上传错误,仅支持上传xlsx,xls）');
        return false;
      }
    },
    onFilePreView() {},
    downloadResult(){
      if(this.deriveJobIf < 5){
        this.$http('get','/api/download/result',{job_id: this.deriveJobId}).then((res)=>{
          if(res.data.code == 1){
            // window.open(res.data.data.url)
            // window.location.href = res.data.data.url
            this.aherfUrl = res.data.data.url
            this.deriveJobId = ''
            this.deriveDis = false
            this.$nextTick(()=>{
              this.$refs.aherfClick.click()
              // this.aderivecli()
            })
          }else{
            setTimeout(()=>{
              this.deriveJobIf++
              this.downloadResult()
            },3000)
          }
        })
      }else{
        this.deriveJobIf = 0
        this.deriveJobId = ''
        this.deriveDis = false
        this.aherfUrl = ''
        this.$message.warning('导出超时');
      }
    },
    exportExcel() {
      this.aherfUrl = ''
      this.$confirm('确认导出积分事件？', '导出', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deriveDis = true
        let params = {
          employee_id: this.$store.getters.user_info.id,
          page: this.formData.page,
          page_size: this.formData.page_size,
        }
        this.formData.rule_id ? params.rule_id = this.formData.rule_id : ''
        this.formData.pt_id ? params.pt_id = this.formData.pt_id : ''
        this.formData.employee_ids ? params.employee_ids = this.formData.employee_ids : ''
        this.formData.dept_id ? params.dept_ids = this.formData.dept_id : ''
        this.formData.start_day ? params.start_day = this.formData.start_day : ''
        this.formData.end_day ? params.end_day = this.formData.end_day : ''
        this.formData.keyword ? params.keyword = this.formData.keyword : ''
        this.$http('get','/api/download/integral',params).then((res)=>{
          if(res.data.code == 1){
            this.deriveJobId = res.data.data.job_id
            this.downloadResult()
          }else{
            this.deriveDis = false
          }
        })
      }).catch(() => {

      })
      
      return
      window.open('https://open.work.weixin.qq.com/wwopen/openData/getTranslateContactOpenData?dataid=_Q-jZZifks4nhgXAXmSGYJwMC40p3sGyeeKZV2I79e0')
      return
      let token = this.$getToken?this.$getToken:getToken()
      window.open(
        this.publicBASE_API +'/api/download/integral?employee_id=' +this.$store.getters.user_info.id +'&page=' + this.formData.page +'&page_size=' +this.formData.page_size +
          (this.formData.rule_id ? '&rule_id=' + this.formData.rule_id : '') +
          (this.formData.pt_id ? '&pt_id=' + this.formData.pt_id : '') +
          (this.formData.employee_ids ? '&employee_ids=' + this.formData.employee_ids : '') +
          (this.formData.dept_id ? '&dept_ids=' + this.formData.dept_id : '') +
          (this.formData.start_day ? '&start_day=' + this.formData.start_day : '') +
          (this.formData.end_day ? '&end_day=' + this.formData.end_day : '') +0
          (this.formData.keyword ? '&keyword=' + this.formData.keyword : '')+
          '&token='+token,
        '_blank'
      );
          // let params = {
          //   employee_id:this.$store.getters.user_info.id,
          //   page:this.formData.page,
          //   page_size:this.formData.page_size,
          //   rule_id:this.formData.rule_id ? this.formData.rule_id : null,
          //   pt_id:this.formData.pt_id ? this.formData.pt_id : null,
          //   employee_ids:this.formData.employee_ids ? this.formData.employee_ids : null,
          //   dept_ids:this.formData.dept_id ? this.formData.dept_id : null,
          //   start_day:this.formData.start_day ? this.formData.start_day : null,
          //   end_day:this.formData.end_day ? this.formData.end_day : null,
          //   keyword:this.formData.keyword ? this.formData.keyword : null,
          // }
        
        // this.$http('get',this.publicBASE_API +'/api/download/integral',params).then((res)=>{
        //   console.log(res)
        // })

        // axios({
        //   method: 'get',
				// 	url: this.publicBASE_API +'/api/download/integral',
				// 	responseType: 'blob',
				// 	params: params,
				// 	headers: {
        //   }
        // }).then((res)=>{
        //   console.log(res)
        // })
    },
    // openPostWindow(url, params) {
    //   var newWin = window.open(),
    //   formStr = '';
    //   //设置样式为隐藏，打开新标签再跳转页面前，如果有可现实的表单选项，用户会看到表单内容数据
    //   formStr = '<form style="visibility:hidden;" method="POST" action="' + url + '">' +
    //         '<input type="hidden" name="params" value="' + params + '" />' +
    //         '</form>';
    //   newWin.document.body.innerHTML = formStr;
    //   // newWin.document.write(formStr)
    //   newWin.document.forms[0].submit();
    //   return newWin;
    // },
    // end 文件上传

    handleSizeChange(val) {
      this.pageLimit = val;
      this.formData.page_size = this.pageLimit;
      this.get_integral_list(this.formData);
    },
    cuttString(data) {
      return data.substring(5);
    },
    // 递归判断列表，把最后的children设为undefined
    getTreeData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].children.length < 1) {
          // children若为空数组，则将children设为undefined
          data[i].children = undefined;
        } else {
          // children若不为空数组，则继续 递归调用 本方法
          this.getTreeData(data[i].children);
        }
      }
      return data;
    },
    // 规则递归 children
    getRuleTreeData(data) {
      for (var i = 0; i < data.length; i++) {
        if (data[i].child.length < 1) {
          // children若为空数组，则将children设为undefined
          data[i].child = undefined;
        } else {
          // children若不为空数组，则继续 递归调用 本方法
          this.getRuleTreeData(data[i].child);
        }
      }
      return data;
    },
    open_detail(item) {
      let self = this;
      self.detail_popup = true;
      let data = {
        event_id: item.id
      };
      self.detail_loading = true;
      self.$http('get','/api/integral/statistics/integral/info',data)
        .then(res => {
          if (res.data.code == 1) {
            self.detail_info = res.data.data;
          } else {
            self.$message.error(res.data.data.msg);
          }
        })
        .finally(() => {
          self.detail_loading = false;
        });
    },
    get_rule_trees() {
      let self = this;
      self.$http('get','/api/integral/rule/trees')
        .then(res => {
          if (res.data.code == 1) {
            let arr = res.data.data.rule_tree;
            self.rule_trees = self.getRuleTreeData(arr);
          } else {
            self.$message.error(res.data.data.msg);
          }
        })
        .finally(() => {});
    },
    get_integral_list(data) {
      let self = this;
      data.dept_ids = data.dept_id;
      self.loading = true;
      self.$http('get','/api/integral/statistics/integral',data)
        .then(res => {
          if (res.data.code == 1) {
            self.list = res.data.data.list;
            self.total = res.data.data.total;
          } else {
            self.$message.error(res.data.data.msg);
          }
        })
        .finally(() => {
          self.loading = false;
        });
    },
    handleCurrentChange(val) {
      this.formData.page = val;
    },
    rule_null(val) {
      if (val.length == 0) {
        this.formData.rule_id = 0;
      } else {
        this.formData.rule_id = this.rule[this.rule.length - 1];
      }
      this.$nextTick(() => {
        this.$refs.rule.dropDownVisible = false;
        this.get_integral_list(this.formData);
      });
    },
    del_integral_event(item) {
      let self = this;
      self.$confirm('删除事件的同时也会撤销积分，确定删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          self.$http('DELETE','/api/integral/statistics/integral',{ event_id: item.event_id }).then(res => {
              if (res.data.code == 1) {
                self.$message.success(res.data.msg);
                self.detail_popup = false;
                self.get_integral_list();
              } else {
                self.$message.error(res.data.msg);
              }
            }) .catch(e => {
              self.$message.error(e.data.msg);
            });
        });
    },
    close_integral_event() {
      this.detail_popup = false;
    },
    point_name(id) {
      return this.point_types.find(item => {
        if (item.id == id) {
          return item.name;
        }
      }).name;
    }
  }
};
</script>
<style scoped lang="scss">
header.el-drawer__header {
  font-size: 18px;
  font-family: MicrosoftYaHei;
  color: #303133;
  width: 500px;
  span {
    :focus {
      outline: 0;
    }
  }
}
.display_flex {
  display: flex;
}
.label {
  line-height: 36px;
  padding-right: 10px;
}
.time_section {
  .el-range-editor {
    width: 330px;
  }
}
.color_green {
  color: #67c23a;
}
.pagination {
  padding: 20px 0;
}
.detail_popup {
  padding: 20px;
  height: 100%;
  .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;
    }
  }
}
.color_red {
  color: #f56c6c;
}
.color_green {
  color: #67c23a;
}
span.point {
  font-size: 16px;
}
.drawer_title {
  font-size: 18px;
  padding: 20px;
  border-bottom: 1px #efefef solid;
}
.row_tips {
  display: block;
  color: #909399;
  font-size: 12px;
  margin-top: 0px;
}
.el-range-editor--medium .el-range-separator {
  width: 25px;
}
.integral_event_box {
  background-color: #ffffff;
  padding: 20px;
  min-height: calc(100vh - 160px);
}
.examine_steps /deep/.el-step.is-vertical .el-step__title {
  padding-bottom: 0;
}

/deep/ .el-dialog__body{
  padding:0px 20px 30px;
}


.dropOuOfPersName {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  z-index: 9;
  margin: 1px 0 0 16px;
  padding-left: 14px;
  background-color: #ffffff;
  color: #1d1d1d;
  width: 170px;
  overflow: hidden;
  cursor: pointer;
  height:34px;
  line-height:34px;
  border-radius: 5px;
}
</style>
