<template>
  <!-- 弹出框表单 -->
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <!-- <Field
          label="绩效规则id"
          prop="ruleId"
          v-model="form.ruleId"
          placeholder="请输入绩效规则id"
        />
        <Field
          label="规则简称"
          prop="ruleBrief"
          v-model="form.ruleBrief"
          placeholder="请输入规则简称"
        />
       
        <Field
          label="规则类型"
          prop="type"
          v-model="form.type"
          type="select"
          :enumData="dict.type"
          placeholder="请选择规则类型"
        /> -->
        <el-row style="width: 100%;">
          <Field
            label="分类名称"
            prop="name"
            v-model="form.name"
            placeholder="请输入分类名称"
          />
        </el-row>
        <Field
          label="备注"
          prop="remark"
          v-model="form.remark"
          type="textarea"
          placeholder="请输入备注"
        />
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        v-if="pageInfo.type !== 'view'"
        @click="submitForm"
        >确 定</el-button
      >
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import form from "@/assets/mixins/formdialog";
import dialogShow from "./dialogshow";
export default {
  mixins: [form],
  components: {
    dialogShow,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "绩效规则分类信息",
      // 是否显示弹出层
      open: false,
      toString: ["type"],
      // 表单校验
      rules: {},
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      // this.urls.currUrl = "perform/rules/category/edit";
      // this.getData();
      this.$get("/perform/rules/category/info", { id: row.id }).then((res) => {
        console.log(res);
        if (res.code == 1) {
          this.form = res.data;
        } else {
          this.form = {};
        }
        this.open = true;
      });
      this.pageInfo.type = "edit";
      this.title = "修改绩效规则分类信息";
    },
    /** 新增 */
    add(row) {
      this.reset();
      // this.urls.currUrl = "perform/rules/category/save";
      // this.getData();
      this.form.type = row;
      this.open = true;
      this.pageInfo.type = "add";
      this.title = "新增绩效规则分类信息";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/rules/category/view";
      this.getData();
      this.pageInfo.type = "view";
      this.title = "绩效规则分类信息详细";
    },
    /**取消按钮 */
    cancel() {
      this.open = false;
    },
    /**获取数据后弹框 */
    afterRender(data) {
      this.open = true;
    },

    afterSubmit(data) {
      this.open = false;
      this.$emit("ok");
    },

    // 表单重置
    reset() {
      this.form = {
        ruleId: null,
        ruleBrief: "",
        name: "",
        type: 1,
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
