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

162 lines
5.1 KiB

// pages/home/employee/index.js
import Scene from '../../index/scene'
import { getCheckList, auditEmploye, adminEmploye, deleteEmploye, generateCode } from "../../../api/user"
import { getEmployeList } from "../../../api/saas"
const util = require('../../../utils/util')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight,
base64: null,
loading: true,
checkList: [],
memberList: [],
showEmbedded: false,
show: false,
actions: [
{ id: 1, name: '删除该员工' }
],
nowIndex: -1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({ height: app.globalData.fragmentHeight })
this.fetchMemberList()
},
fetchMemberList: function(){
wx.showLoading({ title: '加载中', mask: true })
getCheckList({enterpriseId: app.userInfo.enterpriseId}).then(result => {
this.setData({ checkList: result.data.records, loading: false})
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
getEmployeList({enterpriseId: app.userInfo.enterpriseId, isPassFromBackstage: 1}).then(result => {
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
var item = this.data.memberList[this.data.nowIndex]
item.apply = 0
wx.navigateTo({
url: `/pages/home/employee-info/index?id=${item.enterpriseMemberId}`,
events: {
onCallback: (data) => {
if (data.what == 120) {
that.fetchMemberList()
}
}
},
success: function(res) {
res.eventChannel.emit('onParam', 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.enterpriseMemberId] }).then(result => {
// this.fetchMemberList()
// }).catch(err => {
// wx.hideLoading()
// util.showToast(err)
// })
// },
// agreeItem: function(e){
// 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()
// console.log(err)
// 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()
// console.log(err)
// 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 })
}
})
}
})