customer-admin-list.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>管理员列表</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6. <meta name="viewport"
  7. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  8. <!-- 所有的 css & js 资源 -->
  9. <link rel="stylesheet" href="../../static/kj/element-ui/theme-chalk/index.css">
  10. <link rel="stylesheet" href="../../static/sa.css">
  11. <script src="../../static/kj/vue.min.js"></script>
  12. <script src="../../static/kj/element-ui/index.js"></script>
  13. <script src="../../static/kj/httpVueLoader.js"></script>
  14. <script src="../../static/kj/jquery.min.js"></script>
  15. <script src="../../static/kj/layer/layer.js"></script>
  16. <script src="../../static/sa.js"></script>
  17. <script src="../../static/kj/upload-util.js"></script>
  18. <style type="text/css">
  19. .el-radio {
  20. margin-right: 10px;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="vue-box" style="display: none;" :style="'display: block;'">
  26. <div class="c-panel">
  27. <!-- ------------- 检索参数 ------------- -->
  28. <h4 class="c-title">检索参数</h4>
  29. <el-form>
  30. <sa-item type="text" name="用户名" v-model="p.name"></sa-item>
  31. <el-button type="primary" icon="el-icon-search" @click="p.pageNo = 1; f5()">查询</el-button>
  32. <el-button type="primary" icon="el-icon-plus" @click="add()" v-if="sa.isAuth('tb-costomer-user-add')">新增
  33. </el-button>
  34. <el-button type="info" icon="el-icon-refresh" @click="sa.f5()">重置</el-button>
  35. </el-form>
  36. <!-- ------------- 快捷按钮 ------------- -->
  37. <!-- ------------- 数据列表 ------------- -->
  38. <el-table class="data-table" ref="data-table" :data="dataList">
  39. <sa-td type="selection"></sa-td>
  40. <sa-td type="text" name="用户名" prop="name" min-width="120px"></sa-td>
  41. <sa-td type="text" name="姓名" prop="nickname" min-width="120px"></sa-td>
  42. <sa-td type="datetime" name="创建时间" prop="createTime" width="150px"></sa-td>
  43. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px"></sa-td>
  44. <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
  45. <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}"
  46. @change="s => updateStatus(s.row)" width="120px"></sa-td>
  47. <el-table-column label="操作" fixed="right" width="450px">
  48. <template slot-scope="s">
  49. <span @click="getInfo(s.row)">
  50. <el-button type="success" class="c-btn" icon="el-icon-view">查看</el-button>
  51. </span>
  52. <span @click="updateName(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  53. <el-button type="primary" class="c-btn">改名称</el-button>
  54. </span>
  55. <span @click="updateNickname(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  56. <el-button type="primary" class="c-btn">改姓名</el-button>
  57. </span>
  58. <span @click="updateAvatar(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  59. <el-button type="primary" class="c-btn">改头像</el-button>
  60. </span>
  61. <span @click="updatePassword(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  62. <el-button type="primary" class="c-btn">改密码</el-button>
  63. </span>
  64. <span @click="roleFn(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  65. <el-button type="primary" class="c-btn">角色</el-button>
  66. </span>
  67. <span @click="del(s.row)" v-if="sa.isAuth('tb-costomer-user-del')">
  68. <el-button type="danger" class="c-btn">删除</el-button>
  69. </span>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. <!-- 分页 -->
  74. <sa-item type="page" :curr.sync="p.pageNo" :size.sync="p.pageSize" :total="dataCount" @change="f5()">
  75. </sa-item>
  76. </div>
  77. <el-dialog :title="roleDialog.title" :visible.sync="roleDialog.visible" width="60%">
  78. <div>
  79. <el-checkbox @change="handleCheckAllChange">全选</el-checkbox>
  80. <div style="margin: 15px 0;"></div>
  81. <el-checkbox-group v-model="roleDialog.form.roleId">
  82. <el-checkbox v-for="role in roleList" :label="role.id+''" :key="role.id">{{role.name}}
  83. </el-checkbox>
  84. </el-checkbox-group>
  85. </div>
  86. <span slot="footer" class="dialog-footer">
  87. <el-button @click="roleDialog.visible = false">取 消</el-button>
  88. <el-button type="primary" @click="confirmSetRole">确 定</el-button>
  89. </span>
  90. </el-dialog>
  91. </div>
  92. <script>
  93. var app = new Vue({
  94. components: {
  95. "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue'),
  96. "sa-td": httpVueLoader('../../sa-frame/com/sa-td.vue')
  97. },
  98. el: '.vue-box',
  99. data: {
  100. roleDialog: {
  101. visible: false,
  102. title: '',
  103. form: {
  104. id: '',
  105. roleId: [],
  106. }
  107. },
  108. sa: sa, // 超级对象
  109. p: { // 查询参数
  110. name: '',
  111. customerId: sa.p('customerId', ''),
  112. sort_type: 0,
  113. pageNo: 1,
  114. pageSize: 10,
  115. },
  116. dataCount: 0,
  117. dataList: [], // 数据集合
  118. roleList: [], // 角色集合
  119. },
  120. methods: {
  121. roleFn(data) {
  122. Object.assign(this.roleDialog, {
  123. visible: true,
  124. title: '设置[' + data.name + ']角色属性',
  125. form: {
  126. id: data.id,
  127. roleId: data.roleId.split(',')
  128. }
  129. })
  130. },
  131. handleCheckAllChange() {
  132. let roleId = this.roleDialog.form.roleId;
  133. let allIds = this.roleList.map(obj => obj.id + '');
  134. this.roleDialog.form.roleId = roleId.length != allIds.length ? allIds : [];
  135. },
  136. confirmSetRole() {
  137. let roleId = this.roleDialog.form.roleId;
  138. if (roleId.length == 0) {
  139. return sa.msg('请选择一个角色')
  140. }
  141. let o = {
  142. id: this.roleDialog.form.id,
  143. roleId: this.roleDialog.form.roleId.join(',')
  144. }
  145. sa.ajax('/admin/setRole', o, function (resp) {
  146. this.f5();
  147. this.roleDialog.visible = false;
  148. }.bind(this))
  149. },
  150. updateNickname(data) {
  151. layer.prompt({title: '修改名称'}, function (pass, index) {
  152. layer.close(index);
  153. sa.ajax('/admin/updateNickname', {id: data.id, nickname: pass}, function (res) {
  154. data.nickname = pass;
  155. layer.msg('修改成功');
  156. }.bind(this))
  157. });
  158. },
  159. // 刷新
  160. f5: function (isPage) {
  161. sa.ajax('/admin/getCustomerAdminList', this.p, function (res) {
  162. this.dataList = res.data; // 数据
  163. this.dataCount = res.dataCount;
  164. sa.f5TableHeight(); // 刷新表格高度
  165. }.bind(this));
  166. },
  167. // 新增
  168. add: function () {
  169. sa.showIframe('新增用户', 'customer-admin-add.html?customerId=' + this.p.customerId, '550px',
  170. '75%');
  171. },
  172. // 查看详情
  173. getInfo: function (data) {
  174. sa.showIframe('账号详情', '../../sa-view-sp/sp-admin/admin-info.html?id=' + data.id, '700px',
  175. '80%');
  176. //sa.$page.openAdminInfo(data.id, data.name);
  177. },
  178. // 查看 - 根据选中的
  179. getBySelect: function (data) {
  180. var selection = this.$refs['data-table'].selection;
  181. if (selection.length == 0) {
  182. return sa.msg('请选择一条数据')
  183. }
  184. this.getInfo(selection[0]);
  185. },
  186. // 修改名称
  187. updateName: function (data) {
  188. layer.prompt({
  189. title: '修改账号名称'
  190. }, function (pass, index) {
  191. layer.close(index);
  192. sa.ajax('/admin/update', {
  193. id: data.id,
  194. name: pass
  195. }, function (res) {
  196. data.name = pass;
  197. layer.msg('修改成功');
  198. })
  199. });
  200. },
  201. // 修改头像
  202. updateAvatar: function (data) {
  203. sa.uploadImage(function (src) {
  204. var p = {
  205. id: data.id,
  206. avatar: src
  207. };
  208. sa.ajax('/admin/updateAvatar', p, function (res) {
  209. sa.msg('上传成功');
  210. data.avatar = src;
  211. }.bind(this));
  212. })
  213. },
  214. // 修改密码
  215. updatePassword: function (data) {
  216. layer.prompt({
  217. title: '修改密码'
  218. }, function (pass, index) {
  219. layer.close(index);
  220. if (pass.length < 4) {
  221. return layer.msg('新密码长度请不要低于4位');
  222. }
  223. sa.ajax('/admin/updatePassword', {
  224. id: data.id,
  225. password: pass
  226. }, function (res) {
  227. layer.msg('修改成功');
  228. })
  229. });
  230. },
  231. // 修改角色
  232. updateRoleId: function (data, roleId, roleName) {
  233. if (data.id == sa.$sys.getCurrUser().id) {
  234. return sa.alert('不能自己修改自己的角色');
  235. }
  236. if (data.roleId == roleId) {
  237. return sa.alert('该用户已经是' + roleName + '了');
  238. }
  239. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  240. layer.confirm(str, {
  241. title: '请确认'
  242. }, function () {
  243. sa.ajax('/admin/updateRole', {
  244. id: data.id,
  245. roleId: roleId
  246. }, function (res) {
  247. sa.msg('修改成功');
  248. data.roleId = roleId;
  249. data.roleName = roleName;
  250. }.bind(this));
  251. }.bind(this));
  252. },
  253. // 修改用户的状态
  254. updateStatus: function (data) {
  255. if (data.id == sa.$sys.getCurrUser().id) {
  256. data.status = 3 - data.status;
  257. return sa.alert('不能自己封禁自己');
  258. }
  259. var is_ok = false; // 记录是否成功
  260. var ajax = sa.ajax('/admin/updateStatus', {
  261. adminId: data.id,
  262. status: data.status
  263. }, function (res) {
  264. sa.msg('修改成功');
  265. is_ok = true;
  266. }.bind(this));
  267. // 如果未能修改成功, 则回滚
  268. $.when(ajax).done(function () {
  269. if (is_ok == false) {
  270. data.status = 3 - data.status;
  271. }
  272. })
  273. },
  274. // 删除
  275. del: function (data) {
  276. sa.confirm('是否删除,此操作不可撤销', function () {
  277. sa.ajax('/admin/delete', {
  278. id: data.id
  279. }, function (res) {
  280. sa.arrayDelete(app.dataList, data);
  281. sa.ok('删除成功');
  282. sa.f5TableHeight(); // 刷新表格高度
  283. })
  284. });
  285. },
  286. // 批量删除
  287. deleteByIds: function () {
  288. // 获取选中元素的id列表
  289. let selection = this.$refs['data-table'].selection;
  290. let ids = sa.getArrayField(selection, 'id');
  291. if (selection.length == 0) {
  292. return sa.msg('请至少选择一条数据')
  293. }
  294. // 提交删除
  295. sa.confirm('是否批量删除选中数据?此操作不可撤销', function () {
  296. sa.ajax('/admin/deleteByIds', {
  297. ids: ids.join(',')
  298. }, function (res) {
  299. sa.arrayDelete(this.dataList, selection);
  300. sa.ok('删除成功');
  301. sa.f5TableHeight(); // 刷新表格高度
  302. }.bind(this))
  303. }.bind(this));
  304. },
  305. getRoleList() {
  306. // 加载角色
  307. sa.ajax('/role/getCustomerRoleList', {
  308. customerId: this.p.customerId
  309. }, function (res) {
  310. this.roleList = res.data; // 数据
  311. }.bind(this), {
  312. msg: null
  313. });
  314. }
  315. },
  316. created: function () {
  317. this.f5();
  318. sa.onInputEnter(); // 监听回车执行查询
  319. this.getRoleList();
  320. }
  321. })
  322. </script>
  323. </body>
  324. </html>