| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- <template>
- <view class="page-no-tab">
- <view class="form-intro"
- ><ModuleIcon :icon="config.icon" :color="config.color" soft /><view
- ><text class="intro-title">{{ config.title }}</text
- ><text class="intro-sub">{{ config.subtitle }}</text></view
- ></view
- >
- <view class="steps"
- ><view class="step active"><view>1</view><text>填写申请</text></view
- ><view class="step-line"></view
- ><view class="step"><view>2</view><text>主管审批</text></view
- ><view class="step-line"></view
- ><view class="step"><view>3</view><text>完成</text></view></view
- >
- <view class="form-card card section">
- <view class="field"
- ><text class="label">申请人</text
- ><view class="readonly"
- ><view class="avatar small-avatar">{{ currentUser.initials }}</view
- ><text
- >{{ currentUser.name }} · {{ currentUser.department }}</text
- ></view
- ></view
- >
- <view class="divider"></view>
- <view v-if="type === 'leave'" class="field press" @click="chooseLeave"
- ><text class="label required">请假类型</text
- ><text :class="form.leaveType ? 'value' : 'placeholder'">{{
- form.leaveType || "请选择"
- }}</text
- ><text class="arrow">›</text></view
- >
- <view
- v-if="type === 'certificate'"
- class="field press"
- @click="chooseCertificate"
- ><text class="label required">证明类型</text
- ><text :class="form.certificateType ? 'value' : 'placeholder'">{{
- form.certificateType || "请选择"
- }}</text
- ><text class="arrow">›</text></view
- >
- <view v-if="type === 'check'" class="field"
- ><text class="label required">补卡时间</text
- ><picker
- mode="date"
- :value="form.startDate"
- @change="(e) => (form.startDate = e.detail.value)"
- ><text class="value">{{ form.startDate }}</text></picker
- ><text class="arrow">›</text></view
- >
- <template v-if="!['certificate', 'check'].includes(type)"
- ><view class="field"
- ><text class="label required">开始日期</text
- ><picker
- mode="date"
- :value="form.startDate"
- @change="(e) => (form.startDate = e.detail.value)"
- ><text class="value">{{ form.startDate }}</text></picker
- ><text class="arrow">›</text></view
- ><view class="divider"></view
- ><view class="field"
- ><text class="label required">结束日期</text
- ><picker
- mode="date"
- :value="form.endDate"
- @change="(e) => (form.endDate = e.detail.value)"
- ><text class="value">{{ form.endDate }}</text></picker
- ><text class="arrow">›</text></view
- ></template
- >
- <view class="divider"></view>
- <view class="field textarea-field"
- ><text class="label" :class="{ required: type !== 'certificate' }"
- >申请事由</text
- ><textarea
- v-model="form.reason"
- maxlength="200"
- :placeholder="reasonPlaceholder"
- /><text class="counter">{{ form.reason.length }}/200</text></view
- >
- </view>
- <view class="form-card card section"
- ><view class="field"
- ><text class="label">附件</text
- ><view class="upload press" @click="chooseImage"
- ><text class="plus">+</text><text>拍照或上传</text></view
- ><view v-if="form.attachment" class="file-name"
- >已选择 1 张图片</view
- ></view
- ><view class="divider"></view
- ><view class="field"
- ><text class="label">审批人</text
- ><view class="approver"
- ><view class="avatar approve-avatar">宋</view><text>宋慧敏</text
- ><text class="muted">(直属主管)</text></view
- ></view
- ></view
- >
- <view class="bottom-action safe-bottom"
- ><button class="draft-btn" @click="saveDraft">存草稿</button
- ><button class="submit-btn" @click="submit">提交申请</button></view
- >
- </view>
- </template>
- <script setup>
- import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
- import { onLoad, onShow } from "@dcloudio/uni-app";
- import ModuleIcon from "@/components/ModuleIcon.vue";
- import { applicationTypes, currentUser } from "@/data/mock";
- import {
- addApplication,
- getDraft,
- removeDraft,
- saveDraft as persistDraft,
- } from "@/utils/storage";
- const type = ref("leave");
- const form = reactive({
- leaveType: "",
- certificateType: "",
- startDate: "2026-08-06",
- endDate: "2026-08-06",
- reason: "",
- attachment: "",
- });
- const config = computed(
- () => applicationTypes[type.value] || applicationTypes.leave,
- );
- const reasonPlaceholder = computed(() =>
- type.value === "certificate"
- ? "请填写证明用途(选填)"
- : "请简要说明申请原因",
- );
- function syncType(o = {}) {
- const next = o.type || "leave";
- if (type.value !== next) resetForm();
- type.value = next;
- uni.setNavigationBarTitle({ title: config.value.title });
- const draft = getDraft(next);
- if (draft) Object.assign(form, draft);
- }
- onLoad(syncType);
- onShow(() => {
- const pages = getCurrentPages();
- syncType(pages[pages.length - 1]?.options || {});
- });
- function syncHash() {
- if (typeof location === "undefined") return;
- const match = location.hash.match(/[?&]type=([^&]+)/);
- if (match) syncType({ type: decodeURIComponent(match[1]) });
- }
- onMounted(() => {
- syncHash();
- if (typeof window !== "undefined")
- window.addEventListener("hashchange", syncHash);
- });
- onBeforeUnmount(() => {
- if (typeof window !== "undefined")
- window.removeEventListener("hashchange", syncHash);
- });
- function resetForm() {
- Object.assign(form, {
- leaveType: "",
- certificateType: "",
- startDate: "2026-08-06",
- endDate: "2026-08-06",
- reason: "",
- attachment: "",
- });
- }
- function chooseLeave() {
- uni.showActionSheet({
- itemList: ["年假", "事假", "病假", "调休假", "婚假"],
- success: (r) =>
- (form.leaveType = ["年假", "事假", "病假", "调休假", "婚假"][r.tapIndex]),
- });
- }
- function chooseCertificate() {
- uni.showActionSheet({
- itemList: ["在职证明", "收入证明", "离职证明"],
- success: (r) =>
- (form.certificateType = ["在职证明", "收入证明", "离职证明"][r.tapIndex]),
- });
- }
- function chooseImage() {
- uni.chooseImage({
- count: 1,
- success: (r) => (form.attachment = r.tempFilePaths[0]),
- });
- }
- function saveDraft() {
- persistDraft(type.value, form);
- uni.showToast({ title: "草稿已保存", icon: "success" });
- }
- function validate() {
- if (type.value === "leave" && !form.leaveType) return "请选择请假类型";
- if (type.value === "certificate" && !form.certificateType)
- return "请选择证明类型";
- if (form.endDate < form.startDate) return "结束日期不能早于开始日期";
- if (!form.reason && type.value !== "certificate") return "请填写申请事由";
- return "";
- }
- function submit() {
- const error = validate();
- if (error) return uni.showToast({ title: error, icon: "none" });
- addApplication({
- type: config.value.title,
- summary: summary(),
- reason: form.reason || "用于个人材料办理",
- color: config.value.color,
- });
- removeDraft(type.value);
- uni.showModal({
- title: "提交成功",
- content: "申请已提交给宋慧敏审批,可在“我的申请”中查看进度。",
- showCancel: false,
- success: () => uni.redirectTo({ url: "/pages/apply/list" }),
- });
- }
- function summary() {
- if (type.value === "certificate") return form.certificateType || "在职证明";
- if (type.value === "check") return `${form.startDate} · 补卡`;
- return `${form.startDate} 至 ${form.endDate}`;
- }
- </script>
- <style scoped lang="scss">
- .form-intro {
- padding: 30rpx 30rpx 22rpx;
- display: flex;
- align-items: center;
- background: #fff;
- }
- .form-intro > view:last-child {
- margin-left: 22rpx;
- }
- .intro-title {
- display: block;
- font-size: 32rpx;
- font-weight: 600;
- }
- .intro-sub {
- display: block;
- margin-top: 9rpx;
- color: #8b939f;
- font-size: 23rpx;
- }
- .steps {
- height: 128rpx;
- padding: 18rpx 70rpx 12rpx;
- display: flex;
- align-items: flex-start;
- background: #fff;
- border-top: 1rpx solid #f2f3f5;
- }
- .step {
- width: 92rpx;
- text-align: center;
- color: #a0a7b0;
- font-size: 20rpx;
- }
- .step > view {
- width: 42rpx;
- height: 42rpx;
- margin: 0 auto 8rpx;
- border-radius: 50%;
- background: #e8eaed;
- color: #8b939f;
- line-height: 42rpx;
- }
- .step.active {
- color: #1677ff;
- }
- .step.active > view {
- background: #1677ff;
- color: #fff;
- }
- .step-line {
- flex: 1;
- height: 2rpx;
- margin-top: 20rpx;
- background: #e1e4e8;
- }
- .form-card {
- overflow: hidden;
- }
- .field {
- position: relative;
- min-height: 108rpx;
- padding: 28rpx 28rpx;
- display: flex;
- align-items: center;
- }
- .label {
- width: 180rpx;
- flex-shrink: 0;
- font-size: 28rpx;
- }
- .required::before {
- content: "*";
- color: #ee4d4d;
- margin-right: 6rpx;
- }
- .readonly,
- .approver {
- flex: 1;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- font-size: 26rpx;
- }
- .small-avatar,
- .approve-avatar {
- width: 52rpx;
- height: 52rpx;
- margin-right: 14rpx;
- font-size: 22rpx;
- }
- .value {
- color: #1f2329;
- font-size: 27rpx;
- }
- .placeholder {
- color: #b2b7be;
- }
- .arrow {
- margin-left: 13rpx;
- color: #c4c8ce;
- font-size: 38rpx;
- }
- .textarea-field {
- display: block;
- min-height: 260rpx;
- }
- .textarea-field .label {
- display: block;
- width: auto;
- margin-bottom: 20rpx;
- }
- .textarea-field textarea {
- width: 100%;
- height: 130rpx;
- padding: 18rpx;
- border-radius: 12rpx;
- background: #f6f7f8;
- font-size: 27rpx;
- }
- .counter {
- position: absolute;
- right: 45rpx;
- bottom: 38rpx;
- color: #b2b7be;
- font-size: 21rpx;
- }
- .upload {
- width: 160rpx;
- height: 132rpx;
- border: 1rpx dashed #cfd4da;
- border-radius: 12rpx;
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- color: #8b939f;
- font-size: 21rpx;
- }
- .plus {
- font-size: 40rpx;
- color: #9aa1aa;
- }
- .file-name {
- margin-left: 18rpx;
- color: #07a44d;
- font-size: 22rpx;
- }
- .bottom-action {
- position: fixed;
- z-index: 10;
- left: 0;
- right: 0;
- bottom: 0;
- height: 120rpx;
- padding: 16rpx 24rpx;
- display: flex;
- gap: 18rpx;
- background: #fff;
- border-top: 1rpx solid #e8e9eb;
- }
- .draft-btn,
- .submit-btn {
- height: 84rpx;
- border-radius: 12rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 30rpx;
- }
- .draft-btn {
- width: 210rpx;
- border: 1rpx solid #d7dce2;
- color: #4b5563;
- }
- .submit-btn {
- flex: 1;
- background: #1677ff;
- color: #fff;
- }
- @media (min-width: 800px) {
- .bottom-action {
- max-width: 520px;
- left: 50%;
- transform: translateX(-50%);
- }
- }
- </style>
|