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

136 lines
4.0 KiB

// pages/home/employee/index.js
import Scene from '../../index/scene'
import { getCheckList, auditEmploye, 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){
var that = this
this.data.nowIndex = e.currentTarget.dataset.index
var item = this.data.memberList[this.data.nowIndex]
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)
}
})
},
agreeItem: function(e){
var that = this
this.data.nowIndex = e.currentTarget.dataset.index
var item = this.data.checkList[this.data.nowIndex]
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)
}
})
},
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 })
}
})
}
})