123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- // pages/operPeople/add.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: 0, //0是新增,1是编辑
- userInfo: '',
- userInfoBei: '', //被编辑人信息
- showRoles: [],
- rolesList: [],
- rolesIndex: '',
- ents: [],
- entsIndex: '',
- name: '',
- mobile: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- userInfo: utils.getInfo()
- })
- 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/oper/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/oper/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/oper/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/oper/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 () {
- }
- })
|