form.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. <template>
  2. <view class="page-no-tab">
  3. <view class="form-intro">
  4. <ModuleIcon :icon="config.icon" :color="config.color" soft />
  5. <view><text class="intro-title">{{ config.title }}</text><text class="intro-sub">{{ config.subtitle }}</text>
  6. </view>
  7. </view>
  8. <view class="steps">
  9. <view class="step active">
  10. <view>1</view><text>填写申请</text>
  11. </view>
  12. <view class="step-line"></view>
  13. <view class="step">
  14. <view>2</view><text>主管审批</text>
  15. </view>
  16. <view class="step-line"></view>
  17. <view class="step">
  18. <view>3</view><text>完成</text>
  19. </view>
  20. </view>
  21. <view class="form-card card section">
  22. <view class="field"><text class="label">申请人</text>
  23. <view class="readonly">
  24. <view class="avatar small-avatar">{{ currentUser.initials }}</view><text>{{ currentUser.name }} · {{
  25. currentUser.department }}</text>
  26. </view>
  27. </view>
  28. <view class="divider"></view>
  29. <view v-if="type === 'leave'" class="field press" @click="chooseLeave"><text
  30. class="label required">请假类型</text><text :class="form.leaveType ? 'value' : 'placeholder'">{{
  31. form.leaveType || "请选择"
  32. }}</text><text class="arrow">›</text></view>
  33. <view v-if="type === 'certificate'" class="field press" @click="chooseCertificate"><text
  34. class="label required">证明类型</text><text :class="form.certificateType ? 'value' : 'placeholder'">{{
  35. form.certificateType || "请选择"
  36. }}</text><text class="arrow">›</text></view>
  37. <view v-if="type === 'check'" class="field"><text class="label required">补卡日期</text>
  38. <picker mode="date" :value="form.startDate" @change="(e) => (form.startDate = e.detail.value)"><text
  39. class="value">{{ form.startDate }}</text></picker><text class="arrow">›</text>
  40. </view>
  41. <view v-if="type === 'check'" class="divider"></view>
  42. <view v-if="type === 'check'" class="field press" @click="chooseRepairType"><text
  43. class="label required">补卡类型</text><text :class="form.repairType ? 'value' : 'placeholder'">{{
  44. repairTypeLabel
  45. }}</text><text class="arrow">›</text></view>
  46. <view v-if="type === 'check'" class="divider"></view>
  47. <view v-if="type === 'check'" class="field"><text class="label required">打卡时间</text>
  48. <picker mode="time" :value="form.repairTime" @change="(e) => (form.repairTime = e.detail.value)"><text
  49. class="value">{{ form.repairTime || "请选择" }}</text></picker><text class="arrow">›</text>
  50. </view>
  51. <template v-if="!['certificate', 'check', 'resign'].includes(type)">
  52. <view class="field"><text class="label required">开始日期</text>
  53. <picker mode="date" :value="form.startDate" @change="(e) => (form.startDate = e.detail.value)"><text
  54. class="value">{{ form.startDate }}</text></picker><text class="arrow">›</text>
  55. </view>
  56. <view class="divider"></view>
  57. <view class="field"><text class="label required">开始时间</text>
  58. <picker mode="time" :value="form.startTime" @change="(e) => (form.startTime = e.detail.value)"><text
  59. class="value">{{ form.startTime || "请选择" }}</text></picker><text class="arrow">›</text>
  60. </view>
  61. <view class="divider"></view>
  62. <view class="field"><text class="label required">结束日期</text>
  63. <picker mode="date" :value="form.endDate" @change="(e) => (form.endDate = e.detail.value)"><text
  64. class="value">{{ form.endDate }}</text></picker><text class="arrow">›</text>
  65. </view>
  66. <view class="divider"></view>
  67. <view class="field"><text class="label required">结束时间</text>
  68. <picker mode="time" :value="form.endTime" @change="(e) => (form.endTime = e.detail.value)"><text
  69. class="value">{{ form.endTime || "请选择" }}</text></picker><text class="arrow">›</text>
  70. </view>
  71. </template>
  72. <view class="divider"></view>
  73. <template v-if="type === 'resign'">
  74. <view class="field press" @click="chooseResignType"><text
  75. class="label required">离职类型</text><text :class="form.resignType ? 'value' : 'placeholder'">{{
  76. form.resignType || "请选择"
  77. }}</text><text class="arrow">›</text></view>
  78. <view class="divider"></view>
  79. <view class="field press" @click="chooseResignReason"><text
  80. class="label required">离职原因</text><text :class="form.resignReason ? 'value' : 'placeholder'">{{
  81. form.resignReason || "请选择"
  82. }}</text><text class="arrow">›</text></view>
  83. <view class="divider"></view>
  84. <view class="field"><text class="label required">预计离职日期</text>
  85. <picker mode="date" :start="todayStr" :value="form.expectedLeaveDate"
  86. @change="(e) => (form.expectedLeaveDate = e.detail.value)"><text
  87. :class="form.expectedLeaveDate ? 'value' : 'placeholder'">{{ form.expectedLeaveDate || "请选择" }}</text></picker><text class="arrow">›</text>
  88. </view>
  89. <view class="divider"></view>
  90. <view class="field"><text class="label">工作交接人</text>
  91. <input class="input-flex" v-model="form.handover" placeholder="请输入交接人姓名" maxlength="20" /></view>
  92. <view class="divider"></view>
  93. <view class="field textarea-field small-textarea"><text class="label">交接备注</text>
  94. <textarea v-model="form.handoverNote" maxlength="200" placeholder="交接事项、文档与客户说明(选填)" /></view>
  95. <view class="divider"></view>
  96. <view class="field check-field"><text class="label">待归还资产</text>
  97. <view class="check-list">
  98. <label v-for="opt in assetReturnOptions" :key="opt" class="check-row press" @click="toggleAssetReturn(opt)">
  99. <view class="checkbox" :class="{ 'is-checked': form.assetReturnList.includes(opt) }">
  100. <text v-if="form.assetReturnList.includes(opt)">✓</text>
  101. </view>
  102. <text>{{ opt }}</text>
  103. </label>
  104. </view>
  105. </view>
  106. <view class="divider"></view>
  107. <view class="field press" @click="chooseCompensation"><text
  108. class="label">补偿方案</text><text :class="form.compensation ? 'value' : 'placeholder'">{{
  109. form.compensation || "请选择"
  110. }}</text><text class="arrow">›</text></view>
  111. <view class="divider"></view>
  112. <view class="field switch-field"><text class="label">开具离职证明</text>
  113. <switch :checked="form.needCertificate" @change="(e) => (form.needCertificate = e.detail.value)" color="#1677ff" />
  114. </view>
  115. <view class="divider"></view>
  116. </template>
  117. <view class="field textarea-field"><text class="label"
  118. :class="{ required: type !== 'certificate' }">申请事由</text><textarea v-model="form.reason" maxlength="200"
  119. :placeholder="reasonPlaceholder" /><text class="counter">{{ form.reason.length }}/200</text></view>
  120. </view>
  121. <view class="form-card card section">
  122. <view class="field"><text class="label">附件</text>
  123. <view class="upload press" @click="chooseImage"><text class="plus">+</text><text>拍照或上传</text></view>
  124. <view v-if="attachmentSummary" class="file-name">{{ attachmentSummary }}</view>
  125. </view>
  126. <view class="divider"></view>
  127. <view class="field"><text class="label">审批人</text>
  128. <view class="approver approver-auto">
  129. <view class="avatar approve-avatar auto">{{ managerInitial }}</view>
  130. <template v-if="currentUser.managerName">
  131. <text>{{ currentUser.managerName }}</text>
  132. </template>
  133. <template v-else>
  134. <text>系统自动匹配</text>
  135. </template>
  136. </view>
  137. </view>
  138. </view>
  139. <view class="bottom-action safe-bottom"><button class="draft-btn" @click="saveDraft">存草稿</button><button
  140. class="submit-btn" @click="submit">提交申请</button></view>
  141. </view>
  142. </template>
  143. <script setup>
  144. import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
  145. import { onLoad, onShow } from "@dcloudio/uni-app";
  146. import ModuleIcon from "@/components/ModuleIcon.vue";
  147. import { applicationTypes } from "@/data/mock";
  148. import { useAuthGuard } from "@/hooks/useAuthGuard";
  149. import { useCurrentUser } from "@/hooks/useCurrentUser";
  150. import {
  151. addApplication,
  152. getDraft,
  153. removeDraft,
  154. saveDraft as persistDraft,
  155. } from "@/utils/storage";
  156. import {
  157. ATTENDANCE_APPLY_TYPE_MAP,
  158. REPAIR_TYPE_LABEL,
  159. REPAIR_TYPE_OPTIONS,
  160. buildAttendancePayload,
  161. submitAttendanceApplication,
  162. } from "@/api/attendance";
  163. import {
  164. buildResignationPayload,
  165. registerSubmittedResignation,
  166. submitResignationApplication,
  167. } from "@/api/resign";
  168. import { uploadAttachment } from "@/api/file";
  169. import { getServerConfig } from "@/utils/auth";
  170. const type = ref("leave");
  171. useAuthGuard();
  172. const currentUser = useCurrentUser();
  173. // 今天日期(在 reactive() 之前声明,供初始默认值使用)
  174. const todayStr = new Date().toISOString().slice(0, 10);
  175. const form = reactive({
  176. leaveType: "",
  177. certificateType: "",
  178. startDate: todayStr,
  179. startTime: "08:30",
  180. endDate: todayStr,
  181. endTime: "17:30",
  182. reason: "",
  183. attachments: [],
  184. repairType: "",
  185. repairTime: "",
  186. resignType: "",
  187. resignReason: "",
  188. expectedLeaveDate: "",
  189. handover: "",
  190. handoverNote: "",
  191. assetReturnList: [],
  192. compensation: "",
  193. needCertificate: true,
  194. });
  195. const config = computed(
  196. () => applicationTypes[type.value] || applicationTypes.leave,
  197. );
  198. const reasonPlaceholder = computed(() =>
  199. type.value === "certificate"
  200. ? "请填写证明用途(选填)"
  201. : type.value === "check"
  202. ? "请说明补卡原因(如:临时接待客户忘记打卡)"
  203. : "请简要说明申请原因",
  204. );
  205. // 审批人头像首字:服务器模式下展示主管姓名首字;演示模式无 managerName 兜底为 '·'
  206. const managerInitial = computed(() => {
  207. const name = currentUser && currentUser.managerName ? String(currentUser.managerName) : "";
  208. return name ? name.charAt(0) : "·";
  209. });
  210. const repairTypeLabel = computed(() =>
  211. form.repairType ? REPAIR_TYPE_LABEL[form.repairType] : "请选择",
  212. );
  213. const attachmentSummary = computed(() => {
  214. const list = Array.isArray(form.attachments) ? form.attachments : [];
  215. if (!list.length) return "";
  216. const uploading = list.filter((a) => a && a.status === "uploading").length;
  217. const failed = list.filter((a) => a && a.status === "failed").length;
  218. const parts = [`已选择 ${list.length} 张图片`];
  219. if (uploading) parts.push(`${uploading} 上传中`);
  220. if (failed) parts.push(`${failed} 失败`);
  221. return parts.join(" · ");
  222. });
  223. function syncType(o = {}) {
  224. const next = o.type || "leave";
  225. if (type.value !== next) resetForm();
  226. type.value = next;
  227. uni.setNavigationBarTitle({ title: config.value.title });
  228. const draft = getDraft(next);
  229. if (draft) Object.assign(form, draft);
  230. // 草稿兼容:
  231. // - 老草稿没有 startTime / endTime 字段 → 兜底默认值,避免 validate 误报
  232. // - 老草稿字段叫 attachment(字符串)→ 已不在 form 上,忽略
  233. // - 老格式(新字段 attachments)但值为字符串数组(重命名前的中间态)→ 清空让用户重选
  234. // - 跨会话遗留的 uploading 状态 → 视为失败(upload 早已中断)
  235. if (!form.startTime) form.startTime = "08:30";
  236. if (!form.endTime) form.endTime = "17:30";
  237. // 补卡:兜底老草稿里 startDate 为空的情况(resetForm 已默认填今天)
  238. if (next === "check" && !form.startDate) form.startDate = todayStr;
  239. if (!Array.isArray(form.attachments)) {
  240. form.attachments = [];
  241. } else if (form.attachments.some((a) => typeof a === "string")) {
  242. form.attachments = [];
  243. } else {
  244. form.attachments = form.attachments.map((a) =>
  245. a && a.status === "uploading"
  246. ? { ...a, status: "failed", error: "上次会话未完成" }
  247. : a,
  248. );
  249. }
  250. }
  251. onLoad(syncType);
  252. onShow(() => {
  253. const pages = getCurrentPages();
  254. syncType(pages[pages.length - 1]?.options || {});
  255. });
  256. function syncHash() {
  257. if (typeof location === "undefined") return;
  258. const match = location.hash.match(/[?&]type=([^&]+)/);
  259. if (match) syncType({ type: decodeURIComponent(match[1]) });
  260. }
  261. onMounted(() => {
  262. syncHash();
  263. if (typeof window !== "undefined")
  264. window.addEventListener("hashchange", syncHash);
  265. });
  266. onBeforeUnmount(() => {
  267. if (typeof window !== "undefined")
  268. window.removeEventListener("hashchange", syncHash);
  269. });
  270. function resetForm() {
  271. Object.assign(form, {
  272. leaveType: "",
  273. certificateType: "",
  274. startDate: todayStr,
  275. startTime: "08:30",
  276. endDate: todayStr,
  277. endTime: "17:30",
  278. reason: "",
  279. attachments: [],
  280. repairType: "",
  281. repairTime: "",
  282. resignType: "",
  283. resignReason: "",
  284. expectedLeaveDate: "",
  285. handover: "",
  286. handoverNote: "",
  287. assetReturnList: [],
  288. compensation: "",
  289. needCertificate: true,
  290. });
  291. }
  292. function chooseLeave() {
  293. uni.showActionSheet({
  294. itemList: ["年假", "事假", "病假", "调休假", "婚假"],
  295. success: (r) =>
  296. (form.leaveType = ["年假", "事假", "病假", "调休假", "婚假"][r.tapIndex]),
  297. });
  298. }
  299. function chooseCertificate() {
  300. uni.showActionSheet({
  301. itemList: ["在职证明", "收入证明", "离职证明"],
  302. success: (r) =>
  303. (form.certificateType = ["在职证明", "收入证明", "离职证明"][r.tapIndex]),
  304. });
  305. }
  306. function chooseRepairType() {
  307. const itemList = REPAIR_TYPE_OPTIONS.map((k) => REPAIR_TYPE_LABEL[k]);
  308. uni.showActionSheet({
  309. itemList,
  310. success: (r) => (form.repairType = REPAIR_TYPE_OPTIONS[r.tapIndex]),
  311. });
  312. }
  313. const assetReturnOptions = ['工牌', '门禁卡', '办公电脑', '测量仪器', '其他'];
  314. function toggleAssetReturn(opt) {
  315. const list = Array.isArray(form.assetReturnList) ? form.assetReturnList : [];
  316. const idx = list.indexOf(opt);
  317. if (idx >= 0) list.splice(idx, 1);
  318. else list.push(opt);
  319. form.assetReturnList = [...list];
  320. }
  321. function chooseResignType() {
  322. const items = ['主动离职', '协商离职', '辞退', '合同到期', '退休'];
  323. uni.showActionSheet({
  324. itemList: items,
  325. success: (r) => (form.resignType = items[r.tapIndex]),
  326. });
  327. }
  328. function chooseResignReason() {
  329. const items = ['个人发展', '家庭原因', '薪资待遇', '职业转型', '公司调整', '健康原因'];
  330. uni.showActionSheet({
  331. itemList: items,
  332. success: (r) => (form.resignReason = items[r.tapIndex]),
  333. });
  334. }
  335. function chooseCompensation() {
  336. const items = ['N+1', 'N', '协商一致', '不适用'];
  337. uni.showActionSheet({
  338. itemList: items,
  339. success: (r) => (form.compensation = items[r.tapIndex]),
  340. });
  341. }
  342. function chooseImage() {
  343. uni.chooseImage({
  344. count: 9,
  345. success: (r) => {
  346. const paths = (r.tempFilePaths || []).filter(Boolean);
  347. if (!paths.length) return;
  348. // 立即把每张图作为 uploading 项加入列表,触发并行上传,
  349. // 状态变化(success/failed)由 Promise 回调直接写回对应条目。
  350. const items = paths.map((p) => ({ localPath: p, status: "uploading" }));
  351. form.attachments = [...form.attachments, ...items];
  352. items.forEach((item) => {
  353. uploadAttachment(item.localPath, "hr_attendance")
  354. .then((file) => {
  355. item.status = "success";
  356. item.id = String(file?.id ?? "");
  357. })
  358. .catch((e) => {
  359. item.status = "failed";
  360. item.error = e?.message || "上传失败";
  361. uni.showToast({ title: item.error, icon: "none" });
  362. });
  363. });
  364. },
  365. });
  366. }
  367. function saveDraft() {
  368. persistDraft(type.value, form);
  369. uni.showToast({ title: "草稿已保存", icon: "success" });
  370. }
  371. function validate() {
  372. if (type.value === "leave" && !form.leaveType) return "请选择请假类型";
  373. if (type.value === "certificate" && !form.certificateType)
  374. return "请选择证明类型";
  375. if (type.value === "check") {
  376. if (!form.startDate) return "请选择补卡日期";
  377. if (!form.repairType) return "请选择补卡类型";
  378. if (!form.repairTime) return "请选择打卡时间";
  379. if (!form.reason) return "请填写补卡原因";
  380. }
  381. if (type.value === "resign") {
  382. if (!form.resignType) return "请选择离职类型";
  383. if (!form.resignReason) return "请选择离职原因";
  384. if (!form.expectedLeaveDate) return "请选择预计离职日期";
  385. if (form.expectedLeaveDate < todayStr) return "预计离职日期不能早于今天";
  386. if (!form.reason) return "请填写申请事由";
  387. return "";
  388. }
  389. if (!["certificate", "check", "resign"].includes(type.value)) {
  390. if (!form.startDate) return "请选择开始日期";
  391. if (!form.endDate) return "请选择结束日期";
  392. if (!form.startTime) return "请选择开始时间";
  393. if (!form.endTime) return "请选择结束时间";
  394. if (form.endDate < form.startDate) return "结束日期不能早于开始日期";
  395. if (form.endDate === form.startDate && form.endTime <= form.startTime)
  396. return "结束时间不能早于或等于开始时间";
  397. }
  398. if (!form.reason && type.value === "certificate") return "";
  399. if (!form.reason && !["certificate", "check", "resign"].includes(type.value))
  400. return "请填写申请事由";
  401. return "";
  402. }
  403. async function submit() {
  404. const error = validate();
  405. if (error) return uni.showToast({ title: error, icon: "none" });
  406. // 服务器模式 + 考勤类申请(请假 / 加班 / 出差 / 外出 / 补卡 / 调班)
  407. // → POST /hr/attendance/applications(附件已在 chooseImage 时上传完成)
  408. if (
  409. ATTENDANCE_APPLY_TYPE_MAP[type.value] &&
  410. getServerConfig().mode === "server"
  411. ) {
  412. try {
  413. // 等待所有进行中的上传完成(chooseImage 触发的后台任务)
  414. const pending = form.attachments.filter(
  415. (a) => a && a.status === "uploading",
  416. );
  417. if (pending.length) {
  418. uni.showLoading({ title: `附件上传中(${pending.length})` });
  419. await Promise.all(
  420. pending.map((item) =>
  421. uploadAttachment(item.localPath, "hr_attendance")
  422. .then((file) => {
  423. item.status = "success";
  424. item.id = String(file?.id ?? "");
  425. })
  426. .catch((e) => {
  427. item.status = "failed";
  428. item.error = e?.message || "上传失败";
  429. throw e;
  430. }),
  431. ),
  432. );
  433. uni.hideLoading();
  434. }
  435. // 有失败的附件就拦截提交
  436. const failed = form.attachments.filter((a) => a && a.status === "failed");
  437. if (failed.length) {
  438. return uni.showToast({
  439. title: `有 ${failed.length} 张附件上传失败,请重新选择`,
  440. icon: "none",
  441. });
  442. }
  443. const attachmentFileIds = form.attachments
  444. .filter((a) => a && a.status === "success" && a.id)
  445. .map((a) => a.id)
  446. .join(",");
  447. uni.showLoading({ title: "提交中..." });
  448. const payload = buildAttendancePayload(
  449. form,
  450. type.value,
  451. currentUser,
  452. attachmentFileIds,
  453. );
  454. if (!payload) {
  455. uni.hideLoading();
  456. return uni.showToast({
  457. title: "申请类型不支持",
  458. icon: "none",
  459. });
  460. }
  461. await submitAttendanceApplication(payload);
  462. uni.hideLoading();
  463. } catch (e) {
  464. uni.hideLoading();
  465. return uni.showToast({
  466. title: e.message || "申请提交失败",
  467. icon: "none",
  468. });
  469. }
  470. }
  471. // 服务器模式 + 离职申请
  472. // → POST /hr/ess/mobile/applications/resignation
  473. // → 部门和申请人由服务端当前任职确定,前端只送表单字段
  474. // → 响应 data 是后端新建单据主键,作为本地申请 id 保持两端一致
  475. let serverApplicationId = null;
  476. if (type.value === "resign") {
  477. try {
  478. uni.showLoading({ title: "提交中..." });
  479. const payload = buildResignationPayload(form);
  480. if (!payload) throw new Error("申请参数为空");
  481. serverApplicationId =
  482. getServerConfig().mode === "server"
  483. ? await submitResignationApplication(payload)
  484. : null;
  485. // 登记离职单:服务器模式记住服务端主键,演示模式落一条本地离职单,
  486. // 使「人事管理 → 离职管理」能直接看到这条申请并继续交接 / 归档
  487. registerSubmittedResignation({ serverId: serverApplicationId, form });
  488. uni.hideLoading();
  489. } catch (e) {
  490. uni.hideLoading();
  491. return uni.showToast({
  492. title: e.message || "离职申请提交失败",
  493. icon: "none",
  494. });
  495. }
  496. }
  497. addApplication({
  498. ...(serverApplicationId ? { id: serverApplicationId } : {}),
  499. type: config.value.title,
  500. summary: summary(),
  501. reason: form.reason || "用于个人材料办理",
  502. color: config.value.color,
  503. metadata: type.value === "resign" ? {
  504. employeeId: currentUser.id,
  505. resignType: form.resignType,
  506. resignReason: form.resignReason,
  507. expectedLeaveDate: form.expectedLeaveDate,
  508. handover: form.handover,
  509. handoverNote: form.handoverNote,
  510. assetReturnList: form.assetReturnList,
  511. compensation: form.compensation,
  512. needCertificate: form.needCertificate,
  513. source: serverApplicationId ? "server" : "demo",
  514. serverId: serverApplicationId || undefined,
  515. } : undefined,
  516. });
  517. removeDraft(type.value);
  518. // 补卡:返回上一页(考勤页),由 onShow 重新拉月度 + 当日详情
  519. if (type.value === "check") {
  520. const pages = getCurrentPages();
  521. if (pages.length > 1) {
  522. uni.showToast({ title: "补卡申请已提交", icon: "success" });
  523. setTimeout(() => uni.navigateBack({ delta: 1 }), 600);
  524. return;
  525. }
  526. }
  527. uni.showModal({
  528. title: "提交成功",
  529. content: currentUser.managerName
  530. ? `申请已提交给${currentUser.managerName}审批,可在“我的申请”中查看进度。`
  531. : "申请已提交,可在“我的申请”中查看审批进度。",
  532. showCancel: false,
  533. success: () => uni.redirectTo({ url: "/pages/apply/list" }),
  534. });
  535. }
  536. function summary() {
  537. if (type.value === "certificate") return form.certificateType || "在职证明";
  538. if (type.value === "check") {
  539. const date = form.startDate || "";
  540. const typeLabel = form.repairType ? REPAIR_TYPE_LABEL[form.repairType] : "补卡";
  541. return `${date} · ${typeLabel} · ${form.repairTime || ""}`;
  542. }
  543. if (type.value === "resign") {
  544. return `${form.resignType} · ${form.expectedLeaveDate}${form.handover ? " · 交接 " + form.handover : ""}`;
  545. }
  546. return `${form.startDate} 至 ${form.endDate}`;
  547. }
  548. </script>
  549. <style scoped lang="scss">
  550. .page-no-tab {
  551. padding-bottom: 140rpx;
  552. }
  553. .form-intro {
  554. padding: 30rpx 30rpx 22rpx;
  555. display: flex;
  556. align-items: center;
  557. background: #fff;
  558. }
  559. .form-intro>view:last-child {
  560. margin-left: 22rpx;
  561. }
  562. .intro-title {
  563. display: block;
  564. font-size: 32rpx;
  565. font-weight: 600;
  566. }
  567. .intro-sub {
  568. display: block;
  569. margin-top: 9rpx;
  570. color: #8b939f;
  571. font-size: 23rpx;
  572. }
  573. .steps {
  574. height: 128rpx;
  575. padding: 18rpx 70rpx 12rpx;
  576. display: flex;
  577. align-items: flex-start;
  578. background: #fff;
  579. border-top: 1rpx solid #f2f3f5;
  580. }
  581. .step {
  582. width: 92rpx;
  583. text-align: center;
  584. color: #a0a7b0;
  585. font-size: 20rpx;
  586. }
  587. .step>view {
  588. width: 42rpx;
  589. height: 42rpx;
  590. margin: 0 auto 8rpx;
  591. border-radius: 50%;
  592. background: #e8eaed;
  593. color: #8b939f;
  594. line-height: 42rpx;
  595. }
  596. .step.active {
  597. color: #1677ff;
  598. }
  599. .step.active>view {
  600. background: #1677ff;
  601. color: #fff;
  602. }
  603. .step-line {
  604. flex: 1;
  605. height: 2rpx;
  606. margin-top: 20rpx;
  607. background: #e1e4e8;
  608. }
  609. .form-card {
  610. overflow: hidden;
  611. }
  612. .field {
  613. position: relative;
  614. min-height: 108rpx;
  615. padding: 28rpx 28rpx;
  616. display: flex;
  617. align-items: center;
  618. }
  619. .label {
  620. width: 180rpx;
  621. flex-shrink: 0;
  622. font-size: 28rpx;
  623. }
  624. .required::before {
  625. content: "*";
  626. color: #ee4d4d;
  627. margin-right: 6rpx;
  628. }
  629. .readonly,
  630. .approver {
  631. flex: 1;
  632. display: flex;
  633. align-items: center;
  634. justify-content: flex-end;
  635. font-size: 26rpx;
  636. }
  637. .approver {
  638. justify-content: flex-start;
  639. }
  640. .small-avatar,
  641. .approve-avatar {
  642. width: 52rpx;
  643. height: 52rpx;
  644. margin-right: 14rpx;
  645. font-size: 22rpx;
  646. }
  647. .value {
  648. color: #1f2329;
  649. font-size: 27rpx;
  650. }
  651. .placeholder {
  652. color: #b2b7be;
  653. }
  654. .arrow {
  655. margin-left: 13rpx;
  656. color: #c4c8ce;
  657. font-size: 38rpx;
  658. }
  659. .textarea-field {
  660. display: block;
  661. min-height: 260rpx;
  662. }
  663. .textarea-field .label {
  664. display: block;
  665. width: auto;
  666. margin-bottom: 20rpx;
  667. }
  668. .textarea-field textarea {
  669. width: 100%;
  670. height: 130rpx;
  671. padding: 18rpx;
  672. border-radius: 12rpx;
  673. background: #f6f7f8;
  674. font-size: 27rpx;
  675. }
  676. .counter {
  677. position: absolute;
  678. right: 45rpx;
  679. bottom: 38rpx;
  680. color: #b2b7be;
  681. font-size: 21rpx;
  682. }
  683. .upload {
  684. width: 160rpx;
  685. height: 132rpx;
  686. border: 1rpx dashed #cfd4da;
  687. border-radius: 12rpx;
  688. display: flex;
  689. flex-direction: column;
  690. align-items: center;
  691. justify-content: center;
  692. color: #8b939f;
  693. font-size: 21rpx;
  694. }
  695. .plus {
  696. font-size: 40rpx;
  697. color: #9aa1aa;
  698. }
  699. .file-name {
  700. margin-left: 18rpx;
  701. color: #07a44d;
  702. font-size: 22rpx;
  703. }
  704. .approver-auto .auto {
  705. background: #eef3ff;
  706. color: #6b7c93;
  707. border: 1rpx dashed #b8c4d6;
  708. }
  709. .approver-auto {
  710. color: #8b939f;
  711. }
  712. .bottom-action {
  713. position: fixed;
  714. z-index: 10;
  715. left: 0;
  716. right: 0;
  717. bottom: 0;
  718. height: 120rpx;
  719. padding: 16rpx 24rpx;
  720. display: flex;
  721. gap: 18rpx;
  722. background: #fff;
  723. border-top: 1rpx solid #e8e9eb;
  724. }
  725. .draft-btn,
  726. .submit-btn {
  727. height: 84rpx;
  728. border-radius: 12rpx;
  729. display: flex;
  730. align-items: center;
  731. justify-content: center;
  732. font-size: 30rpx;
  733. }
  734. .draft-btn {
  735. width: 210rpx;
  736. border: 1rpx solid #d7dce2;
  737. color: #4b5563;
  738. }
  739. .submit-btn {
  740. flex: 1;
  741. background: #1677ff;
  742. color: #fff;
  743. }
  744. @media (min-width: 800px) {
  745. .bottom-action {
  746. max-width: 520px;
  747. left: 50%;
  748. transform: translateX(-50%);
  749. }
  750. }
  751. .input-flex {
  752. flex: 1;
  753. text-align: right;
  754. font-size: 27rpx;
  755. color: #1f2329;
  756. padding: 0 6rpx;
  757. }
  758. .small-textarea {
  759. min-height: 180rpx;
  760. }
  761. .small-textarea textarea {
  762. height: 100rpx;
  763. }
  764. .check-field {
  765. display: block;
  766. align-items: flex-start;
  767. }
  768. .check-field .label {
  769. display: block;
  770. width: auto;
  771. margin-bottom: 16rpx;
  772. }
  773. .check-list {
  774. display: flex;
  775. flex-wrap: wrap;
  776. gap: 18rpx 24rpx;
  777. padding-top: 4rpx;
  778. }
  779. .check-row {
  780. display: flex;
  781. align-items: center;
  782. gap: 10rpx;
  783. font-size: 26rpx;
  784. color: #4b5563;
  785. }
  786. .checkbox {
  787. width: 32rpx;
  788. height: 32rpx;
  789. border: 1rpx solid #c4c8ce;
  790. border-radius: 6rpx;
  791. display: flex;
  792. align-items: center;
  793. justify-content: center;
  794. font-size: 22rpx;
  795. color: #fff;
  796. background: #fff;
  797. box-sizing: border-box;
  798. }
  799. .checkbox.is-checked {
  800. background: #1677ff;
  801. border-color: #1677ff;
  802. }
  803. .switch-field {
  804. justify-content: space-between;
  805. }
  806. </style>