user.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <template>
  2. <div>
  3. <section class="content">
  4. <div class="box box-info">
  5. <!-- 头信息 -->
  6. <div class="box-header with-border">
  7. <h3 class="box-title">普通用户管理</h3>
  8. <div class="box-tools pull-right">
  9. <button
  10. type="button"
  11. class="btn btn-box-tool"
  12. data-widget="collapse"
  13. >
  14. <i class="fa fa-minus"></i>
  15. </button>
  16. </div>
  17. </div>
  18. <!-- 正文信息 -->
  19. <div class="box-body">
  20. <!-- 搜索 -->
  21. <el-form
  22. :inline="true"
  23. :model="searchForm"
  24. label-position="right"
  25. label-width="80px"
  26. >
  27. <el-row>
  28. <el-form-item label="顶级机构" class="pull-left">
  29. <el-select
  30. style="width: 180px"
  31. class="input_width_lg"
  32. v-model="searchForm.rootOrgId"
  33. placeholder="请选择"
  34. :disabled="!isSuperAdmin"
  35. @change="rootOrgChanged4Search"
  36. >
  37. <el-option
  38. v-for="item in rootOrgList"
  39. :label="item.name"
  40. :value="item.id"
  41. :key="item.id"
  42. >
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="角色" class="pull-left">
  47. <el-select
  48. style="width: 180px"
  49. class="input_width_lg"
  50. clearable
  51. v-model="searchForm.roleId"
  52. placeholder="请选择"
  53. >
  54. <el-option
  55. v-for="item in roleList4Search"
  56. :label="item.roleName"
  57. :value="item.roleId"
  58. :key="item.roleId"
  59. >
  60. </el-option>
  61. </el-select>
  62. </el-form-item>
  63. <el-form-item label="登录名" class="pull-left">
  64. <el-input
  65. style="width: 180px"
  66. class="input_width_lg"
  67. placeholder="请输入登录名"
  68. v-model="searchForm.loginName"
  69. ></el-input>
  70. </el-form-item>
  71. <el-form-item label="姓名" class="pull-left">
  72. <el-input
  73. style="width: 180px"
  74. class="input_width_lg"
  75. placeholder="请输入姓名"
  76. v-model="searchForm.name"
  77. ></el-input>
  78. </el-form-item>
  79. <el-form-item class="pull-right">
  80. <el-button
  81. size="small"
  82. type="primary"
  83. icon="search"
  84. @click="search"
  85. >查询</el-button
  86. >
  87. <el-button
  88. size="small"
  89. type="primary"
  90. icon="plus"
  91. @click="openAddingDialog"
  92. >新增
  93. </el-button>
  94. </el-form-item>
  95. </el-row>
  96. </el-form>
  97. <!-- 添加用户信息弹出框 -->
  98. <el-dialog title="用户信息" :visible.sync="addingDialog">
  99. <el-form
  100. :inline="true"
  101. :model="userForm"
  102. ref="addingForm"
  103. :rules="rules"
  104. label-position="right"
  105. >
  106. <el-row>
  107. <el-form-item label="姓名" label-width="120px" prop="name">
  108. <el-input
  109. class="input_width_lg"
  110. v-model="userForm.name"
  111. auto-complete="off"
  112. placeholder="请输入姓名"
  113. ></el-input>
  114. </el-form-item>
  115. </el-row>
  116. <el-row>
  117. <el-form-item
  118. label="登录名"
  119. label-width="120px"
  120. prop="loginName"
  121. >
  122. <el-input
  123. class="input_width_lg"
  124. v-model="userForm.loginName"
  125. auto-complete="off"
  126. placeholder="请输入登录名"
  127. ></el-input>
  128. </el-form-item>
  129. </el-row>
  130. <el-row>
  131. <el-form-item label="密码" label-width="120px" prop="password">
  132. <el-input
  133. class="input_width_lg"
  134. v-model="userForm.password"
  135. auto-complete="off"
  136. placeholder="请输入密码"
  137. ></el-input>
  138. </el-form-item>
  139. </el-row>
  140. <el-row>
  141. <el-form-item
  142. label="联系方式"
  143. label-width="120px"
  144. prop="mobile"
  145. >
  146. <el-input
  147. class="input_width_lg"
  148. v-model="userForm.mobile"
  149. auto-complete="off"
  150. placeholder="请输入联系方式"
  151. ></el-input>
  152. </el-form-item>
  153. </el-row>
  154. <el-row>
  155. <el-form-item
  156. label="顶级机构"
  157. label-width="120px"
  158. prop="rootOrgId"
  159. >
  160. <el-select
  161. class="select"
  162. v-model="userForm.rootOrgId"
  163. placeholder="请选择"
  164. :disabled="!isSuperAdmin"
  165. @change="rootOrgChanged4InsertOrUpdate"
  166. >
  167. <el-option
  168. v-for="item in rootOrgList"
  169. :label="item.name"
  170. :value="item.id"
  171. :key="item.id"
  172. >
  173. </el-option>
  174. </el-select>
  175. </el-form-item>
  176. </el-row>
  177. <el-row>
  178. <el-form-item label="角色" label-width="120px" prop="roleIds">
  179. <el-select
  180. class="select"
  181. multiple
  182. v-model="userForm.roleIds"
  183. placeholder="请选择"
  184. @change="rolesChanged"
  185. >
  186. <el-option
  187. v-for="item in roleList4InsertOrUpdateWithoutSuperAdmin"
  188. :label="item.roleName"
  189. :value="item.roleId"
  190. :key="item.roleId"
  191. >
  192. </el-option>
  193. </el-select>
  194. </el-form-item>
  195. </el-row>
  196. <el-row>
  197. <el-form-item label="子机构" label-width="120px" prop="orgId">
  198. <el-select
  199. class="select"
  200. :remote-method="getOrgList4InsertOrUpdate"
  201. :loading="orgLoading4InsertOrUpdate"
  202. remote
  203. filterable
  204. clearable
  205. v-model="userForm.orgId"
  206. placeholder="请选择"
  207. >
  208. <el-option
  209. v-for="item in orgList4InsertOrUpdate"
  210. :label="item.name"
  211. :value="item.id"
  212. :key="item.id"
  213. >
  214. </el-option>
  215. </el-select>
  216. </el-form-item>
  217. </el-row>
  218. <el-row>
  219. <el-form-item label="状态" label-width="120px">
  220. <el-radio-group class="pull_right_sm" v-model="enableStr">
  221. <el-radio label="true">启用</el-radio>
  222. <el-radio label="false">禁用</el-radio>
  223. </el-radio-group>
  224. </el-form-item>
  225. </el-row>
  226. <el-row class="pull_center">
  227. <el-button type="primary" @click="add">保 存</el-button>
  228. <el-button @click="addingDialog = false;">取 消</el-button>
  229. </el-row>
  230. </el-form>
  231. </el-dialog>
  232. <!-- 修改用户信息弹出框 -->
  233. <el-dialog title="用户信息" :visible.sync="updateDialog">
  234. <el-form
  235. :inline="true"
  236. :model="userForm"
  237. ref="updateForm"
  238. :rules="rules"
  239. label-position="right"
  240. >
  241. <el-row>
  242. <el-form-item label="ID" label-width="120px">
  243. <el-input
  244. class="input_width_lg"
  245. v-model="userForm.id"
  246. :disabled="true"
  247. ></el-input>
  248. </el-form-item>
  249. </el-row>
  250. <el-row>
  251. <el-form-item label="姓名" label-width="120px" prop="name">
  252. <el-input
  253. class="input_width_lg"
  254. v-model="userForm.name"
  255. auto-complete="off"
  256. placeholder="请输入姓名"
  257. ></el-input>
  258. </el-form-item>
  259. </el-row>
  260. <el-row>
  261. <el-form-item
  262. label="登录名"
  263. label-width="120px"
  264. prop="loginName"
  265. >
  266. <el-input
  267. class="input_width_lg"
  268. v-model="userForm.loginName"
  269. auto-complete="off"
  270. placeholder="请输入登录名"
  271. ></el-input>
  272. </el-form-item>
  273. </el-row>
  274. <el-row>
  275. <el-form-item
  276. label="联系方式"
  277. label-width="120px"
  278. prop="mobile"
  279. >
  280. <el-input
  281. class="input_width_lg"
  282. v-model="userForm.mobile"
  283. auto-complete="off"
  284. placeholder="请输入联系方式"
  285. ></el-input>
  286. </el-form-item>
  287. </el-row>
  288. <el-row>
  289. <el-form-item
  290. label="顶级机构"
  291. label-width="120px"
  292. prop="rootOrgId"
  293. >
  294. <el-select
  295. class="select"
  296. v-model="userForm.rootOrgId"
  297. placeholder="请选择"
  298. :disabled="true"
  299. >
  300. <el-option
  301. v-for="item in rootOrgList"
  302. :label="item.name"
  303. :value="item.id"
  304. :key="item.id"
  305. >
  306. </el-option>
  307. </el-select>
  308. </el-form-item>
  309. </el-row>
  310. <el-row>
  311. <el-form-item label="角色" label-width="120px" prop="roleIds">
  312. <el-select
  313. class="select"
  314. multiple
  315. v-model="userForm.roleIds"
  316. placeholder="请选择"
  317. :disabled="rowIsSuperAdmin"
  318. @change="rolesChanged"
  319. >
  320. <el-option
  321. v-for="item in roleList4InsertOrUpdate"
  322. :label="item.roleName"
  323. :disabled="item.roleCode == 'SUPER_ADMIN'"
  324. :value="item.roleId"
  325. :key="item.roleId"
  326. >
  327. </el-option>
  328. </el-select>
  329. </el-form-item>
  330. </el-row>
  331. <el-row>
  332. <el-form-item label="子机构" label-width="120px" prop="orgId">
  333. <el-select
  334. class="select"
  335. :remote-method="getOrgList4InsertOrUpdate"
  336. :loading="orgLoading4InsertOrUpdate"
  337. remote
  338. filterable
  339. clearable
  340. v-model="userForm.orgId"
  341. placeholder="请选择"
  342. >
  343. <el-option
  344. v-for="item in orgList4InsertOrUpdate"
  345. :label="item.name"
  346. :value="item.id"
  347. :key="item.id"
  348. >
  349. </el-option>
  350. </el-select>
  351. </el-form-item>
  352. </el-row>
  353. <el-row>
  354. <el-form-item label="状态" label-width="120px">
  355. <el-radio-group
  356. class="pull_right_sm"
  357. v-model="enableStr"
  358. :disabled="rowIsSuperAdmin"
  359. >
  360. <el-radio label="true">启用</el-radio>
  361. <el-radio label="false">禁用</el-radio>
  362. </el-radio-group>
  363. </el-form-item>
  364. </el-row>
  365. <el-row class="pull_center">
  366. <el-button type="primary" @click="update">保 存</el-button>
  367. <el-button @click="updateDialog = false;">取 消</el-button>
  368. </el-row>
  369. </el-form>
  370. </el-dialog>
  371. <!-- 页面列表 -->
  372. <el-table
  373. :data="tableData"
  374. border
  375. style="width: 100%;text-align:center;"
  376. @selection-change="selectChange"
  377. >
  378. <el-table-column type="selection" width="55"></el-table-column>
  379. <el-table-column prop="id" width="100" label="ID">
  380. </el-table-column>
  381. <el-table-column prop="name" width="150" label="姓名">
  382. </el-table-column>
  383. <el-table-column prop="loginName" width="150" label="登录名">
  384. </el-table-column>
  385. <el-table-column prop="rootOrgName" width="150" label="顶级机构">
  386. </el-table-column>
  387. <el-table-column prop="roleNamesStr" width="250" label="角色">
  388. </el-table-column>
  389. <el-table-column prop="updateTime" width="180" label="更新时间">
  390. </el-table-column>
  391. <el-table-column width="80" label="状态">
  392. <template slot-scope="scope">
  393. <div>
  394. <span>
  395. <el-tag :type="getTag(scope.row.enable)">
  396. {{ getEnable(scope.row.enable) }}
  397. </el-tag>
  398. </span>
  399. </div>
  400. </template>
  401. </el-table-column>
  402. <el-table-column label="操作">
  403. <template slot-scope="scope">
  404. <div>
  405. <span>
  406. <el-button
  407. size="mini"
  408. type="primary"
  409. @click="openUpdateDialog(scope.row);"
  410. >
  411. <i class="el-icon-edit"></i> 修改
  412. </el-button>
  413. </span>
  414. <span>
  415. <el-button
  416. v-if="false"
  417. size="mini"
  418. type="danger"
  419. @click="deleteById(scope.row);"
  420. >
  421. <i class="el-icon-delete"></i> 删除
  422. </el-button>
  423. </span>
  424. <span>
  425. <el-button
  426. size="mini"
  427. type="info"
  428. @click="resetPass(scope.row);"
  429. >
  430. <i class="el-icon-reset"></i>重置密码
  431. </el-button>
  432. </span>
  433. <span v-if="!scope.row.enable">
  434. <el-button
  435. size="mini"
  436. type="success"
  437. @click="enableById(scope.row);"
  438. >
  439. <i class="fa fa-check" aria-hidden="true"></i>启用
  440. </el-button>
  441. </span>
  442. <span v-if="scope.row.enable">
  443. <el-button
  444. size="mini"
  445. type="warning"
  446. @click="disableById(scope.row);"
  447. >
  448. <i class="fa fa-close" aria-hidden="true"></i>禁用
  449. </el-button>
  450. </span>
  451. </div>
  452. </template>
  453. </el-table-column>
  454. </el-table>
  455. <div class="page pull-right">
  456. <el-pagination
  457. @current-change="handleCurrentChange"
  458. :current-page="currentPage"
  459. :page-size="10"
  460. layout="total, prev, pager, next, jumper"
  461. :total="total"
  462. >
  463. </el-pagination>
  464. </div>
  465. </div>
  466. </div>
  467. </section>
  468. </div>
  469. </template>
  470. <script>
  471. import { core_api } from "../constants/constants.js";
  472. import { mapState } from "vuex";
  473. export default {
  474. data() {
  475. var validateRootOrg = (rule, value, callback) => {
  476. if (0 != value && !value) {
  477. callback(new Error("请选择顶级机构"));
  478. } else {
  479. callback();
  480. }
  481. };
  482. var validateRoles = (rule, value, callback) => {
  483. if (value.length == 0) {
  484. callback(new Error("请选择角色"));
  485. } else {
  486. callback();
  487. }
  488. };
  489. return {
  490. orgLoading4InsertOrUpdate: false,
  491. isSuperAdmin: false,
  492. roleList4Search: [],
  493. roleList4InsertOrUpdate: [],
  494. rootOrgList: [],
  495. orgList4InsertOrUpdate: [],
  496. searchForm: {
  497. name: "",
  498. loginName: "",
  499. enable: true,
  500. rootOrgId: "",
  501. roleId: ""
  502. },
  503. userForm: {
  504. id: null,
  505. name: "",
  506. loginName: "",
  507. password: "",
  508. mobile: "",
  509. enable: true,
  510. rootOrgId: null,
  511. orgId: null,
  512. roleIds: []
  513. },
  514. enableStr: "true",
  515. tempOrgList: [],
  516. userId: "",
  517. selectedUserIds: [],
  518. tableData: [],
  519. currentPage: 1,
  520. pageSize: 10,
  521. total: 10,
  522. addingDialog: false,
  523. updateDialog: false,
  524. rowIsSuperAdmin: false,
  525. rules: {
  526. name: [
  527. {
  528. required: true,
  529. message: "请输入姓名",
  530. trigger: "blur"
  531. }
  532. ],
  533. loginName: [
  534. {
  535. required: true,
  536. message: "请输入登录名",
  537. trigger: "blur"
  538. }
  539. ],
  540. password: [
  541. {
  542. required: true,
  543. message: "请输入密码",
  544. trigger: "blur"
  545. }
  546. ],
  547. mobile: [
  548. {
  549. message: "请输入联系方式",
  550. trigger: "blur"
  551. }
  552. ],
  553. rootOrgId: [
  554. {
  555. validator: validateRootOrg,
  556. trigger: "blur,change"
  557. }
  558. ],
  559. orgId: [],
  560. roleIds: [
  561. {
  562. validator: validateRoles,
  563. trigger: "blur,change"
  564. }
  565. ]
  566. }
  567. };
  568. },
  569. computed: {
  570. ...mapState({
  571. user: state => state.user
  572. }),
  573. userIds() {
  574. var userIds = "";
  575. for (let userId of this.selectedUserIds) {
  576. if (!userIds) {
  577. userIds += userId;
  578. } else {
  579. userIds += "," + userId;
  580. }
  581. }
  582. return userIds;
  583. },
  584. roleList4InsertOrUpdateWithoutSuperAdmin() {
  585. return this.roleList4InsertOrUpdate.filter(
  586. item => item.roleCode != "SUPER_ADMIN"
  587. );
  588. }
  589. },
  590. methods: {
  591. validateOrg(rule, value, callback) {
  592. if (0 != value && !value) {
  593. callback(new Error("请选择子机构"));
  594. } else {
  595. callback();
  596. }
  597. },
  598. rolesChanged() {
  599. var isLC = false;
  600. for (let cur of this.roleList4InsertOrUpdate) {
  601. if (
  602. cur.roleCode == "LC_USER" &&
  603. this.userForm.roleIds.contains(cur.roleId)
  604. ) {
  605. isLC = true;
  606. break;
  607. }
  608. }
  609. console.log("rolesChanged(); isLC:", isLC);
  610. if (isLC) {
  611. this.rules.orgId = [
  612. {
  613. validator: this.validateOrg,
  614. trigger: "blur,change"
  615. }
  616. ];
  617. } else {
  618. this.rules.orgId = [];
  619. }
  620. },
  621. rootOrgChanged4Search() {
  622. var url =
  623. core_api +
  624. "/rolePrivilege/getRoles?includeSuperAdmin=" +
  625. true +
  626. "&rootOrgId=" +
  627. this.searchForm.rootOrgId;
  628. this.$http
  629. .post(url)
  630. .then(response => {
  631. this.roleList4Search = response.data;
  632. })
  633. .catch(response => {
  634. if (response.status == 500) {
  635. this.$notify({
  636. showClose: true,
  637. message: response.data.desc,
  638. type: "error"
  639. });
  640. }
  641. });
  642. },
  643. rootOrgChanged4InsertOrUpdate() {
  644. this.orgList4InsertOrUpdate = [];
  645. var url =
  646. core_api +
  647. "/rolePrivilege/getRoles?includeSuperAdmin=" +
  648. true +
  649. "&rootOrgId=" +
  650. this.userForm.rootOrgId;
  651. this.$http
  652. .post(url)
  653. .then(response => {
  654. this.roleList4InsertOrUpdate = response.data;
  655. this.rolesChanged();
  656. })
  657. .catch(response => {
  658. if (response.status == 500) {
  659. this.$notify({
  660. showClose: true,
  661. message: response.data.desc,
  662. type: "error"
  663. });
  664. }
  665. });
  666. },
  667. getOrgList4InsertOrUpdate(query) {
  668. this.orgLoading4InsertOrUpdate = true;
  669. var url =
  670. core_api +
  671. "/org/query?" +
  672. new URLSearchParams({
  673. name: query,
  674. rootOrgId: this.userForm.rootOrgId
  675. });
  676. this.$http
  677. .get(url)
  678. .then(response => {
  679. this.orgList4InsertOrUpdate = response.data;
  680. this.orgLoading4InsertOrUpdate = false;
  681. })
  682. .catch(response => {
  683. if (response.status == 500) {
  684. this.$notify({
  685. showClose: true,
  686. message: response.data.desc,
  687. type: "error"
  688. });
  689. }
  690. this.orgLoading4InsertOrUpdate = false;
  691. });
  692. },
  693. getEnable(enable) {
  694. if (enable == true) {
  695. return "启用";
  696. } else if (enable == false) {
  697. return "禁用";
  698. }
  699. return enable;
  700. },
  701. getTag(status) {
  702. if (status == true) {
  703. return "success";
  704. } else if (status == false) {
  705. return "danger";
  706. }
  707. return status;
  708. },
  709. getLevel(level) {
  710. if (level == "ZSB") {
  711. return "专升本";
  712. } else if (level == "GQZ") {
  713. return "高起专";
  714. }
  715. return level;
  716. },
  717. search() {
  718. this.loading = true;
  719. var param = new URLSearchParams(this.searchForm);
  720. var url =
  721. core_api +
  722. "/user/all/" +
  723. this.currentPage +
  724. "/" +
  725. this.pageSize +
  726. "?" +
  727. param;
  728. this.$http.get(url).then(response => {
  729. console.log(response);
  730. this.tableData = response.data.list;
  731. this.total = response.data.total;
  732. this.loading = false;
  733. });
  734. },
  735. handleCurrentChange(val) {
  736. this.currentPage = val;
  737. this.search();
  738. },
  739. selectChange(row) {
  740. this.selectedUserIds = [];
  741. row.forEach(element => {
  742. this.selectedUserIds.push(element.id);
  743. });
  744. console.log(this.selectedUserIds);
  745. },
  746. //新增
  747. openAddingDialog() {
  748. if (this.$refs.addingForm) {
  749. this.$refs.addingForm.resetFields();
  750. }
  751. if (this.$refs.updateForm) {
  752. this.$refs.updateForm.resetFields();
  753. }
  754. this.addingDialog = true;
  755. this.userForm.name = "";
  756. this.userForm.loginName = "";
  757. this.userForm.password = "";
  758. this.userForm.mobile = "";
  759. this.userForm.roleIds = [];
  760. this.userForm.orgId = null;
  761. this.enableStr = "true";
  762. this.orgList4InsertOrUpdate = [];
  763. this.rolesChanged();
  764. },
  765. //修改
  766. openUpdateDialog(row) {
  767. if (this.$refs.updateForm) {
  768. this.$refs.updateForm.resetFields();
  769. }
  770. if (this.$refs.addingForm) {
  771. this.$refs.addingForm.resetFields();
  772. }
  773. this.updateDialog = true;
  774. this.userForm.id = row.id;
  775. this.userForm.roleIds = row.roleIds;
  776. this.userForm.name = row.name;
  777. this.userForm.loginName = row.loginName;
  778. this.enableStr = row.enable ? "true" : "false";
  779. this.userForm.mobile = row.mobile;
  780. this.userForm.password = null;
  781. this.userForm.rootOrgId = row.rootOrgId;
  782. this.rowIsSuperAdmin = false;
  783. for (let roleCode of row.roleCodes) {
  784. if (roleCode == "SUPER_ADMIN") {
  785. this.rowIsSuperAdmin = true;
  786. break;
  787. }
  788. }
  789. this.rootOrgChanged4InsertOrUpdate();
  790. this.orgList4InsertOrUpdate = [{ id: row.orgId, name: row.orgName }];
  791. this.userForm.orgId = row.orgId;
  792. },
  793. exportUser() {
  794. var param = new URLSearchParams(this.searchForm);
  795. window.open(core_api + "/user/export?" + param);
  796. },
  797. //保存
  798. add() {
  799. var url = core_api + "/user";
  800. this.$refs.addingForm.validate(valid => {
  801. if (valid) {
  802. this.userForm.enable = this.enableStr == "true";
  803. this.$http.post(url, this.userForm).then(
  804. () => {
  805. this.$notify({
  806. type: "success",
  807. message: "添加成功"
  808. });
  809. this.search();
  810. this.addingDialog = false;
  811. },
  812. resp => {
  813. this.$notify({
  814. type: "error",
  815. message: resp.body.desc
  816. });
  817. }
  818. );
  819. } else {
  820. return false;
  821. }
  822. });
  823. },
  824. //保存
  825. update() {
  826. var url = core_api + "/user";
  827. this.$refs.updateForm.validate(valid => {
  828. if (valid) {
  829. this.userForm.enable = this.enableStr == "true";
  830. this.$http.put(url, this.userForm).then(
  831. () => {
  832. this.$notify({
  833. type: "success",
  834. message: "添加成功"
  835. });
  836. this.search();
  837. this.updateDialog = false;
  838. },
  839. resp => {
  840. this.$notify({
  841. type: "error",
  842. message: resp.body.desc
  843. });
  844. }
  845. );
  846. } else {
  847. return false;
  848. }
  849. });
  850. },
  851. //重置密码
  852. resetPass(row) {
  853. this.$confirm("是否重置密码?", "提示", {
  854. confirmButtonText: "确定",
  855. cancelButtonText: "取消",
  856. type: "warning"
  857. }).then(() => {
  858. var url = core_api + "/user/resetPass/" + row.id;
  859. this.$http
  860. .put(url)
  861. .then(() => {
  862. this.$notify({
  863. type: "success",
  864. message: "重置成功!"
  865. });
  866. this.search();
  867. })
  868. .catch(response => {
  869. if (response.status == 500) {
  870. this.$notify({
  871. showClose: true,
  872. message: response.data.desc,
  873. type: "error"
  874. });
  875. }
  876. });
  877. });
  878. },
  879. //删除单个数据
  880. deleteById(row) {
  881. this.$confirm("是否删除该用户?", "提示", {
  882. confirmButtonText: "确定",
  883. cancelButtonText: "取消",
  884. type: "warning"
  885. }).then(() => {
  886. var url = core_api + "/user/" + row.id;
  887. this.$http
  888. .delete(url)
  889. .then(() => {
  890. this.$notify({
  891. type: "success",
  892. message: "删除成功!"
  893. });
  894. this.search();
  895. })
  896. .catch(response => {
  897. if (response.status == 500) {
  898. this.$notify({
  899. showClose: true,
  900. message: response.data.desc,
  901. type: "error"
  902. });
  903. }
  904. });
  905. });
  906. },
  907. //删除多条数据
  908. deleteByIds() {
  909. if (this.selectedUserIds.length === 0) {
  910. this.$notify({
  911. type: "warning",
  912. message: "请选择要删除的用户"
  913. });
  914. } else {
  915. this.$confirm("是否删除这些用户?", "提示", {
  916. confirmButtonText: "确定",
  917. cancelButtonText: "取消",
  918. type: "error"
  919. }).then(() => {
  920. var url = core_api + "/user/" + this.userIds;
  921. this.$http
  922. .delete(url)
  923. .then(() => {
  924. this.$notify({
  925. type: "success",
  926. message: "删除成功!"
  927. });
  928. this.search();
  929. })
  930. .catch(response => {
  931. if (response.status == 500) {
  932. this.$notify({
  933. showClose: true,
  934. message: response.data.desc,
  935. type: "error"
  936. });
  937. }
  938. });
  939. });
  940. }
  941. },
  942. //启用
  943. enableByIds() {
  944. if (this.selectedUserIds.length === 0) {
  945. this.$notify({
  946. type: "warning",
  947. message: "请选择要开启的用户"
  948. });
  949. } else {
  950. this.$confirm("是否启用这些用户?", "提示", {
  951. confirmButtonText: "确定",
  952. cancelButtonText: "取消",
  953. type: "warning"
  954. }).then(() => {
  955. var url = core_api + "/user/enable/" + this.userIds;
  956. this.$http
  957. .put(url, {})
  958. .then(() => {
  959. this.$notify({
  960. type: "success",
  961. message: "开启成功!"
  962. });
  963. this.search();
  964. })
  965. .catch(response => {
  966. if (response.status == 500) {
  967. this.$notify({
  968. showClose: true,
  969. message: response.data.desc,
  970. type: "error"
  971. });
  972. }
  973. });
  974. });
  975. }
  976. },
  977. enableById(row) {
  978. this.$confirm("是否启用该用户?", "提示", {
  979. confirmButtonText: "确定",
  980. cancelButtonText: "取消",
  981. type: "warning"
  982. }).then(() => {
  983. var url = core_api + "/user/enable/" + row.id;
  984. this.$http
  985. .put(url, {})
  986. .then(() => {
  987. this.$notify({
  988. type: "success",
  989. message: "开启成功!"
  990. });
  991. this.search();
  992. })
  993. .catch(response => {
  994. if (response.status == 500) {
  995. this.$notify({
  996. showClose: true,
  997. message: response.data.desc,
  998. type: "error"
  999. });
  1000. }
  1001. });
  1002. });
  1003. },
  1004. //禁用
  1005. disableByIds() {
  1006. if (this.selectedUserIds.length === 0) {
  1007. this.$notify({
  1008. type: "warning",
  1009. message: "请选择要禁用的用户"
  1010. });
  1011. } else {
  1012. this.$confirm("是否禁用这些用户?", "提示", {
  1013. confirmButtonText: "确定",
  1014. cancelButtonText: "取消",
  1015. type: "error"
  1016. }).then(() => {
  1017. var url = core_api + "/user/disable/" + this.userIds;
  1018. this.$http
  1019. .put(url, {})
  1020. .then(() => {
  1021. this.$notify({
  1022. type: "success",
  1023. message: "禁用成功!"
  1024. });
  1025. this.search();
  1026. })
  1027. .catch(response => {
  1028. if (response.status == 500) {
  1029. this.$notify({
  1030. showClose: true,
  1031. message: response.data.desc,
  1032. type: "error"
  1033. });
  1034. }
  1035. });
  1036. });
  1037. }
  1038. },
  1039. //禁用
  1040. disableById(row) {
  1041. this.$confirm("是否禁用该用户?", "提示", {
  1042. confirmButtonText: "确定",
  1043. cancelButtonText: "取消",
  1044. type: "error"
  1045. }).then(() => {
  1046. var url = core_api + "/user/disable/" + row.id;
  1047. this.$http
  1048. .put(url, {})
  1049. .then(() => {
  1050. this.$notify({
  1051. type: "success",
  1052. message: "禁用成功!"
  1053. });
  1054. this.search();
  1055. })
  1056. .catch(response => {
  1057. if (response.status == 500) {
  1058. this.$notify({
  1059. showClose: true,
  1060. message: response.data.desc,
  1061. type: "error"
  1062. });
  1063. }
  1064. });
  1065. });
  1066. },
  1067. /*初始化*/
  1068. init() {
  1069. for (let role of this.user.roleList) {
  1070. if (role.roleCode == "SUPER_ADMIN") {
  1071. this.isSuperAdmin = true;
  1072. break;
  1073. }
  1074. }
  1075. this.searchForm.rootOrgId = this.user.rootOrgId;
  1076. this.userForm.rootOrgId = this.user.rootOrgId;
  1077. var url1 = core_api + "/org/getRootOrgList";
  1078. var url2 =
  1079. core_api +
  1080. "/rolePrivilege/getRoles?includeSuperAdmin=" +
  1081. true +
  1082. "&rootOrgId=" +
  1083. this.user.rootOrgId;
  1084. Promise.all([this.$http.get(url1), this.$http.post(url2)]).then(
  1085. ([resp1, resp2]) => {
  1086. this.rootOrgList = resp1.data;
  1087. this.roleList4Search = resp2.data;
  1088. this.roleList4InsertOrUpdate = resp2.data;
  1089. this.search();
  1090. }
  1091. );
  1092. }
  1093. },
  1094. //初始化查询
  1095. created() {
  1096. this.init();
  1097. }
  1098. };
  1099. </script>
  1100. <style scoped>
  1101. .select {
  1102. width: 195px;
  1103. }
  1104. </style>