adminuser.js 9.2 KB

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