纸通宝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.
 

178 lines
5.3 KiB

// pages/home/employee/index.js
import { getCheckList, getEmployeList, auditEmploye, adminEmploye, deleteEmploye, qrcodeEmploye } from "../../api/user"
const util = require('../../../utils/util')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight,
base64: null,
loading: true,
checkList: [],
memberList: [],
eemidList: [],
showEmbedded: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ height: app.globalData.fragmentHeight })
wx.showLoading({ title: '加载中', mask: true })
this.fetchMemberList()
},
fetchMemberList: function(){
getCheckList({enterpriseId: app.accountInfo.enterpriseId}).then(result => {
//成功回调
this.setData({ checkList: result.data, loading: false})
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
this.data.eemidList = []
getEmployeList({enterpriseId: app.accountInfo.enterpriseId, isPassFromBackstage: 1}).then(result => {
//成功回调
for (let index = 0; index < result.data.length; index++) {
const element = result.data[index]
if(element.position == 'ADMINISTRATOR'){
this.data.eemidList.push(element.id)
}
}
this.setData({ memberList: result.data, loading: false })
wx.hideLoading()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
lookItem: function(event){
var item = this.data.memberList[event.currentTarget.dataset.index]
if(item.position == 'ADMINISTRATOR'){
return
}
var that = this
wx.showActionSheet({
itemList: ['设为管理员'],
success(res){
if (res.tapIndex === 0){
that.setAdmin(event.currentTarget.dataset.index, item)
}if (res.tapIndex === 1){
that.deleteItem(event.currentTarget.dataset.index, item)
}
}
})
},
setAdmin: function(index, item){
wx.showLoading({ title: '加载中', mask: true })
if(item.position == 'ADMINISTRATOR'){
var sindex = -1
for (var i = 0; i < this.data.eemidList.length; i++) {
if (this.data.eemidList[i] == item.id){
sindex = i
break
}
}
this.data.eemidList.splice(sindex, 1)
} else {
if(this.data.eemidList.indexOf(item.id) < 0){
this.data.eemidList.push(item.id)
}
}
adminEmploye({ids: this.data.eemidList }).then(result => {
//成功回调
this.setData({ ['memberList[' + index + '].position'] : item.position == 'ADMINISTRATOR' ? 'ORDINARY' : 'ADMINISTRATOR'})
wx.hideLoading()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
deleteItem: function(index, item){
wx.showLoading({ title: '加载中', mask: true })
deleteEmploye({idList: [item.id] }).then(result => {
//成功回调
this.fetchMemberList()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
agreeItem: function(event){
// /employees/audit 员工审核
wx.showLoading({ title: '加载中', mask: true })
var item = this.data.checkList[event.currentTarget.dataset.index]
auditEmploye({id: item.id, status: 1 }).then(result => {
//成功回调
this.fetchMemberList()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
refuseItem: function(event){
wx.showLoading({ title: '加载中', mask: true })
var item = this.data.checkList[event.currentTarget.dataset.index]
auditEmploye({id: item.id, status: 2 }).then(result => {
//成功回调
this.setData({ ['checkList[' + event.currentTarget.dataset.index + '].applicantStatus']: 2})
wx.hideLoading()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
onClickHideEmbedded: function(){
this.setData({ showEmbedded: false })
},
addEmployee: function(event){
wx.showLoading({ title: '加载中', mask: true })
const form = { id: 2, action: '/page/index/shenqing' }
form.metaData = { enterpriseId: app.accountInfo.enterpriseId, name: app.accountInfo.enterpriseName }
qrcodeEmploye(form).then(result => {
//成功回调
this.setData({ showEmbedded: true, base64: result.data })
wx.hideLoading()
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
saveQrcode: function(){
var fsm = wx.getFileSystemManager()
var ten = parseInt( Math.random() * 10)
var that = this
var number = Math.random().toString().replace('.', '')
fsm.writeFile({
filePath: wx.env.USER_DATA_PATH + '/qrcode' + (ten + number) + '.png',
data: that.data.base64,
encoding: 'base64',
success: res => {
wx.saveImageToPhotosAlbum({
filePath: wx.env.USER_DATA_PATH + '/qrcode' + (ten + number) + '.png',
success: function (res) {
that.setData({ showEmbedded: false })
util.showToast('保存成功')
},
fail: function (err) {
that.setData({ showEmbedded: false })
}
})
}, fail: err => {
that.setData({ showEmbedded: false })
}
})
},
noop: function() {
}
})