addDialog.vue 4.65 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>
33
        <el-form-item label="机构地理位置:" prop="areaName" required>
乐宝呗666's avatar
乐宝呗666 committed
34 35 36 37
          <el-input
            v-model="formItem.areaName"
            disabled
          ></el-input>
38
        </el-form-item>
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        <el-form-item label="账号有效期" prop="permanent">
          <el-radio-group v-model="formItem.permanent">
            <el-radio :label="true">永久有效</el-radio>
            <el-radio :label="false">设置有效期</el-radio>
          </el-radio-group>
          <div v-if="!formItem.permanent">
            <el-date-picker
              class="mt16"
              v-model="formItem.date"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </el-form-item>
57
      </el-form>
qzhxx's avatar
qzhxx committed
58 59 60
    </div>
    <div slot="footer" class="dialog-footer btn-group">
      <el-button @click="close">取 消</el-button>
乐宝呗666's avatar
乐宝呗666 committed
61
      <el-button type="primary" @click="submitForm('formItem')">确定</el-button>
62 63 64 65 66 67 68 69
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
乐宝呗666's avatar
乐宝呗666 committed
70
      title: "", // 标题
71 72
      formVisible: false,
      formItem: {},
乐宝呗666's avatar
乐宝呗666 committed
73
      orgOptions: [], // 单位信息
74
      rules: {
乐宝呗666's avatar
乐宝呗666 committed
75 76 77
        orgId: [
          { required: true, message: "请选择所属单位", trigger: "change" },
        ],
78 79 80
        permanent: [
          { required: true, message: "请选择账号有效期", trigger: "change" },
        ],
乐宝呗666's avatar
乐宝呗666 committed
81
      },
82 83
    };
  },
乐宝呗666's avatar
乐宝呗666 committed
84
  mounted() {},
85 86 87
  methods: {
    backFn(item) {
      this.formVisible = true;
乐宝呗666's avatar
乐宝呗666 committed
88
      this.$nextTick(() => {
89
        this.$refs.formItem.clearValidate();
乐宝呗666's avatar
乐宝呗666 committed
90
      });
qzhxx's avatar
qzhxx committed
91
      // 新增
乐宝呗666's avatar
乐宝呗666 committed
92 93
      this.orgOptions = item;
      this.title = "新增";
94 95 96 97
      this.formItem = {
        permanent: true,
        date: "",
      };
98 99 100 101 102 103 104 105 106 107 108
    },
    // 关闭
    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
109 110 111 112
      this.orgOptions.forEach((item) => {
        if (val === item.id) {
          this.formItem.areaName = item.areaName;
          this.formItem.areaId = item.areaId;
qzhxx's avatar
qzhxx committed
113
        }
乐宝呗666's avatar
乐宝呗666 committed
114 115 116

        if (item.id === this.formItem.orgId) {
          this.formItem.userName = item.name;
qzhxx's avatar
qzhxx committed
117
        }
乐宝呗666's avatar
乐宝呗666 committed
118
      });
119 120 121 122
    },
    // 保存编辑信息
    submitForm() {
      let _this = this;
乐宝呗666's avatar
乐宝呗666 committed
123
      _this.$refs.formItem.validate((valid) => {
124
        if (valid) {
125 126 127 128
           if (!this.formItem.permanent && !this.formItem.date) {
            this.$message.error("请选择有效期");
            return false;
          }
129 130 131
          let searchObj = {};
          for (let key in _this.formItem) {
            if (this.formItem[key]) {
乐宝呗666's avatar
乐宝呗666 committed
132
              searchObj[key] = _this.formItem[key]
133 134
            }
          }
135 136 137 138 139 140
          if (!this.formItem.permanent) {
            searchObj.effectiveDate = this.formItem.date[0];
            searchObj.exiredDate = this.formItem.date[1];
          }
          delete searchObj.date
          console.log(searchObj)
乐宝呗666's avatar
乐宝呗666 committed
141 142 143
          _this
            .$https(
              {
qzhxx's avatar
qzhxx committed
144 145
                url: "tUser/boxAdd",
                method: "post",
乐宝呗666's avatar
乐宝呗666 committed
146
                authType: this.backToken,
qzhxx's avatar
qzhxx committed
147 148
              },
              _this.$qs.stringify(searchObj)
乐宝呗666's avatar
乐宝呗666 committed
149 150 151 152 153 154 155
            )
            .then(
              (res) => {
                if (res.data.resultCode === "200") {
                  _this.$message.success(res.data.message)
                  _this.formVisible = false
                  _this.$emit("refreshFn")
qzhxx's avatar
qzhxx committed
156
                } else {
乐宝呗666's avatar
乐宝呗666 committed
157
                  _this.$message.error(res.data.message)
qzhxx's avatar
qzhxx committed
158 159
                }
              },
乐宝呗666's avatar
乐宝呗666 committed
160 161
              (error) => {
                console.log(error)
qzhxx's avatar
qzhxx committed
162
              }
乐宝呗666's avatar
乐宝呗666 committed
163
            )
164
        }
乐宝呗666's avatar
乐宝呗666 committed
165 166 167
      })
    },
  },
168 169 170 171 172
};
</script>

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