<template>
  <a @click="dialogCreateVisible = true" class="integral-create-review-btn">
    <el-button type="primary" plain>关联工作任务</el-button>
    <el-dialog
      append-to-body
      class="integral-create-review-dialog"
      title="积分事件录入"
      width="1000px"
      top="50px"
      ref="integral_create_review_dialog"
      :visible.sync="dialogCreateVisible"
      :close-on-click-modal="false"
      @open="setDefaultValueForDialog"
    >
      <el-steps :active="activeIndex" finish-status="success" simple style="margin:10px 22px">
        <el-step title="选择对象"></el-step>
        <el-step title="选择工作任务"></el-step>
        <el-step title="提交保存"></el-step>
      </el-steps>
      <el-row :gutter="15" style="padding:0px 30px;">
        <el-col :span="24" v-show="activeIndex==0" style="margin-top:10px;">
          <EmployeeSelector @check="set_target_ids"></EmployeeSelector>
        </el-col>
        <el-col
          :span="24"
          v-show="activeIndex==1"
          style="padding-left:0; padding-right:0; margin-top:10px;"
        >
          <el-form
            ref="newEventForm"
            :model="newEventForm"
            :rules="rules"
            @submit.native.prevent
            style="padding:0;"
          >
            <el-row>

              <el-col :span="24">
                <div style="margin-top:2px; margin-bottom:15px;" class="inline-block-btn-list">

                  <el-cascader
                    clearable
                    :options="categoryTree"
                    change-on-select
                    v-model="filter.category_id"
                    @change="onFilterChanged"
                    placeholder="选择分类进行筛选或编辑"
                    class="gap-right-8 first-element-btn"
                  ></el-cascader>



                  <div class="gap-right-8" style="display:inline-block; width:220px;">
                    <el-input
                      placeholder="输入关键词查找"
                      ref="search-bar"
                      v-model="filter.keywords"
                      class="input-with-select"
                      @keyup.enter.native="onFilterChanged"
                    >
                      <el-button slot="append" icon="el-icon-search" @click="onFilterChanged"></el-button>
                    </el-input>
                  </div>


                  <el-pagination style="float:right; margin:0; padding:0;"
                    background
                    layout="prev, pager, next"
                    :page-sizes="[10, 20, 50, 100]"
                    :total="totalCount"
                    :current-page.sync="currentPage"
                    @current-change="changePage"
                  ></el-pagination>
<div style="clear:both;"></div>
                </div>
                <el-scrollbar
                  wrap-class="column-wrapper scrollable-items-container"
                  :native="false"
                  style="height: 396px;"
                  v-loading="setformloading"
                >


                  <el-table
                    v-loading="loading"
                    ref="multipleTable"

                    @selection-change="handleSelectionChange"
                    :data="tableData"
                    :border="false"
                    tooltip-effect="dark"
                    style="width: 100%"
                  >
                    <el-table-column
                      type="selection"
                      width="42"
                      v-if="profile.manager_type > 1"
                      :selectable="selectable"
                    ></el-table-column>
                    <!-- <el-table-column prop="category_name" label="积分分类" :filterMultiple="false" column-key="category" :filters="status_list"> -->
                    <el-table-column prop="category_name" label="分类" :filterMultiple="false"></el-table-column>
                    <el-table-column prop="name" label="任务名称"></el-table-column>
                    <!-- <el-table-column prop="items" label="细则内容" :show-overflow-tooltip="true"> -->
                    <el-table-column label="备注">
                      <template slot-scope="scope">
                        {{scope.row.remark}}
                      </template>
                    </el-table-column>
                    <el-table-column
                      prop="point"
                      label="积分"
                    ></el-table-column>

                    <el-table-column label="分发周期">
                      <template slot-scope="scope">
                        <span v-if="scope.row.cycle_type == 0">每天</span>
                        <span v-if="scope.row.cycle_type == 1">每周</span>
                        <span v-if="scope.row.cycle_type == 2">每月</span>
                      </template>
                    </el-table-column>

                    <el-table-column label="分发时间">
                      <template slot-scope="scope">
                        <span v-if="scope.row.cycle_type == 0">{{scope.row.distribution_time}}:00</span>
                        <span v-if="scope.row.cycle_type == 1">
            <span v-if="scope.row.distribution_date==1">星期一 </span>
            <span v-if="scope.row.distribution_date==2">星期二 </span>
            <span v-if="scope.row.distribution_date==3">星期三 </span>
            <span v-if="scope.row.distribution_date==4">星期四 </span>
            <span v-if="scope.row.distribution_date==5">星期五 </span>
            <span v-if="scope.row.distribution_date==6">星期六 </span>
            <span v-if="scope.row.distribution_date==7">星期日 </span>{{scope.row.distribution_time}}:00
          </span>
                        <span v-if="scope.row.cycle_type == 2">第{{scope.row.distribution_date}}天 {{scope.row.distribution_time}}:00</span>
                      </template>
                    </el-table-column>



                  </el-table>



                </el-scrollbar>
              </el-col>
            </el-row>
          </el-form>
        </el-col>
      </el-row>

      <el-row :gutter="15" style="margin:0 15px;" v-show="activeIndex == 2">
        <el-col :span="7">
          <el-card class="box-card card-box-item" shadow="never" style="margin-top:15px;">
            <el-scrollbar
              wrap-class="column-wrapper scrollable-items-container check-item-box dept_tree"
              :native="false"
              style="height: 350px;"
            >
              <div style="padding-right:15px;">
                <el-table
                  :data="target_list"
                  :border="false"
                  tooltip-effect="dark"
                  style="width: 100%"
                >
                  <el-table-column prop="name" :label="'已选择人员（'+(target_list.length)+'人）'">
                    <template slot-scope="scope">
                      <div class="rank_head" style="cursor: pointer;">
                        <img
                          v-if="scope.row.img_url != null"
                          v-bind:src="scope.row.img_url"
                          width="42px"
                          height="42px"
                        >
                        <img
                          v-if="scope.row.img_url == null"
                          src="static/images/head_default.png"
                          width="42px"
                          height="42px"
                        >
                        {{scope.row.name}}
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-scrollbar>
          </el-card>
        </el-col>
        <el-col :span="17">





          <el-table
            :data="multipleSelection"
            :border="false"
            tooltip-effect="dark"
            style="width: 100%"
          >


            <el-table-column prop="category_name" label="分类" :filterMultiple="false"></el-table-column>
            <el-table-column prop="name" label="任务名称"></el-table-column>

            <el-table-column label="备注">
              <template slot-scope="scope">
                {{scope.row.remark}}
              </template>
            </el-table-column>
            <el-table-column
              prop="point"
              label="积分"
            ></el-table-column>

            <el-table-column label="分发周期">
              <template slot-scope="scope">
                <span v-if="scope.row.cycle_type == 0">每天</span>
                <span v-if="scope.row.cycle_type == 1">每周</span>
                <span v-if="scope.row.cycle_type == 2">每月</span>
              </template>
            </el-table-column>

            <el-table-column label="分发时间">
              <template slot-scope="scope">
                <span v-if="scope.row.cycle_type == 0">{{scope.row.distribution_time}}:00</span>
                <span v-if="scope.row.cycle_type == 1">
            <span v-if="scope.row.distribution_date==1">星期一 </span>
            <span v-if="scope.row.distribution_date==2">星期二 </span>
            <span v-if="scope.row.distribution_date==3">星期三 </span>
            <span v-if="scope.row.distribution_date==4">星期四 </span>
            <span v-if="scope.row.distribution_date==5">星期五 </span>
            <span v-if="scope.row.distribution_date==6">星期六 </span>
            <span v-if="scope.row.distribution_date==7">星期日 </span>{{scope.row.distribution_time}}:00
          </span>
                <span v-if="scope.row.cycle_type == 2">第{{scope.row.distribution_date}}天 {{scope.row.distribution_time}}:00</span>
              </template>
            </el-table-column>



          </el-table>





        </el-col>
      </el-row>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogCreateVisible = false">取 消</el-button>
        <el-button @click="activeIndexPrev" v-show="activeIndex > 0">上一步</el-button>
        <el-button @click="activeIndexNext" type="primary" v-show="activeIndex < 2">下一步</el-button>

        <el-button
          v-show="activeIndex == 2"
          :loading="submitLoading"
          type="primary"
          @click="submitCreateForm('newEventForm')"
        >提 交</el-button>
        <div style="clear:both;"></div>
      </div>
    </el-dialog>
  </a>
</template>
<script>
import EmployeeSelector from "@/views/integral/EmployeeSelector";
export default {
  components: { EmployeeSelector },
  name: "IntegralCreateReviewBtn",
  data() {
    let validateTarget = (rule, value, callback) => {
      if (!value || value.length == 0) {
        this.$message({
          message: "请选择奖扣积分对象",
          type: "error"
        });

        return callback(new Error("请选择奖扣积分对象"));
      } else {
        callback();
      }
    };
    let validateCategory = (rule, value, callback) => {
      if (!value || value.length == 0) {
        return callback(new Error("请选择积分分类"));
      } else {
        callback();
      }
    };
    let validateRule = (rule, value, callback) => {
      if (!value || isNaN(value)) {
        return callback(new Error("请选择积分规则"));
      } else {
        callback();
      }
    };
    let validateItem = (rule, value, callback) => {
      if (isNaN(value.point) || parseInt(value.point) == 0) {
        return callback(new Error("请填写有效的积分数值"));
      }
      callback();
    };
    return {
      setformloading: false,
      submitLoading: false,
      activeIndex: 0,
      dialogWidth: "510px",
      dialogWidth_left: 16,
      dialogWidth_right: 0,
      dialogWidth_employee: 8,
      profile: this.$store.getters.user_info,
      totalCount: 0,
      tableData: null,
      currentPage: 1,
      multipleSelection: [],
      dialogCreateVisible: false,
      dialogEditVisible: false,
      dialogExcelVisible: false,
      formLabelWidth: "90px",
      newEventForm: {
        query_time: "",
        target_id_set: [],
        category_id: [],
        rule_id: "",
        event_time: "",
        items: []
      },
      eventForm: {
        id: "",
        target_name: "",
        event_time: "",
        category_path: "",
        rule_name: "",
        point: "",
        remark: "",
        item: {
          content: "",
          is_range: false,
          is_negative: false,
          point_type: "",
          value_1: 0,
          value_2: 0
        }
      },
      target_list: [],
      itemSelectForm: {
        target_id_set: [],
        category_id: [],
        rule_id: "",
        event_time: "",
        items: [],
        get_category: 1
      },
      selectedItems: [],
      rules: {
        target_id_set: [{ validator: validateTarget, trigger: "blur" }],
        category_id: [{ validator: validateCategory, trigger: "blur" }],
        rule_id: [{ validator: validateRule, trigger: "v" }]
      },
      itemRules: {
        validator: validateItem,
        trigger: "blur"
      },
      deptTree: [],
      filter: {
        keywords: "",
        target_id_set: [],

        point_type: 0,
        time_range: "",
        dept_id: [],
        status: 1,

        category_id: null
      },

      categoryTree: [],
      employeeOptions: [],
      pointTypes: [],
      availableRuleOptions: [],
      task_ids:[],
      un_task_ids: [],
      assistantOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      instantPickerOptions: {
        shortcuts: [
          {
            text: "本周",
            onClick(picker) {
              const now = new Date(new Date().toLocaleDateString());
              let start =
                now.getTime() - (now.getDay() - 1) * 24 * 60 * 60 * 1000;
              let end = start + 7 * 24 * 60 * 60 * 1000 - 1000;
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "上周",
            onClick(picker) {
              const now = new Date(new Date().toLocaleDateString());
              let start =
                now.getTime() - (now.getDay() + 6) * 24 * 60 * 60 * 1000;
              let end = start + 7 * 24 * 60 * 60 * 1000 - 1000;
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "本月",
            onClick(picker) {
              const now = new Date();
              let startDate = new Date(now.getFullYear(), now.getMonth(), 1);
              let endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0);
              picker.$emit("pick", [startDate.getTime(), endDate.getTime()]);
            }
          },
          {
            text: "上月",
            onClick(picker) {
              const now = new Date();
              let startDate = new Date(
                now.getFullYear() - (now.getMonth() > 0 ? 0 : 1),
                (now.getMonth() + 11) % 12,
                1
              );
              let endDate = new Date(now.getFullYear(), now.getMonth(), 0);
              picker.$emit("pick", [startDate.getTime(), endDate.getTime()]);
            }
          }
        ]
      }
    };
  },
  methods: {

    selectable: function(){
      return true
    },
    onFilterChanged: function() {
      this.currentPage = 1
      this.loadRuleList()
    },
    loadRuleList: function() {
      var self = this
      self.loading = true
      var params = {
        page: this.currentPage,
        interval: 8
      }
      for (const item in this.filter) {
        const value = this.filter[item]
        if (item == 'category_id') {
          if (!value || value.length == 0) {
            continue
          }

          //params[item] = value
          params[item] = value[value.length - 1];
        } else {
          const valueStr = value.toString()
          if (valueStr && valueStr.length > 0) {
            params[item] = valueStr
          }
        }
      }
      this.$http('get','/integral.php/performance_work/get_task_list',params)
        .then(function(response) {
          if (response.status == 200) {
            self.loading = false
            var jsonData = response.data
            try {
              self.totalCount = jsonData.data.total
              self.tableData = jsonData.data.data
              self.$nextTick(() => {
                for(let i in self.tableData){
                  if(self.task_ids.indexOf(self.tableData[i].id) >= 0){
                    self.$refs['multipleTable'].toggleRowSelection(self.tableData[i])
                  }
                }
              })
            } catch (err) {
              console.log(err)
            }
          }
        })
        .catch(function(error) {
          console.log(error)
        })
    },
    changePage: function(current) {
      if (isNaN(current) || current < 1) {
        return false
      }

      this.loadRuleList()
    },
    activeIndexNext() {
      const self = this;
      if (
        this.activeIndex == 0 &&
        self.newEventForm.target_id_set.length == 0
      ) {
        this.$message({
          message: "请选择员工",
          type: "error"
        });
        return false;
      }
      if (this.activeIndex == 1) {
        if (self.multipleSelection.length == 0) {
          this.$message({
            message: "请选择工作任务",
            type: "error"
          });
          return false;
        }
      }

      this.activeIndex++;
    },
    activeIndexPrev() {
      this.activeIndex--;
    },
    dateFormatter: function(row, column, cellValue) {
      return this.$moment(cellValue * 1000).format("YYYY年MM月DD日");
    },

    //employee_checked(dd){console.log(dd,'dfasdfa')},
    set_target_ids(data) {
      const self = this;
      self.newEventForm.target_id_set = [];
      for (let i in data) {
        self.newEventForm.target_id_set.push(data[i].id);
      }
      self.target_list = data;
    },

    handleNodeClick(data) {
      this.newEventForm.category_id = [data.value];
      this.loadAvailableRules(this.newEventForm);
    },

    loadPointType: function() {
      var self = this;
      this.$http('get',"/integral.php/ajax_request_common/get_point_types")
        .then(function(response) {
          if (response.status == 200) {
            let jsonData = response.data;
            try {
              self.pointTypes = jsonData;
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    toggleSelection: function(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    //选择积分分类时更新积分规则
    loadAvailableRules: function(formObj) {
      this.setformloading = true;
      if (!formObj) {
        return;
      }
      let categoryPath = formObj.category_id;
      if (!categoryPath || categoryPath.length == 0) {
        return;
      }
      var self = this;
      this.$http('get',"/integral.php/performance_work/task_category_tree",{category_id: categoryPath[categoryPath.length - 1]})
        .then(function(response) {
          self.setformloading = false;
          if (response.status == 200) {
            let jsonData = response.data;
            try {
              self.availableRuleOptions = jsonData;
              formObj.rule_id = "";
              formObj.items = [];
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    //选择积分规则时更新细则列表
    loadAvailableItems: function(formObj, callback) {
      const self = this;
      if (!formObj) {
        return;
      }
      let ruleId = formObj.rule_id;
      if (isNaN(ruleId) || ruleId < 0) {
        return;
      }
      let params = {
        rule_id: ruleId
      };
      if (formObj.get_category) {
        params.get_category = formObj.get_category;
      }
      this.$http('get',"/integral.php/ajax_request_common/get_integral_items_by_rule",params)
        .then(function(response) {
          if (response.status == 200) {
            let jsonData = response.data;

            try {
              if (callback) {
                jsonData = callback.call(null, jsonData);
              }
              formObj.items = jsonData;
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    initializeItemData: function(jsonData) {
      for (let index = 0; index < jsonData.length; index++) {
        let item = jsonData[index];
        item.checked = false;
        item.point = item.value_1;
        item.remark = "";
      }
      return jsonData;
    },
    applyItemSelection: function(jsonData) {
      let selectedItemIds = this.selectedItems.map(x => x.id);
      for (let index = 0; index < jsonData.length; index++) {
        let item = jsonData[index];
        item.checked = selectedItemIds.indexOf(item.id) > -1;
      }
      return jsonData;
    },
    generatePointIndication: function(item) {
      let propertyText = item.is_negative == 1 ? "扣除" : "奖励";
      let valueText =
        item.is_range == 1 ? item.value_1 + "～" + item.value_2 : item.value_1;
      let typeText = "";
      for (let index = 0; index < this.pointTypes.length; index++) {
        let pointType = this.pointTypes[index];
        if (item.point_type == pointType.value) {
          typeText = pointType.label;
          break;
        }
      }
      return "标准： " + propertyText + "  " + valueText + "  " + typeText;
    },
    handleSelectionChange: function(val) {
      setTimeout(() => {
        let ids = []
        let un_ids = []
        for(let i in val){
          ids.push(val[i].id)
          if(this.task_ids.indexOf(val[i].id) < 0){
            this.task_ids.push(val[i].id)
            this.multipleSelection.push(val[i])
          }
        }
        //所有没有选中的记录
        for(let i in this.tableData){
          if(ids.indexOf(this.tableData[i].id) < 0){
            un_ids.push(this.tableData[i].id)
          }
        }
        let task_ids = []
        let multipleSelection = []

        for(let i in this.task_ids){
          if(un_ids.indexOf(this.task_ids[i]) < 0){
            task_ids.push(this.task_ids[i])
          }
        }
        for(let i in this.multipleSelection){
          if(un_ids.indexOf(this.multipleSelection[i].id) < 0){
            multipleSelection.push(this.multipleSelection[i])
          }
        }
        this.multipleSelection = multipleSelection
        this.task_ids = task_ids
        console.log(this.task_ids, this.multipleSelection)
      }, 50)

      //this.multipleSelection = JSON.parse(JSON.stringify(val));
    },

    resetCreateDialog: function() {
      this.newEventForm.rule_id = "";
      this.newEventForm.items = [];
      this.dialogWidth = "510px";

      this.newEventForm.category_id = [];
      this.newEventForm.rule_id = "";
      this.newEventForm.event_time = "";
      this.newEventForm.items = [];

      let form = this.$refs["newEventForm"];
      form.clearValidate();

      this.activeIndex = 0;
    },
    openEditDialog: function(eventId) {
      var self = this;
      this.$http('get',"/integral.php/ajax_request_common/get_event_detail",{id: eventId})
        .then(function(response) {
          if (response.status == 200) {
            let jsonData = response.data;
            try {
              self.eventForm = self.processDetailData(jsonData);
              self.dialogEditVisible = true;
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    onDismissEditDialog: function() {
      let form = this.$refs["eventForm"];
      form.clearValidate();
      this.eventForm = {
        id: "",
        target_name: "",
        event_time: "",
        category_path: "",
        rule_name: "",
        point: "",
        remark: "",
        item: {
          content: "",
          is_range: false,
          is_negative: false,
          point_type: "",
          value_1: 0,
          value_2: 0
        }
      };
    },
    submitCreateForm: function(formName) {
      this.sendCreateRequest();
    },
    sendCreateRequest: function() {
      let formData = {
        employee_id: this.newEventForm.target_id_set,
        task_id: this.task_ids
      }

      var self = this;
      self.submitLoading = true;
      this.$http("post","/integral.php/performance_work/taskrelation",formData,'','',
        {transformRequest: [
          data => {
            let paramArray = new Array();
            for (let it in data) {
              paramArray.push(
                encodeURIComponent(it) + "=" + encodeURIComponent(data[it])
              );
            }
            return paramArray.join("&");
          }
        ]},
        // headers: {
        //   "Content-Type": "application/x-www-form-urlencoded"
        // }
      )
        .then(function(response) {
          self.submitLoading = false;
          self.$emit("send_success", response);
          let data = response.data;
          self.$message({
            message: data.msg,
            type: data.code == 1000 ? "success" : "error"
          });
          if (data.code == 1000) {
            self.resetCreateDialog();
          }
        })
        .catch(function(error) {
          self.submitLoading = false;
          console.log(error);
        });
    },
    sendEditRequest: function() {
      let dataObj = this.eventForm;
      if (isNaN(dataObj.point) || !dataObj.point) {
        this.$message({
          message: "请填写积分数值",
          type: "error"
        });
        this.$refs["pointEditor"].focus();
        return;
      }
      let formData = {
        id: dataObj.id,
        event_time: parseInt(dataObj.event_time / 1000),
        point: dataObj.point,
        remark: dataObj.remark,
        is_negative: dataObj.item.is_negative
      };
      var self = this;
      this.$http("post","/integral.php/ajax_request_common/update_event",formData,'','',
        {transformRequest: [
          data => {
            let paramArray = new Array();
            for (let it in data) {
              paramArray.push(
                encodeURIComponent(it) + "=" + encodeURIComponent(data[it])
              );
            }
            return paramArray.join("&");
          }
        ]},
        // headers: {
        //   "Content-Type": "application/x-www-form-urlencoded"
        // }
      )
        .then(function(response) {
          let message = "";
          let status = 0;
          if (response.status == 200) {
            let data = response.data;
            status = isNaN(data.status) ? 0 : parseInt(data.status);
            switch (status) {
              case 1:
                message = "修改积分事件成功";
                break;
              case -1:
                message = "表单参数错误";
                break;
              default:
                message = "修改积分事件失败";
            }
          } else {
            message = "服务器出现问题";
          }
          self.$message({
            message: message,
            type: status == 1 ? "success" : "error"
          });
          if (status == 1) {
            self.loadEventList();
            self.dialogEditVisible = false;
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    confirmDelete(eventId) {
      this.$confirm("确定要删除此积分事件吗?", "删除积分事件", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deleteItem(eventId);
        })
        .catch(() => {
          //console.log('已取消删除');
        });
    },

    deleteItem(eventId, isMultiple) {
      if (!eventId) {
        return false;
      }
      isMultiple = isMultiple || false;
      let url = "";
      let params = null;
      if (isMultiple) {
        url = "/integral.php/ajax_request_common/delete_event_multiple";
        params = {
          ids: eventId
        };
      } else {
        url = "/integral.php/ajax_request_common/delete_event";
        params = {
          id: eventId
        };
      }
      var self = this;
      this.$http('get',url,params)
        .then(function(response) {
          let message = "";
          let status = 0;
          if (response.status == 200) {
            var data = response.data;
            status = isNaN(data.status) ? 0 : parseInt(data.status);
            switch (status) {
              case 1:
                message = "删除积分事件成功";
                break;
              case -1:
                message = "表单参数错误";
                break;
              default:
                message = data.info ? data.info : "删除积分事件失败";
            }
          } else {
            message = "服务器出现问题";
          }
          self.$message({
            message: message,
            type: status == 1 ? "success" : "error"
          });
          if (status == 1) {
            self.loadEventList();
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    //获取控件所需数据
    loadWidgetData: function() {
      var self = this;
      this.$http('get',"/integral.php/performance_work/task_category_tree")
        .then(function(response) {
          if (response.status == 200) {
            var jsonData = response.data;
            try {
              self.categoryTree = jsonData.data;
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    //获取可录入积分对象的列表
    loadTargetRange: function() {
      var self = this;
      this.$http('get',"/integral.php/ajax_request_common/load_target_range",{recorder_id: this.profile.id})
        .then(function(response) {
          if (response.status == 200) {
            var jsonData = response.data;
            try {
              self.employeeOptions = jsonData;
            } catch (err) {
              console.log(err);
            }
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    setDefaultValueForDialog: function() {
      if (!this.newEventForm.event_time) {
        this.newEventForm.event_time = new Date().getTime();
      }
    },
    processDetailData: function(object) {
      //时间戳转换
      object.event_time *= 1000;
      return object;
    },
    updateItemSelection: function(item, checked) {
      if (checked) {
        let itemIds = this.selectedItems.map(x => x.id);
        if (itemIds && (itemIds.length == 0 || itemIds.indexOf(item.id) < 0)) {
          this.selectedItems.push(item);
        }
      } else {
        this.selectedItems = this.selectedItems.filter(x => {
          if (x.id != item.id) {
            return x;
          }
        });
      }
    },
    removeItemSelection: function(itemId) {
      let index = this.selectedItems.map(x => x.id).indexOf(itemId);
      if (!isNaN(index) && index > -1) {
        this.selectedItems.splice(index, 1);
        let itemArray = this.itemSelectForm.items;
        for (let i = 0; i < itemArray.length; i++) {
          if (itemArray[i].id == itemId) {
            itemArray[i].checked = false;
          }
        }
      }
    }
  },
  created() {
    this.loadRuleList()
    this.loadWidgetData();
    this.loadTargetRange();
  }
};
</script>

<style>
.integral-create-review-btn .tpzs3 {
  margin: 0 auto;
  width: 40px;
  height: 40px;
  background-image: url(/images/jflr.png);
  background-size: 100%;
}
.integral-create-review-btn .card-panel-description {
  width: 100%;
  text-align: center;
  color: #666;
}
.integral-create-review-btn .card-panel-text {
  line-height: 40px;
  font-size: 20px;
  font-weight: bold;
}

.integral-create-review-btn .card-panel-text2 {
  font-size: 14px;
  line-height: 20px;
  color: rgba(102, 102, 102, 1);
}
.check-item-box .el-card__body {

}
.integral-create-review-dialog .el-dialog__header {
  display: none;
}
.integral-create-review-dialog .el-dialog__body {
  padding-bottom: 0;
}
.integral-create-review-dialog .card-box-item .el-card__body {
  padding: 5px 15px;
}
</style>
