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

169 lines
5.0 KiB

// pages/home/employee/index.js
import { getCheckList, getEmployeList, auditEmploye, adminEmploye, deleteEmploye, generateCode } 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,
show: false,
actions: [
{ id: 1, name: '删除该员工' }
],
nowIndex: -1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ height: app.globalData.fragmentHeight })
wx.showLoading({ title: '加载中', mask: true })
this.fetchMemberList()
},
fetchMemberList: function(){
getCheckList({enterpriseId: app.userInfo.enterpriseId}).then(result => {
this.setData({ checkList: result.data.records, loading: false})
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
this.data.eemidList = []
getEmployeList({enterpriseId: app.userInfo.enterpriseId, isPassFromBackstage: 1}).then(result => {
for (let index = 0; index < result.data.records.length; index++) {
const element = result.data.records[index]
if(element.position == 'ADMINISTRATOR'){
this.data.eemidList.push(element.id)
}
}
this.setData({ memberList: result.data.records, loading: false })
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
lookItem: function(e){
this.data.nowIndex = e.currentTarget.dataset.index
this.setData({ show: true })
},
showSheet: function(){
this.setData({ show: true })
},
onClose() {
this.setData({ show: false })
},
onSelect({detail}) {
if(detail.id === 1){
var item = this.data.memberList[this.data.nowIndex]
this.deleteItem(this.data.nowIndex, item)
this.data.nowIndex = -1
}
},
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(e){
// /employees/audit 员工审核
wx.showLoading({ title: '加载中', mask: true })
var item = this.data.checkList[e.currentTarget.dataset.index]
auditEmploye({id: item.id, status: 1 }).then(result => {
this.fetchMemberList()
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
refuseItem: function(e){
wx.showLoading({ title: '加载中', mask: true })
var item = this.data.checkList[e.currentTarget.dataset.index]
auditEmploye({id: item.id, status: 2 }).then(result => {
this.setData({ ['checkList[' + e.currentTarget.dataset.index + '].status']: 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: 5 }
form.metaData = { factoryId: app.userInfo.factoryId, factoryName: app.userInfo.factoryName }
generateCode(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() {
}
})