<template>
  <basic-container>
    <!-- 绩效模板维护 -->
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      v-model="form"
      v-model:page="page"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template #menu-left>
        <el-button type="primary" @click="handleAdd">新增绩效</el-button>
        <el-button type="primary" @click="maintenanceContents">绩效内容维护</el-button>
      </template>
      <template #menu="scope">
        <el-button type="primary" text @click="editRow(scope.row)">修改</el-button>
        <el-button type="primary" text @click="deleteRow(scope.row)">删除</el-button>
        <el-button type="primary" text>下发</el-button>
      </template>
    </avue-crud>
    <batchAddPerf v-if="showDialog" :showDialog="showDialog" :title="title"
    :checkRow="checkRow"
    :moldAddMore="moldAddMore" @closeDialog="closeDialog"></batchAddPerf>
    <batchAddContent v-if="showContent" :showContent="showContent" :title="title"  @closeDialog="closeDialog"></batchAddContent>
  </basic-container>
</template>

<script>
import batchAddPerf from "./components/batchAddPerf.vue"
import batchAddContent from "./components/batchAddContent.vue"
import {pageList,delItem} from "@/api/performanceManagement/templateMaintenance.js"
export default {
  components: { batchAddPerf,batchAddContent },
  data() {
    return {
      selectionList: [],
      query: {},
      loading: false,
      data: [],
      form: {},
      showDialog:false,
      moldAddMore:false,
      showContent:false,
      title:"",
      checkRow:{},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      option: {
        height: "auto",
        align: "center",
        calcHeight: 32,
        tip: false,
        simplePage: true,
        searchShow: true,
        searchMenuSpan: 6,
        searchIcon: true,
        searchIndex: 3,
        tree: false,
        border: true,
        index: false,
        selection: true,
        viewBtn: false,
        delBtn: false,
        addBtn: false,
        editBtn: false,
        editBtnText: "修改",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        viewBtnText: "详情",
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 150,
        dialogWidth: 1200,
        dialogClickModal: false,
        searchEnter: true,
        excelBtn: false,
        filterBtn: true,
        searchShowBtn: false,
        columnSort: true,
        excelBtn: true,
        columnSort: true,
        showOverflowTooltip: true,
        searchLabelPosition: "left",
        searchLabelPosition: "left",
        searchGutter: 24,
        searchSpan: 6,
        menuAlign: "center",
        gridBtn: false,
        searchMenuPosition: "right",
        column: [
          // {
          //   label: "模板类型",
          //   prop: "templateType",
          //   type: "select",
          //   search: true,
          //   sortable: true,
          //   overHidden: true,
          //   dicData: [
          //     { label: "通用", value: 1 },
          //     { label: "非通用", value: 2 },
          //   ],
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入模板类型",
          //       trigger: "blur",
          //     },
          //   ],
          //   control: (val, form) => {
          //     if (val == 1) {
          //       return {
          //         applicationDept: {
          //           rules: [
          //             {
          //               required: true,
          //               message: "请输入模板应用部门",
          //               trigger: "blur",
          //             },
          //           ],
          //         },
          //       };
          //     } else {
          //       return {
          //         applicationDept: {
          //           rules: [],
          //         },
          //       };
          //     }
          //   },
          // },
          // {
          //   label: "模板应用部门",
          //   prop: "applicationDept",
          //   type: "select",
          //   search: true,
          //   sortable: true,
          //   overHidden: true,
          //   dicData: [
          //     { label: "质量", value: 1 },
          //     { label: "工艺", value: 2 },
          //     { label: "辅助人员", value: 3 },
          //     { label: "生产线", value: 4 },
          //   ],
          //   // rules: [
          //   //     {
          //   //         required: true,
          //   //         message: '请输入模板应用部门',
          //   //         trigger: 'blur',
          //   //     },
          //   // ],
          // },
          {
            label: "绩效任务名称",
            prop: "taskName",
            search: false,
            sortable: true,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请输入模板名称",
                trigger: "blur",
              },
            ],
          },
          // {
          //   label: "模板内容",
          //   prop: "templateContent",
          //   search: false,
          //   width: 500,
          //   sortable: true,
          //   overHidden: true,
          //   rules: [
          //     {
          //       required: true,
          //       message: "请输入模板内容",
          //       trigger: "blur",
          //     },
          //   ],
          // },
          {
            label: "绩效填报人",
            prop: "reportUserName",
            type: "select",
            search: false,
            sortable: true,
            overHidden: true,
            rules: [
              {
                required: true,
                message: "请输入绩效填报人",
                trigger: "blur",
              },
            ],
          },
          {
            label: "维护人",
            prop: "createUser",
            search: false,
            sortable: true,
            overHidden: true,
          },
          {
            label: "维护时间",
            prop: "updateTime",
            search: false,
            sortable: true,
            overHidden: true,
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    closeDialog(val){
      this.showDialog = false
      this.moldAddMore = false
      this.showContent = false
      if(val){
        this.onLoad()
      }
    },
    handleAdd(){
      this.title = "新增"
      this.moldAddMore = true
      this.showDialog = true
    },
    editRow(row){
      this.title = "修改"
      this.checkRow = row
      this.moldAddMore = false
      this.showDialog = true
    },
    deleteRow(row){
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        delItem({
          ids:row.id
        }).then((res) => {
          if(res.data.code == 200){
            this.$message.success('删除成功')
            this.onLoad()
          }
        })
      })
    },
    maintenanceContents(){
      this.title = "模板内容维护"
      this.showContent = true
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    searchReset() {
      this.query = {};
      this.treeDeptId = "";
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    onLoad() {
      this.loading = true
      pageList({
        current:this.page.currentPage,
        size:this.page.pageSize,
        ...this.query,
      }).then((res) => {
        this.data = res.data.data.records
        this.page.total = res.data.data.total
        this.loading = false
      })

      // this.data = [
      //   {
      //     templateType: 2,
      //     applicationDept: 1,
      //     templateName: "质量 关键KPI绩效模板",
      //     templateContent: "KPI得分、KPI*70%",
      //     informant: 1,
      //   },
      //   {
      //     templateType: 2,
      //     applicationDept: 1,
      //     templateName: "质量 量化绩效模板",
      //     templateContent: "量化得分、量化*30%",
      //     informant: 1,
      //   },
      //   {
      //     templateType: 2,
      //     applicationDept: 4,
      //     templateName: "一线员工 绩效模板",
      //     templateContent:
      //       "订单准时完成率、重点零件完成率、后工序审理单分数、出厂不合格率DPPM、成本费用率",
      //     informant: 1,
      //   },
      //   {
      //     templateType: 1,
      //     templateName: "通用 绩效模板",
      //     templateContent:
      //       "通报、请假扣分、考勤扣分、投稿加分项、群策群力、优秀员工加分、成本",
      //     informant: 2,
      //   },
      // ];
      // this.page.total = this.data.length;
    },
  },
};
</script>

<style></style>
