123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- $(function () {
- $("#jqGrid").Grid({
- url: '../sys/user/list',
- rownumWidth:60,
- colModel: [
- {label: '用户ID', name: 'userId', index: "user_id", key: true, hidden: true},
- {label: '用户名', name: 'username', width: 75},
- // {label: '所属部门', name: 'deptName', width: 75},
- // {label: '邮箱', name: 'email', width: 90},
- {label: '手机号', name: 'mobile', width: 100},
- {label: '店铺关联', name: 'brandList', width: 100,sortable:false,formatter:function (value) {
- let temp = []
- value.forEach(function (item) {
- temp.push(item.brandName||item.name)
- })
- return temp.join('、')
- }},
- {label: '角色', name: 'roleList', width: 100,sortable:false,formatter:function (value,row,col) {
- let roleList = col.roleList
- return roleList[0]? roleList[0].roleName:'-'
- }},
- {
- label: '状态', name: 'status', width: 80, formatter: function (value) {
- return value === 0 ?
- '<span class="label label-danger">禁用</span>' :
- '<span class="label label-success">正常</span>';
- }
- },
- {
- label: '创建时间', name: 'createTime', index: "create_time", width: 80, formatter: function (value) {
- return transDate(value);
- }
- }]
- });
- });
- var setting = {
- data: {
- simpleData: {
- enable: true,
- idKey: "deptId",
- pIdKey: "parentId",
- rootPId: -1
- },
- key: {
- url: "nourl"
- }
- }
- };
- var ztree;
- const validatePhoneCheck = function (rule, value, callback){
- if (value === ''||!value) {
- callback(new Error('手机号不能为空'));
- } else if(!(/^1[3456789]\d{9}$/.test(value))){
- callback(new Error('手机号不正确'));
- } else {
- callback();
- }
- };
- var vm = new Vue({
- el: '#rrapp',
- data: {
- modal1:false,
- q: {
- username: null
- },
- showList: true,
- title: null,
- roleList: {},
- user: {
- status: 1,
- deptName: '',
- roleIdList: [],
- brandIdList: [],
- brandList: []
- },
- ruleValidate: {
- username: [
- {required: true, message: '姓名不能为空', trigger: 'blur'}
- ],
- email: [
- {required: true, message: '邮箱不能为空', trigger: 'blur'},
- {type: 'email', message: '邮箱格式不正确', trigger: 'blur'}
- ],
- mobile: [
- {required: true, validator: validatePhoneCheck, trigger: 'blur'}
- ]
- },
- brandsList:[],
- brandPage:1,
- brandPerPage:10,
- brandTotal:0,
- brandSeleced:[],
- social:[],
- cacheData:{},
- cacheDataFirst:{}
- },
- watch:{
- brandPage:function name(newVal) {
- this.getBrandList()
- }
- },
- methods: {
- clickCheck:function(item,idx){
- item['checked'] = !item['checked']
- this.$set(this.brandsList,idx,item)
- },
- ok: function() {
- let temp = []
- let tempid = []
- var that = this
- Object.keys(vm.cacheData).forEach(function(item){
- that.cacheData[item].page.list.forEach(function(sub){
- if (sub['checked']) {
- temp.push(sub)
- tempid.push(sub.id)
- }
- })
- })
- vm.user.brandList = temp
- vm.user.brandIdList = tempid
- },
- cancel:function () {
- this.cacheData={}
- this.modal1 = false
- },
- query: function () {
- vm.reload();
- },
- add: function () {
- vm.showList = false;
- vm.title = "新增(默认密码:888888)";
- vm.roleList = {};
- vm.user = {status: 1, roleIdList: [], brandIdList:[], deptId: '', deptName: ''};
- //获取角色信息
- this.getRoleList();
- vm.getDept();
- },
- getDept: function () {
- //加载部门树
- Ajax.request({
- url: '../sys/dept/list',
- async: true,
- successCallback: function (r) {
- ztree = $.fn.zTree.init($("#deptTree"), setting, r.list);
- var node = ztree.getNodeByParam("deptId", vm.user.deptId);
- if (node != null) {
- ztree.selectNode(node);
- vm.user.deptName = node.name;
- }
- }
- });
- },
- pageChange:function(page){
- this.brandPage = page
- },
- getBrandList: function () {
- this.modal1 = true
- if (this.cacheData[this.brandPage]) {
- let temp = this.cacheData[this.brandPage]
- this.brandsList = temp.page.list
- this.brandPage = temp.page.currPage
- this.brandTotal = temp.page.totalCount
- return
- }
- let that = this
- Ajax.request({
- url: '../brand/list?_search=false&limit='+that.brandPerPage+'&page='+that.brandPage+'&sidx=&order=asc',
- async: true,
- successCallback: function (res) {
- res.page.list.forEach(function (item,index){
- item['checked'] = false
- if (that.user.brandList) {
- that.user.brandList.forEach(function(sub){
- // item['checked'] = false
- if (item.id===sub.brandId) {
- item['checked'] = true
- return
- }
- })
- }
- })
- that.cacheData[res.page.currPage] = res
- that.brandsList = res.page.list
- that.brandPage = res.page.currPage
- that.brandTotal = res.page.totalCount
- }
- });
- },
- update: function () {
- var userId = getSelectedRow("#jqGrid");
- if (userId == null) {
- return;
- }
- vm.showList = false;
- vm.title = "修改";
- Ajax.request({
- url: "../sys/user/info/" + userId,
- async: true,
- successCallback: function (r) {
- vm.user = r.user;
- //获取角色信息
- vm.getRoleList();
- vm.getDept();
- }
- });
- },
- del: function () {
- var userIds = getSelectedRows("#jqGrid");
- if (userIds == null) {
- return;
- }
- confirm('确定要删除选中的记录?', function () {
- Ajax.request({
- url: "../sys/user/delete",
- params: JSON.stringify(userIds),
- contentType: "application/json",
- type: 'POST',
- successCallback: function () {
- alert('操作成功', function (index) {
- vm.reload();
- });
- }
- });
- });
- },
- saveOrUpdate: function (event) {
- var url = vm.user.userId == null ? "../sys/user/save" : "../sys/user/update";
- Ajax.request({
- url: url,
- params: JSON.stringify(vm.user),
- contentType: "application/json",
- type: 'POST',
- successCallback: function () {
- alert('操作成功', function (index) {
- vm.reload();
- });
- }
- });
- },
- getRoleList: function () {
- Ajax.request({
- url: '../sys/role/select',
- async: true,
- successCallback: function (r) {
- vm.roleList = r.list;
- }
- });
- },
- reload: function (event) {
- vm.showList = true;
- var page = $("#jqGrid").jqGrid('getGridParam', 'page');
- $("#jqGrid").jqGrid('setGridParam', {
- postData: {'username': vm.q.username},
- page: page
- }).trigger("reloadGrid");
- vm.handleReset('formValidate');
- },
- deptTree: function () {
- openWindow({
- title: "选择部门",
- area: ['300px', '450px'],
- content: jQuery("#deptLayer"),
- btn: ['确定', '取消'],
- btn1: function (index) {
- var node = ztree.getSelectedNodes();
- //选择上级部门
- vm.user.deptId = node[0].deptId;
- vm.user.deptName = node[0].name;
- layer.close(index);
- }
- });
- },
- handleSubmit: function (name) {
- handleSubmitValidate(this, name, function () {
- vm.saveOrUpdate()
- });
- },
- handleReset: function (name) {
- handleResetForm(this, name);
- this.cacheData = {}
- this.user= {
- status: 1,
- deptName: '',
- roleIdList: [],
- brandIdList: [],
- brandList: []
- }
- }
- }
- });
|