add.vue 5.4 KB
Newer Older
xulili's avatar
xulili committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
<template>
  <el-dialog
    custom-class="party-dialog"
    title="新建机构"
    :visible.sync="dialogVisible"
    width="468px"
    :before-close="handleClose"
  >
    <div class="dialog-content">
      <el-form
        ref="form"
        :rules="rules"
        :model="form"
        label-width="80px"
        label-position="top"
        class="party-form"
      >
        <el-form-item label="新增类别:" prop="level">
          <el-radio-group v-model="form.level">
            <el-radio
              v-for="(item, index) in levelOption"
              :key="index"
              :label="item.label"
            >
              {{ item.value }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="机构名称:" prop="name">
          <el-input
            v-model="form.name"
            placeholder="请填写"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="机构地理位置:" prop="areaId">
          <el-cascader
            v-model="form.areaId"
            change-on-select
            :props="cascaderProps"
            :options="areaOptions"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="form.remarks"
            type="textarea"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button @click="handleCancle()">取 消</el-button>
      <el-button type="primary" @click="handleSubmit()" :disabled="disabled"
        >确 定</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { getAreas } from "@/config/area";
export default {
  data() {
    return {
xulili's avatar
xulili committed
67
      dialogVisible: false,
xulili's avatar
xulili committed
68 69 70 71 72 73 74
      form: {
        name: "",
        areaId: [],
        level: "",
        remarks: "",
      },
      disabled: false,
xulili's avatar
xulili committed
75
      areaOptions:  [],
xulili's avatar
xulili committed
76 77 78
      cascaderProps: {
        label: "name",
        value: "id",
xulili's avatar
xulili committed
79
        checkStrictly: true
xulili's avatar
xulili committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      },
      levelOption: [],
      rules: {
        level: [
          { required: true, message: "请选择用户类别", trigger: "change" },
        ],
        name: [
          { required: true, message: "请输入机构名称", trigger: "change" },
        ],
        areaId: [
          { required: true, message: "请选择地理位置", trigger: "change" },
        ],
      },
    };
  },
  props: {
    level: {
      type: Number,
      default: 1,
    },
xulili's avatar
xulili committed
100 101 102 103
    parentId:{
      type: String,
      default: '0',
    }
xulili's avatar
xulili committed
104 105 106 107 108 109 110 111 112 113 114 115
  },
  mounted() {
    this.getLevelOption();
    getAreas().then((res) => {
      this.areaOptions = res;
    });
  },
  methods: {
    // 弹窗关闭
    handleClose() {
      this.$confirm("确认关闭?")
        .then((_) => {
xulili's avatar
xulili committed
116
          this.handleReset()  
xulili's avatar
xulili committed
117 118 119
        })
        .catch((_) => {});
    },
xulili's avatar
xulili committed
120 121 122 123 124 125 126 127 128 129
    handleReset(){
        this.dialogVisible = false
        this.$refs.form.resetFields()
        this.form = {
            name: "",
            areaId: [],
            level: "",
            remarks: "",
        }
    },
xulili's avatar
xulili committed
130 131 132 133 134 135 136 137 138 139 140 141
    handleCancle() {
      this.handleClose();
    },
    handleSubmit() {
      // 校验用户输入值
      this.$refs.form.validate((valid) => {
        if (valid) {
          let params = {};
          params.name = this.form.name;
          params.areaId = [...this.form.areaId].pop();
          params.remarks = this.form.remarks;
          params.level = this.form.level;
xulili's avatar
xulili committed
142
          params.parentId = this.parentId
xulili's avatar
xulili committed
143 144 145 146 147
          let requestparams = this.$qs.stringify(params);
          this.$https(
            {
              method: "post",
              url: "organ/add",
xulili's avatar
xulili committed
148
              authType: this.backToken,
xulili's avatar
xulili committed
149 150 151 152
            },
            requestparams
          )
            .then((res) => {
xulili's avatar
xulili committed
153 154 155 156 157 158 159 160 161 162 163 164
              if(res.status == 200 ){
                if (res.data.resultCode == 200  ) {
                    this.$message({
                        type: "success",
                        message: res.data.message,
                    });
                    this.handleReset()  
                    this.$emit('success',true)
                } else {
                     this.$message.error(res.data.message);
                     this.$emit('success',false)
               } 
xulili's avatar
xulili committed
165
              } else {
xulili's avatar
xulili committed
166 167 168
                   this.$message.error(res.data);
                   this.$emit('success',false)
              }    
xulili's avatar
xulili committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
            })
            .catch((err) => {
              console.log(res);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    getLevelOption() {
      this.form.level = this.level;
      if (this.level === 1) {
        this.levelOption = [
          { label: 1, value: "平级机构" },
          { label: 2, value: "下级机构" },
        ];
      } else if (this.level === 2) {
        this.levelOption = [
          { label: 1, value: "上级机构" },
          { label: 2, value: "平级机构" },
          { label: 3, value: "下级机构" },
        ];
      } else if (this.level === 3) {
        this.levelOption = [
          { label: 2, value: "上级机构" },
          { label: 3, value: "平级机构" },
        ];
      } else {
        this.levelOption = [];
      }
    },
  },
  watch: {
    level() {
      // level 1 没有上级 level 3 没有下级
      this.getLevelOption();
    },
  },
};
</script>
<style lang="less" scoped>
</style>