regularizationHandlingDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <!-- 转正申请详情 -->
  2. <template>
  3. <main class="regularization-detail" v-loading="loading">
  4. <!-- 员工信息 -->
  5. <section class="detail-section">
  6. <div class="info-card">
  7. <div class="info-card__head">
  8. <i class="el-icon-user-solid"></i>
  9. <span>员工信息</span>
  10. <span v-if="approvalStatusText" class="info-card__code">
  11. <el-tag :type="approvalStatusTag" size="mini">{{ approvalStatusText }}</el-tag>
  12. </span>
  13. </div>
  14. <div class="info-card__body">
  15. <div class="info-item">
  16. <span class="info-item__label">申请员工</span>
  17. <span class="info-item__value">{{ employeeInfo.userName || '-' }}
  18. <span v-if="employeeInfo.jobNumber" class="info-item__sub">({{ employeeInfo.jobNumber }})</span>
  19. </span>
  20. </div>
  21. <div class="info-item">
  22. <span class="info-item__label">手机号</span>
  23. <span class="info-item__value">{{ employeeInfo.mobile || '-' }}</span>
  24. </div>
  25. <div class="info-item">
  26. <span class="info-item__label">所属机构</span>
  27. <span class="info-item__value">{{ employeeInfo.groupName || '-' }}</span>
  28. </div>
  29. <div class="info-item">
  30. <span class="info-item__label">所属部门</span>
  31. <span class="info-item__value">{{ employeeInfo.deptName || '-' }}</span>
  32. </div>
  33. <div class="info-item">
  34. <span class="info-item__label">岗位</span>
  35. <span class="info-item__value">{{ employeeInfo.postName || employeeInfo.positionName || '-' }}</span>
  36. </div>
  37. <div class="info-item">
  38. <span class="info-item__label">直属上级</span>
  39. <span class="info-item__value">{{ employeeInfo.managerName || '-' }}</span>
  40. </div>
  41. </div>
  42. </div>
  43. </section>
  44. <!-- 转正信息(表单可操作) -->
  45. <section class="detail-section">
  46. <div class="info-card">
  47. <div class="info-card__head">
  48. <i class="el-icon-date"></i>
  49. <span>转正信息</span>
  50. </div>
  51. <el-form
  52. ref="formRef"
  53. class="regular-form"
  54. :model="form"
  55. :rules="formRules"
  56. label-width="110px"
  57. label-position="right"
  58. >
  59. <div class="form-row">
  60. <el-form-item label="入职日期" prop="joinDate">
  61. <el-date-picker
  62. v-model="form.joinDate"
  63. type="date"
  64. value-format="yyyy-MM-dd"
  65. placeholder="请选择入职日期"
  66. style="width: 100%"
  67. :disabled="isReadonly"
  68. />
  69. </el-form-item>
  70. <el-form-item label="转正类型" prop="regularizationType">
  71. <el-select
  72. v-model="form.regularizationType"
  73. placeholder="请选择转正类型"
  74. style="width: 100%"
  75. :disabled="isReadonly"
  76. @change="onRegularizationTypeChange"
  77. >
  78. <el-option
  79. v-for="opt in regularizationTypeOptions"
  80. :key="opt.value"
  81. :label="opt.label"
  82. :value="opt.value"
  83. />
  84. </el-select>
  85. </el-form-item>
  86. </div>
  87. <div class="form-row">
  88. <el-form-item label="计划转正日期" prop="plannedRegularDate">
  89. <el-date-picker
  90. v-model="form.plannedRegularDate"
  91. type="date"
  92. value-format="yyyy-MM-dd"
  93. placeholder="请选择计划转正日期"
  94. style="width: 100%"
  95. :disabled="isReadonly"
  96. />
  97. </el-form-item>
  98. <el-form-item label="实际生效日期" prop="effectiveDate">
  99. <el-date-picker
  100. v-model="form.effectiveDate"
  101. type="date"
  102. value-format="yyyy-MM-dd"
  103. placeholder="留空按计划日期生效"
  104. style="width: 100%"
  105. :disabled="isReadonly"
  106. />
  107. </el-form-item>
  108. </div>
  109. <!-- 延期转正专属字段 -->
  110. <template v-if="form.regularizationType === 'EXTENDED'">
  111. <div class="form-row form-row--extended">
  112. <div class="extended-title">
  113. <i class="el-icon-warning-outline"></i>
  114. <span>延期转正信息</span>
  115. </div>
  116. </div>
  117. <div class="form-row">
  118. <el-form-item label="延期天数" prop="extensionDays">
  119. <el-input-number
  120. v-model="form.extensionDays"
  121. :min="1"
  122. :max="365"
  123. :step="1"
  124. placeholder="请输入延期天数"
  125. style="width: 100%"
  126. :disabled="isReadonly"
  127. />
  128. </el-form-item>
  129. <el-form-item label="延期后试用期结束" prop="newProbationEndDate">
  130. <el-date-picker
  131. v-model="form.newProbationEndDate"
  132. type="date"
  133. value-format="yyyy-MM-dd"
  134. placeholder="选择延期后试用期结束日期"
  135. style="width: 100%"
  136. :disabled="isReadonly"
  137. />
  138. </el-form-item>
  139. </div>
  140. <div class="form-row">
  141. <el-form-item label="延期原因" prop="extensionReason">
  142. <el-input
  143. v-model="form.extensionReason"
  144. type="textarea"
  145. :rows="3"
  146. placeholder="请填写延期转正的原因(必填)"
  147. :disabled="isReadonly"
  148. />
  149. </el-form-item>
  150. </div>
  151. </template>
  152. <div class="form-row">
  153. <el-form-item label="签署方式">
  154. <span class="plain-text">{{ signWayText }}</span>
  155. </el-form-item>
  156. <el-form-item label="申请资料">
  157. <fileMain
  158. v-model="approvalFileIds"
  159. type="view"
  160. size="small"
  161. :view-disabled="!approvalFileIds.length"
  162. />
  163. </el-form-item>
  164. </div>
  165. </el-form>
  166. </div>
  167. </section>
  168. </main>
  169. </template>
  170. <script>
  171. import { getRegularizationById } from '@/api/main';
  172. import { getEmployeeById } from '@/api/organization';
  173. const empty = () => ({
  174. id: '',
  175. userId: null,
  176. joinDate: '',
  177. plannedRegularDate: '',
  178. effectiveDate: '',
  179. regularizationType: '',
  180. extensionDays: null,
  181. extensionReason: '',
  182. newProbationEndDate: '',
  183. signWay: 'ONLINE',
  184. approvalDocumentFileId: null,
  185. userSummary: '',
  186. managerEvaluation: '',
  187. hrComment: '',
  188. approvalStatus: '',
  189. result: ''
  190. });
  191. const REGULARIZATION_TYPE_OPTIONS = [
  192. { value: 'NORMAL', label: '按期转正' },
  193. { value: 'EARLY', label: '提前转正' },
  194. { value: 'EXTENDED', label: '延期转正' },
  195. { value: 'FAILED', label: '转正不通过' }
  196. ];
  197. const APPROVAL_STATUS_MAP = {
  198. DRAFT: { text: '草稿', tag: 'info' },
  199. APPROVING: { text: '审批中', tag: 'warning' },
  200. APPROVED: { text: '已通过', tag: 'success' },
  201. REJECTED: { text: '已驳回', tag: 'danger' },
  202. COMPLETED: { text: '已完成', tag: 'success' }
  203. };
  204. /** 从多种字段名中取值 */
  205. function pick(obj, keys) {
  206. if (obj == null || typeof obj !== 'object') return '';
  207. for (let i = 0; i < keys.length; i++) {
  208. const v = obj[keys[i]];
  209. if (v !== undefined && v !== null && v !== '') return v;
  210. }
  211. return '';
  212. }
  213. export default {
  214. name: 'RegularizationHandlingDetail',
  215. props: {
  216. businessId: {
  217. default: ''
  218. },
  219. /** 是否只读(BPM 详情页一般只读) */
  220. readonly: {
  221. type: Boolean,
  222. default: true
  223. }
  224. },
  225. data() {
  226. return {
  227. loading: false,
  228. form: empty(),
  229. employeeInfo: {},
  230. approvalDocumentFileId: null,
  231. approvalFileIds: [],
  232. regularizationTypeOptions: REGULARIZATION_TYPE_OPTIONS
  233. };
  234. },
  235. computed: {
  236. isReadonly() {
  237. return this.readonly;
  238. },
  239. formRules() {
  240. const base = {
  241. regularizationType: [
  242. { required: true, message: '请选择转正类型', trigger: 'change' }
  243. ],
  244. plannedRegularDate: [
  245. { required: true, message: '请选择计划转正日期', trigger: 'change' }
  246. ]
  247. };
  248. if (this.form.regularizationType === 'EXTENDED') {
  249. base.extensionDays = [
  250. { required: true, message: '请输入延期天数', trigger: 'blur' },
  251. { type: 'number', min: 1, message: '延期天数必须大于 0', trigger: 'blur' }
  252. ];
  253. base.extensionReason = [
  254. { required: true, message: '请填写延期原因', trigger: 'blur' }
  255. ];
  256. }
  257. return base;
  258. },
  259. approvalStatusText() {
  260. const key = String(this.form.approvalStatus || '').toUpperCase();
  261. return APPROVAL_STATUS_MAP[key]?.text || '';
  262. },
  263. approvalStatusTag() {
  264. const key = String(this.form.approvalStatus || '').toUpperCase();
  265. return APPROVAL_STATUS_MAP[key]?.tag || 'info';
  266. },
  267. signWayText() {
  268. const map = { ONLINE: '线上签署', OFFLINE: '线下签署' };
  269. return map[this.form.signWay] || this.form.signWay || '-' ;
  270. }
  271. },
  272. watch: {
  273. businessId: {
  274. immediate: true,
  275. handler(id) {
  276. if (id) this.bootstrap(id);
  277. }
  278. }
  279. },
  280. methods: {
  281. onRegularizationTypeChange(val) {
  282. // 切换为非延期转正时,清空延期相关字段
  283. if (val !== 'EXTENDED') {
  284. this.form.extensionDays = null;
  285. this.form.extensionReason = '';
  286. this.form.newProbationEndDate = '';
  287. }
  288. if (this.$refs.formRef) {
  289. this.$nextTick(() => this.$refs.formRef.clearValidate());
  290. }
  291. },
  292. /** 将 swagger 字段 → 组件 form */
  293. mapRegularization(data) {
  294. if (!data || typeof data !== 'object') return empty();
  295. return {
  296. id: data.id ?? '',
  297. userId: pick(data, ['userId']),
  298. joinDate: this.toDateStr(pick(data, ['joinDate', 'joinDateTime', 'hireDate'])),
  299. plannedRegularDate: this.toDateStr(pick(data, ['plannedRegularDate'])),
  300. effectiveDate: this.toDateStr(pick(data, ['effectiveDate'])),
  301. regularizationType: pick(data, ['regularizationType']),
  302. extensionDays: pick(data, ['extensionDays']) ?? null,
  303. extensionReason: pick(data, ['extensionReason']),
  304. newProbationEndDate: this.toDateStr(pick(data, ['newProbationEndDate'])),
  305. signWay: pick(data, ['signWay', 'signatureWay']) || 'ONLINE',
  306. approvalDocumentFileId: pick(data, ['approvalDocumentFileId']),
  307. userSummary: pick(data, ['userSummary']),
  308. managerEvaluation: pick(data, ['managerEvaluation']),
  309. hrComment: pick(data, ['hrComment']),
  310. approvalStatus: pick(data, ['approvalStatus']),
  311. result: pick(data, ['result'])
  312. };
  313. },
  314. /** 员工信息:转正单接口优先,缺失则从 getEmployeeById 补
  315. * 真实原始字段名对照 HR adaptEmployee:
  316. * - 转正单 raw: employeeName / employeeNo / groupName / deptName / positionName / managerUserName
  317. * - 员工档案 raw: name / jobNumber / groupName / deptName / postName / managerUserName / phone
  318. */
  319. mapEmployeeInfo(regularization, employee) {
  320. const r = regularization || {};
  321. const e = employee || {};
  322. this.approvalDocumentFileId = pick(r, ['approvalDocumentFileId']);
  323. return {
  324. userId: r.userId || e.id,
  325. // 申请员工
  326. userName: r.employeeName || e.name,
  327. // 工号
  328. jobNumber: r.employeeNo || e.jobNumber,
  329. // 手机号
  330. mobile: e.phone || e.mobile,
  331. // 所属机构
  332. groupName: r.groupName || e.groupName,
  333. // 所属部门
  334. deptName: r.departmentName || r.deptName || e.deptName,
  335. // 岗位(模板用 positionName 渲染)
  336. positionName: r.positionName || e.postName,
  337. // 岗位(兜底)
  338. postName: e.postName,
  339. // 直属上级
  340. managerName: r.managerUserName || e.managerUserName
  341. };
  342. },
  343. /** 后端日期 → yyyy-MM-dd */
  344. toDateStr(val) {
  345. if (!val) return '';
  346. const s = String(val);
  347. // 已经是 yyyy-MM-dd / yyyy-MM-dd HH:mm:ss
  348. if (/^\d{4}-\d{2}-\d{2}/.test(s)) return s.slice(0, 10);
  349. // 毫秒时间戳
  350. if (/^\d{10,13}$/.test(s)) {
  351. const d = new Date(Number(s));
  352. if (!isNaN(d.getTime())) {
  353. const pad = n => String(n).padStart(2, '0');
  354. return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
  355. }
  356. }
  357. return s.slice(0, 10);
  358. },
  359. async bootstrap(id) {
  360. this.loading = true;
  361. try {
  362. const regularization = await getRegularizationById(id);
  363. this.form = this.mapRegularization(regularization);
  364. // 用转正单的 userId 补查员工档案,拿到完整的员工信息
  365. let employee = null;
  366. if (regularization?.userId) {
  367. try {
  368. employee = await getEmployeeById(regularization.userId);
  369. if (process.env.NODE_ENV !== 'production') {
  370. // eslint-disable-next-line no-console
  371. console.log('[RegularizationDetail] 员工档案 raw employee:', employee);
  372. // eslint-disable-next-line no-console
  373. console.log('[RegularizationDetail] 转正单 raw keys:', Object.keys(regularization));
  374. }
  375. } catch (e) {
  376. if (process.env.NODE_ENV !== 'production') {
  377. console.warn('[RegularizationDetail] 员工档案补查失败:', e);
  378. }
  379. }
  380. }
  381. this.employeeInfo = this.mapEmployeeInfo(regularization, employee);
  382. // 转正单 swagger 只有单个 approvalDocumentFileId,统一转成数组给 fileMain
  383. const fileId = this.approvalDocumentFileId;
  384. this.approvalFileIds = fileId ? [fileId] : [];
  385. } catch (error) {
  386. this.form = empty();
  387. this.employeeInfo = {};
  388. if (process.env.NODE_ENV !== 'production') {
  389. console.warn('[RegularizationDetail] 加载转正单失败:', error);
  390. }
  391. } finally {
  392. this.loading = false;
  393. }
  394. }
  395. }
  396. };
  397. </script>
  398. <style lang="scss" scoped>
  399. .regularization-detail {
  400. padding: 8px;
  401. }
  402. .detail-section {
  403. margin-bottom: 16px;
  404. }
  405. .info-card {
  406. border: 1px solid #ebeef5;
  407. border-radius: 4px;
  408. background: #fff;
  409. overflow: hidden;
  410. &__head {
  411. display: flex;
  412. align-items: center;
  413. gap: 6px;
  414. padding: 10px 16px;
  415. font-size: 14px;
  416. font-weight: 600;
  417. color: #303133;
  418. background: #f5f7fa;
  419. border-bottom: 1px solid #ebeef5;
  420. i {
  421. font-size: 16px;
  422. color: #409eff;
  423. }
  424. }
  425. &__code {
  426. margin-left: auto;
  427. font-size: 12px;
  428. font-weight: normal;
  429. }
  430. }
  431. .info-card__body {
  432. display: flex;
  433. flex-wrap: wrap;
  434. gap: 12px 32px;
  435. padding: 16px;
  436. }
  437. .info-item {
  438. display: flex;
  439. align-items: center;
  440. min-width: 240px;
  441. &__label {
  442. flex-shrink: 0;
  443. width: 90px;
  444. color: #909399;
  445. font-size: 13px;
  446. text-align: right;
  447. padding-right: 8px;
  448. }
  449. &__value {
  450. color: #303133;
  451. font-size: 13px;
  452. font-weight: 500;
  453. }
  454. &__sub {
  455. color: #909399;
  456. font-weight: normal;
  457. margin-left: 4px;
  458. }
  459. }
  460. .regular-form {
  461. padding: 8px 16px 16px;
  462. .form-row {
  463. display: flex;
  464. gap: 16px;
  465. flex-wrap: wrap;
  466. margin-bottom: 4px;
  467. .el-form-item {
  468. flex: 1;
  469. min-width: 320px;
  470. }
  471. &--extended {
  472. .extended-title {
  473. width: 100%;
  474. padding: 10px 0 4px;
  475. color: #e6a23c;
  476. font-size: 13px;
  477. font-weight: 600;
  478. border-top: 1px dashed #ebeef5;
  479. margin-top: 8px;
  480. i {
  481. margin-right: 6px;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. .plain-text {
  488. color: #303133;
  489. font-size: 14px;
  490. line-height: 32px;
  491. }
  492. </style>