// pages/ispPeople/add.js const utils = require('../../utils/util.js') Page({ /** * 页面的初始数据 */ data: { type: 0, //0是新增,1是编辑 userInfoBei: '', //被编辑人信息 showRoles: [], rolesList: [], rolesIndex: '', ents: [], entsIndex: '', name: '', mobile: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ type: Number(options.type) }) if (this.data.type === 0) { this.getRoles() } if (this.data.type === 1) { this.setData({ mobile: options.mobile }) this.getDetail() } }, //如果是编辑操作,就获取回显信息 getDetail() { wx.setNavigationBarTitle({ title: '编辑人员' }) let params = { mobile: this.data.mobile } utils.axios({ method: 'get', url: '/auth/isp/user/findManageInfoByMobile', data: params, sendBefore() { wx.showLoading({ title: '信息加载中...', mask: true }) }, complete() { wx.hideLoading() }, success: res => { this.setData({ name: res.data.name, userInfoBei: res.data }) this.getRoles() } }) }, //提交 submitData() { if (this.data.type === 0) { this.addNew() } if (this.data.type === 1) { this.edit() } }, //新增人员 addNew() { let params = { currentUserMobile: utils.getInfo().mobile, reqChannel: 5, name: utils.trimAll(this.data.name), mobile: utils.trimAll(this.data.mobile) } if (params.name === '') { utils.toast('员工姓名不能为空') return } if (params.mobile === '') { utils.toast('员工手机号码不能为空') return } if (this.data.rolesIndex !== '') { params.roleIds = [this.data.rolesList[this.data.rolesIndex].id] } if (this.data.entsIndex !== '') { params.entTaxIds = [this.data.ents[this.data.entsIndex].entTaxId] } utils.axios({ method: 'post', url: '/auth/isp/user/save', data: params, sendBefore() { wx.showLoading({ title: '人员新增中...', mask: true }) }, complete() { wx.hideLoading() }, success: res => { utils.funPrev(prev => { prev.toFresh() utils.toast('人员新增成功') wx.navigateBack() }) } }) }, //编辑人员 edit() { let params = { currentUserMobile: utils.getInfo().mobile, reqChannel: 5, name: utils.trimAll(this.data.name), mobile: utils.trimAll(this.data.mobile), status: true } if (params.name === '') { utils.toast('员工姓名不能为空') return } if (params.mobile === '') { utils.toast('员工手机号码不能为空') return } if (this.data.rolesIndex !== '') { params.roleIds = [this.data.rolesList[this.data.rolesIndex].id] } if (this.data.entsIndex !== '') { params.entTaxIds = [this.data.ents[this.data.entsIndex].entTaxId] } utils.axios({ method: 'post', url: '/auth/isp/user/updateManageInfo', data: params, sendBefore() { wx.showLoading({ title: '保存中...', mask: true }) }, complete() { wx.hideLoading() }, success: res => { utils.funPrev(prev => { prev.toFresh() utils.toast('编辑成功') wx.navigateBack() }) } }) }, //角色列表 getRoles() { utils.axios({ method: 'get', url: '/auth/isp/role/findCategoryRoles', sendBefore() { wx.showLoading({ title: '角色获取中...', mask: true }) }, complete() { wx.hideLoading() }, success: res => { let rolesList = res.data let showRoles = [] for (let i = 0; i < rolesList.length; i++) { showRoles.push(rolesList[i].remark) } this.setData({ showRoles, rolesList }) if (this.data.type === 1) { let userRoles = this.data.userInfoBei.userRoles[0].remark for (let i = 0; i < rolesList.length; i++) { if (rolesList[i].remark === userRoles) { this.setData({ rolesIndex: i }) } } } } }) }, setRoles(e) { let rolesIndex = Number(e.detail.value) this.setData({ rolesIndex }) }, //员工姓名 getName(e) { let value = e.detail.value this.setData({ name: value }) }, getMobile(e) { let value = e.detail.value this.setData({ mobile: value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })