customer-admin-list.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. <br>
  33. </el-form>
  34. <!-- ------------- 快捷按钮 ------------- -->
  35. <el-button type="primary" icon="el-icon-plus" @click="add()" v-if="sa.isAuth('tb-costomer-user-add')">新增
  36. </el-button>
  37. <el-button type="danger" icon="el-icon-delete" @click="deleteByIds()"
  38. v-if="sa.isAuth('tb-costomer-maintain-user-del')">删除
  39. </el-button>
  40. <el-button type="info" icon="el-icon-refresh" @click="sa.f5()">重置</el-button>
  41. <!-- ------------- 数据列表 ------------- -->
  42. <el-table class="data-table" ref="data-table" :data="dataList">
  43. <sa-td type="selection"></sa-td>
  44. <sa-td type="text" name="用户名" prop="name" min-width="120px"></sa-td>
  45. <sa-td type="datetime" name="创建时间" prop="createTime" width="150px"></sa-td>
  46. <sa-td type="datetime" name="最后登录" prop="loginTime" width="150px"></sa-td>
  47. <sa-td type="text" name="登录次数" prop="loginCount" not="0" width="100px"></sa-td>
  48. <sa-td type="switch" name="账号状态" prop="status" :jv="{1: '正常', 2: '禁用[#ff4949]'}"
  49. @change="s => updateStatus(s.row)" width="120px"></sa-td>
  50. <el-table-column label="操作" fixed="right" width="450px">
  51. <template slot-scope="s">
  52. <span @click="getInfo(s.row)">
  53. <el-button type="success" class="c-btn" icon="el-icon-view">查看</el-button>
  54. </span>
  55. <span @click="updateName(s.row)" v-if="sa.isAuth('tb-costomer-user-edit')">
  56. <el-button type="primary" class="c-btn" icon="el-icon-edit">改名称</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" icon="el-icon-edit">改头像</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" icon="el-icon-edit">改密码</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" icon="el-icon-edit">角色</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" icon="el-icon-delete">删除</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. // 刷新
  151. f5: function(isPage) {
  152. sa.ajax('/admin/getCustomerAdminList', this.p, function(res) {
  153. this.dataList = res.data; // 数据
  154. this.dataCount = res.dataCount;
  155. sa.f5TableHeight(); // 刷新表格高度
  156. }.bind(this));
  157. },
  158. // 新增
  159. add: function() {
  160. sa.showIframe('新增用户', 'customer-admin-add.html?customerId=' + this.p.customerId, '550px',
  161. '75%');
  162. },
  163. // 查看详情
  164. getInfo: function(data) {
  165. sa.showIframe('账号详情', '../../sa-view-sp/sp-admin/admin-info.html?id=' + data.id, '700px',
  166. '80%');
  167. //sa.$page.openAdminInfo(data.id, data.name);
  168. },
  169. // 查看 - 根据选中的
  170. getBySelect: function(data) {
  171. var selection = this.$refs['data-table'].selection;
  172. if (selection.length == 0) {
  173. return sa.msg('请选择一条数据')
  174. }
  175. this.getInfo(selection[0]);
  176. },
  177. // 修改名称
  178. updateName: function(data) {
  179. layer.prompt({
  180. title: '修改账号名称'
  181. }, function(pass, index) {
  182. layer.close(index);
  183. sa.ajax('/admin/update', {
  184. id: data.id,
  185. name: pass
  186. }, function(res) {
  187. data.name = pass;
  188. layer.msg('修改成功');
  189. })
  190. });
  191. },
  192. // 修改头像
  193. updateAvatar: function(data) {
  194. sa.uploadImage(function(src) {
  195. var p = {
  196. id: data.id,
  197. avatar: src
  198. };
  199. sa.ajax('/admin/updateAvatar', p, function(res) {
  200. sa.msg('上传成功');
  201. data.avatar = src;
  202. }.bind(this));
  203. })
  204. },
  205. // 修改密码
  206. updatePassword: function(data) {
  207. layer.prompt({
  208. title: '修改密码'
  209. }, function(pass, index) {
  210. layer.close(index);
  211. if (pass.length < 4) {
  212. return layer.msg('新密码长度请不要低于4位');
  213. }
  214. sa.ajax('/admin/updatePassword', {
  215. id: data.id,
  216. password: pass
  217. }, function(res) {
  218. layer.msg('修改成功');
  219. })
  220. });
  221. },
  222. // 修改角色
  223. updateRoleId: function(data, roleId, roleName) {
  224. if (data.id == sa.$sys.getCurrUser().id) {
  225. return sa.alert('不能自己修改自己的角色');
  226. }
  227. if (data.roleId == roleId) {
  228. return sa.alert('该用户已经是' + roleName + '了');
  229. }
  230. var str = '将此账号修改为 [' + roleName + '], 请确认?';
  231. layer.confirm(str, {
  232. title: '请确认'
  233. }, function() {
  234. sa.ajax('/admin/updateRole', {
  235. id: data.id,
  236. roleId: roleId
  237. }, function(res) {
  238. sa.msg('修改成功');
  239. data.roleId = roleId;
  240. data.roleName = roleName;
  241. }.bind(this));
  242. }.bind(this));
  243. },
  244. // 修改用户的状态
  245. updateStatus: function(data) {
  246. if (data.id == sa.$sys.getCurrUser().id) {
  247. data.status = 3 - data.status;
  248. return sa.alert('不能自己封禁自己');
  249. }
  250. var is_ok = false; // 记录是否成功
  251. var ajax = sa.ajax('/admin/updateStatus', {
  252. adminId: data.id,
  253. status: data.status
  254. }, function(res) {
  255. sa.msg('修改成功');
  256. is_ok = true;
  257. }.bind(this));
  258. // 如果未能修改成功, 则回滚
  259. $.when(ajax).done(function() {
  260. if (is_ok == false) {
  261. data.status = 3 - data.status;
  262. }
  263. })
  264. },
  265. // 删除
  266. del: function(data) {
  267. sa.confirm('是否删除,此操作不可撤销', function() {
  268. sa.ajax('/admin/delete', {
  269. id: data.id
  270. }, function(res) {
  271. sa.arrayDelete(app.dataList, data);
  272. sa.ok('删除成功');
  273. sa.f5TableHeight(); // 刷新表格高度
  274. })
  275. });
  276. },
  277. // 批量删除
  278. deleteByIds: function() {
  279. // 获取选中元素的id列表
  280. let selection = this.$refs['data-table'].selection;
  281. let ids = sa.getArrayField(selection, 'id');
  282. if (selection.length == 0) {
  283. return sa.msg('请至少选择一条数据')
  284. }
  285. // 提交删除
  286. sa.confirm('是否批量删除选中数据?此操作不可撤销', function() {
  287. sa.ajax('/admin/deleteByIds', {
  288. ids: ids.join(',')
  289. }, function(res) {
  290. sa.arrayDelete(this.dataList, selection);
  291. sa.ok('删除成功');
  292. sa.f5TableHeight(); // 刷新表格高度
  293. }.bind(this))
  294. }.bind(this));
  295. },
  296. getRoleList() {
  297. // 加载角色
  298. sa.ajax('/role/getCustomerRoleList', {
  299. customerId: this.p.customerId
  300. }, function(res) {
  301. this.roleList = res.data; // 数据
  302. }.bind(this), {
  303. msg: null
  304. });
  305. }
  306. },
  307. created: function() {
  308. this.f5();
  309. sa.onInputEnter(); // 监听回车执行查询
  310. this.getRoleList();
  311. }
  312. })
  313. </script>
  314. </body>
  315. </html>