<template>
  <!-- 弹出框表单 -->
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
    <el-form ref="form" :model="form" :rules="rules" label-width="180px">
      <el-row>
        <Field
          label="负责人id号"
          prop="ownerId"
          v-model="form.ownerId"
          placeholder="请输入负责人id号"
        />
        <Field
          label="负责人名称"
          prop="ownerName"
          v-model="form.ownerName"
          placeholder="请输入负责人名称"
        />
        <Field
          label="窗口工作人员id号"
          prop="staffId"
          v-model="form.staffId"
          placeholder="请输入窗口工作人员id号"
        />
        <Field
          label="请假类型"
          prop="assessmentType"
          v-model="form.assessmentType"
          type="select"
          :enumData="dict.assessmentType"
          placeholder="请选择请假类型"
        />
        <Field
          label="考核范围"
          prop="assessmentScope"
          v-model="form.assessmentScope"
          type="select"
          :enumData="dict.assessmentScope"
          placeholder="请选择考核范围"
        />
        <Field
          label="考比较类型"
          prop="compareScope"
          v-model="form.compareScope"
          type="select"
          :enumData="dict.compareScope"
          placeholder="请选择考比较类型"
        />
        <Field
          label="比例"
          prop="ratio"
          v-model="form.ratio"
          placeholder="请输入比例"
        />
        <Field
          label="周期类型"
          prop="periodType"
          v-model="form.periodType"
          type="select"
          :enumData="dict.periodType"
          placeholder="请选择周期类型"
        />
        <Field
          label="年"
          prop="year"
          v-model="form.year"
          placeholder="请输入年"
        />
        <Field
          label="月"
          prop="month"
          v-model="form.month"
          type="select"
          :enumData="dict.month"
          placeholder="请选择月"
        />
        <Field
          label="半年类型"
          prop="halfYear"
          v-model="form.halfYear"
          type="select"
          :enumData="dict.halfYear"
          placeholder="请选择半年类型"
        />
        <Field
          label="半年类型"
          prop="halfYear"
          v-model="form.halfYear"
          type="select"
          :enumData="dict.halfYear"
          placeholder="请选择半年类型"
        />
        <Field
          label="季度类型"
          prop="quarter"
          v-model="form.quarter"
          type="select"
          :enumData="dict.quarter"
          placeholder="请选择季度类型"
        />
        <Field
          label="负责人，多个逗号分割"
          prop="leaders"
          v-model="form.leaders"
          type="textarea"
          placeholder="请输入负责人，多个逗号分割"
        />
        <Field
          label="负责人电话，多个逗号分割"
          prop="leaderMobiles"
          v-model="form.leaderMobiles"
          type="textarea"
          placeholder="请输入负责人电话，多个逗号分割"
        />
        <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: [
        "assessmentType",
        "assessmentScope",
        "compareScope",
        "periodType",
        "month",
        "halfYear",
        "halfYear",
        "quarter",
      ],
      // 表单校验
      rules: {
        year: [{ required: true, message: "请输入年", trigger: "blur" }],
        month: [{ required: true, message: "请输入月", trigger: "blur" }],
      },
    };
  },

  methods: {
    /** 编辑 */
    edit(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/perpose/edit";
      this.getData();
      this.pageInfo.type = "edit";
      this.title = "修改考核目标";
    },
    /** 新增 */
    add(row) {
      this.reset();
      this.urls.currUrl = "perform/perpose/add";
      this.getData();
      this.pageInfo.type = "add";
      this.title = "新增考核目标";
    },
    /** 查看*/
    view(row) {
      this.reset();
      this.query = { id: row.id };
      this.urls.currUrl = "perform/perpose/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 = {
        ownerId: null,
        ownerName: "",
        staffId: null,
        assessmentType: null,
        assessmentScope: 1,
        compareScope: 1,
        ratio: 0.0,
        periodType: 1,
        year: null,
        month: null,
        halfYear: 1,
        halfYear: 1,
        quarter: 1,
        leaders: "",
        leaderMobiles: "",
        remark: "",
      };
      this.resetForm("form");
    },
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields();
      }
    },
  },
};
</script>
