index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <div class="common-box">
  3. <!--条件-->
  4. <el-form :model="listQuery" ref="queryForm" :inline="true">
  5. <el-form-item label="用户编码">
  6. <el-input
  7. v-model="listQuery.loginId"
  8. placeholder="请输入用户编码"
  9. ></el-input>
  10. </el-form-item>
  11. <el-form-item label="用户名称">
  12. <el-input
  13. v-model="listQuery.userName"
  14. placeholder="请输入用户名称"
  15. ></el-input>
  16. </el-form-item>
  17. <el-form-item label="联系方式">
  18. <el-input
  19. v-model="listQuery.coninfo"
  20. placeholder="请输入联系方式"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item label="所属机构">
  24. <el-select
  25. v-model="listQuery.orgnId"
  26. placeholder="搜索所属机构"
  27. filterable
  28. remote
  29. :remote-method="remoteMethod"
  30. :loading="loadingsearch"
  31. >
  32. <el-option
  33. v-for="item in orgData"
  34. :key="item.orgId"
  35. :label="item.orgName"
  36. :value="item.orgId"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" @click="getData('search')">查询 </el-button>
  42. <el-button @click="reset()">重置</el-button>
  43. </el-form-item>
  44. <el-form-item>
  45. <el-button
  46. class="lake-Blue"
  47. type="primary"
  48. icon="el-icon-plus"
  49. @click="handleAddOrEdit(0, null, 'create')"
  50. >新增
  51. </el-button>
  52. </el-form-item>
  53. </el-form>
  54. <!--列表-->
  55. <div>
  56. <el-table
  57. v-loading="listLoading"
  58. element-loading-text="加载中"
  59. :data="list"
  60. fit
  61. stripe
  62. >
  63. <template slot="empty">
  64. <img src="@/assets/nopage.png" alt />
  65. <p>暂无数据</p>
  66. </template>
  67. <el-table-column
  68. fixed
  69. type="index"
  70. label="序号"
  71. width="60"
  72. ></el-table-column>
  73. <el-table-column label="用户编码" prop="loginId" />
  74. <el-table-column label="用户名称" prop="userName" />
  75. <el-table-column label="联系方式" width="120" prop="coninfo" />
  76. <el-table-column label="年龄" width="80" prop="age" />
  77. <el-table-column label="性别" width="80" prop="gend" />
  78. <el-table-column label="创建时间" width="140" prop="crteTime" />
  79. <el-table-column label="修改时间" width="140" prop="lstUpdTime" />
  80. <el-table-column label="说明" prop="dscr" />
  81. <el-table-column fixed="right" label="操作" width="250">
  82. <template
  83. slot-scope="scope"
  84. v-if="scope.row.loginId !== 'super-admin'"
  85. >
  86. <el-button
  87. icon="el-icon-edit"
  88. style="color: #52c8cc"
  89. type="text"
  90. @click="handleAddOrEdit(scope.$index, scope.row, 'update')"
  91. >编辑</el-button
  92. >
  93. <el-button
  94. icon="el-icon-delete"
  95. style="color: #ce4745"
  96. type="text"
  97. @click="handleDelete(scope.row, 'deleted')"
  98. >删除</el-button
  99. >
  100. <el-dropdown
  101. @command="(command) => handleCommand(command, scope.row)"
  102. >
  103. <span class="el-dropdown-link">
  104. <el-button
  105. icon="el-icon-d-arrow-right"
  106. style="color: #505152; margin-left: 10px"
  107. type="text"
  108. >更多
  109. </el-button>
  110. </span>
  111. <el-dropdown-menu slot="dropdown">
  112. <el-dropdown-item command="setRole">
  113. <i class="el-icon-setting el-icon--left"></i>设置角色
  114. </el-dropdown-item>
  115. <el-dropdown-item command="resetPass" divided
  116. ><i class="el-icon-refresh-right el-icon--left"></i>重置密码
  117. </el-dropdown-item>
  118. </el-dropdown-menu>
  119. </el-dropdown>
  120. </template>
  121. </el-table-column>
  122. </el-table>
  123. </div>
  124. <!--分页-->
  125. <yl-pagination
  126. v-show="total > 0"
  127. :total="total"
  128. :page.sync="listQuery.current"
  129. :limit.sync="listQuery.size"
  130. @pagination="getData"
  131. />
  132. <!--添加/修改-->
  133. <el-dialog
  134. :title="textMap[dialogStatus]"
  135. :visible.sync="dialogFormVisible"
  136. width="420px"
  137. :close-on-click-modal="false"
  138. >
  139. <el-form
  140. ref="dataForm"
  141. :rules="rules"
  142. :model="temp"
  143. label-position="right"
  144. label-width="80px"
  145. style="width: 370px; margin-left: 10px"
  146. >
  147. <el-form-item label="用户名称" prop="userName">
  148. <el-input v-model.trim="temp.userName" />
  149. </el-form-item>
  150. <el-form-item label="所属机构" prop="orgId">
  151. <el-input
  152. disabled
  153. v-model.trim="orgName"
  154. style="width: 210px; margin-right: 3px"
  155. />
  156. <el-button type="primary" icon="el-icon-plus" @click="chooseOrg"
  157. >选择</el-button
  158. >
  159. </el-form-item>
  160. <el-form-item label="联系方式" prop="coninfo">
  161. <el-input v-model.trim="temp.coninfo" />
  162. </el-form-item>
  163. <el-form-item label="年龄" prop="age">
  164. <el-input v-model="temp.age"></el-input>
  165. </el-form-item>
  166. <el-form-item label="性别">
  167. <el-radio-group v-model="temp.gend">
  168. <el-radio label="男"></el-radio>
  169. <el-radio label="女"></el-radio>
  170. </el-radio-group>
  171. </el-form-item>
  172. <el-form-item label="说明">
  173. <el-input type="textarea" v-model.trim="temp.dscr" />
  174. </el-form-item>
  175. </el-form>
  176. <div slot="footer" class="dialog-footer">
  177. <el-button @click="dialogFormVisible = false">取消</el-button>
  178. <el-button type="primary" @click="commitData()">确认</el-button>
  179. </div>
  180. </el-dialog>
  181. <!--用户id,密码对话框-->
  182. <el-dialog
  183. title="提示"
  184. :visible.sync="passFormVisible"
  185. width="50%"
  186. :close-on-click-modal="false"
  187. >
  188. <el-alert
  189. title="请保存用户编码和密码,方便后续进行登录!!!"
  190. type="warning"
  191. show-icon
  192. style="margin-bottom: 20px"
  193. >
  194. </el-alert>
  195. <el-descriptions class="margin-top" title="" :column="1" border>
  196. <el-descriptions-item>
  197. <template slot="label"> 用户名称 </template>
  198. {{ passData.userName }}
  199. </el-descriptions-item>
  200. <el-descriptions-item>
  201. <template slot="label"> 用户编码 </template>
  202. {{ passData.loginId }}
  203. </el-descriptions-item>
  204. <el-descriptions-item>
  205. <template slot="label"> 密码 </template>
  206. {{ passData.pwd }}
  207. </el-descriptions-item>
  208. </el-descriptions>
  209. <div slot="footer" class="dialog-footer">
  210. <el-button type="primary" @click="passFormVisible = false"
  211. >关闭</el-button
  212. >
  213. </div>
  214. </el-dialog>
  215. <!--设置角色对话框-->
  216. <el-dialog
  217. title="设置角色"
  218. :visible.sync="roleFormVisible"
  219. width="610px"
  220. :close-on-click-modal="false"
  221. >
  222. <el-transfer
  223. filterable
  224. :filter-method="filterMethod"
  225. filter-placeholder="请输入角色名称"
  226. v-model="roles"
  227. :data="newRoleList"
  228. :titles="['可选角色', '已选角色']"
  229. >
  230. </el-transfer>
  231. <div slot="footer" class="dialog-footer">
  232. <el-button @click="roleFormVisible = false">取消</el-button>
  233. <el-button type="primary" @click="setRole()">确认</el-button>
  234. </div>
  235. </el-dialog>
  236. <!--选择机构-->
  237. <el-dialog
  238. v-if="dialogOrgFormVisible"
  239. title="选择机构"
  240. :visible.sync="dialogOrgFormVisible"
  241. width="1000px"
  242. :close-on-click-modal="false"
  243. >
  244. <organization
  245. @orgClose="orgClose"
  246. @orgSubmit="orgSubmit"
  247. :orgRadio="temp.orgId"
  248. ></organization>
  249. </el-dialog>
  250. </div>
  251. </template>
  252. <script>
  253. import {
  254. setUser,
  255. resetPass,
  256. getUserData,
  257. getOrganData,
  258. getRoleData,
  259. setUserRole
  260. } from "@/api/system/users";
  261. import ylPagination from "@/components/yl-pagination";
  262. import Organization from "@/views/page/system/users/components/organization";
  263. export default {
  264. components: {
  265. ylPagination,
  266. Organization
  267. },
  268. watch: {},
  269. data() {
  270. return {
  271. // 回显机构名称
  272. orgName: "",
  273. // 选择机构对话框
  274. dialogOrgFormVisible: false,
  275. // 当前用户id
  276. currentUserId: "",
  277. // 角色列表
  278. roleList: [],
  279. newRoleList: [],
  280. // 选中的角色
  281. roles: [],
  282. filterMethod(query, item) {
  283. return item.label.indexOf(query) > -1;
  284. },
  285. // 打开角色设置对话框
  286. roleFormVisible: false,
  287. // 机构列表
  288. organList: [],
  289. // 打开用户id,密码对话框
  290. passFormVisible: false,
  291. // 用户id,密码
  292. passData: {},
  293. list: [], //列表
  294. total: 0, //分页
  295. listLoading: false,
  296. listQuery: {
  297. //条件查询
  298. userName: "",
  299. current: 1,
  300. size: 10,
  301. loginId: "",
  302. orgnId: "",
  303. coninfo: ""
  304. },
  305. searchForm: {
  306. current: 1,
  307. size: 10,
  308. orgName: "",
  309. orgId: ""
  310. },
  311. orgData: [],
  312. loadingsearch: false,
  313. rolesValue: [],
  314. dialogFormVisible: false, //是否对话框
  315. dialogStatus: "",
  316. textMap: {
  317. update: "编辑",
  318. create: "添加"
  319. },
  320. temp: {
  321. //表单
  322. age: ""
  323. },
  324. dialogRoleFormVisible: false, //角色对话框
  325. tempRole: {},
  326. rules: {
  327. userName: [
  328. {
  329. required: true,
  330. message: "用户名称不能为空",
  331. trigger: "blur"
  332. },
  333. {
  334. min: 2,
  335. max: 20,
  336. message: "用户名称长度必须介于 2 和 20 之间",
  337. trigger: "blur"
  338. }
  339. ],
  340. orgId: [
  341. {
  342. required: true,
  343. message: "请选择所属机构",
  344. trigger: "change"
  345. }
  346. ],
  347. age: [
  348. {
  349. required: false,
  350. message: "年龄不能为空",
  351. trigger: "blur"
  352. },
  353. {
  354. pattern: /^(?:[1-9][0-9]?|1[01][0-9]|120)$/,
  355. message: "请输入正确的格式",
  356. trigger: "blur"
  357. }
  358. ],
  359. coninfo: [
  360. {
  361. required: true,
  362. message: "联系方式不能为空",
  363. trigger: "blur"
  364. },
  365. {
  366. pattern: /^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/,
  367. message: "请输入正确的格式",
  368. trigger: "blur"
  369. }
  370. ]
  371. }
  372. };
  373. },
  374. created() {
  375. this.getData();
  376. },
  377. methods: {
  378. // 更多
  379. handleCommand(command, row) {
  380. if (command == "setRole") {
  381. this.setRoleBox(row);
  382. } else if (command == "resetPass") {
  383. this.editPass(row);
  384. }
  385. },
  386. // 选择机构
  387. chooseOrg() {
  388. this.dialogOrgFormVisible = true;
  389. },
  390. // 关闭机构对话框
  391. orgClose() {
  392. this.dialogOrgFormVisible = false;
  393. },
  394. // 获取到选中的机构
  395. orgSubmit(orgRadio, orgName) {
  396. this.temp.orgId = orgRadio;
  397. this.orgName = orgName;
  398. this.dialogOrgFormVisible = false;
  399. },
  400. // 获取机构列表
  401. getOrgaList(orgId) {
  402. if (orgId) {
  403. getOrganData({ orgId: orgId }).then((response) => {
  404. this.organList = response.data.records;
  405. if (this.organList.length > 0) {
  406. this.orgName = this.organList[0].orgName;
  407. } else {
  408. this.orgName = this.temp.orgId;
  409. }
  410. });
  411. }
  412. },
  413. // 重置密码
  414. editPass(row) {
  415. this.$confirm("确认重置密码", "提示", {
  416. confirmButtonText: "确定",
  417. cancelButtonText: "取消",
  418. type: "warning"
  419. }).then(() => {
  420. let data = { id: row.id };
  421. resetPass(data).then((response) => {
  422. this.$message({
  423. message: "操作成功",
  424. type: "success"
  425. });
  426. this.passData = {
  427. loginId: row.loginId,
  428. pwd: response.data,
  429. userName: row.userName
  430. };
  431. this.passFormVisible = true;
  432. });
  433. });
  434. },
  435. // 打开设置角色对话框
  436. setRoleBox(row) {
  437. this.currentUserId = row.userId;
  438. this.roles = [];
  439. getRoleData({ userId: row.userId, current: 1, size: 1000 }).then(
  440. (response) => {
  441. this.roleList = response.data.records;
  442. this.newRoleList = [];
  443. this.roleList.forEach((item, index) => {
  444. this.newRoleList.push({
  445. label: item.roleName,
  446. key: item.roleId
  447. });
  448. if (item.cho == "0") {
  449. this.roles.push(item.roleId);
  450. }
  451. });
  452. this.roleFormVisible = true;
  453. }
  454. );
  455. },
  456. // 去重
  457. duplicateRemoval(tempArr) {
  458. for (let i = 0; i < tempArr.length; i++) {
  459. for (let j = i + 1; j < tempArr.length; j++) {
  460. if (tempArr[i].roleId == tempArr[j].roleId) {
  461. tempArr.splice(j, 1);
  462. j--;
  463. }
  464. }
  465. }
  466. return tempArr;
  467. },
  468. // 设置角色
  469. setRole() {
  470. this.$confirm("确认提交", "提示", {
  471. confirmButtonText: "确定",
  472. cancelButtonText: "取消",
  473. type: "warning"
  474. }).then(() => {
  475. let newRoles = [];
  476. this.roles.forEach((item, index) => {
  477. newRoles.push({ roleId: item, userId: this.currentUserId });
  478. });
  479. let newData = this.duplicateRemoval(newRoles);
  480. setUserRole(newData).then((response) => {
  481. this.$message({
  482. message: "操作成功",
  483. type: "success"
  484. });
  485. this.roleFormVisible = false;
  486. });
  487. });
  488. },
  489. // 重置页面
  490. reset() {
  491. this.listQuery.loginId = "";
  492. this.listQuery.userName = "";
  493. this.listQuery.coninfo = "";
  494. this.listQuery.orgnId = "";
  495. this.getData();
  496. },
  497. // 查询所属机构
  498. remoteMethod(val) {
  499. this.loadingsearch = true;
  500. this.searchForm.orgName = val;
  501. getOrganData(this.searchForm)
  502. .then((response) => {
  503. this.orgData = response.data.records;
  504. this.loadingsearch = false;
  505. })
  506. .catch((err) => {});
  507. },
  508. //获取列表数据
  509. getData(type) {
  510. if (type == "search") {
  511. this.listQuery.current = 1;
  512. }
  513. this.listLoading = true;
  514. getUserData(this.listQuery)
  515. .then((response) => {
  516. this.list = response.data.records;
  517. this.total = response.data.total;
  518. this.listLoading = false;
  519. })
  520. .catch((err) => {
  521. this.listLoading = false;
  522. });
  523. },
  524. //提交表单数据
  525. commitData() {
  526. this.$refs["dataForm"].validate((valid) => {
  527. if (valid) {
  528. this.$confirm("确认提交", "提示", {
  529. confirmButtonText: "确定",
  530. cancelButtonText: "取消",
  531. type: "warning"
  532. }).then(() => {
  533. setUser(this.temp).then((response) => {
  534. this.$message({
  535. message: "操作成功",
  536. type: "success"
  537. });
  538. this.dialogFormVisible = false;
  539. if (this.dialogStatus === "create") {
  540. this.passData = {
  541. loginId: response.data.loginId,
  542. pwd: response.data.pwd,
  543. userName: this.temp.userName
  544. };
  545. this.passFormVisible = true;
  546. }
  547. this.getData();
  548. });
  549. });
  550. }
  551. });
  552. },
  553. // 打开添加/修改对话框
  554. handleAddOrEdit(index, row, type) {
  555. this.orgName = "";
  556. this.temp.orgId = "";
  557. //修改对话框
  558. if (type === "update") {
  559. this.temp = {
  560. id: row.id,
  561. userName: row.userName,
  562. orgId: row.orgId,
  563. age: row.age,
  564. gend: row.gend,
  565. coninfo: row.coninfo,
  566. dscr: row.dscr,
  567. type: "updt"
  568. };
  569. this.getOrgaList(row.orgId);
  570. } else {
  571. this.temp = {
  572. id: "",
  573. userName: "",
  574. orgId: "",
  575. age: "",
  576. gend: "",
  577. coninfo: "",
  578. dscr: "",
  579. type: "add"
  580. };
  581. }
  582. this.dialogStatus = type;
  583. this.dialogFormVisible = true;
  584. this.$nextTick(() => {
  585. this.$refs["dataForm"].clearValidate();
  586. });
  587. },
  588. //删除
  589. handleDelete(row, status) {
  590. this.$confirm("确认删除", "提示", {
  591. confirmButtonText: "确定",
  592. cancelButtonText: "取消",
  593. type: "warning"
  594. }).then(() => {
  595. this.temp = {
  596. id: row.id,
  597. userName: row.userName,
  598. orgId: row.orgId,
  599. age: row.age,
  600. gend: row.gend,
  601. coninfo: row.coninfo,
  602. dscr: row.dscr,
  603. type: "del"
  604. };
  605. setUser(this.temp).then((response) => {
  606. this.$message({
  607. message: "操作成功",
  608. type: "success"
  609. });
  610. // 解决element el-pagination分页最后一页数据清空了页码显示正确,但是列表为空
  611. const totalPage = Math.ceil((this.total - 1) / this.listQuery.size);
  612. const currentPage =
  613. this.listQuery.current > totalPage
  614. ? totalPage
  615. : this.listQuery.current;
  616. this.listQuery.current = currentPage < 1 ? 1 : currentPage;
  617. this.getData();
  618. });
  619. });
  620. }
  621. }
  622. };
  623. </script>
  624. <style scoped lang="scss">
  625. ::v-deep .el-transfer-panel__body {
  626. height: 520px;
  627. }
  628. ::v-deep .el-transfer-panel__list.is-filterable {
  629. height: 100%;
  630. }
  631. </style>