<template>
  <div class="rule-type">
    <el-dialog
      width="50%"
      :title="index >= 0 ? '编辑履职内容' : '新增履职内容'"
      :visible.sync="dataVisible"
      :show-close="false"
      append-to-body
    >
      <div>
        <el-form
          ref="form"
          :model="formData"
          :rules="formDataRules"
          label-width="110px"
          class="formbox"
        >
          <!-- <el-form-item label="检查要点编号" prop="pointNum">
            <el-input
              v-model="formData.pointNum"
              type="number"
              laceholder="请输入检查要点编号"
              @blur="check()"
              @input="formData.pointNum = Number(formData.pointNum)"
            ></el-input>
          </el-form-item> -->
          <el-form-item label="履职内容" prop="pointName">
            <el-input
              v-model="formData.pointName"
              placeholder="请输入履职内容"
              @blur="check()"
              maxlength="100"
            ></el-input>
          </el-form-item>
          <el-form-item label="履职区域" prop="areaId">
            <el-select
              v-model="formData.areaId"
              placeholder="请选择履职区域"
              clearable
            >
              <el-option
                v-for="item in areas"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="数据来源" prop="businessType">
            <el-select
              v-model="formData.businessType"
              placeholder="请选择数据来源"
              clearable
            >
              <el-option
                v-for="item in dict.type.point_data_source"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input
              type="textarea"
              v-model="formData.remark"
              maxlength="200"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dataVisible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit()" v-if="index>=0">{{
          index >= 0 ? "保 存" : "添 加"
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import {allAreaByOrgtype} from '@/api/system/area'
export default {
  dicts:['point_data_source'],
  data() {
    return {
      index: null,
      dataVisible: false,
      formData: this.reset(),
      formDataRules: {
        name: [{ required: true, message: "请输入履职内容" }],
        areaId: [{ required: true, message: "请选择履职区域" }],
      },
      areas:[]
    };
  },
  props: {
    orgType:{
      type:String
    }
  },
  watch: {},
  computed: {
    ...mapState([]),
  },
  methods: {
    ...mapMutations([]),
    reset() {
      return {
        id: null,
        name: null,
        areaId: null,
        businessType: null,
        remark: null,
      };
    },
    async show(index, data) {
      if (index >= 0) {
        this.index = index;
        this.formData = data;
      } else {
        this.index = -1;
        this.formData = this.reset();
      }
      allAreaByOrgtype(this.orgType).then(d=>{
        this.areas=d;
      })
      this.dataVisible = true;
    },
    onSubmit() {
      this.$refs.form.validate((isValidate) => {
        if (!isValidate) return;
        let obj = {};
        obj = { ...this.formData };
        this.$emit("submit", obj);
        this.dataVisible = false;
      });
    },
    // 事件
    onHide() {
      this.isShow = false;
    },
  },
  mounted() {},
  components: {},
};
</script>

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