<template>
  <div class="app-container">
    <div class="filter-container">
      <el-date-picker
        v-model="searchTime"
        :picker-options="pickerOptions"
        class="filter-item"
        type="daterange"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
      />
      <el-cascader
        v-model="department"
        placeholder="请选择部门"
        clearable
        change-on-select
        @change="handleTeam"
        :props="prop"
        :options="departmentData"
      ></el-cascader>
      <el-select v-model="team" clearable placeholder="请选择团队">
        <el-option
          v-for="item in teamData"
          :key="item.F_Id"
          :label="item.F_Name"
          :value="item.F_Id"
        ></el-option>
      </el-select>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="btn_search">搜索</el-button>
      <el-button
        v-permission="'HY_add'"
        type="primary"
        class="filter-item"
        icon="el-icon-plus"
        @click="btn_add"
      >添加</el-button>
      <!-- <el-button
        v-permission="'HY_deletes'"
        type="primary"
        class="filter-item"
        icon="el-icon-delete"
        @click="btn_deletes"
      >批量删除</el-button> -->
    </div>

    <el-table v-loading="loading" :data="dataLists" border stripe @selection-change="changeSelects">
      <!-- <el-table-column type="selection" width="40" fixed></el-table-column> -->
      <el-table-column type="index" label="编号" align="center" fixed width="80" />
      <el-table-column prop="F_Dept" label="部门" align="center" min-width />
      <el-table-column prop="F_Team" label="团队" align="center" min-width />
      <!-- <el-table-column prop="F_Post" label="职务" align="center" min-width /> -->
      <!-- <el-table-column prop="F_Type" label="销售类型" align="center" min-width /> -->
      <el-table-column prop="F_TaskRate" label="任务完成比例" align="center" min-width />
      <!-- <el-table-column prop="F_CallTotleNumber" label="总单线" align="center" min-width /> -->
      <el-table-column prop="F_SendTotleNumber" label="发货总单数" align="center" min-width />
      <el-table-column prop="F_TotleMoney" label="发货总金额" align="center" min-width />
      <el-table-column prop="F_SignNumber" label="签收总单数" align="center" min-width />
      <el-table-column prop="F_SignMoney" label="签收总金额" align="center" min-width />
      <el-table-column prop="F_NoSignNumber" label="未签收单数" align="center" min-width />
      <el-table-column prop="F_NoSignMoney" label="未签收金额" align="center" min-width />
      <el-table-column prop="F_RefuseNumber" label="拒收单数" align="center" min-width />
      <el-table-column prop="F_RefuseMoney" label="拒收金额" align="center" min-width />
      <el-table-column prop="F_SignRate" label="签收率" align="center" min-width />
      <!-- <el-table-column prop="F_ErrorNumber" label="录错单数" align="center" min-width /> -->
      <el-table-column prop="F_ErrorMoney" label="录错金额" align="center" min-width />
      <!-- <el-table-column prop="F_AfterNumber" label="售后单数" align="center" min-width /> -->
      <el-table-column prop="F_AfterMoney" label="售后金额" align="center" min-width />
      <el-table-column prop="F_AlongMoney" label="鞋垫/袜子金额" align="center" min-width />
      <!-- <el-table-column prop="F_CreateTime" label="创建时间" align="center" min-width=""/> -->
      <el-table-column label="操作" width="170" align="center" class-name="oparate_btn" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button
            v-permission="'HY_edit'"
            size="mini"
            plain
            type="primary"
            @click="btn_edit(scope.row.F_Id)"
          >编辑</el-button> -->
          <!-- <el-button
            v-permission="'HY_detail'"
            size="mini"
            plain
            type="primary"
            @click="btn_detail(scope.row.F_ID.toString())"
          >详情</el-button> -->
          <el-button
            v-permission="'HY_delete'"
            size="mini"
            plain
            type="danger"
            @click="btn_delete(scope.row.F_Id)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageParams.total > 0"
      :total="pageParams.total"
      :pageindex.sync="pageParams.pageindex"
      :pagesize.sync="pageParams.pagesize"
      class="pagination"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getTeamPerformance,deleteTeamPerformance} from "@/api/reportFormManagement/teamPerformance/teamPerformance";
import { getDepartmentList } from "@/api/systemSetup/roleSetting/department";
import { getTeamLists } from "@/api/systemSetup/sysSetting/teamManagement";
import add from "./add";
import edit from "./edit";
import detail from "./detail";
import { pickerOptions } from "@/utils";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装

export default {
  name: "BlackList",
  components: {
    Pagination,
  },
  data() {
    return {
      loading: false,
      searchTime: "",
      team: "",
      department: [],
      valNum: [],
      departmentData: [], //部门数据
      teamData: [], //团队数据
      searchDate: "",
      pickerOptions,
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0, // 总共多少数据
      },
      prop: {
        label: "F_DeptName",
        value: "F_DeptId",
        children: "children",
      },
      dataLists: [], // 列表数据
      multipleSelection: [], // 选中的数据
      selectedId: [], //选中的id
    };
  },
  created() {
    this.getList();
    this.getDepartment();
    this.getTeam();
    document.onkeyup = (e) => {
      if (e.keyCode === 13) {
        this.getList();
      }
    };
  },
  methods: {
    getList() {
      this.loading = true;
      return new Promise((resolve) => {
        const params = {
          pageindex: this.pageParams.pageindex, // 第几页
          pagesize: this.pageParams.pagesize, // 每页几条信息
          SearchStartTime: this.searchTime&&this.searchTime[0],
          SearchEndTime: this.searchTime&&this.searchTime[1],
          F_DeptId:
            this.department.length > 0
              ? this.department[this.department.length - 1]
              : "",
          F_TeamId: this.team,
        };
        getTeamPerformance(params).then((response) => {
          this.loading = false;
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.data.Totals;
            this.dataLists = response.data.Rows;
          }
        });
        resolve();
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
    btn_add() {
      this.$layer.iframe({
        content: {
          content: add, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: "" }, // props//该方法会自动添加一个key为layerid的值， 该值为创建层的id， 可以直接使用
        },
        area: ["40%", "60%"],
        title: "添加团队绩效",
      });
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: edit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId }, // props
        },
        area: ["80%", "70%"],
        title: "编辑团队绩效",
      });
    },
    btn_detail(editId) {
      this.$layer.iframe({
        content: {
          content: detail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId }, // props
        },
        area: ["70%", "60%"],
        title: "待办信息详情",
      });
    },
    btn_delete(editId) {
      this.$confirm("您确定要将此绩效信息删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteTeamPerformance(editId).then((response) => {
            if (response.state.toLowerCase() === "success") {
              this.getList();
              this.$message.success("删除成功!");
            }
          });
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },
    //批量删除
    btn_deletes() {
      if (this.selectedId.length == 0) {
        this.$message("请选择一个选项");
        return;
      } else {
        this.$confirm("您确定要删除吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            deleteTeamPerformance(this.selectedId.toString()).then((response) => {
              if (response.state.toLowerCase() === "success") {
                this.getList();
                this.$message.success("删除成功!");
              }
            });
          })
          .catch(() => {
            this.$message.info("已取消删除");
          });
      }
    },
    changeSelects(val) {
      const ids = [];
      this.multipleSelection = val;
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].F_Id);
      }
      this.selectedId = ids;
    },
    //获取部门信息
    getDepartment() {
      getDepartmentList().then((response) => {
        response.map((item) => {
          if (item.F_DeptId == "1") {
            this.departmentData.push(item);
          }
        });
        this.departmentData.unshift(
          {
            F_DeptId: 0,
            F_DeptName: "全部",
          },
          {
            F_DeptId: -1,
            F_DeptName: "不更新",
          }
        );
      });
    },
    handleTeam(val){
      if(val.toString()==0||val.toString()==-1){
         this.valNum=[1]
      }else{
         this.valNum=val
      }
      this.getTeam()
    },
    //获取团队信息
    getTeam() {
      const params = {
        pageindex: 1,
        pagesize: 100,
        deptid:this.valNum.length>0?this.valNum[this.valNum.length-1]:'1'
      };
      getTeamLists(params).then((response) => {
        if (response.state == "success") {
          this.teamData = response.data.Rows;
          if(response.data.Rows.length>0){
            this.teamData.unshift(
            {
              F_Id: 0,
              F_Name: "全部",
            },
            {
              F_Id: -1,
              F_Name: "不更新",
            }
          );
          }
        }
      });
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
