纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

148 lines
4.7 KiB

// pages/home/customer-info/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { getRoleList} from "../../../api/saas"
import { editEmploye, auditEmploye } from "../../../api/user"
import { deleteEmploye } from "../../../api/saas"
const util = require('../../../utils/util')
const event = require('../../../utils/event')
Scene({
/**
* 页面的初始数据
*/
data: {
cardNo: null,
form: {},
visible: false,
roleList: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
let channel = this.getOpenerEventChannel()
let that = this
channel.on('onParam', function (data) {
if(data.enterpriseRoleIds && data.enterpriseRoleIds.indexOf(',') > 0){
data.enterpriseRoleIds = data.enterpriseRoleIds.split(',')
} else if(data.enterpriseRoleIds && !Array.isArray(data.enterpriseRoleIds)){
data.enterpriseRoleIds = [data.enterpriseRoleIds]
} else {
data.enterpriseRoleIds = []
}
that.setData({ form: data })
})
}
if(options.cardNo){
this.setData({ cardNo: options.cardNo, ['form.cardNo']: options.cardNo })
Dialog.alert({ title: '温馨提示', message: '员工绑定卡号,需要从现有员工中进行选择,现在去选择?' }).then(() => {
this.chooseMember()
})
}
getRoleList().then(result => {
this.setData({ roleList: result.data.records })
})
},
bindInput: function(e){
this.data.form[e.currentTarget.id] = e.detail
},
chooseMethod: function(e){
this.setData({ visible: true })
},
onHide: function() {
this.setData({ visible: false })
},
onConfirm: function({detail}) {
var rolename = ''
for (let index = 0; index < this.data.roleList.length; index++) {
const element = this.data.roleList[index]
if(detail.indexOf(element.id) > -1){
if(util.isEmpty(rolename)){
rolename = element.name
} else {
rolename += ',' + element.name
}
}
}
this.setData({ visible: false, ['form.enterpriseRoleIds']: detail, ['form.enterpriseRoleNames']: rolename })
},
onChange: function({detail}) {
this.setData({ ['form.status']: detail })
},
submitForm: function(){
if (util.isEmpty(this.data.form.enterpriseRoleIds) || !this.data.form.enterpriseRoleIds.length) {
util.showToast('请选择员工角色')
return
}
wx.showLoading({ title: '处理中', mask: true })
if(!util.isEmpty(this.data.form.joinAt)){
this.data.form.joinAt = this.data.form.joinAt.substring(0, 10)
}
if(!Array.isArray(this.data.form.enterpriseRoleIds)){
this.data.form.enterpriseRoleIds = [this.data.form.enterpriseRoleIds]
}
editEmploye(this.data.form).then(result => {
wx.hideLoading()
event.emit('EventMessage', { what: 120, detail: '' })
const channel = this.getOpenerEventChannel()
channel.emit('onCallback', { what: 120 })
util.showBackToast('保存成功')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
agreeForm: function(){
if (util.isEmpty(this.data.form.enterpriseRoleIds) || !this.data.form.enterpriseRoleIds.length) {
util.showToast('请选择员工角色')
return
}
wx.showLoading({ title: '处理中', mask: true })
this.data.form.status = 1
auditEmploye(this.data.form).then(result => {
wx.hideLoading()
const channel = this.getOpenerEventChannel()
channel.emit('onCallback', { what: 120 })
util.showBackToast('审核已通过')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
deleteForm: function(){
Dialog.confirm({ title: '温馨提示', message: '确定删除该员工?' }).then(() => {
wx.showLoading({ title: '处理中', mask: true })
var enterpriseDepartmentId = this.data.form.enterpriseDepartmentId
deleteEmploye({idList: [this.data.form.enterpriseMemberId], enterpriseDepartmentId }).then(result => {
wx.hideLoading()
const channel = this.getOpenerEventChannel()
channel.emit('onCallback', { what: 120 })
util.showBackToast('员工已经删除')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
})
},
chooseMember: function(){
if(!this.data.cardNo){
return
}
var that = this
wx.navigateTo({
url: `/pages/home/employee/index?type=1`,
events: {
onCallback: (data) => {
if (data.what == 121) {
if(!util.isEmpty(that.data.cardNo)){
data.detail.cardNo = that.data.cardNo
}
that.setData({ form: data.detail })
}
}
}
})
}
})