dialog.vue 3.41 KB
Newer Older
1 2 3 4
<template>
  <el-dialog
    custom-class="party-dialog"
    :title="title"
乐宝呗666's avatar
乐宝呗666 committed
5
    width="468px"
6 7 8 9 10 11 12 13 14
    :visible.sync="formVisible"
    :before-close="close"
  >
    <div class="dialog-content">
      <el-form
        :model="formItem"
        class="party-form"
        ref="formItem"
        label-width="125px"
乐宝呗666's avatar
乐宝呗666 committed
15
        label-position="top"
16 17
        :rules="rules"
      >
qzhxx's avatar
qzhxx committed
18
        <el-form-item label="所属单位:" prop="orgId">
19
          <el-select
qzhxx's avatar
qzhxx committed
20
            v-model="formItem.orgId"
21 22 23 24 25
            clearable
            placeholder="请选择所属单位"
            @change="selectItem"
          >
            <el-option
qzhxx's avatar
qzhxx committed
26 27 28 29
              v-for="item in orgOptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
30 31 32
            ></el-option>
          </el-select>
        </el-form-item>
qzhxx's avatar
qzhxx committed
33
        <el-form-item label="机构地理位置:" prop="areaName">
乐宝呗666's avatar
乐宝呗666 committed
34 35 36 37
          <el-input
            v-model="formItem.areaName"
            disabled
          ></el-input>
38 39
        </el-form-item>
      </el-form>
qzhxx's avatar
qzhxx committed
40 41 42
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button @click="close">取 消</el-button>
乐宝呗666's avatar
乐宝呗666 committed
43
      <el-button type="primary" @click="submitForm('formItem')">确定</el-button>
44 45 46 47 48 49 50 51
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
乐宝呗666's avatar
乐宝呗666 committed
52
      title: "", // 标题
53 54
      formVisible: false,
      formItem: {},
乐宝呗666's avatar
乐宝呗666 committed
55
      orgOptions: [], // 单位信息
56
      rules: {
乐宝呗666's avatar
乐宝呗666 committed
57 58 59 60
        orgId: [
          { required: true, message: "请选择所属单位", trigger: "change" },
        ],
      },
61 62
    };
  },
乐宝呗666's avatar
乐宝呗666 committed
63
  mounted() {},
64 65 66
  methods: {
    backFn(item) {
      this.formVisible = true;
乐宝呗666's avatar
乐宝呗666 committed
67
      this.$nextTick(() => {
68
        this.$refs.formItem.clearValidate();
乐宝呗666's avatar
乐宝呗666 committed
69
      });
qzhxx's avatar
qzhxx committed
70
      // 新增
乐宝呗666's avatar
乐宝呗666 committed
71 72
      this.orgOptions = item;
      this.title = "新增";
qzhxx's avatar
qzhxx committed
73
      this.formItem = {};
74 75 76 77 78 79 80 81 82 83 84
    },
    // 关闭
    close() {
      this.formVisible = false;
      for (let key in this.formItem) {
        this.formItem[key] = null;
      }
      this.$refs["formItem"].resetFields();
    },
    // 联动出地址
    selectItem(val) {
乐宝呗666's avatar
乐宝呗666 committed
85 86 87 88
      this.orgOptions.forEach((item) => {
        if (val === item.id) {
          this.formItem.areaName = item.areaName;
          this.formItem.areaId = item.areaId;
qzhxx's avatar
qzhxx committed
89
        }
乐宝呗666's avatar
乐宝呗666 committed
90 91 92

        if (item.id === this.formItem.orgId) {
          this.formItem.userName = item.name;
qzhxx's avatar
qzhxx committed
93
        }
乐宝呗666's avatar
乐宝呗666 committed
94
      });
95 96 97 98
    },
    // 保存编辑信息
    submitForm() {
      let _this = this;
乐宝呗666's avatar
乐宝呗666 committed
99
      _this.$refs.formItem.validate((valid) => {
100 101 102 103
        if (valid) {
          let searchObj = {};
          for (let key in _this.formItem) {
            if (this.formItem[key]) {
乐宝呗666's avatar
乐宝呗666 committed
104
              searchObj[key] = _this.formItem[key]
105 106
            }
          }
乐宝呗666's avatar
乐宝呗666 committed
107 108 109
          _this
            .$https(
              {
qzhxx's avatar
qzhxx committed
110 111
                url: "tUser/boxAdd",
                method: "post",
乐宝呗666's avatar
乐宝呗666 committed
112
                authType: this.backToken,
qzhxx's avatar
qzhxx committed
113 114
              },
              _this.$qs.stringify(searchObj)
乐宝呗666's avatar
乐宝呗666 committed
115 116 117 118 119 120 121
            )
            .then(
              (res) => {
                if (res.data.resultCode === "200") {
                  _this.$message.success(res.data.message)
                  _this.formVisible = false
                  _this.$emit("refreshFn")
qzhxx's avatar
qzhxx committed
122
                } else {
乐宝呗666's avatar
乐宝呗666 committed
123
                  _this.$message.error(res.data.message)
qzhxx's avatar
qzhxx committed
124 125
                }
              },
乐宝呗666's avatar
乐宝呗666 committed
126 127
              (error) => {
                console.log(error)
qzhxx's avatar
qzhxx committed
128
              }
乐宝呗666's avatar
乐宝呗666 committed
129
            )
130
        }
乐宝呗666's avatar
乐宝呗666 committed
131 132 133
      })
    },
  },
134 135 136 137 138
};
</script>

<style lang="less">
</style>