Files
FreeERP.Applet/miniprogram/pages/manage/staff/staff.ts

210 lines
5.0 KiB
TypeScript
Raw Normal View History

2026-02-02 16:58:37 +08:00
import { loginStatus, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
getDataSet,
2026-02-06 14:49:13 +08:00
searchValueFormat,
2026-02-02 16:58:37 +08:00
showModal,
sleep,
toArray,
toastSuccess,
toNumber,
} from '@/utils/util';
const defaultParams = { curr_page: 1, page_count: 20 };
Page({
/**
*
*/
data: {
params: cloneLite(defaultParams) as any,
list: [] as any[],
count: 0,
orderStep: [] as any[],
sort: [
{ label: '部门', value: 'dep_name' },
{ label: '岗位', value: 'group_id' },
{ label: '状态', value: 'state' },
{ label: '创建日期', value: 'create_date' },
],
user_id: wx.getStorageSync('user_id'),
depOption: [] as any[],
groupsOption: [] as any[],
},
handleLogin(e: any) {
this.setData({ isLogin: e.detail });
if (e.detail) {
this.init();
}
},
init() {
this.setData({ authInfo: getAuthInfo() });
this.getList();
this.getOrderStep();
},
searchChange(e: any) {
const key = getDataSet(e).key;
2026-02-06 14:49:13 +08:00
const val = searchValueFormat(e.detail.value);
2026-02-02 16:58:37 +08:00
if (val) {
this.data.params[key] = val;
} else {
delete this.data.params[key];
}
this.setData({ params: this.data.params });
},
searchOk() {
this.getList(1);
},
searchReset() {
this.data.params = cloneLite(defaultParams);
this.getList(1);
},
onSort(e: any) {
this.data.params.order = e.detail.value;
this.setData({ params: this.data.params });
this.getList(1);
},
onSearchState(e: any) {
const key = getDataSet(e).key;
if (key) {
this.data.params.state = key;
} else {
delete this.data.params.state;
}
this.setData({ params: this.data.params });
this.getList(1);
},
paginationChange(e: any) {
this.getList(e.detail.curr_page);
},
getOrderStep() {
post('Departments/list').then((res: any) => {
this.setData({
depOption: [
{ label: '全部', value: '' },
...toArray(res.data).map((el) => ({
label: el.name,
value: el.department_id,
})),
],
});
});
post('Groups/list').then((res: any) => {
this.setData({
groupsOption: [
{ label: '全部', value: '' },
...toArray(res.data).map((el) => ({
label: el.name,
value: el.group_id,
})),
],
});
});
},
getList(curr: number = 1) {
this.data.params.curr_page = curr;
this.setData({ params: this.data.params });
const temp = cloneLite(this.data.params);
post('Users/getStaff', temp).then((res: any) => {
const list = toArray(res.data);
if (list.length == 0 && this.data.params.curr_page > 1) {
this.getList(this.data.params.curr_page - 1);
}
this.setData({ count: toNumber(res.count), list: list });
});
},
onReinstatedStaff(e: any) {
const data = getDataSet(e);
const index = data.index;
const item = this.data.list[index];
showModal({ content: `确认复职 ${item.login_name}?` }).then(() => {
post('Users/reinstatedStaff', { staff_id: item.staff_id }).then(() => {
toastSuccess('复职成功');
sleep(() => {
this.getList();
}, 1000);
});
});
},
onFireStaff(e: any) {
const data = getDataSet(e);
const index = data.index;
const item = this.data.list[index];
showModal({ content: `确认解雇 ${item.login_name}?` }).then(() => {
post('Users/fireStaff', { staff_id: item.staff_id }).then(() => {
toastSuccess('解雇成功');
sleep(() => {
this.getList();
}, 1000);
});
});
},
onStaffState(e: any) {
const data = getDataSet(e);
const index = data.index;
const item = this.data.list[index];
showModal({ content: `确认${item.state == 1 ? '禁用' : '启用'} ${item.login_name}?` }).then(
() => {
post('Users/setStaffState', { staff_id: item.staff_id }).then(() => {
toastSuccess(`${item.state == 1 ? '禁用' : '启用'}成功`);
sleep(() => {
this.getList();
}, 1000);
});
},
);
},
/**
* --
*/
onLoad(_options) {},
/**
* --
*/
onReady() {},
/**
* --
*/
onShow() {
this.setData({ loading: true });
loginStatus()
.then(() => {
this.setData({ isLogin: true, loading: false });
this.init();
})
.catch((err) => {
this.setData({ isLogin: false, loading: false });
console.log('调用登录状态请求失败', err);
});
},
/**
* --
*/
onHide() {},
/**
* --
*/
onUnload() {},
/**
* --
*/
onPullDownRefresh() {},
/**
*
*/
onReachBottom() {},
/**
*
*/
onShareAppMessage() {},
});