综合办公系统
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

staffList.vue 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. <template>
  2. <view class="container">
  3. <!-- 搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-input">
  6. <input class="search-input-field" v-model="queryParams.nickName" placeholder="请输入姓名搜索" @input="handleQuery"
  7. @confirm="handleQuery" />
  8. </view>
  9. <view class="filter-btn" @click="showFilter = true">
  10. <text class="filter-icon">筛选</text>
  11. </view>
  12. </view>
  13. <!-- 部门选择 -->
  14. <view class="dept-section" v-if="deptOptions.length > 0">
  15. <view class="dept-header">
  16. <text class="dept-title">部门</text>
  17. <text class="dept-name">{{ currentDeptName || '全部部门' }}</text>
  18. </view>
  19. <scroll-view class="dept-scroll" scroll-x>
  20. <view class="dept-list">
  21. <view class="dept-item" :class="{ active: !queryParams.deptId }" @click="selectDept(null, '全部部门')">
  22. 全部
  23. </view>
  24. <view v-for="dept in deptOptions" :key="dept.id" class="dept-item"
  25. :class="{ active: queryParams.deptId === dept.id }" @click="selectDept(dept.id, dept.label)">
  26. {{ dept.label }}
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <!-- 状态选择 -->
  32. <view class="status-section">
  33. <view class="status-header">
  34. <text class="status-title">状态</text>
  35. <text class="status-name">{{ getStatusLabel(queryParams.status) || '在职' }}</text>
  36. </view>
  37. <scroll-view class="status-scroll" scroll-x>
  38. <view class="status-list">
  39. <view class="status-item" :class="{ active: queryParams.status === '0' }" @click="selectStatus('0')">
  40. 在职
  41. </view>
  42. <view class="status-item" :class="{ active: queryParams.status === '1' }" @click="selectStatus('1')">
  43. 离职
  44. </view>
  45. <view class="status-item" :class="{ active: queryParams.status === '2' }" @click="selectStatus('2')">
  46. 退休
  47. </view>
  48. </view>
  49. </scroll-view>
  50. </view>
  51. <!-- 筛选弹窗 -->
  52. <view v-if="showFilter" class="filter-overlay" @click="showFilter = false">
  53. <view class="filter-popup" @click.stop>
  54. <view class="filter-header">
  55. <text class="filter-title">筛选条件</text>
  56. <view class="filter-close" @click="showFilter = false">
  57. <text>✕</text>
  58. </view>
  59. </view>
  60. <view class="filter-content">
  61. <view class="filter-item">
  62. <text class="filter-label">职称</text>
  63. <picker v-model="queryParams.titles" :range="titleOptions" range-key="label" @change="onTitleChange">
  64. <view class="picker-view">
  65. {{ getTitleLabel(queryParams.titles) || '请选择职称' }}
  66. </view>
  67. </picker>
  68. </view>
  69. <view class="filter-item">
  70. <text class="filter-label">状态</text>
  71. <picker v-model="queryParams.status" :range="statusOptions" range-key="label" @change="onStatusChange">
  72. <view class="picker-view">
  73. {{ getStatusLabel(queryParams.status) || '请选择状态' }}
  74. </view>
  75. </picker>
  76. </view>
  77. </view>
  78. <view class="filter-actions">
  79. <button class="btn-default" @click="resetQuery">重置</button>
  80. <button class="btn-primary" @click="applyFilter">确定</button>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 员工列表 -->
  85. <mescroll-uni ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
  86. :up="upOption" :fixed="false" :top="10" style="padding: 30rpx;">
  87. <view class="staff-list">
  88. <view v-for="(item, index) in staffList" :key="index" class="staff-card" @click="handleView(item)">
  89. <view class="staff-header">
  90. <view class="staff-avatar">
  91. <image class="avatar-image" :src="item.avatar || '/static/images/user.png'" mode="aspectFill" />
  92. </view>
  93. <view class="staff-info">
  94. <view class="staff-name">{{ item.nickName }}</view>
  95. <view class="staff-dept">{{ (item.dept && item.dept.deptName) || '未分配部门' }}</view>
  96. <view class="staff-status">
  97. <text class="status-tag" :class="'status-' + item.status">
  98. {{ getStatusText(item.status) }}
  99. </text>
  100. </view>
  101. </view>
  102. <view class="staff-actions">
  103. <text class="arrow-icon">></text>
  104. </view>
  105. </view>
  106. <view class="staff-details">
  107. <view class="detail-item">
  108. <text class="detail-label">年龄:</text>
  109. <text class="detail-value">{{ String(getAgeByIdCard(item.idCard)).slice(0, 2) }}岁</text>
  110. </view>
  111. <view class="detail-item">
  112. <text class="detail-label">性别:</text>
  113. <text class="detail-value">{{ item.sex == 0 ? '男' : '女' }}</text>
  114. </view>
  115. <view class="detail-item">
  116. <text class="detail-label">手机:</text>
  117. <text class="detail-value">{{ item.phonenumber || '未填写' }}</text>
  118. </view>
  119. <view class="detail-item">
  120. <text class="detail-label">职称:</text>
  121. <text class="detail-value">{{ getTitleText(item.titles) || '未填写' }}</text>
  122. </view>
  123. <view class="detail-item">
  124. <text class="detail-label">职务:</text>
  125. <text class="detail-value">{{ item.postNames || '未填写' }}</text>
  126. </view>
  127. <view class="detail-item">
  128. <text class="detail-label">入职时间:</text>
  129. <text class="detail-value">{{ formatDate(item.entryDate) || '未填写' }}</text>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </mescroll-uni>
  135. </view>
  136. </template>
  137. <script>
  138. import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus } from "@/api/system/user";
  139. import { deptTreeSelectNew } from "@/api/system/dept";
  140. import MescrollMixin from '@/uni_modules/mescroll/components/mescroll-uni/mescroll-mixins.js';
  141. export default {
  142. mixins: [MescrollMixin],
  143. data() {
  144. return {
  145. mescroll: null, // mescroll实例
  146. downOption: {
  147. auto: true,
  148. textOutOffset: '下拉刷新',
  149. textLoading: '加载中...'
  150. },
  151. upOption: {
  152. auto: false,
  153. page: { num: 1, size: 10 },
  154. noMoreSize: 5,
  155. empty: { tip: '暂无更多员工数据' },
  156. textNoMore: '~ 没有更多数据了 ~'
  157. },
  158. staffList: [],
  159. deptOptions: [],
  160. currentDeptName: '',
  161. showFilter: false,
  162. queryParams: {
  163. pageNum: 1,
  164. pageSize: 10,
  165. nickName: '',
  166. titles: '',
  167. certificates: '',
  168. degree: '',
  169. status: '0',
  170. deptId: undefined
  171. },
  172. // 筛选选项
  173. titleOptions: [
  174. { label: '高级工程师', value: '1' },
  175. { label: '工程师', value: '2' },
  176. { label: '助理工程师', value: '3' },
  177. { label: '技术员', value: '4' }
  178. ],
  179. certificateOptions: [
  180. { label: '注册测绘师', value: '1' },
  181. { label: '注册建筑师', value: '2' },
  182. { label: '注册结构师', value: '3' },
  183. { label: '注册造价师', value: '4' }
  184. ],
  185. degreeOptions: [
  186. { label: '博士', value: '1' },
  187. { label: '硕士', value: '2' },
  188. { label: '本科', value: '3' },
  189. { label: '专科', value: '4' },
  190. { label: '高中', value: '5' }
  191. ],
  192. statusOptions: [
  193. { label: '在职', value: '0' },
  194. { label: '离职', value: '1' },
  195. { label: '退休', value: '2' },
  196. { label: '试用', value: '3' },
  197. { label: '返聘', value: '4' }
  198. ]
  199. }
  200. },
  201. onLoad: function (options) {
  202. this.getDeptTree();
  203. uni.startPullDownRefresh();
  204. },
  205. methods: {
  206. mescrollInit(mescroll) {
  207. this.mescroll = mescroll;
  208. },
  209. // 获取部门树
  210. async getDeptTree() {
  211. try {
  212. const res = await deptTreeSelectNew();
  213. this.deptOptions = res.data[0].children || [];
  214. } catch (error) {
  215. console.error('获取部门树失败:', error);
  216. }
  217. },
  218. // 选择部门
  219. selectDept(deptId, deptName) {
  220. this.queryParams.deptId = deptId;
  221. this.currentDeptName = deptName;
  222. this.handleQuery();
  223. },
  224. // 选择状态
  225. selectStatus(status) {
  226. this.queryParams.status = status;
  227. this.handleQuery();
  228. },
  229. // 搜索
  230. handleQuery() {
  231. this.queryParams.pageNum = 1;
  232. this.staffList = [];
  233. this.mescroll.resetUpScroll();
  234. },
  235. // 重置查询
  236. resetQuery() {
  237. this.queryParams = {
  238. pageNum: 1,
  239. pageSize: 10,
  240. nickName: '',
  241. titles: '',
  242. certificates: '',
  243. degree: '',
  244. status: '0', // 默认选中在职
  245. deptId: undefined
  246. };
  247. this.currentDeptName = '';
  248. this.showFilter = false;
  249. this.handleQuery();
  250. },
  251. // 应用筛选
  252. applyFilter() {
  253. this.showFilter = false;
  254. this.handleQuery();
  255. },
  256. // 处理职称选择变化
  257. onTitleChange(e) {
  258. const option = this.titleOptions[e.detail.value];
  259. this.queryParams.titles = option ? option.value : '';
  260. },
  261. // 处理状态选择变化
  262. onStatusChange(e) {
  263. const option = this.statusOptions[e.detail.value];
  264. this.queryParams.status = option ? option.value : '';
  265. },
  266. // 获取职称标签
  267. getTitleLabel(value) {
  268. const item = this.titleOptions.find(item => item.value === value);
  269. return item ? item.label : '';
  270. },
  271. // 获取状态标签
  272. getStatusLabel(value) {
  273. const item = this.statusOptions.find(item => item.value === value);
  274. return item ? item.label : '';
  275. },
  276. // 加载数据
  277. async loadData() {
  278. try {
  279. const res = await listUser(this.queryParams);
  280. return { data: res.rows, total: res.total };
  281. } catch (e) {
  282. console.error('加载员工数据失败:', e);
  283. return { data: [], error: true };
  284. }
  285. },
  286. // mescroll下拉刷新回调
  287. async downCallback() {
  288. this.staffList = []; // 清空列表
  289. this.queryParams.pageNum = 1;
  290. const res = await this.loadData();
  291. if (res.error) {
  292. this.mescroll.endErr();
  293. } else {
  294. this.staffList = res.data;
  295. this.mescroll.endSuccess(res.data.length, res.total);
  296. }
  297. uni.stopPullDownRefresh();
  298. },
  299. // mescroll上拉加载回调
  300. async upCallback(page) {
  301. this.queryParams.pageNum = page.num;
  302. const res = await this.loadData();
  303. if (res.error) {
  304. this.mescroll.endErr();
  305. } else {
  306. this.staffList = this.staffList.concat(res.data);
  307. this.mescroll.endSuccess(res.data.length, res.total);
  308. }
  309. },
  310. // 查看员工详情
  311. handleView(item) {
  312. uni.navigateTo({
  313. url: `/pages/oa/staff/staffDetail?userId=${item.userId}&nickName=${item.nickName}`
  314. });
  315. },
  316. // 获取状态文本
  317. getStatusText(status) {
  318. const statusMap = {
  319. '0': '在职',
  320. '1': '离职',
  321. '2': '退休',
  322. '3': '试用',
  323. '4': '返聘'
  324. };
  325. return statusMap[status] || '未知';
  326. },
  327. // 获取状态类型
  328. getStatusType(status) {
  329. const typeMap = {
  330. '0': 'success',
  331. '1': 'error',
  332. '2': 'warning',
  333. '3': 'primary',
  334. '4': 'info'
  335. };
  336. return typeMap[status] || 'default';
  337. },
  338. // 获取职称文本
  339. getTitleText(titles) {
  340. const titleMap = {
  341. '1': '高级工程师',
  342. '2': '工程师',
  343. '3': '助理工程师',
  344. '4': '技术员'
  345. };
  346. return titleMap[titles] || '';
  347. },
  348. // 根据身份证计算年龄
  349. getAgeByIdCard(idCard) {
  350. if (!idCard) return 0;
  351. const birthStr = idCard.substring(6, 14);
  352. const birthYear = parseInt(birthStr.substring(0, 4), 10);
  353. const birthMonth = parseInt(birthStr.substring(4, 6), 10) - 1;
  354. const birthDay = parseInt(birthStr.substring(6, 8), 10);
  355. const birthDate = new Date(birthYear, birthMonth, birthDay);
  356. const now = new Date();
  357. let age = now.getFullYear() - birthDate.getFullYear();
  358. const monthDiff = now.getMonth() - birthDate.getMonth();
  359. if (monthDiff < 0 || (monthDiff === 0 && now.getDate() < birthDate.getDate())) {
  360. age--;
  361. }
  362. return age;
  363. },
  364. // 格式化日期
  365. formatDate(dateStr) {
  366. if (!dateStr) return '';
  367. const date = new Date(dateStr);
  368. return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
  369. }
  370. },
  371. }
  372. </script>
  373. <style lang="scss" scoped>
  374. .container {
  375. padding: 10rpx;
  376. background-color: #f5f5f5;
  377. height: 100vh;
  378. display: flex;
  379. flex-direction: column;
  380. }
  381. .search-bar {
  382. display: flex;
  383. align-items: center;
  384. padding: 20rpx 30rpx;
  385. background-color: #fff;
  386. border-bottom: 1rpx solid #eee;
  387. .search-input {
  388. flex: 1;
  389. margin-right: 20rpx;
  390. .search-input-field {
  391. width: 100%;
  392. height: 60rpx;
  393. padding: 0 20rpx;
  394. border: 1rpx solid #ddd;
  395. border-radius: 30rpx;
  396. font-size: 28rpx;
  397. }
  398. }
  399. .filter-btn {
  400. padding: 10rpx 20rpx;
  401. background-color: #f5f5f5;
  402. border-radius: 20rpx;
  403. .filter-icon {
  404. font-size: 26rpx;
  405. color: #666;
  406. }
  407. }
  408. }
  409. .dept-section {
  410. background-color: #fff;
  411. padding: 20rpx 30rpx;
  412. border-bottom: 1rpx solid #eee;
  413. .dept-header {
  414. display: flex;
  415. justify-content: space-between;
  416. align-items: center;
  417. margin-bottom: 20rpx;
  418. .dept-title {
  419. font-size: 28rpx;
  420. color: #333;
  421. font-weight: bold;
  422. }
  423. .dept-name {
  424. font-size: 24rpx;
  425. color: #666;
  426. }
  427. }
  428. .dept-scroll {
  429. white-space: nowrap;
  430. .dept-list {
  431. display: flex;
  432. .dept-item {
  433. display: inline-block;
  434. padding: 10rpx 20rpx;
  435. margin-right: 20rpx;
  436. background-color: #f5f5f5;
  437. border-radius: 20rpx;
  438. font-size: 24rpx;
  439. color: #666;
  440. white-space: nowrap;
  441. &.active {
  442. background-color: #007aff;
  443. color: #fff;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. .status-section {
  450. background-color: #fff;
  451. padding: 20rpx 30rpx;
  452. border-bottom: 1rpx solid #eee;
  453. .status-header {
  454. display: flex;
  455. justify-content: space-between;
  456. align-items: center;
  457. margin-bottom: 20rpx;
  458. .status-title {
  459. font-size: 28rpx;
  460. color: #333;
  461. font-weight: bold;
  462. }
  463. .status-name {
  464. font-size: 24rpx;
  465. color: #666;
  466. }
  467. }
  468. .status-scroll {
  469. white-space: nowrap;
  470. .status-list {
  471. display: flex;
  472. .status-item {
  473. display: inline-block;
  474. padding: 10rpx 20rpx;
  475. margin-right: 20rpx;
  476. background-color: #f5f5f5;
  477. border-radius: 20rpx;
  478. font-size: 24rpx;
  479. color: #666;
  480. white-space: nowrap;
  481. &.active {
  482. background-color: #007aff;
  483. color: #fff;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. .filter-overlay {
  490. position: fixed;
  491. top: 0;
  492. left: 0;
  493. right: 0;
  494. bottom: 0;
  495. background-color: rgba(0, 0, 0, 0.5);
  496. z-index: 1000;
  497. display: flex;
  498. align-items: flex-end;
  499. }
  500. .filter-popup {
  501. background-color: #fff;
  502. border-radius: 20rpx 20rpx 0 0;
  503. padding: 40rpx;
  504. width: 100%;
  505. max-height: 80vh;
  506. .filter-header {
  507. display: flex;
  508. justify-content: space-between;
  509. align-items: center;
  510. margin-bottom: 40rpx;
  511. .filter-title {
  512. font-size: 32rpx;
  513. font-weight: bold;
  514. color: #333;
  515. }
  516. .filter-close {
  517. padding: 10rpx;
  518. text {
  519. font-size: 24rpx;
  520. color: #999;
  521. }
  522. }
  523. }
  524. .filter-content {
  525. .filter-item {
  526. margin-bottom: 30rpx;
  527. .filter-label {
  528. display: block;
  529. font-size: 28rpx;
  530. color: #333;
  531. margin-bottom: 10rpx;
  532. }
  533. picker {
  534. .picker-view {
  535. padding: 20rpx;
  536. background-color: #f5f5f5;
  537. border-radius: 10rpx;
  538. font-size: 28rpx;
  539. color: #333;
  540. }
  541. }
  542. }
  543. }
  544. .filter-actions {
  545. display: flex;
  546. justify-content: space-between;
  547. margin-top: 40rpx;
  548. gap: 20rpx;
  549. button {
  550. flex: 1;
  551. height: 80rpx;
  552. border-radius: 10rpx;
  553. font-size: 28rpx;
  554. border: none;
  555. &.btn-default {
  556. background-color: #f5f5f5;
  557. color: #666;
  558. }
  559. &.btn-primary {
  560. background-color: #007aff;
  561. color: #fff;
  562. }
  563. }
  564. }
  565. }
  566. .staff-list {
  567. .staff-card {
  568. background-color: #fff;
  569. border-radius: 20rpx;
  570. margin-bottom: 20rpx;
  571. padding: 30rpx;
  572. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  573. .staff-header {
  574. display: flex;
  575. align-items: center;
  576. margin-bottom: 20rpx;
  577. .staff-avatar {
  578. margin-right: 20rpx;
  579. .avatar-image {
  580. width: 60rpx;
  581. height: 60rpx;
  582. border-radius: 50%;
  583. }
  584. }
  585. .staff-info {
  586. flex: 1;
  587. .staff-name {
  588. font-size: 32rpx;
  589. font-weight: bold;
  590. color: #333;
  591. margin-bottom: 10rpx;
  592. }
  593. .staff-dept {
  594. font-size: 24rpx;
  595. color: #666;
  596. margin-bottom: 10rpx;
  597. }
  598. .staff-status {
  599. display: inline-block;
  600. .status-tag {
  601. padding: 4rpx 12rpx;
  602. border-radius: 10rpx;
  603. font-size: 20rpx;
  604. &.status-0 {
  605. background-color: #e6f7ff;
  606. color: #1890ff;
  607. }
  608. &.status-1 {
  609. background-color: #fff2e8;
  610. color: #fa8c16;
  611. }
  612. &.status-2 {
  613. background-color: #f6ffed;
  614. color: #52c41a;
  615. }
  616. &.status-3 {
  617. background-color: #f9f0ff;
  618. color: #722ed1;
  619. }
  620. &.status-4 {
  621. background-color: #f0f0f0;
  622. color: #8c8c8c;
  623. }
  624. }
  625. }
  626. }
  627. .staff-actions {
  628. padding: 10rpx;
  629. .arrow-icon {
  630. font-size: 24rpx;
  631. color: #999;
  632. }
  633. }
  634. }
  635. .staff-details {
  636. .detail-item {
  637. display: flex;
  638. margin-bottom: 15rpx;
  639. .detail-label {
  640. width: 140rpx;
  641. font-size: 26rpx;
  642. color: #999;
  643. }
  644. .detail-value {
  645. flex: 1;
  646. font-size: 26rpx;
  647. color: #333;
  648. }
  649. }
  650. }
  651. }
  652. }
  653. </style>