OrganizationMember.vue 9.1 KB
Newer Older
S
shiziyuan9527 已提交
1 2
<template>
  <div v-loading="result.loading">
王振 已提交
3
    <el-card class="table-card">
C
chenjianxing 已提交
4
      <template v-slot:header>
S
shiziyuan9527 已提交
5
        <ms-table-header :condition.sync="condition" @search="initTableData" @create="create"
S
i18n  
shiziyuan9527 已提交
6
                         :create-tip="$t('member.create')" :title="$t('commons.member')"/>
C
chenjianxing 已提交
7
      </template>
S
shiziyuan9527 已提交
8
      <el-table :data="tableData" style="width: 100%">
S
shiziyuan9527 已提交
9 10 11 12
        <el-table-column prop="name" :label="$t('commons.username')"/>
        <el-table-column prop="email" :label="$t('commons.email')"/>
        <el-table-column prop="phone" :label="$t('commons.phone')"/>
        <el-table-column prop="roles" :label="$t('commons.role')" width="140">
C
v-slot  
Captain.B 已提交
13
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
14
            <ms-roles-tag :roles="scope.row.roles"/>
15 16
          </template>
        </el-table-column>
S
shiziyuan9527 已提交
17
        <el-table-column>
C
v-slot  
Captain.B 已提交
18
          <template v-slot:default="scope">
S
shiziyuan9527 已提交
19
            <ms-table-operator @editClick="edit(scope.row)" @deleteClick="del(scope.row)"/>
S
shiziyuan9527 已提交
20 21 22
          </template>
        </el-table-column>
      </el-table>
S
shiziyuan9527 已提交
23 24
      <ms-table-pagination :change="initTableData" :current-page.sync="currentPage" :page-size.sync="pageSize"
                           :total="total"/>
S
shiziyuan9527 已提交
25 26
    </el-card>

S
shiziyuan9527 已提交
27
    <el-dialog :title="$t('member.create')" :visible.sync="createVisible" width="30%" :destroy-on-close="true"
S
shiziyuan9527 已提交
28
               @close="handleClose">
29
      <el-form :model="form" ref="form" :rules="rules" label-position="right" label-width="100px" size="small">
S
shiziyuan9527 已提交
30
        <el-form-item :label="$t('commons.member')" prop="userIds">
S
shiziyuan9527 已提交
31 32
          <el-select v-model="form.userIds" multiple :placeholder="$t('member.please_choose_member')"
                     class="select-width">
S
shiziyuan9527 已提交
33 34 35 36 37
            <el-option
              v-for="item in form.userList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
38 39
              <span class="org-member-name">{{ item.name }}</span>
              <span class="org-member-email">{{ item.email }}</span>
S
shiziyuan9527 已提交
40 41 42
            </el-option>
          </el-select>
        </el-form-item>
S
shiziyuan9527 已提交
43 44
        <el-form-item :label="$t('commons.role')" prop="roleIds">
          <el-select v-model="form.roleIds" multiple :placeholder="$t('role.please_choose_role')" class="select-width">
45 46 47 48 49 50 51 52
            <el-option
              v-for="item in form.roles"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
S
shiziyuan9527 已提交
53
      </el-form>
C
chenjianxing 已提交
54
      <template v-slot:footer>
S
shiziyuan9527 已提交
55 56 57
        <ms-dialog-footer
          @cancel="createVisible = false"
          @confirm="submitForm('form')"/>
C
chenjianxing 已提交
58
      </template>
S
shiziyuan9527 已提交
59
    </el-dialog>
S
shiziyuan9527 已提交
60

S
shiziyuan9527 已提交
61
    <el-dialog :title="$t('member.modify')" :visible.sync="updateVisible" width="30%" :destroy-on-close="true"
S
shiziyuan9527 已提交
62
               @close="handleClose">
63
      <el-form :model="form" label-position="right" label-width="100px" size="small" ref="updateUserForm">
S
shiziyuan9527 已提交
64 65 66
        <el-form-item label="ID" prop="id">
          <el-input v-model="form.id" autocomplete="off" :disabled="true"/>
        </el-form-item>
S
shiziyuan9527 已提交
67
        <el-form-item :label="$t('commons.username')" prop="name">
68
          <el-input v-model="form.name" autocomplete="off" :disabled="true"/>
S
shiziyuan9527 已提交
69
        </el-form-item>
S
shiziyuan9527 已提交
70
        <el-form-item :label="$t('commons.email')" prop="email">
71
          <el-input v-model="form.email" autocomplete="off" :disabled="true"/>
S
shiziyuan9527 已提交
72
        </el-form-item>
S
shiziyuan9527 已提交
73
        <el-form-item :label="$t('commons.phone')" prop="phone">
74
          <el-input v-model="form.phone" autocomplete="off" :disabled="true"/>
S
shiziyuan9527 已提交
75
        </el-form-item>
S
shiziyuan9527 已提交
76 77
        <el-form-item :label="$t('commons.role')" prop="roleIds">
          <el-select v-model="form.roleIds" multiple :placeholder="$t('role.please_choose_role')" class="select-width">
S
shiziyuan9527 已提交
78 79 80 81 82 83 84 85 86
            <el-option
              v-for="item in form.allroles"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
C
chenjianxing 已提交
87
      <template v-slot:footer>
S
shiziyuan9527 已提交
88 89 90
        <ms-dialog-footer
          @cancel="updateVisible = false"
          @confirm="updateOrgMember('updateUserForm')"/>
C
chenjianxing 已提交
91
      </template>
S
shiziyuan9527 已提交
92
    </el-dialog>
S
shiziyuan9527 已提交
93 94 95 96
  </div>
</template>

<script>
S
shiziyuan9527 已提交
97
  import MsCreateBox from "../CreateBox";
S
shiziyuan9527 已提交
98
  import MsTablePagination from "../../common/pagination/TablePagination";
C
Captain.B 已提交
99
  import MsTableHeader from "../../common/components/MsTableHeader";
S
shiziyuan9527 已提交
100
  import MsRolesTag from "../../common/components/MsRolesTag";
S
shiziyuan9527 已提交
101
  import MsTableOperator from "../../common/components/MsTableOperator";
S
shiziyuan9527 已提交
102
  import MsDialogFooter from "../../common/components/MsDialogFooter";
S
shiziyuan9527 已提交
103
  import {getCurrentUser} from "../../../../common/js/utils";
C
Captain.B 已提交
104

S
shiziyuan9527 已提交
105
  export default {
S
shiziyuan9527 已提交
106
    name: "MsOrganizationMember",
S
shiziyuan9527 已提交
107
    components: {MsCreateBox, MsTablePagination, MsTableHeader, MsRolesTag, MsTableOperator, MsDialogFooter},
S
shiziyuan9527 已提交
108 109 110 111 112 113 114
    created() {
      this.initTableData();
    },
    data() {
      return {
        result: {},
        createVisible: false,
S
shiziyuan9527 已提交
115
        updateVisible: false,
S
shiziyuan9527 已提交
116
        form: {},
S
shiziyuan9527 已提交
117
        queryPath: "/user/org/member/list",
C
Captain.B 已提交
118
        condition: {},
S
shiziyuan9527 已提交
119 120 121
        tableData: [],
        rules: {
          userIds: [
S
shiziyuan9527 已提交
122
            {required: true, message: this.$t('member.please_choose_member'), trigger: ['blur']}
123 124
          ],
          roleIds: [
S
shiziyuan9527 已提交
125
            {required: true, message: this.$t('role.please_choose_role'), trigger: ['blur']}
S
shiziyuan9527 已提交
126 127 128 129 130
          ]
        },
        multipleSelection: [],
        currentPage: 1,
        pageSize: 5,
S
shiziyuan9527 已提交
131
        total: 0,
S
shiziyuan9527 已提交
132 133 134
      }
    },
    methods: {
S
shiziyuan9527 已提交
135
      currentUser: () => {
S
shiziyuan9527 已提交
136
        return getCurrentUser();
S
shiziyuan9527 已提交
137
      },
S
shiziyuan9527 已提交
138 139
      initTableData() {
        let param = {
C
Captain.B 已提交
140
          name: this.condition.name,
141
          organizationId: this.currentUser().lastOrganizationId
S
shiziyuan9527 已提交
142 143 144 145
        };
        this.result = this.$post(this.buildPagePath(this.queryPath), param, response => {
          let data = response.data;
          this.tableData = data.listObject;
146
          let url = "/userrole/list/org/" + this.currentUser().lastOrganizationId;
147 148 149 150 151 152 153
          for (let i = 0; i < this.tableData.length; i++) {
            this.$get(url + "/" + this.tableData[i].id, response => {
              let roles = response.data;
              this.$set(this.tableData[i], "roles", roles);
            })
          }
          this.total = data.itemCount;
S
shiziyuan9527 已提交
154 155 156 157 158
        })
      },
      buildPagePath(path) {
        return path + "/" + this.currentPage + "/" + this.pageSize;
      },
S
shiziyuan9527 已提交
159
      handleClose() {
160 161
        this.form = {};
      },
S
shiziyuan9527 已提交
162 163
      edit(row) {
        this.updateVisible = true;
S
shiziyuan9527 已提交
164
        this.form = Object.assign({}, row);
S
shiziyuan9527 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        let roleIds = this.form.roles.map(r => r.id);
        this.result = this.$get('/role/list/org', response => {
          this.$set(this.form, "allroles", response.data);
        })
        // 编辑使填充角色信息
        this.$set(this.form, 'roleIds', roleIds);
      },
      updateOrgMember() {
        let param = {
          id: this.form.id,
          name: this.form.name,
          email: this.form.email,
          phone: this.form.phone,
          roleIds: this.form.roleIds,
          organizationId: this.currentUser().lastOrganizationId
        }
S
shiziyuan9527 已提交
181
        this.result = this.$post("/organization/member/update", param, () => {
S
shiziyuan9527 已提交
182
          this.$success(this.$t('commons.modify_success'));
S
shiziyuan9527 已提交
183 184 185 186
          this.updateVisible = false;
          this.initTableData();
        });
      },
S
shiziyuan9527 已提交
187
      del(row) {
S
shiziyuan9527 已提交
188 189 190
        this.$confirm(this.$t('member.delete_confirm'), '', {
          confirmButtonText: this.$t('commons.confirm'),
          cancelButtonText: this.$t('commons.cancel'),
S
shiziyuan9527 已提交
191 192
          type: 'warning'
        }).then(() => {
S
shiziyuan9527 已提交
193
          this.result = this.$get('/user/org/member/delete/' + this.currentUser().lastOrganizationId + '/' + row.id, () => {
S
shiziyuan9527 已提交
194
            this.$success(this.$t('commons.delete_success'));
S
shiziyuan9527 已提交
195 196 197
            this.initTableData();
          });
        }).catch(() => {
S
shiziyuan9527 已提交
198
          this.$info(this.$t('commons.delete_cancel'))
S
shiziyuan9527 已提交
199 200 201
        });
      },
      create() {
S
shiziyuan9527 已提交
202 203
        let orgId = this.currentUser().lastOrganizationId;
        if (!orgId) {
S
shiziyuan9527 已提交
204
          this.$warning(this.$t('organization.select_organization'));
S
shiziyuan9527 已提交
205 206
          return false;
        }
207
        this.form = {};
S
shiziyuan9527 已提交
208
        this.result = this.$get('/user/besideorg/list/' + this.currentUser().lastOrganizationId, response => {
209
          this.createVisible = true;
210 211 212 213
          this.$set(this.form, "userList", response.data);
        });
        this.result = this.$get('/role/list/org', response => {
          this.$set(this.form, "roles", response.data);
S
shiziyuan9527 已提交
214
        })
S
shiziyuan9527 已提交
215 216 217
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
S
shiziyuan9527 已提交
218
          let orgId = this.currentUser().lastOrganizationId;
S
shiziyuan9527 已提交
219 220 221
          if (valid) {
            let param = {
              userIds: this.form.userIds,
222
              roleIds: this.form.roleIds,
S
shiziyuan9527 已提交
223
              organizationId: orgId
S
shiziyuan9527 已提交
224
            };
S
shiziyuan9527 已提交
225
            this.result = this.$post("user/org/member/add", param, () => {
S
shiziyuan9527 已提交
226 227 228 229 230 231 232 233 234 235 236 237 238
              this.initTableData();
              this.createVisible = false;
            })
          } else {
            return false;
          }
        });
      }
    }
  }
</script>

<style scoped>
239 240 241 242 243 244 245 246 247 248 249 250 251 252

  .org-member-name {
    float: left;
  }

  .org-member-email {
    float: right;
    color: #8492a6;
    font-size: 13px;
  }

  .select-width {
    width: 100%;
  }
S
shiziyuan9527 已提交
253
</style>