index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <div id="accountManagement">
  3. <table-list
  4. :tableSets="tableSet"
  5. :tableData="tableData"
  6. :navText="navText"
  7. :loading="loading"
  8. @addClick="addClick"
  9. >
  10. <template slot="btn" slot-scope="props">
  11. <el-button type="text" @click="addClick(props.scope.row, 0)"
  12. >修改</el-button
  13. >
  14. <el-button type="text" @click="del(props.scope.row)">删除</el-button>
  15. </template>
  16. </table-list>
  17. <pagination
  18. :total="total"
  19. :pageSize="pageSize"
  20. :currentPage="currentPage"
  21. @handleSizeChange="handleSizeChange"
  22. @handleCurrentChange="handleCurrentChange"
  23. />
  24. <el-dialog
  25. :visible.sync="dialogVisible"
  26. width="560px"
  27. :show-close="false"
  28. :close-on-click-modal="false"
  29. @close="onClose"
  30. @closed="loadingClose"
  31. >
  32. <div slot="title" class="hearders">
  33. <div class="leftTitle">
  34. {{ statusPop === 1 ? "添加" : statusPop === 0 ? "修改" : "详情" }}
  35. </div>
  36. <div class="rightBoxs">
  37. <img src="@/assets/images/Close@2x.png" alt="" @click="close" />
  38. </div>
  39. </div>
  40. <div>
  41. <el-form
  42. label-position="right"
  43. label-width="110px"
  44. :model="listData"
  45. :rules="rules"
  46. ref="listData"
  47. >
  48. <el-form-item label="账号名称" prop="userName">
  49. <el-input
  50. v-model="listData.userName"
  51. placeholder="请输入账号名称"
  52. clearable
  53. :style="{ width: '100%' }"
  54. >
  55. </el-input>
  56. </el-form-item>
  57. <el-form-item
  58. label="账号密码"
  59. :prop="statusPop === 1 ? 'password' : ''"
  60. >
  61. <el-input
  62. v-model="listData.password"
  63. placeholder="请输入账号密码"
  64. clearable
  65. :style="{ width: '100%' }"
  66. >
  67. </el-input>
  68. </el-form-item>
  69. <el-form-item label="真实姓名" prop="nickName">
  70. <el-input
  71. v-model="listData.nickName"
  72. placeholder="请输入真实姓名"
  73. clearable
  74. :style="{ width: '100%' }"
  75. >
  76. </el-input>
  77. </el-form-item>
  78. <el-form-item label="手机号码" prop="phonenumber">
  79. <el-input
  80. v-model="listData.phonenumber"
  81. placeholder="请输入手机号码"
  82. clearable
  83. :style="{ width: '100%' }"
  84. >
  85. </el-input>
  86. </el-form-item>
  87. <el-form-item label="邮箱" prop="email">
  88. <el-input
  89. v-model="listData.email"
  90. placeholder="请输入邮箱"
  91. clearable
  92. :style="{ width: '100%' }"
  93. >
  94. </el-input>
  95. </el-form-item>
  96. <el-form-item label="角色名称" prop="roleIds">
  97. <el-select
  98. multiple
  99. v-model="listData.roleIds"
  100. placeholder="请选择角色名称"
  101. clearable
  102. :style="{ width: '100%' }"
  103. >
  104. <el-option
  105. v-for="(item, index) in roleList"
  106. :key="index"
  107. :label="item.roleName"
  108. :value="item.roleId"
  109. :disabled="item.disabled"
  110. ></el-option>
  111. </el-select>
  112. </el-form-item>
  113. <el-form-item label="状态" prop="status">
  114. <el-radio-group v-model="listData.status" size="medium">
  115. <el-radio
  116. v-for="(item, index) in statusOptions"
  117. :key="index"
  118. :label="item.value"
  119. :disabled="item.disabled"
  120. >{{ item.label }}</el-radio
  121. >
  122. </el-radio-group>
  123. </el-form-item>
  124. </el-form>
  125. </div>
  126. <span slot="footer" class="dialog-footer">
  127. <el-button @click="close">取 消</el-button>
  128. <el-button
  129. type="primary"
  130. v-if="statusPop !== 2"
  131. :loading="disabledBtn"
  132. @click="submit('listData')"
  133. >确 定</el-button
  134. >
  135. </span>
  136. </el-dialog>
  137. </div>
  138. </template>
  139. <script>
  140. import { mapGetters } from "vuex";
  141. import searchBox from "@/components/searchBox";
  142. import tableList from "@/components/tableList";
  143. import pagination from "@/components/pagination";
  144. export default {
  145. name: "AccountManagement",
  146. components: { searchBox, tableList, pagination },
  147. data() {
  148. return {
  149. disabledBtn: false,
  150. loading: false, //当前表单加载是否加载动画
  151. navText: {
  152. title: "账号管理",
  153. index: 0,
  154. ch: "条",
  155. num: false,
  156. choice: true,
  157. addHide: false,
  158. backFatherBtn: {
  159. status: false,
  160. title: "未定义",
  161. },
  162. },
  163. // 表单
  164. tableSet: [
  165. {
  166. label: "用户编码",
  167. prop: "code",
  168. hidden: true,
  169. },
  170. {
  171. label: "账号名称",
  172. prop: "userName",
  173. hidden: true,
  174. },
  175. {
  176. label: "角色名称",
  177. prop: "roles",
  178. prop1: "roleName",
  179. scope: "aboutChapter",
  180. hidden: true,
  181. },
  182. {
  183. label: "真实姓名",
  184. prop: "nickName",
  185. hidden: true,
  186. },
  187. {
  188. label: "手机号码",
  189. prop: "phonenumber",
  190. hidden: true,
  191. },
  192. {
  193. label: "邮箱",
  194. prop: "email",
  195. hidden: true,
  196. },
  197. {
  198. label: "状态",
  199. prop: "status",
  200. hidden: true,
  201. scope: "status",
  202. },
  203. ],
  204. listData: {},
  205. rules: {
  206. userName: [
  207. {
  208. required: true,
  209. message: "请输入账号名称",
  210. trigger: "blur",
  211. },
  212. ],
  213. password: [
  214. {
  215. required: true,
  216. message: "请输入账号密码",
  217. trigger: "blur",
  218. },
  219. ],
  220. nickName: [
  221. {
  222. required: true,
  223. message: "请输入真实姓名",
  224. trigger: "blur",
  225. },
  226. ],
  227. phonenumber: [
  228. {
  229. required: false,
  230. message: "请输入手机号码",
  231. trigger: "blur",
  232. },
  233. {
  234. pattern: /^1[34578]\d{9}$/,
  235. message: "请输入正确手机号",
  236. trigger: "blur",
  237. },
  238. ],
  239. email: [
  240. {
  241. required: false,
  242. message: "请输入邮箱",
  243. trigger: "blur",
  244. },
  245. ],
  246. roleIds: [
  247. {
  248. required: true,
  249. message: "请选择角色名称",
  250. trigger: "change",
  251. },
  252. ],
  253. status: [
  254. {
  255. required: true,
  256. message: "状态不能为空",
  257. trigger: "change",
  258. },
  259. ],
  260. },
  261. statusOptions: [
  262. {
  263. label: "启用",
  264. value: 1,
  265. },
  266. {
  267. label: "关闭",
  268. value: 0,
  269. },
  270. ],
  271. statusPop: 1,
  272. dialogVisible: false,
  273. listData: {},
  274. tableData: [], //表单数据
  275. total: 0, //一共多少条
  276. pageSize: 10, //每页多少条数据
  277. currentPage: 1, //当前页码
  278. };
  279. },
  280. computed: { ...mapGetters(["roleList"]) },
  281. mounted() {
  282. this.search();
  283. },
  284. methods: {
  285. loadingClose() {
  286. this.disabledBtn = false;
  287. },
  288. search(v) {
  289. this.loading = true;
  290. var data = {
  291. statusArray: "0,1",
  292. pageSize: this.pageSize,
  293. pageNum: this.currentPage,
  294. };
  295. this.$api
  296. .obtainUserList(data)
  297. .then((res) => {
  298. this.tableData = res.rows;
  299. this.total = res.total;
  300. this.navText.index = res.total;
  301. })
  302. .finally(() => {
  303. this.loading = false;
  304. });
  305. },
  306. init() {
  307. this.search();
  308. },
  309. addClick(v, int) {
  310. if (v === undefined) {
  311. this.statusPop = 1;
  312. this.listData = {
  313. status: 1,
  314. };
  315. } else {
  316. this.statusPop = int;
  317. this.listData = JSON.parse(JSON.stringify(v));
  318. }
  319. this.$nextTick(() => {
  320. this.$refs.listData.clearValidate();
  321. });
  322. this.dialogVisible = true;
  323. },
  324. del(v) {
  325. this.$confirm("此操作将删除该岗位, 是否继续?", "提示", {
  326. confirmButtonText: "确定",
  327. cancelButtonText: "取消",
  328. type: "warning",
  329. })
  330. .then(() => {
  331. // var data = JSON.parse(JSON.stringify(v));
  332. // data.menuIds = [];
  333. // data.status = "-1";
  334. var data = {
  335. userId: v.userId,
  336. status: -1,
  337. userName: v.userName,
  338. roleIds: [],
  339. };
  340. this.$api.editUser(data).then((res) => {
  341. if (res.code === 200) {
  342. this.$message.success("删除成功");
  343. this.search();
  344. this.dialogVisible = false;
  345. }
  346. });
  347. })
  348. .catch(() => {
  349. this.$message({
  350. type: "info",
  351. message: "已取消删除",
  352. });
  353. });
  354. },
  355. onClose() {
  356. this.$refs["listData"].resetFields();
  357. },
  358. close() {
  359. this.dialogVisible = false;
  360. },
  361. submit(formName) {
  362. this.$refs[formName].validate((valid) => {
  363. if (!valid) return;
  364. this.disabledBtn = true;
  365. if (this.listData.userId) {
  366. this.$api
  367. .editUser(this.listData)
  368. .then((res) => {
  369. this.$message.success("修改成功");
  370. this.search();
  371. this.close();
  372. })
  373. .catch(() => {
  374. this.disabledBtn = false;
  375. });
  376. } else {
  377. this.$api
  378. .addUser(this.listData)
  379. .then((res) => {
  380. this.$message.success("新增成功");
  381. this.search();
  382. this.close();
  383. })
  384. .catch(() => {
  385. this.disabledBtn = false;
  386. });
  387. }
  388. });
  389. },
  390. handleSizeChange(v) {
  391. this.pageSize = v;
  392. this.currentPage = 1;
  393. this.search();
  394. },
  395. handleCurrentChange(v) {
  396. this.currentPage = v;
  397. this.search();
  398. },
  399. },
  400. };
  401. </script>
  402. <style lang="less" scoped>
  403. /deep/.el-button {
  404. border-radius: 8px;
  405. }
  406. /deep/.el-dialog {
  407. border-radius: 8px;
  408. .el-dialog__header {
  409. padding: 0;
  410. .hearders {
  411. height: 40px;
  412. display: flex;
  413. align-items: center;
  414. justify-content: space-between;
  415. padding: 0px 18px 0px 20px;
  416. border-bottom: 1px solid #e2e2e2;
  417. .leftTitle {
  418. font-size: 14px;
  419. font-weight: bold;
  420. color: #2f4378;
  421. }
  422. .rightBoxs {
  423. display: flex;
  424. align-items: center;
  425. img {
  426. width: 14px;
  427. height: 14px;
  428. margin-left: 13px;
  429. cursor: pointer;
  430. }
  431. }
  432. }
  433. }
  434. .el-dialog__footer {
  435. padding: 0;
  436. .dialog-footer {
  437. padding: 0px 40px;
  438. height: 70px;
  439. border-top: 1px solid #e2e2e2;
  440. display: flex;
  441. align-items: center;
  442. justify-content: flex-end;
  443. }
  444. }
  445. }
  446. .imgBox {
  447. width: 100%;
  448. // height: 210px;
  449. border: 1px solid #e2e2e2;
  450. border-radius: 8px;
  451. padding: 8px 8px 3px;
  452. display: flex;
  453. flex-direction: column;
  454. align-items: center;
  455. .imgLabel {
  456. flex: 1;
  457. width: 100%;
  458. border: 1px dotted #e2e2e2;
  459. color: #999;
  460. font-size: 14px;
  461. cursor: pointer;
  462. border-radius: 8px;
  463. .msPhoto {
  464. display: flex;
  465. justify-content: center;
  466. align-items: center;
  467. max-width: 100%;
  468. max-height: 270px;
  469. img {
  470. max-width: 100%;
  471. max-height: 270px;
  472. }
  473. }
  474. .imgbbx {
  475. display: flex;
  476. flex-direction: column;
  477. align-items: center;
  478. justify-content: center;
  479. width: 100%;
  480. height: 100%;
  481. i {
  482. font-weight: bold;
  483. margin: 14px 0;
  484. font-size: 24px;
  485. }
  486. }
  487. }
  488. p {
  489. margin: 5px 0px;
  490. }
  491. }
  492. </style>