form.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view class="page-no-tab">
  3. <view class="form-intro"
  4. ><ModuleIcon :icon="config.icon" :color="config.color" soft /><view
  5. ><text class="intro-title">{{ config.title }}</text
  6. ><text class="intro-sub">{{ config.subtitle }}</text></view
  7. ></view
  8. >
  9. <view class="steps"
  10. ><view class="step active"><view>1</view><text>填写申请</text></view
  11. ><view class="step-line"></view
  12. ><view class="step"><view>2</view><text>主管审批</text></view
  13. ><view class="step-line"></view
  14. ><view class="step"><view>3</view><text>完成</text></view></view
  15. >
  16. <view class="form-card card section">
  17. <view class="field"
  18. ><text class="label">申请人</text
  19. ><view class="readonly"
  20. ><view class="avatar small-avatar">{{ currentUser.initials }}</view
  21. ><text
  22. >{{ currentUser.name }} · {{ currentUser.department }}</text
  23. ></view
  24. ></view
  25. >
  26. <view class="divider"></view>
  27. <view v-if="type === 'leave'" class="field press" @click="chooseLeave"
  28. ><text class="label required">请假类型</text
  29. ><text :class="form.leaveType ? 'value' : 'placeholder'">{{
  30. form.leaveType || "请选择"
  31. }}</text
  32. ><text class="arrow">›</text></view
  33. >
  34. <view
  35. v-if="type === 'certificate'"
  36. class="field press"
  37. @click="chooseCertificate"
  38. ><text class="label required">证明类型</text
  39. ><text :class="form.certificateType ? 'value' : 'placeholder'">{{
  40. form.certificateType || "请选择"
  41. }}</text
  42. ><text class="arrow">›</text></view
  43. >
  44. <view v-if="type === 'check'" class="field"
  45. ><text class="label required">补卡时间</text
  46. ><picker
  47. mode="date"
  48. :value="form.startDate"
  49. @change="(e) => (form.startDate = e.detail.value)"
  50. ><text class="value">{{ form.startDate }}</text></picker
  51. ><text class="arrow">›</text></view
  52. >
  53. <template v-if="!['certificate', 'check'].includes(type)"
  54. ><view class="field"
  55. ><text class="label required">开始日期</text
  56. ><picker
  57. mode="date"
  58. :value="form.startDate"
  59. @change="(e) => (form.startDate = e.detail.value)"
  60. ><text class="value">{{ form.startDate }}</text></picker
  61. ><text class="arrow">›</text></view
  62. ><view class="divider"></view
  63. ><view class="field"
  64. ><text class="label required">结束日期</text
  65. ><picker
  66. mode="date"
  67. :value="form.endDate"
  68. @change="(e) => (form.endDate = e.detail.value)"
  69. ><text class="value">{{ form.endDate }}</text></picker
  70. ><text class="arrow">›</text></view
  71. ></template
  72. >
  73. <view class="divider"></view>
  74. <view class="field textarea-field"
  75. ><text class="label" :class="{ required: type !== 'certificate' }"
  76. >申请事由</text
  77. ><textarea
  78. v-model="form.reason"
  79. maxlength="200"
  80. :placeholder="reasonPlaceholder"
  81. /><text class="counter">{{ form.reason.length }}/200</text></view
  82. >
  83. </view>
  84. <view class="form-card card section"
  85. ><view class="field"
  86. ><text class="label">附件</text
  87. ><view class="upload press" @click="chooseImage"
  88. ><text class="plus">+</text><text>拍照或上传</text></view
  89. ><view v-if="form.attachment" class="file-name"
  90. >已选择 1 张图片</view
  91. ></view
  92. ><view class="divider"></view
  93. ><view class="field"
  94. ><text class="label">审批人</text
  95. ><view class="approver"
  96. ><view class="avatar approve-avatar">宋</view><text>宋慧敏</text
  97. ><text class="muted">(直属主管)</text></view
  98. ></view
  99. ></view
  100. >
  101. <view class="bottom-action safe-bottom"
  102. ><button class="draft-btn" @click="saveDraft">存草稿</button
  103. ><button class="submit-btn" @click="submit">提交申请</button></view
  104. >
  105. </view>
  106. </template>
  107. <script setup>
  108. import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
  109. import { onLoad, onShow } from "@dcloudio/uni-app";
  110. import ModuleIcon from "@/components/ModuleIcon.vue";
  111. import { applicationTypes, currentUser } from "@/data/mock";
  112. import {
  113. addApplication,
  114. getDraft,
  115. removeDraft,
  116. saveDraft as persistDraft,
  117. } from "@/utils/storage";
  118. const type = ref("leave");
  119. const form = reactive({
  120. leaveType: "",
  121. certificateType: "",
  122. startDate: "2026-08-06",
  123. endDate: "2026-08-06",
  124. reason: "",
  125. attachment: "",
  126. });
  127. const config = computed(
  128. () => applicationTypes[type.value] || applicationTypes.leave,
  129. );
  130. const reasonPlaceholder = computed(() =>
  131. type.value === "certificate"
  132. ? "请填写证明用途(选填)"
  133. : "请简要说明申请原因",
  134. );
  135. function syncType(o = {}) {
  136. const next = o.type || "leave";
  137. if (type.value !== next) resetForm();
  138. type.value = next;
  139. uni.setNavigationBarTitle({ title: config.value.title });
  140. const draft = getDraft(next);
  141. if (draft) Object.assign(form, draft);
  142. }
  143. onLoad(syncType);
  144. onShow(() => {
  145. const pages = getCurrentPages();
  146. syncType(pages[pages.length - 1]?.options || {});
  147. });
  148. function syncHash() {
  149. if (typeof location === "undefined") return;
  150. const match = location.hash.match(/[?&]type=([^&]+)/);
  151. if (match) syncType({ type: decodeURIComponent(match[1]) });
  152. }
  153. onMounted(() => {
  154. syncHash();
  155. if (typeof window !== "undefined")
  156. window.addEventListener("hashchange", syncHash);
  157. });
  158. onBeforeUnmount(() => {
  159. if (typeof window !== "undefined")
  160. window.removeEventListener("hashchange", syncHash);
  161. });
  162. function resetForm() {
  163. Object.assign(form, {
  164. leaveType: "",
  165. certificateType: "",
  166. startDate: "2026-08-06",
  167. endDate: "2026-08-06",
  168. reason: "",
  169. attachment: "",
  170. });
  171. }
  172. function chooseLeave() {
  173. uni.showActionSheet({
  174. itemList: ["年假", "事假", "病假", "调休假", "婚假"],
  175. success: (r) =>
  176. (form.leaveType = ["年假", "事假", "病假", "调休假", "婚假"][r.tapIndex]),
  177. });
  178. }
  179. function chooseCertificate() {
  180. uni.showActionSheet({
  181. itemList: ["在职证明", "收入证明", "离职证明"],
  182. success: (r) =>
  183. (form.certificateType = ["在职证明", "收入证明", "离职证明"][r.tapIndex]),
  184. });
  185. }
  186. function chooseImage() {
  187. uni.chooseImage({
  188. count: 1,
  189. success: (r) => (form.attachment = r.tempFilePaths[0]),
  190. });
  191. }
  192. function saveDraft() {
  193. persistDraft(type.value, form);
  194. uni.showToast({ title: "草稿已保存", icon: "success" });
  195. }
  196. function validate() {
  197. if (type.value === "leave" && !form.leaveType) return "请选择请假类型";
  198. if (type.value === "certificate" && !form.certificateType)
  199. return "请选择证明类型";
  200. if (form.endDate < form.startDate) return "结束日期不能早于开始日期";
  201. if (!form.reason && type.value !== "certificate") return "请填写申请事由";
  202. return "";
  203. }
  204. function submit() {
  205. const error = validate();
  206. if (error) return uni.showToast({ title: error, icon: "none" });
  207. addApplication({
  208. type: config.value.title,
  209. summary: summary(),
  210. reason: form.reason || "用于个人材料办理",
  211. color: config.value.color,
  212. });
  213. removeDraft(type.value);
  214. uni.showModal({
  215. title: "提交成功",
  216. content: "申请已提交给宋慧敏审批,可在“我的申请”中查看进度。",
  217. showCancel: false,
  218. success: () => uni.redirectTo({ url: "/pages/apply/list" }),
  219. });
  220. }
  221. function summary() {
  222. if (type.value === "certificate") return form.certificateType || "在职证明";
  223. if (type.value === "check") return `${form.startDate} · 补卡`;
  224. return `${form.startDate} 至 ${form.endDate}`;
  225. }
  226. </script>
  227. <style scoped lang="scss">
  228. .form-intro {
  229. padding: 30rpx 30rpx 22rpx;
  230. display: flex;
  231. align-items: center;
  232. background: #fff;
  233. }
  234. .form-intro > view:last-child {
  235. margin-left: 22rpx;
  236. }
  237. .intro-title {
  238. display: block;
  239. font-size: 32rpx;
  240. font-weight: 600;
  241. }
  242. .intro-sub {
  243. display: block;
  244. margin-top: 9rpx;
  245. color: #8b939f;
  246. font-size: 23rpx;
  247. }
  248. .steps {
  249. height: 128rpx;
  250. padding: 18rpx 70rpx 12rpx;
  251. display: flex;
  252. align-items: flex-start;
  253. background: #fff;
  254. border-top: 1rpx solid #f2f3f5;
  255. }
  256. .step {
  257. width: 92rpx;
  258. text-align: center;
  259. color: #a0a7b0;
  260. font-size: 20rpx;
  261. }
  262. .step > view {
  263. width: 42rpx;
  264. height: 42rpx;
  265. margin: 0 auto 8rpx;
  266. border-radius: 50%;
  267. background: #e8eaed;
  268. color: #8b939f;
  269. line-height: 42rpx;
  270. }
  271. .step.active {
  272. color: #1677ff;
  273. }
  274. .step.active > view {
  275. background: #1677ff;
  276. color: #fff;
  277. }
  278. .step-line {
  279. flex: 1;
  280. height: 2rpx;
  281. margin-top: 20rpx;
  282. background: #e1e4e8;
  283. }
  284. .form-card {
  285. overflow: hidden;
  286. }
  287. .field {
  288. position: relative;
  289. min-height: 108rpx;
  290. padding: 28rpx 28rpx;
  291. display: flex;
  292. align-items: center;
  293. }
  294. .label {
  295. width: 180rpx;
  296. flex-shrink: 0;
  297. font-size: 28rpx;
  298. }
  299. .required::before {
  300. content: "*";
  301. color: #ee4d4d;
  302. margin-right: 6rpx;
  303. }
  304. .readonly,
  305. .approver {
  306. flex: 1;
  307. display: flex;
  308. align-items: center;
  309. justify-content: flex-end;
  310. font-size: 26rpx;
  311. }
  312. .small-avatar,
  313. .approve-avatar {
  314. width: 52rpx;
  315. height: 52rpx;
  316. margin-right: 14rpx;
  317. font-size: 22rpx;
  318. }
  319. .value {
  320. color: #1f2329;
  321. font-size: 27rpx;
  322. }
  323. .placeholder {
  324. color: #b2b7be;
  325. }
  326. .arrow {
  327. margin-left: 13rpx;
  328. color: #c4c8ce;
  329. font-size: 38rpx;
  330. }
  331. .textarea-field {
  332. display: block;
  333. min-height: 260rpx;
  334. }
  335. .textarea-field .label {
  336. display: block;
  337. width: auto;
  338. margin-bottom: 20rpx;
  339. }
  340. .textarea-field textarea {
  341. width: 100%;
  342. height: 130rpx;
  343. padding: 18rpx;
  344. border-radius: 12rpx;
  345. background: #f6f7f8;
  346. font-size: 27rpx;
  347. }
  348. .counter {
  349. position: absolute;
  350. right: 45rpx;
  351. bottom: 38rpx;
  352. color: #b2b7be;
  353. font-size: 21rpx;
  354. }
  355. .upload {
  356. width: 160rpx;
  357. height: 132rpx;
  358. border: 1rpx dashed #cfd4da;
  359. border-radius: 12rpx;
  360. display: flex;
  361. flex-direction: column;
  362. align-items: center;
  363. justify-content: center;
  364. color: #8b939f;
  365. font-size: 21rpx;
  366. }
  367. .plus {
  368. font-size: 40rpx;
  369. color: #9aa1aa;
  370. }
  371. .file-name {
  372. margin-left: 18rpx;
  373. color: #07a44d;
  374. font-size: 22rpx;
  375. }
  376. .bottom-action {
  377. position: fixed;
  378. z-index: 10;
  379. left: 0;
  380. right: 0;
  381. bottom: 0;
  382. height: 120rpx;
  383. padding: 16rpx 24rpx;
  384. display: flex;
  385. gap: 18rpx;
  386. background: #fff;
  387. border-top: 1rpx solid #e8e9eb;
  388. }
  389. .draft-btn,
  390. .submit-btn {
  391. height: 84rpx;
  392. border-radius: 12rpx;
  393. display: flex;
  394. align-items: center;
  395. justify-content: center;
  396. font-size: 30rpx;
  397. }
  398. .draft-btn {
  399. width: 210rpx;
  400. border: 1rpx solid #d7dce2;
  401. color: #4b5563;
  402. }
  403. .submit-btn {
  404. flex: 1;
  405. background: #1677ff;
  406. color: #fff;
  407. }
  408. @media (min-width: 800px) {
  409. .bottom-action {
  410. max-width: 520px;
  411. left: 50%;
  412. transform: translateX(-50%);
  413. }
  414. }
  415. </style>