user.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. $(function () {
  2. $("#jqGrid").Grid({
  3. url: '../sys/user/list',
  4. rownumWidth:60,
  5. colModel: [
  6. {label: '用户ID', name: 'userId', index: "user_id", key: true, hidden: true},
  7. {label: '用户名', name: 'username', width: 75},
  8. // {label: '所属部门', name: 'deptName', width: 75},
  9. // {label: '邮箱', name: 'email', width: 90},
  10. {label: '手机号', name: 'mobile', width: 100},
  11. {label: '店铺关联', name: 'brandList', width: 100,sortable:false,formatter:function (value) {
  12. let temp = []
  13. value.forEach(function (item) {
  14. temp.push(item.brandName||item.name)
  15. })
  16. return temp.join('、')
  17. }},
  18. {label: '角色', name: 'roleList', width: 100,sortable:false,formatter:function (value,row,col) {
  19. let roleList = col.roleList
  20. return roleList[0]? roleList[0].roleName:'-'
  21. }},
  22. {
  23. label: '状态', name: 'status', width: 80, formatter: function (value) {
  24. return value === 0 ?
  25. '<span class="label label-danger">禁用</span>' :
  26. '<span class="label label-success">正常</span>';
  27. }
  28. },
  29. {
  30. label: '创建时间', name: 'createTime', index: "create_time", width: 80, formatter: function (value) {
  31. return transDate(value);
  32. }
  33. }]
  34. });
  35. });
  36. var setting = {
  37. data: {
  38. simpleData: {
  39. enable: true,
  40. idKey: "deptId",
  41. pIdKey: "parentId",
  42. rootPId: -1
  43. },
  44. key: {
  45. url: "nourl"
  46. }
  47. }
  48. };
  49. var ztree;
  50. const validatePhoneCheck = function (rule, value, callback){
  51. if (value === ''||!value) {
  52. callback(new Error('手机号不能为空'));
  53. } else if(!(/^1[3456789]\d{9}$/.test(value))){
  54. callback(new Error('手机号不正确'));
  55. } else {
  56. callback();
  57. }
  58. };
  59. var vm = new Vue({
  60. el: '#rrapp',
  61. data: {
  62. modal1:false,
  63. q: {
  64. username: null
  65. },
  66. showList: true,
  67. title: null,
  68. roleList: {},
  69. user: {
  70. status: 1,
  71. deptName: '',
  72. roleIdList: [],
  73. brandIdList: [],
  74. brandList: []
  75. },
  76. ruleValidate: {
  77. username: [
  78. {required: true, message: '姓名不能为空', trigger: 'blur'}
  79. ],
  80. email: [
  81. {required: true, message: '邮箱不能为空', trigger: 'blur'},
  82. {type: 'email', message: '邮箱格式不正确', trigger: 'blur'}
  83. ],
  84. mobile: [
  85. {required: true, validator: validatePhoneCheck, trigger: 'blur'}
  86. ]
  87. },
  88. brandsList:[],
  89. brandPage:1,
  90. brandPerPage:10,
  91. brandTotal:0,
  92. brandSeleced:[],
  93. social:[],
  94. cacheData:{},
  95. cacheDataFirst:{}
  96. },
  97. watch:{
  98. brandPage:function name(newVal) {
  99. this.getBrandList()
  100. }
  101. },
  102. methods: {
  103. clickCheck:function(item,idx){
  104. item['checked'] = !item['checked']
  105. this.$set(this.brandsList,idx,item)
  106. },
  107. ok: function() {
  108. let temp = []
  109. let tempid = []
  110. var that = this
  111. Object.keys(vm.cacheData).forEach(function(item){
  112. that.cacheData[item].page.list.forEach(function(sub){
  113. if (sub['checked']) {
  114. temp.push(sub)
  115. tempid.push(sub.id)
  116. }
  117. })
  118. })
  119. vm.user.brandList = temp
  120. vm.user.brandIdList = tempid
  121. },
  122. cancel:function () {
  123. this.cacheData={}
  124. this.modal1 = false
  125. },
  126. query: function () {
  127. vm.reload();
  128. },
  129. add: function () {
  130. vm.showList = false;
  131. vm.title = "新增(默认密码:888888)";
  132. vm.roleList = {};
  133. vm.user = {status: 1, roleIdList: [], brandIdList:[], deptId: '', deptName: ''};
  134. //获取角色信息
  135. this.getRoleList();
  136. vm.getDept();
  137. },
  138. getDept: function () {
  139. //加载部门树
  140. Ajax.request({
  141. url: '../sys/dept/list',
  142. async: true,
  143. successCallback: function (r) {
  144. ztree = $.fn.zTree.init($("#deptTree"), setting, r.list);
  145. var node = ztree.getNodeByParam("deptId", vm.user.deptId);
  146. if (node != null) {
  147. ztree.selectNode(node);
  148. vm.user.deptName = node.name;
  149. }
  150. }
  151. });
  152. },
  153. pageChange:function(page){
  154. this.brandPage = page
  155. },
  156. getBrandList: function () {
  157. this.modal1 = true
  158. if (this.cacheData[this.brandPage]) {
  159. let temp = this.cacheData[this.brandPage]
  160. this.brandsList = temp.page.list
  161. this.brandPage = temp.page.currPage
  162. this.brandTotal = temp.page.totalCount
  163. return
  164. }
  165. let that = this
  166. Ajax.request({
  167. url: '../brand/list?_search=false&limit='+that.brandPerPage+'&page='+that.brandPage+'&sidx=&order=asc',
  168. async: true,
  169. successCallback: function (res) {
  170. res.page.list.forEach(function (item,index){
  171. item['checked'] = false
  172. if (that.user.brandList) {
  173. that.user.brandList.forEach(function(sub){
  174. // item['checked'] = false
  175. if (item.id===sub.brandId) {
  176. item['checked'] = true
  177. return
  178. }
  179. })
  180. }
  181. })
  182. that.cacheData[res.page.currPage] = res
  183. that.brandsList = res.page.list
  184. that.brandPage = res.page.currPage
  185. that.brandTotal = res.page.totalCount
  186. }
  187. });
  188. },
  189. update: function () {
  190. var userId = getSelectedRow("#jqGrid");
  191. if (userId == null) {
  192. return;
  193. }
  194. vm.showList = false;
  195. vm.title = "修改";
  196. Ajax.request({
  197. url: "../sys/user/info/" + userId,
  198. async: true,
  199. successCallback: function (r) {
  200. vm.user = r.user;
  201. //获取角色信息
  202. vm.getRoleList();
  203. vm.getDept();
  204. }
  205. });
  206. },
  207. del: function () {
  208. var userIds = getSelectedRows("#jqGrid");
  209. if (userIds == null) {
  210. return;
  211. }
  212. confirm('确定要删除选中的记录?', function () {
  213. Ajax.request({
  214. url: "../sys/user/delete",
  215. params: JSON.stringify(userIds),
  216. contentType: "application/json",
  217. type: 'POST',
  218. successCallback: function () {
  219. alert('操作成功', function (index) {
  220. vm.reload();
  221. });
  222. }
  223. });
  224. });
  225. },
  226. saveOrUpdate: function (event) {
  227. var url = vm.user.userId == null ? "../sys/user/save" : "../sys/user/update";
  228. Ajax.request({
  229. url: url,
  230. params: JSON.stringify(vm.user),
  231. contentType: "application/json",
  232. type: 'POST',
  233. successCallback: function () {
  234. alert('操作成功', function (index) {
  235. vm.reload();
  236. });
  237. }
  238. });
  239. },
  240. getRoleList: function () {
  241. Ajax.request({
  242. url: '../sys/role/select',
  243. async: true,
  244. successCallback: function (r) {
  245. vm.roleList = r.list;
  246. }
  247. });
  248. },
  249. reload: function (event) {
  250. vm.showList = true;
  251. var page = $("#jqGrid").jqGrid('getGridParam', 'page');
  252. $("#jqGrid").jqGrid('setGridParam', {
  253. postData: {'username': vm.q.username},
  254. page: page
  255. }).trigger("reloadGrid");
  256. vm.handleReset('formValidate');
  257. },
  258. deptTree: function () {
  259. openWindow({
  260. title: "选择部门",
  261. area: ['300px', '450px'],
  262. content: jQuery("#deptLayer"),
  263. btn: ['确定', '取消'],
  264. btn1: function (index) {
  265. var node = ztree.getSelectedNodes();
  266. //选择上级部门
  267. vm.user.deptId = node[0].deptId;
  268. vm.user.deptName = node[0].name;
  269. layer.close(index);
  270. }
  271. });
  272. },
  273. handleSubmit: function (name) {
  274. handleSubmitValidate(this, name, function () {
  275. vm.saveOrUpdate()
  276. });
  277. },
  278. handleReset: function (name) {
  279. handleResetForm(this, name);
  280. this.cacheData = {}
  281. this.user= {
  282. status: 1,
  283. deptName: '',
  284. roleIdList: [],
  285. brandIdList: [],
  286. brandList: []
  287. }
  288. }
  289. }
  290. });