添加页面

This commit is contained in:
zhengw
2026-02-02 16:58:37 +08:00
parent bdee04ad67
commit 1c0e0b265d
38 changed files with 1575 additions and 10 deletions

View File

@@ -0,0 +1,15 @@
{
"usingComponents": {
"search-popup": "/pages/components/search-popup/search-popup",
"card-plugin": "/pages/components/card-plugin/card-plugin",
"card-item-plugin": "/pages/components/card-item-plugin/card-item-plugin",
"option-cell-plugin": "/pages/components/option-cell-plugin/option-cell-plugin",
"date-picker-plugin": "/pages/components/date-picker-plugin/date-picker-plugin",
"sort-plugin": "/pages/components/sort-plugin/sort-plugin",
"count-plugin": "/pages/components/count-plugin/count-plugin",
"total-bar-plugin": "/pages/components/total-bar-plugin/total-bar-plugin",
"pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin",
"search-input": "/pages/components/search-input/search-input"
},
"navigationBarTitleText": "员工管理"
}

View File

@@ -0,0 +1,223 @@
import { loginStatus, post } from '@/utils/https';
import {
cloneLite,
getAuthInfo,
getDataSet,
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;
this.data.params[key] = e.detail.value;
this.setData({ params: this.data.params });
},
searchChange2(e: any) {
const key = getDataSet(e).key;
const val = `${e.detail.value || ''}`.trim();
if (val) {
this.data.params[key] = val;
} else {
delete this.data.params[key];
}
this.setData({ params: this.data.params });
},
onOptionChange(e: any) {
const key = getDataSet(e).key;
this.data.params[key] = e.detail.value;
this.setData({ params: this.data.params });
},
datePickerConfirm(e: any) {
const data = getDataSet(e);
this.data.params[data.key] = e.detail.value;
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() {},
});

View File

@@ -0,0 +1,65 @@
<page-plugin isAuth="{{authInfo['SF_ERP_STAFF_VIEW']}}" loading="{{loading}}" is-login="{{isLogin}}"
bind:handleLogin="handleLogin">
<search-popup placeholder="输入员工账号" bind:change="searchChange" bind:ok="searchOk"
bind:reset="searchReset" value="{{params.login_name}}" data-key="login_name">
<view slot="content">
<search-input label="手机" value="{{params.user_phone}}" data-key="user_phone"
bind:change="searchChange2" />
<option-cell-plugin title="组织架构" value="{{params.department_id || ''}}"
bind:change="onOptionChange" mode="radio" options="{{depOption}}"
data-key="department_id" />
<option-cell-plugin title="组织架构" value="{{params.group_id || ''}}"
bind:change="onOptionChange" mode="radio" options="{{groupsOption}}" data-key="group_id" />
<!-- <date-picker-plugin title="创建开始日期" value="{{params.create_dateL}}" data-key="create_dateL"
bind:confirm="datePickerConfirm" />
<date-picker-plugin title="创建结束日期" value="{{params.create_dateU}}" data-key="create_dateU"
bind:confirm="datePickerConfirm" /> -->
</view>
</search-popup>
<count-plugin count="{{count}}">
<view slot="left">
<t-button size="small" theme="{{params.state == '-1' ? '': 'primary'}}" class="btn-left"
bind:tap="onSearchState" data-key="">在职员工</t-button>
<t-button size="small" theme="{{params.state == '-1' ? 'primary': ''}}" class="btn-right"
bind:tap="onSearchState" data-key="-1">离职员工</t-button>
</view>
<sort-plugin options="{{sort}}" bind:ok="onSort" value="{{params.order}}" slot="right" />
</count-plugin>
<empty-plugin wx:if="{{list.length == 0}}" />
<card-plugin wx:for="{{ list }}" wx:key="staff_id" showAll="{{true}}">
<view slot="header"
style="display: flex;justify-content: space-between;align-items: center;width: 100%;">
<view style="word-break: break-all;">
{{ item.login_name }}
<text wx:if="{{item.nick_name}}">({{item.nick_name}})</text>
</view>
<view style="font-weight: normal;color: #999;flex-shrink: 0;display: flex;">
{{ item.state== 1 ? '正常' : '禁用'}}
</view>
</view>
<view slot="content">
<card-item-plugin label="手机" value="{{item.user_phone}}" />
<card-item-plugin label="部门" value="{{item.dep_name}}" />
<card-item-plugin label="岗位" value="{{item.group_name}}" />
<card-item-plugin label="创建日期" value="{{item.create_date}}" />
</view>
<view slot="footer" class="card-plugin-footer">
<block wx:if="{{item.state == -1}}">
<t-button wx:if="{{authInfo['SF_ERP_STAFF_EDIT']}}" size="small" theme="primary"
bind:tap="onReinstatedStaff" data-index="{{index}}">复职</t-button>
</block>
<block wx:else>
<t-button wx:if="{{user_id != item.user_id && authInfo['SF_ERP_STAFF_FIRE']}}" size="small"
theme="danger" bind:tap="onFireStaff" data-index="{{index}}">解雇</t-button>
<t-button wx:if="{{authInfo['SF_ERP_STAFF_EDIT']}}" size="small"
theme="{{ item.state== 1 ? 'danger' : 'primary'}}" bind:tap="onStaffState"
data-index="{{index}}">{{ item.state== 1 ? '禁用' : '启用'}}</t-button>
</block>
</view>
</card-plugin>
<pagination-plugin curr_page="{{params.curr_page}}" page_count="{{params.page_count}}"
total="{{count}}" bind:change="paginationChange" />
</page-plugin>

View File

@@ -0,0 +1,11 @@
button.btn-left,
button.btn-left::after {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}
button.btn-right,
button.btn-right::after {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}