AdminManage.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. <template>
  2. <div class="context">
  3. <div class="panel">
  4. <h5>管理员管理</h5>
  5. <div class="panel-body">
  6. <div class="panel_control">
  7. <el-row :gutter="20">
  8. <el-col :span="4">
  9. <em>姓名:</em>
  10. <el-input v-model="panel.name" placeholder="请输入用户名"></el-input>
  11. </el-col>
  12. <el-col :span="4">
  13. <em>手机号:</em>
  14. <el-input v-model="panel.phone" placeholder="请输入手机号"></el-input>
  15. </el-col>
  16. <el-col :span="4">
  17. <em>店面:</em>
  18. <el-select v-model="panel.shopId">
  19. <el-option
  20. v-for="item in panel.options"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value">
  24. </el-option>
  25. </el-select>
  26. </el-col>
  27. <el-col :span="4">
  28. <el-button size="" type="primary" @click="query" plain>查询</el-button>
  29. </el-col>
  30. </el-row>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="change">
  35. <el-button @click="addAdmin">新增管理员</el-button>
  36. <el-button @click="editList">编辑</el-button>
  37. <el-button @click="delList">删除</el-button>
  38. </div>
  39. <div class="table">
  40. <el-table
  41. :data="tableData"
  42. border
  43. is-horizontal-resize
  44. :default-sort="{prop: 'date', order: 'descending'}"
  45. element-loading-background="rgba(0, 0, 0, 0.8)"
  46. class=""
  47. @selection-change="handleSelectionChange"
  48. >
  49. <el-table-column
  50. type="selection"
  51. width="55">
  52. </el-table-column>
  53. <el-table-column
  54. type="index"
  55. label="序号"
  56. width="50">
  57. </el-table-column>
  58. <el-table-column
  59. prop="Usercode"
  60. label="用户名"
  61. sortable
  62. >
  63. </el-table-column>
  64. <el-table-column
  65. prop="Name"
  66. label="姓名"
  67. sortable
  68. >
  69. </el-table-column>
  70. <el-table-column
  71. prop="Phone"
  72. label="手机号"
  73. >
  74. </el-table-column>
  75. <el-table-column
  76. prop="ShopName"
  77. label="所属门店"
  78. sortable
  79. >
  80. </el-table-column>
  81. <el-table-column
  82. prop="LastLoginTime"
  83. label="上次登陆时间"
  84. :formatter="filterFmtDate"
  85. sortable
  86. >
  87. </el-table-column>
  88. <el-table-column
  89. prop="Memo"
  90. label="备注"
  91. sortable
  92. >
  93. <template slot-scope="scope">
  94. <el-popover
  95. placement="top"
  96. title="备注"
  97. width="200"
  98. trigger="hover"
  99. :content="scope.row.Memo">
  100. <span slot="reference"
  101. v-if="scope.row.Memo.length > 10">{{scope.row.Memo.substr(0,10)}} ....</span>
  102. </el-popover>
  103. <span v-if="scope.row.Memo.length <= 10">{{scope.row.Memo}}</span>
  104. </template>
  105. </el-table-column>
  106. <el-table-column
  107. prop="Status"
  108. label="操作"
  109. >
  110. <template slot-scope="scope">
  111. <el-button type="danger" size="mini" v-if="scope.row.Status == 1"
  112. @click="runAndPause(scope.row,8)">禁用
  113. </el-button>
  114. <el-button type="success" size="mini" v-if="scope.row.Status == 8"
  115. @click="runAndPause(scope.row,1)">启用
  116. </el-button>
  117. </template>
  118. </el-table-column>
  119. </el-table>
  120. <br>
  121. <el-pagination
  122. background
  123. :total="pageination.total"
  124. :page-size="pageination.pageItem"
  125. @current-change="pageChange"
  126. ></el-pagination>
  127. </div>
  128. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="650px">
  129. <div>
  130. <el-form ref="form" :model="form" label-width="80px">
  131. <el-form-item label="登陆账号">
  132. <el-input v-model="form.userCode"></el-input>
  133. </el-form-item>
  134. <el-form-item label="密码">
  135. <el-input v-model="form.password" type="password"></el-input>
  136. </el-form-item>
  137. <el-form-item label="姓名">
  138. <el-input v-model="form.name"></el-input>
  139. </el-form-item>
  140. <el-form-item label="手机号">
  141. <el-input v-model="form.phone"></el-input>
  142. </el-form-item>
  143. <el-form-item label="所属门店">
  144. <el-select v-model="form.shopId" placeholder="请选择所属门店">
  145. <el-option
  146. v-for="item in shops"
  147. :key="item.value"
  148. :label="item.label"
  149. :value="item.value"
  150. ></el-option>
  151. </el-select>
  152. </el-form-item>
  153. <el-form-item label="备注">
  154. <el-input v-model="form.memo"></el-input>
  155. </el-form-item>
  156. </el-form>
  157. </div>
  158. <div class="dialogFooter">
  159. <el-button type="primary" size="small" @click="confirmAdmin" v-if="form.btnState == 0">确定</el-button>
  160. <el-button type="primary" size="small" @click="confirmEdit" v-if="form.btnState == 1">确定</el-button>
  161. <el-button @click="dialogVisible = false" size="small">取消</el-button>
  162. </div>
  163. </el-dialog>
  164. </div>
  165. </template>
  166. <script>
  167. import Global from '../Global.js'
  168. import {
  169. ShopManagerListQuery,
  170. ShopListQuery,
  171. ShopManagerAdd,
  172. ShopManagerEdit,
  173. ShopManagerStatusEdit,
  174. testTable,
  175. testSelect
  176. } from "../api/getApiRes";
  177. let qs = require('qs');
  178. export default {
  179. data() {
  180. return {
  181. dialogVisible: false,
  182. dialogTitle: '新增管理员',
  183. // panel 配置项目
  184. panel: {
  185. userCode: '',
  186. name: '',
  187. phone: '',
  188. shopId: '',
  189. options: [],
  190. draw: 1,
  191. start: 0,
  192. recordsTotal: 0,
  193. tableData: [],
  194. allTableData: [],
  195. limit: '10',
  196. multipleSort: false,
  197. loading: false,
  198. fileList: [],
  199. multipleSelection: [],
  200. detectedmac: '',
  201. time1: globalBt(),
  202. },
  203. multipleSelection: [],
  204. pageination: {
  205. pageItem: 100,
  206. pageoptions: pageOptions(),
  207. total: 100,
  208. pageIndex: 1,
  209. },
  210. form: {
  211. shopId: '',
  212. userId: '',
  213. userCode: '',
  214. password: '',
  215. name: '',
  216. phone: '',
  217. memo: '',
  218. btnState: 0,
  219. },
  220. shops: [],
  221. tableData: []
  222. }
  223. },
  224. mounted() {
  225. this.panelSelect();
  226. this.getTableQuery();
  227. },
  228. methods: {
  229. // 新增 确认提交
  230. confirmAdmin() {
  231. let that = this;
  232. // checkNum
  233. if (!that.form.userCode) {
  234. this.$message.error('错了哦,登陆账号不能为空');
  235. return false
  236. }
  237. if (that.form.name.length > 20) {
  238. this.$message.error('错了哦,登陆账号字数超过20个字');
  239. return false
  240. }
  241. if (!that.form.password) {
  242. this.$message.error('错了哦,密码不能为空');
  243. return false
  244. }
  245. if (that.form.password.length < 6) {
  246. this.$message.error('错了哦,密码字数小于6个字');
  247. return false
  248. }
  249. if (that.form.password.length > 8) {
  250. this.$message.error('错了哦,密码字数超过8个字');
  251. return false
  252. }
  253. if (!that.form.name) {
  254. this.$message.error('错了哦,姓名不能为空');
  255. return false
  256. }
  257. if (that.form.name.length > 8) {
  258. this.$message.error('错了哦,姓名字数超过8个字');
  259. return false
  260. }
  261. if (!that.form.phone) {
  262. this.$message.error('错了哦,手机号码不能为空');
  263. return false
  264. }
  265. if (!globalCheckPhone(that.form.phone)) {
  266. this.$message.error('错了哦,手机号格式不正确');
  267. return false
  268. }
  269. if (that.form.memo) {
  270. if (that.form.name.memo > 200) {
  271. this.$message.error('错了哦,备注字数超过200个字');
  272. return false
  273. }
  274. }
  275. let param = {
  276. token: localStorage.token,
  277. shopId: that.form.shopId,
  278. usercode: that.form.userCode,
  279. password: that.form.password,
  280. name: that.form.name,
  281. phone: that.form.phone,
  282. memo: that.form.memo,
  283. };
  284. let postdata = qs.stringify(param);
  285. ShopManagerAdd(postdata).then(res => {
  286. let json = res;
  287. if (json.Code == 0) {
  288. // 关闭弹窗
  289. that.dialogVisible = false;
  290. that.$message({
  291. showClose: true,
  292. message: '管理员添加成功!',
  293. type: 'success'
  294. });
  295. // 重载列表
  296. that.getTableQuery();
  297. } else {
  298. that.$message.error(json.Memo);
  299. }
  300. })
  301. },
  302. confirmEdit() {
  303. // ShopManagerEdit
  304. let that = this;
  305. // checkNum
  306. if (!that.form.userCode) {
  307. this.$message.error('错了哦,登陆账号不能为空');
  308. return false
  309. }
  310. if (that.form.name.length > 20) {
  311. this.$message.error('错了哦,登陆账号字数超过20个字');
  312. return false
  313. }
  314. // 密码有输入才检测,没输入默认传空不修改
  315. if (that.form.password) {
  316. if (that.form.password.length < 6) {
  317. this.$message.error('错了哦,密码字数小于6个字');
  318. return false
  319. }
  320. if (that.form.password.length > 8) {
  321. this.$message.error('错了哦,密码字数超过8个字');
  322. return false
  323. }
  324. }
  325. if (!that.form.name) {
  326. this.$message.error('错了哦,姓名不能为空');
  327. return false
  328. }
  329. if (that.form.name.length > 8) {
  330. this.$message.error('错了哦,姓名字数超过8个字');
  331. return false
  332. }
  333. if (!that.form.phone) {
  334. this.$message.error('错了哦,手机号码不能为空');
  335. return false
  336. }
  337. if (!globalCheckPhone(that.form.phone)) {
  338. this.$message.error('错了哦,手机号格式不正确');
  339. return false
  340. }
  341. if (that.form.memo) {
  342. if (that.form.name.memo > 200) {
  343. this.$message.error('错了哦,备注字数超过200个字');
  344. return false
  345. }
  346. }
  347. let param = {
  348. token: localStorage.token,
  349. userId: that.form.userId,
  350. shopId: that.form.shopId,
  351. usercode: that.form.userCode,
  352. password: that.form.password,
  353. name: that.form.name,
  354. phone: that.form.phone,
  355. memo: that.form.memo,
  356. };
  357. let postdata = qs.stringify(param);
  358. ShopManagerEdit(postdata).then(res => {
  359. let json = res;
  360. if (json.Code == 0) {
  361. // 关闭弹窗
  362. that.dialogVisible = false;
  363. that.$message({
  364. showClose: true,
  365. message: '管理员信息修改成功!',
  366. type: 'success'
  367. });
  368. // 重载列表
  369. that.getTableQuery();
  370. } else {
  371. that.$message.error(json.Memo);
  372. }
  373. })
  374. },
  375. // 加载选项
  376. panelSelect() {
  377. let that = this;
  378. let param = {
  379. token: localStorage.token,
  380. };
  381. let postdata = qs.stringify(param);
  382. ShopListQuery(postdata).then(res => {
  383. let json = res;
  384. if (json.Code == 0) {
  385. that.panel.options = turnShopResToOption(json.Rs);
  386. that.shops = turnShopResToOption(json.Rs);
  387. that.form.shopId = json.Rs[0].ShopID;
  388. that.panel.options.unshift({value: '', label: "全部"});
  389. } else {
  390. that.$message.error(json.Memo);
  391. }
  392. })
  393. },
  394. // 删除
  395. delList() {
  396. let that = this;
  397. // checkNum
  398. if (!this.multipleSelection.length) {
  399. that.$message({
  400. showClose: true,
  401. message: '错了哦,需要先选中至少一条记录',
  402. type: 'error'
  403. });
  404. return false
  405. }
  406. if (this.multipleSelection.length != 1) {
  407. that.$message({
  408. showClose: true,
  409. message: '错了哦,只能选中一条记录',
  410. type: 'error'
  411. });
  412. return false
  413. }
  414. let userId = that.multipleSelection[0].Id;
  415. let param = {
  416. token: localStorage.token,
  417. userId : userId ,
  418. status: 9,//0禁用1启用9删除
  419. };
  420. let postdata = qs.stringify(param);
  421. this.$confirm('此操作将永久删除该管理员, 是否继续?', '提示', {
  422. confirmButtonText: '确定',
  423. cancelButtonText: '取消',
  424. type: 'warning'
  425. }).then(() => {
  426. ShopManagerStatusEdit(postdata).then(res => {
  427. let json = res;
  428. if (json.Code == 0) {
  429. that.$message({
  430. showClose: true,
  431. message: '选中的管理员已删除!',
  432. type: 'success'
  433. });
  434. // 重载列表
  435. that.getTableQuery();
  436. } else {
  437. that.$message.error(json.Memo);
  438. }
  439. });
  440. }).catch(() => {
  441. this.$message({
  442. type: 'info',
  443. message: '已取消删除'
  444. });
  445. });
  446. },
  447. runAndPause(row, status) {
  448. let that = this;
  449. let param = {
  450. token: localStorage.token,
  451. userId: row.Id,
  452. status: status,
  453. };
  454. let postdata = qs.stringify(param);
  455. ShopManagerStatusEdit(postdata).then(res => {
  456. let json = res;
  457. if (json.Code == 0) {
  458. that.$message({
  459. showClose: true,
  460. message: '管理员状态已修改成功!',
  461. type: 'success'
  462. });
  463. // 重载列表
  464. that.getTableQuery();
  465. } else {
  466. that.$message.error(json.Memo);
  467. }
  468. })
  469. },
  470. clearForm() {
  471. // clear
  472. this.form.shopId = this.shops[0].value;
  473. this.form.name = '';
  474. this.form.userCode = '';
  475. this.form.password = '';
  476. this.form.phone = '';
  477. this.form.memo = '';
  478. },
  479. // 新增管理员
  480. addAdmin() {
  481. this.clearForm();
  482. // 重载店面列表
  483. this.panelSelect();
  484. this.dialogVisible = true
  485. this.dialogTitle = '新增管理员'
  486. this.form.btnState = 0;
  487. },
  488. // 编辑管理员
  489. editList() {
  490. let that = this;
  491. this.clearForm();
  492. // 重载门店列表
  493. this.panelSelect();
  494. // checkNum
  495. if (!this.multipleSelection.length) {
  496. that.$message({
  497. showClose: true,
  498. message: '错了哦,需要先选中至少一条记录',
  499. type: 'error'
  500. });
  501. return false
  502. }
  503. if (this.multipleSelection.length != 1) {
  504. that.$message({
  505. showClose: true,
  506. message: '错了哦,只能选中一条记录',
  507. type: 'error'
  508. });
  509. return false
  510. }
  511. let row = that.multipleSelection[0];
  512. this.form.shopid = row.ShopId;
  513. this.form.userId = row.Id;
  514. this.form.name = row.Name;
  515. this.form.userCode = row.Usercode;
  516. this.form.password = '';
  517. this.form.phone = row.Phone;
  518. this.form.memo = row.Memo;
  519. this.dialogVisible = true
  520. this.dialogTitle = '编辑管理员'
  521. this.form.btnState = 1;
  522. },
  523. handleSelectionChange(val) {
  524. this.multipleSelection = val;
  525. },
  526. // 查询按钮
  527. query() {
  528. this.getTableQuery();
  529. this.$message.success('查询完毕');
  530. },
  531. // 页面数据查询
  532. getTableQuery() {
  533. let that = this;
  534. that.loading = true;
  535. let param = {
  536. token: localStorage.token,
  537. shopId: this.panel.shopId,
  538. name: this.panel.name,
  539. phone: this.panel.phone,
  540. start: 1,//
  541. tableMax: 9999,//
  542. };
  543. let postdata = qs.stringify(param);
  544. ShopManagerListQuery(postdata).then(res => {
  545. let json = res;
  546. if (json.Code == 0) {
  547. that.loading = false;
  548. if (json.Rs) {
  549. that.allTableData = json.Rs;
  550. that.recordsTotal = json.Rs.length;
  551. } else {
  552. that.allTableData = [];
  553. that.recordsTotal = 0;
  554. }
  555. // 设置分页数据
  556. that.setPaginations();
  557. } else {
  558. that.$message.error(json.Memo);
  559. }
  560. })
  561. },
  562. // 设置分页数据
  563. setPaginations() {
  564. // 分页属性
  565. let that = this;
  566. that.pageination.total = that.recordsTotal;
  567. // 默认分页
  568. that.tableData = that.allTableData.filter((item, index) => {
  569. return index < that.pageination.pageItem;
  570. });
  571. },
  572. // 每页显示数量
  573. handleSizeChange() {
  574. let that = this;
  575. that.tableData = that.allTableData.filter((item, index) => {
  576. return index < that.pageination.pageItem;
  577. });
  578. that.draw = that.pageination.pageItem;
  579. that.getTableQuery();
  580. },
  581. // 翻页
  582. pageChange(pageIndex) {
  583. let that = this;
  584. // 获取当前页
  585. let index = that.pageination.pageItem * (pageIndex - 1);
  586. // 数据总数
  587. let nums = that.pageination.pageItem * pageIndex;
  588. // 容器
  589. let tables = [];
  590. for (var i = index; i < nums; i++) {
  591. if (that.allTableData[i]) {
  592. tables.push(that.allTableData[i])
  593. }
  594. this.tableData = tables;
  595. }
  596. that.start = index * that.draw;
  597. that.getTableQuery();
  598. },
  599. // 自动排序
  600. sortChange(params) {
  601. console.log(params)
  602. },
  603. // 过滤时间
  604. filterFmtDate(value, row, column) {
  605. let that = this;
  606. return nonTfmtDate(column, 11);
  607. },
  608. // 过滤金额
  609. filterMoney(value, row, column) {
  610. let that = this;
  611. return parseFloat(column).toFixed(2);
  612. },
  613. },
  614. }
  615. </script>
  616. <style scoped>
  617. @import "../assets/css/panel.css";
  618. .context { height: 770px;
  619. overflow-y: scroll;
  620. display: block;
  621. margin: 0 auto;
  622. background-color: #fff !important;
  623. padding: 30px;
  624. padding-bottom: 60px;
  625. }
  626. .panel-body {
  627. padding: 20px;
  628. background: #F0F2F5;
  629. }
  630. .change {
  631. width: 100%;
  632. overflow: hidden;
  633. display: block;
  634. margin: 0 auto;
  635. padding-top: 10px;
  636. padding-bottom: 10px;
  637. }
  638. .change button {
  639. float: left;
  640. }
  641. .change button.pull-right {
  642. float: right;
  643. }
  644. .dialogTitle {
  645. width: 100%;
  646. overflow: hidden;
  647. display: block;
  648. margin: 0 auto;
  649. color: #000000;
  650. font-size: 18px;
  651. text-align: center;
  652. }
  653. .dialogTitle em {
  654. float: none;
  655. font-style: normal;
  656. color: #3799FF;
  657. margin: 0;
  658. }
  659. /deep/ .el-transfer-panel__item .el-checkbox__input {
  660. left: 40px;
  661. }
  662. .dialogFooter {
  663. width: 90%;
  664. overflow: hidden;
  665. display: block;
  666. margin: 0 auto;
  667. margin-top: 10px;
  668. }
  669. .dialogFooter button {
  670. float: right;
  671. margin-left: 10px;
  672. }
  673. /deep/ .el-dialog .el-select .el-input__inner {
  674. width: 240px;
  675. }
  676. /deep/ .el-dialog .el-select {
  677. width: 530px;
  678. }
  679. /deep/ .el-dialog .el-select .el-input__inner {
  680. width: 530px;
  681. }
  682. </style>