123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <template>
- <el-dialog
- class="modify-organization"
- :visible.sync="modalIsShow"
- :title="title"
- top="10vh"
- width="500px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- @opened="visibleChange"
- >
- <div class="part-box part-box-pad part-box-border">
- <el-form
- ref="modalFormComp"
- :model="modalForm"
- :rules="rules"
- label-width="100px"
- >
- <el-form-item prop="orgName" label="机构名称:">
- <el-input
- style="width:282px;"
- v-model.trim="modalForm.orgName"
- placeholder="请输入机构名称"
- clearable
- ></el-input>
- </el-form-item>
- <el-form-item prop="orgCode" label="机构代码:">
- <el-input
- style="width:282px;"
- v-model.trim="modalForm.orgCode"
- placeholder="请输入机构代码"
- clearable
- ></el-input>
- </el-form-item>
- <el-form-item label="上级机构:">
- <el-input
- style="width:282px;"
- v-model.trim="modalForm.parentName"
- disabled
- ></el-input>
- </el-form-item>
- <el-form-item label="启用/禁用:">
- <el-select
- v-model="modalForm.enable"
- style="width: 100px;"
- placeholder="请选择"
- >
- <el-option
- v-for="(val, key) in ABLE_TYPE"
- :key="key"
- :value="key * 1"
- :label="val"
- ></el-option>
- </el-select>
- </el-form-item>
- </el-form>
- </div>
- <div slot="footer">
- <el-button type="primary" :disabled="isSubmit" @click="submit"
- >确认</el-button
- >
- <el-button type="danger" @click="cancel" plain>取消</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import { ABLE_TYPE } from "@/constants/enumerate";
- import { updateOrganization } from "../api";
- const initModalForm = {
- id: null,
- orgName: "",
- orgCode: "",
- parentId: null,
- parentName: "",
- enable: 1
- };
- export default {
- name: "modify-organization",
- props: {
- instance: {
- type: Object,
- default() {
- return {};
- }
- }
- },
- computed: {
- isEdit() {
- return !!this.instance.id;
- },
- title() {
- return (this.isEdit ? "编辑" : "新增") + "机构";
- }
- },
- data() {
- return {
- modalIsShow: false,
- isSubmit: false,
- modalForm: {},
- ABLE_TYPE,
- rules: {
- orgName: [
- {
- required: true,
- pattern: /^[0-9a-zA-Z\u4E00-\u9FA5]{1,30}$/,
- message: "机构名称只能输入汉字、数字和字母,长度不能超过30",
- trigger: "change"
- }
- ],
- orgCode: [
- {
- required: true,
- pattern: /^[0-9a-zA-Z_-]{3,30}$/,
- message: "机构代码只能由数字字母短横线组成,长度在3-30之间",
- trigger: "change"
- }
- ]
- }
- };
- },
- methods: {
- initData(val) {
- this.modalForm = this.$objAssign(initModalForm, val);
- },
- visibleChange() {
- this.initData(this.instance);
- this.$nextTick(() => {
- this.$refs.modalFormComp.clearValidate();
- });
- },
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- async submit() {
- const valid = await this.$refs.modalFormComp.validate().catch(() => {});
- if (!valid) return;
- if (this.isSubmit) return;
- this.isSubmit = true;
- const datas = { ...this.modalForm };
- const data = await updateOrganization(datas).catch(() => {});
- this.isSubmit = false;
- if (!data) return;
- this.$emit("confirm", this.modalForm);
- this.cancel();
- }
- }
- };
- </script>
|