323 lines
9.2 KiB
Vue
323 lines
9.2 KiB
Vue
<template>
|
|
<div v-can="permissionCodes.fund.revoke" class="package-operation-edit">
|
|
<t-cell-group v-if="record" title="原资金记录" theme="card" v-entrance-transition>
|
|
<t-cell title="操作类型" :note="getFundOperationText(record.operationType)" />
|
|
<t-cell title="金额">
|
|
<template #note>
|
|
<div class="red" v-text="formatPackageAmount(record.amount)" />
|
|
</template>
|
|
</t-cell>
|
|
<t-cell title="原状态" :note="getRecordStatusText(record)" />
|
|
<t-cell
|
|
title="销售订单详情"
|
|
:arrow="!!record.bizId && canReadSalesOrder"
|
|
@click="toSalesOrder"
|
|
/>
|
|
</t-cell-group>
|
|
<t-form v-if="record" class="form" v-entrance-transition="70">
|
|
<t-form-item label="冲正原因" required-mark>
|
|
<div class="reason">
|
|
<t-textarea
|
|
v-model="reason"
|
|
borderless
|
|
autosize
|
|
maxlength="500"
|
|
placeholder="请输入或选择冲正原因"
|
|
/>
|
|
<t-button
|
|
size="extra-small"
|
|
theme="primary"
|
|
variant="outline"
|
|
@click="openReasonPicker"
|
|
>选择</t-button>
|
|
</div>
|
|
</t-form-item>
|
|
<t-form-item
|
|
label="冲正时间"
|
|
content-align="right"
|
|
>
|
|
<div class="time-actions">
|
|
<t-button
|
|
theme="primary"
|
|
variant="outline"
|
|
size="extra-small"
|
|
:content="occurredAtText || '此刻'"
|
|
@click="openOccurredAtPicker"
|
|
/>
|
|
<t-button
|
|
v-if="occurredAtText"
|
|
theme="primary"
|
|
variant="text"
|
|
size="extra-small"
|
|
content="此刻"
|
|
@click="resetOccurredAt"
|
|
/>
|
|
</div>
|
|
</t-form-item>
|
|
<t-form-item label="备注">
|
|
<t-textarea
|
|
v-model="remark"
|
|
borderless
|
|
autosize
|
|
maxlength="500"
|
|
placeholder="备注(可选)"
|
|
/>
|
|
</t-form-item>
|
|
<div class="photo-wrap">
|
|
<media-selector
|
|
v-if="record"
|
|
:model-value="photoUrlList"
|
|
v-model:photo-items="photoItems"
|
|
:upload="uploadPhotoList"
|
|
:edit-mode="true"
|
|
required
|
|
title="冲正凭证照片"
|
|
/>
|
|
</div>
|
|
</t-form>
|
|
<t-empty v-if="!record" :description="isLoading ? '正在加载资金记录' : '资金记录不存在'" />
|
|
<t-popup v-model="reasonPickerVisible" placement="bottom">
|
|
<t-picker
|
|
v-if="reasonPickerVisible"
|
|
v-model="reasonPickerDraft"
|
|
:columns="reasonPickerColumns"
|
|
title="选择冲正原因"
|
|
@cancel="reasonPickerVisible = false"
|
|
@confirm="confirmReason"
|
|
/>
|
|
</t-popup>
|
|
<t-popup v-model="occurredAtPickerVisible" placement="bottom">
|
|
<t-date-time-picker
|
|
v-if="occurredAtPickerVisible"
|
|
v-model="occurredAtDraftText"
|
|
:start="minimumDateTimeText"
|
|
:mode="['date', 'minute']"
|
|
format="YYYY-MM-DD HH:mm"
|
|
title="冲正时间"
|
|
@cancel="occurredAtPickerVisible = false"
|
|
@confirm="confirmOccurredAt"
|
|
/>
|
|
</t-popup>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { Time } from "timi-web";
|
|
import { useUserStore, type Attachment } from "timi-web-api";
|
|
import SalesOrderAPI from "@/api/SalesOrderAPI";
|
|
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
|
|
import { useNavBarStore } from "@/store/navBarStore";
|
|
import type { FundRecord } from "@/types/SalesOrder";
|
|
import type { PhotoItem } from "@/types/Photo";
|
|
import { createPackageRequestNo, formatPackageAmount } from "@/utils/package";
|
|
import { getFundOperationText, getFundStatusText } from "@/utils/salesOrder";
|
|
import { getErrorMessage } from "@/utils/error";
|
|
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
|
import { Message } from "@/utils/message";
|
|
import { permissionCodes } from "@/utils/permission";
|
|
import { uploadPhotoList } from "@/utils/photo";
|
|
|
|
defineOptions({ name: "FundRecordRevoke" });
|
|
|
|
const route = useRoute();
|
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
|
const navBarStore = useNavBarStore();
|
|
const record = ref<FundRecord>();
|
|
const reason = ref("");
|
|
const remark = ref("");
|
|
const occurredAtText = ref("");
|
|
const occurredAtDraftText = ref("");
|
|
const occurredAtPickerVisible = ref(false);
|
|
const reasonPickerDraft = ref<string[]>([]);
|
|
const reasonPickerVisible = ref(false);
|
|
const photoItems = ref<PhotoItem[]>([]);
|
|
const isLoading = ref(false);
|
|
const isSaving = ref(false);
|
|
const requestNo = ref("");
|
|
const photoUrlList = computed(() => photoItems.value.map(item => item.url));
|
|
const canReadSalesOrder = computed(() => userStore.hasPermissions(permissionCodes.salesOrder.read));
|
|
const reasonOptions = [
|
|
"客户申请撤销本次资金操作",
|
|
"收款金额填写有误",
|
|
"退款金额填写有误",
|
|
"资金操作重复",
|
|
"资金操作有误",
|
|
"订单信息有误"
|
|
];
|
|
const reasonPickerColumns = reasonOptions.map(item => ({ label: item, value: item }));
|
|
|
|
const minimumDateTimeText = "1970-01-01 00:00";
|
|
|
|
function openOccurredAtPicker(): void {
|
|
occurredAtDraftText.value = occurredAtText.value || Time.formatDateTime(new Date());
|
|
occurredAtPickerVisible.value = true;
|
|
}
|
|
|
|
function confirmOccurredAt(value?: string | number): void {
|
|
occurredAtText.value = String(value || occurredAtDraftText.value);
|
|
occurredAtPickerVisible.value = false;
|
|
}
|
|
|
|
function resetOccurredAt(): void {
|
|
occurredAtText.value = "";
|
|
occurredAtDraftText.value = "";
|
|
}
|
|
|
|
function openReasonPicker(): void {
|
|
const currentReason = reasonOptions.includes(reason.value.trim()) ? reason.value.trim() : reasonOptions[0];
|
|
reasonPickerDraft.value = [currentReason];
|
|
reasonPickerVisible.value = true;
|
|
}
|
|
|
|
function confirmReason(value: Array<string | number>): void {
|
|
reason.value = String(value[0] || reasonPickerDraft.value[0] || "");
|
|
reasonPickerVisible.value = false;
|
|
}
|
|
|
|
function buildOccurredAt(): number {
|
|
return Time.toTimestamp(parseDateTime(occurredAtText.value));
|
|
}
|
|
|
|
function getRecordStatusText(recordValue: FundRecord): string {
|
|
return recordValue.revokeRecordId ? "已被冲正" : getFundStatusText(recordValue.status);
|
|
}
|
|
|
|
function parseDateTime(value: string): Date {
|
|
if (!value) {
|
|
return new Date();
|
|
}
|
|
|
|
const [dateText, timeText = "00:00"] = value.split(" ");
|
|
const [year, month, day] = dateText.split("-").map(Number);
|
|
const [hour, minute] = timeText.split(":").map(Number);
|
|
return new Date(year, month - 1, day, hour || 0, minute || 0, 0, 0);
|
|
}
|
|
|
|
function buildAttachments(): Partial<Attachment>[] {
|
|
return photoItems.value.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
|
|
}
|
|
|
|
async function loadData(): Promise<void> {
|
|
const id = String(route.params.id || "");
|
|
if (!id) {
|
|
return;
|
|
}
|
|
isLoading.value = true;
|
|
try {
|
|
record.value = await SalesOrderAPI.fundRecordDetail(id);
|
|
} catch (error) {
|
|
Message.error(getErrorMessage(error, "资金记录加载失败"));
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
// ---------- 订单详情 ----------
|
|
|
|
async function toSalesOrder(): Promise<void> {
|
|
if (!record.value?.bizId || !canReadSalesOrder.value) {
|
|
return;
|
|
}
|
|
await router.push({
|
|
path: `/management/sales-orders/${record.value.bizId}`,
|
|
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
|
|
});
|
|
}
|
|
|
|
function getCurrentRouteDepth(): number {
|
|
const transitionDepth = Array.isArray(route.query.transitionDepth)
|
|
? route.query.transitionDepth[0]
|
|
: route.query.transitionDepth;
|
|
const depth = Number(transitionDepth);
|
|
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
|
|
return depth;
|
|
}
|
|
return Number(route.meta.depth ?? 0);
|
|
}
|
|
|
|
async function save(): Promise<void> {
|
|
if (isSaving.value) {
|
|
return;
|
|
}
|
|
if (!record.value?.id || record.value.revokeRecordId || record.value.status !== "VERIFIED" || record.value.operationType === "REVOKE") {
|
|
Message.warning("只有已核销、未被冲正且不是冲正记录的资金记录可以冲正");
|
|
return;
|
|
}
|
|
if (!reason.value.trim()) {
|
|
Message.warning("请输入冲正原因");
|
|
return;
|
|
}
|
|
if (!photoItems.value.some(item => item.tempFileId)) {
|
|
Message.warning("资金冲正必须上传至少一张照片");
|
|
return;
|
|
}
|
|
isSaving.value = true;
|
|
try {
|
|
if (!requestNo.value) {
|
|
requestNo.value = createPackageRequestNo();
|
|
}
|
|
const result = await SalesOrderAPI.revokeFund({
|
|
requestNo: requestNo.value,
|
|
fundRecordId: record.value.id,
|
|
occurredAt: buildOccurredAt(),
|
|
reason: reason.value.trim(),
|
|
attachmentList: buildAttachments(),
|
|
remark: remark.value.trim() || null
|
|
});
|
|
emitListDataChanged(listDataEventKeys.salesOrderChanged, record.value.bizId);
|
|
Message.success("资金记录已冲正");
|
|
if (record.value.bizId) {
|
|
await router.replace(`/management/sales-orders/${record.value.bizId}`);
|
|
return;
|
|
}
|
|
await router.replace(`/management/fund-records/${result.id || record.value.id}`);
|
|
} catch (error) {
|
|
Message.error(getErrorMessage(error, "资金冲正失败,请刷新后确认状态"));
|
|
} finally {
|
|
isSaving.value = false;
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
if (userStore.hasPermissions(permissionCodes.fund.revoke)) {
|
|
navBarStore.setRightText("提交", "var(--td-error-color)", save);
|
|
}
|
|
await loadData();
|
|
});
|
|
|
|
onUnmounted(() => navBarStore.clearRight());
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.package-operation-edit {
|
|
gap: 1rem;
|
|
padding: calc(var(--app-nav-height) + 1rem) 0 2rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
|
|
.reason {
|
|
gap: .5rem;
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: flex-start;
|
|
|
|
.t-textarea {
|
|
min-width: 0;
|
|
flex: 1;
|
|
}
|
|
}
|
|
|
|
.time-actions {
|
|
gap: .5rem;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: flex-end;
|
|
}
|
|
|
|
.photo-wrap {
|
|
padding: 1rem;
|
|
}
|
|
}
|
|
</style>
|