customer-admin-list.html 13 KB

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