<template>
  <div>
    <section class="content">
      <div class="box box-info">
        <!-- 头信息 -->
        <div class="box-header with-border">
          <h3 class="box-title">普通用户管理</h3>
          <div class="box-tools pull-right">
            <button
              type="button"
              class="btn btn-box-tool"
              data-widget="collapse"
            >
              <i class="fa fa-minus"></i>
            </button>
          </div>
        </div>

        <!-- 正文信息 -->
        <div class="box-body">
          <!-- 搜索 -->
          <el-form
            :inline="true"
            :model="searchForm"
            label-position="right"
            label-width="80px"
          >
            <el-row>
              <el-form-item label="顶级机构" class="pull-left">
                <el-select
                  style="width: 180px"
                  class="input_width_lg"
                  v-model="searchForm.rootOrgId"
                  placeholder="请选择"
                  :disabled="!isSuperAdmin"
                  @change="rootOrgChanged4Search"
                >
                  <el-option
                    v-for="item in rootOrgList"
                    :label="item.name"
                    :value="item.id"
                    :key="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="角色" class="pull-left">
                <el-select
                  style="width: 180px"
                  class="input_width_lg"
                  clearable
                  v-model="searchForm.roleId"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in roleList4Search"
                    :label="item.roleName"
                    :value="item.roleId"
                    :key="item.roleId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="登录名" class="pull-left">
                <el-input
                  style="width: 180px"
                  class="input_width_lg"
                  placeholder="请输入登录名"
                  v-model="searchForm.loginName"
                ></el-input>
              </el-form-item>
              <el-form-item label="姓名" class="pull-left">
                <el-input
                  style="width: 180px"
                  class="input_width_lg"
                  placeholder="请输入姓名"
                  v-model="searchForm.name"
                ></el-input>
              </el-form-item>
              <el-form-item class="pull-right">
                <el-button
                  size="small"
                  type="primary"
                  icon="search"
                  @click="search"
                  >查询</el-button
                >
                <el-button
                  size="small"
                  type="primary"
                  icon="plus"
                  @click="openAddingDialog"
                  >新增
                </el-button>
              </el-form-item>
            </el-row>
          </el-form>

          <!-- 添加用户信息弹出框 -->
          <el-dialog title="用户信息" :visible.sync="addingDialog">
            <el-form
              :inline="true"
              :model="userForm"
              ref="addingForm"
              :rules="rules"
              label-position="right"
            >
              <el-row>
                <el-form-item label="姓名" label-width="120px" prop="name">
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.name"
                    auto-complete="off"
                    placeholder="请输入姓名"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="登录名"
                  label-width="120px"
                  prop="loginName"
                >
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.loginName"
                    auto-complete="off"
                    placeholder="请输入登录名"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="密码" label-width="120px" prop="password">
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.password"
                    auto-complete="off"
                    placeholder="请输入密码"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="联系方式"
                  label-width="120px"
                  prop="mobile"
                >
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.mobile"
                    auto-complete="off"
                    placeholder="请输入联系方式"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="顶级机构"
                  label-width="120px"
                  prop="rootOrgId"
                >
                  <el-select
                    class="select"
                    v-model="userForm.rootOrgId"
                    placeholder="请选择"
                    :disabled="!isSuperAdmin"
                    @change="rootOrgChanged4InsertOrUpdate"
                  >
                    <el-option
                      v-for="item in rootOrgList"
                      :label="item.name"
                      :value="item.id"
                      :key="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="角色" label-width="120px" prop="roleIds">
                  <el-select
                    class="select"
                    multiple
                    v-model="userForm.roleIds"
                    placeholder="请选择"
                    @change="rolesChanged"
                  >
                    <el-option
                      v-for="item in roleList4InsertOrUpdateWithoutSuperAdmin"
                      :label="item.roleName"
                      :value="item.roleId"
                      :key="item.roleId"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="子机构" label-width="120px" prop="orgId">
                  <el-select
                    class="select"
                    :remote-method="getOrgList4InsertOrUpdate"
                    :loading="orgLoading4InsertOrUpdate"
                    remote
                    filterable
                    clearable
                    v-model="userForm.orgId"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in orgList4InsertOrUpdate"
                      :label="item.name"
                      :value="item.id"
                      :key="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="状态" label-width="120px">
                  <el-radio-group class="pull_right_sm" v-model="enableStr">
                    <el-radio label="true">启用</el-radio>
                    <el-radio label="false">禁用</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-row>
              <el-row class="pull_center">
                <el-button type="primary" @click="add">保 存</el-button>
                <el-button @click="addingDialog = false;">取 消</el-button>
              </el-row>
            </el-form>
          </el-dialog>

          <!-- 修改用户信息弹出框 -->
          <el-dialog title="用户信息" :visible.sync="updateDialog">
            <el-form
              :inline="true"
              :model="userForm"
              ref="updateForm"
              :rules="rules"
              label-position="right"
            >
              <el-row>
                <el-form-item label="ID" label-width="120px">
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.id"
                    :disabled="true"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="姓名" label-width="120px" prop="name">
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.name"
                    auto-complete="off"
                    placeholder="请输入姓名"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="登录名"
                  label-width="120px"
                  prop="loginName"
                >
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.loginName"
                    auto-complete="off"
                    placeholder="请输入登录名"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="联系方式"
                  label-width="120px"
                  prop="mobile"
                >
                  <el-input
                    class="input_width_lg"
                    v-model="userForm.mobile"
                    auto-complete="off"
                    placeholder="请输入联系方式"
                  ></el-input>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item
                  label="顶级机构"
                  label-width="120px"
                  prop="rootOrgId"
                >
                  <el-select
                    class="select"
                    v-model="userForm.rootOrgId"
                    placeholder="请选择"
                    :disabled="true"
                  >
                    <el-option
                      v-for="item in rootOrgList"
                      :label="item.name"
                      :value="item.id"
                      :key="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="角色" label-width="120px" prop="roleIds">
                  <el-select
                    class="select"
                    multiple
                    v-model="userForm.roleIds"
                    placeholder="请选择"
                    :disabled="rowIsSuperAdmin"
                    @change="rolesChanged"
                  >
                    <el-option
                      v-for="item in roleList4InsertOrUpdate"
                      :label="item.roleName"
                      :disabled="item.roleCode == 'SUPER_ADMIN'"
                      :value="item.roleId"
                      :key="item.roleId"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="子机构" label-width="120px" prop="orgId">
                  <el-select
                    class="select"
                    :remote-method="getOrgList4InsertOrUpdate"
                    :loading="orgLoading4InsertOrUpdate"
                    remote
                    filterable
                    clearable
                    v-model="userForm.orgId"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in orgList4InsertOrUpdate"
                      :label="item.name"
                      :value="item.id"
                      :key="item.id"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="状态" label-width="120px">
                  <el-radio-group
                    class="pull_right_sm"
                    v-model="enableStr"
                    :disabled="rowIsSuperAdmin"
                  >
                    <el-radio label="true">启用</el-radio>
                    <el-radio label="false">禁用</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-row>
              <el-row class="pull_center">
                <el-button type="primary" @click="update">保 存</el-button>
                <el-button @click="updateDialog = false;">取 消</el-button>
              </el-row>
            </el-form>
          </el-dialog>

          <!-- 页面列表 -->
          <el-table
            :data="tableData"
            border
            style="width: 100%;text-align:center;"
            @selection-change="selectChange"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="id" width="100" label="ID">
            </el-table-column>
            <el-table-column prop="name" width="150" label="姓名">
            </el-table-column>
            <el-table-column prop="loginName" width="150" label="登录名">
            </el-table-column>
            <el-table-column prop="rootOrgName" width="150" label="顶级机构">
            </el-table-column>
            <el-table-column prop="roleNamesStr" width="250" label="角色">
            </el-table-column>
            <el-table-column prop="updateTime" width="180" label="更新时间">
            </el-table-column>
            <el-table-column width="80" label="状态">
              <template slot-scope="scope">
                <div>
                  <span>
                    <el-tag :type="getTag(scope.row.enable)">
                      {{ getEnable(scope.row.enable) }}
                    </el-tag>
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <div>
                  <span>
                    <el-button
                      size="mini"
                      type="primary"
                      @click="openUpdateDialog(scope.row);"
                    >
                      <i class="el-icon-edit"></i> 修改
                    </el-button>
                  </span>
                  <span>
                    <el-button
                      v-if="false"
                      size="mini"
                      type="danger"
                      @click="deleteById(scope.row);"
                    >
                      <i class="el-icon-delete"></i> 删除
                    </el-button>
                  </span>
                  <span>
                    <el-button
                      size="mini"
                      type="info"
                      @click="resetPass(scope.row);"
                    >
                      <i class="el-icon-reset"></i>重置密码
                    </el-button>
                  </span>
                  <span v-if="!scope.row.enable">
                    <el-button
                      size="mini"
                      type="success"
                      @click="enableById(scope.row);"
                    >
                      <i class="fa fa-check" aria-hidden="true"></i>启用
                    </el-button>
                  </span>
                  <span v-if="scope.row.enable">
                    <el-button
                      size="mini"
                      type="warning"
                      @click="disableById(scope.row);"
                    >
                      <i class="fa fa-close" aria-hidden="true"></i>禁用
                    </el-button>
                  </span>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <div class="page pull-right">
            <el-pagination
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-size="10"
              layout="total, prev, pager, next, jumper"
              :total="total"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { core_api } from "../constants/constants.js";
import { mapState } from "vuex";

export default {
  data() {
    var validateRootOrg = (rule, value, callback) => {
      if (0 != value && !value) {
        callback(new Error("请选择顶级机构"));
      } else {
        callback();
      }
    };
    var validateRoles = (rule, value, callback) => {
      if (value.length == 0) {
        callback(new Error("请选择角色"));
      } else {
        callback();
      }
    };
    return {
      orgLoading4InsertOrUpdate: false,
      isSuperAdmin: false,
      roleList4Search: [],
      roleList4InsertOrUpdate: [],
      rootOrgList: [],
      orgList4InsertOrUpdate: [],
      searchForm: {
        name: "",
        loginName: "",
        enable: true,
        rootOrgId: "",
        roleId: ""
      },
      userForm: {
        id: null,
        name: "",
        loginName: "",
        password: "",
        mobile: "",
        enable: true,
        rootOrgId: null,
        orgId: null,
        roleIds: []
      },
      enableStr: "true",

      tempOrgList: [],
      userId: "",
      selectedUserIds: [],
      tableData: [],
      currentPage: 1,
      pageSize: 10,
      total: 10,
      addingDialog: false,
      updateDialog: false,
      rowIsSuperAdmin: false,
      rules: {
        name: [
          {
            required: true,
            message: "请输入姓名",
            trigger: "blur"
          }
        ],
        loginName: [
          {
            required: true,
            message: "请输入登录名",
            trigger: "blur"
          }
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur"
          }
        ],
        mobile: [
          {
            message: "请输入联系方式",
            trigger: "blur"
          }
        ],
        rootOrgId: [
          {
            validator: validateRootOrg,
            trigger: "blur,change"
          }
        ],
        orgId: [],
        roleIds: [
          {
            validator: validateRoles,
            trigger: "blur,change"
          }
        ]
      }
    };
  },
  computed: {
    ...mapState({
      user: state => state.user
    }),
    userIds() {
      var userIds = "";
      for (let userId of this.selectedUserIds) {
        if (!userIds) {
          userIds += userId;
        } else {
          userIds += "," + userId;
        }
      }
      return userIds;
    },
    roleList4InsertOrUpdateWithoutSuperAdmin() {
      return this.roleList4InsertOrUpdate.filter(
        item => item.roleCode != "SUPER_ADMIN"
      );
    }
  },
  methods: {
    validateOrg(rule, value, callback) {
      if (0 != value && !value) {
        callback(new Error("请选择子机构"));
      } else {
        callback();
      }
    },
    rolesChanged() {
      var isLC = false;
      for (let cur of this.roleList4InsertOrUpdate) {
        if (
          cur.roleCode == "LC_USER" &&
          this.userForm.roleIds.contains(cur.roleId)
        ) {
          isLC = true;
          break;
        }
      }
      console.log("rolesChanged(); isLC:", isLC);
      if (isLC) {
        this.rules.orgId = [
          {
            validator: this.validateOrg,
            trigger: "blur,change"
          }
        ];
      } else {
        this.rules.orgId = [];
      }
    },
    rootOrgChanged4Search() {
      var url =
        core_api +
        "/rolePrivilege/getRoles?includeSuperAdmin=" +
        true +
        "&rootOrgId=" +
        this.searchForm.rootOrgId;
      this.$http
        .post(url)
        .then(response => {
          this.roleList4Search = response.data;
        })
        .catch(response => {
          if (response.status == 500) {
            this.$notify({
              showClose: true,
              message: response.data.desc,
              type: "error"
            });
          }
        });
    },
    rootOrgChanged4InsertOrUpdate() {
      this.orgList4InsertOrUpdate = [];

      var url =
        core_api +
        "/rolePrivilege/getRoles?includeSuperAdmin=" +
        true +
        "&rootOrgId=" +
        this.userForm.rootOrgId;
      this.$http
        .post(url)
        .then(response => {
          this.roleList4InsertOrUpdate = response.data;
          this.rolesChanged();
        })
        .catch(response => {
          if (response.status == 500) {
            this.$notify({
              showClose: true,
              message: response.data.desc,
              type: "error"
            });
          }
        });
    },
    getOrgList4InsertOrUpdate(query) {
      this.orgLoading4InsertOrUpdate = true;
      var url =
        core_api +
        "/org/query?" +
        new URLSearchParams({
          name: query,
          rootOrgId: this.userForm.rootOrgId
        });
      this.$http
        .get(url)
        .then(response => {
          this.orgList4InsertOrUpdate = response.data;
          this.orgLoading4InsertOrUpdate = false;
        })
        .catch(response => {
          if (response.status == 500) {
            this.$notify({
              showClose: true,
              message: response.data.desc,
              type: "error"
            });
          }
          this.orgLoading4InsertOrUpdate = false;
        });
    },
    getEnable(enable) {
      if (enable == true) {
        return "启用";
      } else if (enable == false) {
        return "禁用";
      }
      return enable;
    },
    getTag(status) {
      if (status == true) {
        return "success";
      } else if (status == false) {
        return "danger";
      }
      return status;
    },
    getLevel(level) {
      if (level == "ZSB") {
        return "专升本";
      } else if (level == "GQZ") {
        return "高起专";
      }
      return level;
    },
    search() {
      this.loading = true;
      var param = new URLSearchParams(this.searchForm);
      var url =
        core_api +
        "/user/all/" +
        this.currentPage +
        "/" +
        this.pageSize +
        "?" +
        param;
      this.$http.get(url).then(response => {
        console.log(response);
        this.tableData = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.search();
    },
    selectChange(row) {
      this.selectedUserIds = [];
      row.forEach(element => {
        this.selectedUserIds.push(element.id);
      });
      console.log(this.selectedUserIds);
    },
    //新增
    openAddingDialog() {
      if (this.$refs.addingForm) {
        this.$refs.addingForm.resetFields();
      }
      if (this.$refs.updateForm) {
        this.$refs.updateForm.resetFields();
      }
      this.addingDialog = true;
      this.userForm.name = "";
      this.userForm.loginName = "";
      this.userForm.password = "";
      this.userForm.mobile = "";
      this.userForm.roleIds = [];
      this.userForm.orgId = null;
      this.enableStr = "true";
      this.orgList4InsertOrUpdate = [];
      this.rolesChanged();
    },
    //修改
    openUpdateDialog(row) {
      if (this.$refs.updateForm) {
        this.$refs.updateForm.resetFields();
      }
      if (this.$refs.addingForm) {
        this.$refs.addingForm.resetFields();
      }

      this.updateDialog = true;
      this.userForm.id = row.id;
      this.userForm.roleIds = row.roleIds;
      this.userForm.name = row.name;
      this.userForm.loginName = row.loginName;
      this.enableStr = row.enable ? "true" : "false";
      this.userForm.mobile = row.mobile;
      this.userForm.password = null;
      this.userForm.rootOrgId = row.rootOrgId;
      this.rowIsSuperAdmin = false;
      for (let roleCode of row.roleCodes) {
        if (roleCode == "SUPER_ADMIN") {
          this.rowIsSuperAdmin = true;
          break;
        }
      }

      this.rootOrgChanged4InsertOrUpdate();
      this.orgList4InsertOrUpdate = [{ id: row.orgId, name: row.orgName }];
      this.userForm.orgId = row.orgId;
    },
    exportUser() {
      var param = new URLSearchParams(this.searchForm);
      window.open(core_api + "/user/export?" + param);
    },
    //保存
    add() {
      var url = core_api + "/user";
      this.$refs.addingForm.validate(valid => {
        if (valid) {
          this.userForm.enable = this.enableStr == "true";
          this.$http.post(url, this.userForm).then(
            () => {
              this.$notify({
                type: "success",
                message: "添加成功"
              });
              this.search();
              this.addingDialog = false;
            },
            resp => {
              this.$notify({
                type: "error",
                message: resp.body.desc
              });
            }
          );
        } else {
          return false;
        }
      });
    },
    //保存
    update() {
      var url = core_api + "/user";
      this.$refs.updateForm.validate(valid => {
        if (valid) {
          this.userForm.enable = this.enableStr == "true";
          this.$http.put(url, this.userForm).then(
            () => {
              this.$notify({
                type: "success",
                message: "添加成功"
              });
              this.search();
              this.updateDialog = false;
            },
            resp => {
              this.$notify({
                type: "error",
                message: resp.body.desc
              });
            }
          );
        } else {
          return false;
        }
      });
    },
    //重置密码
    resetPass(row) {
      this.$confirm("是否重置密码？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        var url = core_api + "/user/resetPass/" + row.id;
        this.$http
          .put(url)
          .then(() => {
            this.$notify({
              type: "success",
              message: "重置成功！"
            });
            this.search();
          })
          .catch(response => {
            if (response.status == 500) {
              this.$notify({
                showClose: true,
                message: response.data.desc,
                type: "error"
              });
            }
          });
      });
    },
    //删除单个数据
    deleteById(row) {
      this.$confirm("是否删除该用户？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        var url = core_api + "/user/" + row.id;
        this.$http
          .delete(url)
          .then(() => {
            this.$notify({
              type: "success",
              message: "删除成功！"
            });
            this.search();
          })
          .catch(response => {
            if (response.status == 500) {
              this.$notify({
                showClose: true,
                message: response.data.desc,
                type: "error"
              });
            }
          });
      });
    },
    //删除多条数据
    deleteByIds() {
      if (this.selectedUserIds.length === 0) {
        this.$notify({
          type: "warning",
          message: "请选择要删除的用户"
        });
      } else {
        this.$confirm("是否删除这些用户？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "error"
        }).then(() => {
          var url = core_api + "/user/" + this.userIds;
          this.$http
            .delete(url)
            .then(() => {
              this.$notify({
                type: "success",
                message: "删除成功！"
              });
              this.search();
            })
            .catch(response => {
              if (response.status == 500) {
                this.$notify({
                  showClose: true,
                  message: response.data.desc,
                  type: "error"
                });
              }
            });
        });
      }
    },
    //启用
    enableByIds() {
      if (this.selectedUserIds.length === 0) {
        this.$notify({
          type: "warning",
          message: "请选择要开启的用户"
        });
      } else {
        this.$confirm("是否启用这些用户？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          var url = core_api + "/user/enable/" + this.userIds;
          this.$http
            .put(url, {})
            .then(() => {
              this.$notify({
                type: "success",
                message: "开启成功！"
              });
              this.search();
            })
            .catch(response => {
              if (response.status == 500) {
                this.$notify({
                  showClose: true,
                  message: response.data.desc,
                  type: "error"
                });
              }
            });
        });
      }
    },
    enableById(row) {
      this.$confirm("是否启用该用户？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        var url = core_api + "/user/enable/" + row.id;
        this.$http
          .put(url, {})
          .then(() => {
            this.$notify({
              type: "success",
              message: "开启成功！"
            });
            this.search();
          })
          .catch(response => {
            if (response.status == 500) {
              this.$notify({
                showClose: true,
                message: response.data.desc,
                type: "error"
              });
            }
          });
      });
    },
    //禁用
    disableByIds() {
      if (this.selectedUserIds.length === 0) {
        this.$notify({
          type: "warning",
          message: "请选择要禁用的用户"
        });
      } else {
        this.$confirm("是否禁用这些用户？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "error"
        }).then(() => {
          var url = core_api + "/user/disable/" + this.userIds;
          this.$http
            .put(url, {})
            .then(() => {
              this.$notify({
                type: "success",
                message: "禁用成功！"
              });
              this.search();
            })
            .catch(response => {
              if (response.status == 500) {
                this.$notify({
                  showClose: true,
                  message: response.data.desc,
                  type: "error"
                });
              }
            });
        });
      }
    },
    //禁用
    disableById(row) {
      this.$confirm("是否禁用该用户？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error"
      }).then(() => {
        var url = core_api + "/user/disable/" + row.id;
        this.$http
          .put(url, {})
          .then(() => {
            this.$notify({
              type: "success",
              message: "禁用成功！"
            });
            this.search();
          })
          .catch(response => {
            if (response.status == 500) {
              this.$notify({
                showClose: true,
                message: response.data.desc,
                type: "error"
              });
            }
          });
      });
    },

    /*初始化*/
    init() {
      for (let role of this.user.roleList) {
        if (role.roleCode == "SUPER_ADMIN") {
          this.isSuperAdmin = true;
          break;
        }
      }

      this.searchForm.rootOrgId = this.user.rootOrgId;
      this.userForm.rootOrgId = this.user.rootOrgId;

      var url1 = core_api + "/org/getRootOrgList";
      var url2 =
        core_api +
        "/rolePrivilege/getRoles?includeSuperAdmin=" +
        true +
        "&rootOrgId=" +
        this.user.rootOrgId;

      Promise.all([this.$http.get(url1), this.$http.post(url2)]).then(
        ([resp1, resp2]) => {
          this.rootOrgList = resp1.data;
          this.roleList4Search = resp2.data;
          this.roleList4InsertOrUpdate = resp2.data;
          this.search();
        }
      );
    }
  },
  //初始化查询
  created() {
    this.init();
  }
};
</script>

<style scoped>
.select {
  width: 195px;
}
</style>
