<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"
    ></avue-crud>
  </basic-container>
</template>

<script>
export default {
  data() {
    return {
      selectionList: [],
      query: {},
      loading: false,
      data: [],
      form: {},
      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: true,
        selection: false,
        viewBtn: false,
        delBtn: false,
        addBtn: true,
        editBtn: true,
        editBtnText: "修改",
        addBtnIcon: " ",
        viewBtnIcon: " ",
        delBtnIcon: " ",
        editBtnIcon: " ",
        viewBtnText: "详情",
        labelWidth: 120,
        searchLabelWidth: 120,
        menu: true,
        menuWidth: 220,
        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: "left",
        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: "templateName",
            search: true,
            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: "informant",
            type: "select",
            search: false,
            sortable: true,
            overHidden: true,
            dicData: [
              { label: "张三", value: 1 },
              { label: "李四", value: 2 },
            ],
            rules: [
              {
                required: true,
                message: "请输入绩效填报人",
                trigger: "blur",
              },
            ],
          },
        ],
      },
    };
  },
  mounted() {},
  methods: {
    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.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>
