<template>
  <div class="rule-type">
    <el-dialog
      :title="!formData.id ? '新增检查项' : '编辑检查项'"
      :visible.sync="dialogVisible"
      width="60%"
      :show-close="true"
      @close="onHide"
    >
      <div>
        <div class="box">
          <p>履职项</p>
          <el-form
            ref="form"
            :model="formData"
            :rules="formDataRules"
            label-width="110px"
          >
            <el-form-item prop="name" label="履职项">
              <el-input
                v-model="formData.name"
                :maxlength="50"
                name="name"
                placeholder="请输入履职项"
                clearable
              />
            </el-form-item>
          </el-form>
        </div>
        <div class="box">
          <p>履职内容</p>
          <div style="margin-bottom: 10px">
            <el-button type="primary" @click="onAddPoint(-1)">新增</el-button>
          </div>
          <el-table :data="formData.pointDtoList" border style="width: 100%">            
            <el-table-column prop="name" label="履职要点">
            </el-table-column>
            <el-table-column prop="areaName" label="履职区域">
            </el-table-column>            
            <el-table-column label="操作" width="140">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="onEdit(scope.$index, scope.row)"
                  >编辑</el-button
                >
                <k-btn-tip
                  type="text"
                  :tip="'确定删除该条履职内容？'"
                  @click="delitem(scope.$index)"
                  >删除</k-btn-tip
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit()">保 存</el-button>
      </span>
    </el-dialog>
    <EditPoint ref="editDialog" @submit="onPointSubmit"></EditPoint>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import EditPoint from "./dialog.editPoint.vue";
import { get, update } from "@/api/resumption/ruleManager.js";

export default {
  data() {
    return {
      dialogVisible: false,
      formData: this.reset(),
      formDataRules:{
      name: [{ required: true, message: "请输入履职项" }],
      }
    };
  },
  props: {},
  watch: {},
  computed: {
    ...mapState([]),
  },
  methods: {
    ...mapMutations([]),
    reset() {
      return {
        id: null,
        nme: null,
        ruleId: null,
        pointDtoList: [],
      };
    },

    async show(id) {
      const data = id ? await get(id) : this.reset();
      this.formData = data;
      this.dialogVisible = true;
    },
    // 事件
    onHide() {
      this.formData = this.reset();
    },
    async onSubmit() {
      this.formData.ruleId = this.formruleID;
      await update(this.formData).then((v) => {
        console.log(v);
        this.formData = this.reset();
        this.dialogVisible = false;
        this.getlist();
      });
    },
    onclose() {
      this.dataVisible = false;
    },
    onEdit(index, row) {
      this.$refs.editDialog.show(index, row);
    },
    onPointSubmit(index, point) {
      if (index >= 0) {
        this.$set(this.formData.pointDtoList, i, point);
      } else {
        this.formData.pointDtoList.push(point);
      }
    },
    delitem(val) {
      this.formdetail.pointDtoList.splice(val, 1);
    },
  },
  mounted() {},
  components: { EditPoint },
};
</script>

<style lang="scss">
.brand_info {
  .el-form {
    width: 600px;
    padding-top: 40px;
  }
}
</style>
