243 lines
7.5 KiB
Vue
243 lines
7.5 KiB
Vue
<template>
|
|
<bottom-popup
|
|
v-model="visible"
|
|
:title="isRevoke ? '冲正兑换单' : '撤销兑换单'"
|
|
left-button-text="取消"
|
|
:right-button-text="operating ? '提交中' : (isRevoke ? '确认冲正' : '确认撤销')"
|
|
:z-index="popupZIndex"
|
|
:overlay-props="{ zIndex: popupZIndex - 1 }"
|
|
@left-button-click="visible = false"
|
|
@right-button-click="submit"
|
|
>
|
|
<t-form class="action-form" label-width="7.5rem">
|
|
<t-form-item :label="isRevoke ? '冲正原因' : '撤销原因'" :required-mark="isRevoke">
|
|
<div class="reason">
|
|
<t-textarea
|
|
v-model.trim="reason"
|
|
borderless
|
|
autosize
|
|
maxlength="500"
|
|
:placeholder="isRevoke ? '请输入或选择冲正原因' : '可不填'"
|
|
/>
|
|
<t-button
|
|
size="extra-small"
|
|
theme="primary"
|
|
variant="outline"
|
|
@click="openReasonPicker"
|
|
>选择</t-button>
|
|
</div>
|
|
</t-form-item>
|
|
<t-form-item label="回收物退还" required-mark>
|
|
<t-radio-group v-model="recycleReturnedText" variant="default-filled">
|
|
<t-radio value="true" :block="false" borderless>全部退还客户</t-radio>
|
|
<t-radio value="false" :block="false" borderless>不退还</t-radio>
|
|
</t-radio-group>
|
|
</t-form-item>
|
|
<t-form-item v-if="recycleReturnedText === 'true'" label-width="0">
|
|
<span class="tips" v-text="returnTipText" />
|
|
</t-form-item>
|
|
<template v-if="isRevoke && stockEnabled">
|
|
<t-form-item label="商品退回门店" required-mark>
|
|
<t-checkbox v-model="stockReturned" borderless>
|
|
<span v-text="`兑换商品 ${productText} 已退回门店`" />
|
|
</t-checkbox>
|
|
</t-form-item>
|
|
<t-form-item label-width="0">
|
|
<attachment-selector
|
|
v-model:items="photoItems"
|
|
:upload="uploadPhotoList"
|
|
required
|
|
title="退货凭证照片"
|
|
/>
|
|
</t-form-item>
|
|
</template>
|
|
<t-form-item label="备注">
|
|
<t-textarea v-model.trim="remark" borderless autosize maxlength="500" placeholder="可不填" />
|
|
</t-form-item>
|
|
</t-form>
|
|
</bottom-popup>
|
|
<t-popup
|
|
v-model="reasonPickerVisible"
|
|
placement="bottom"
|
|
:z-index="reasonPickerZIndex"
|
|
:overlay-props="{ zIndex: reasonPickerZIndex - 1 }"
|
|
>
|
|
<t-picker
|
|
v-model="reasonPickerDraft"
|
|
:columns="reasonPickerColumns"
|
|
:title="isRevoke ? '选择冲正原因' : '选择撤销原因'"
|
|
@cancel="reasonPickerVisible = false"
|
|
@confirm="confirmReason"
|
|
/>
|
|
</t-popup>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { BottomPopup } from "timi-tdesign-mobile";
|
|
import type { Attachment } from "timi-web-api";
|
|
import RecycleAPI from "@/api/RecycleAPI";
|
|
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
|
|
import type { PhotoItem } from "@/types/Photo";
|
|
import type { RecycleExchange } from "@/types/Recycle";
|
|
import { getErrorMessage } from "@/utils/error";
|
|
import { Message } from "@/utils/message";
|
|
import { uploadPhotoList } from "@/utils/photo";
|
|
import { getRecycleQuantityText } from "@/utils/recycle";
|
|
|
|
defineOptions({ name: "RecycleExchangeActionPopup" });
|
|
|
|
const props = defineProps<{
|
|
exchange: RecycleExchange;
|
|
/** 撤销待核销单;冲正已核销单 */
|
|
action: "CANCEL" | "REVOKE";
|
|
}>();
|
|
const emit = defineEmits<{
|
|
success: [];
|
|
}>();
|
|
const visible = defineModel<boolean>("visible", { default: false });
|
|
|
|
const popupZIndex = 12000;
|
|
const reasonPickerZIndex = popupZIndex + 1;
|
|
const operating = ref(false);
|
|
const reason = ref("");
|
|
const remark = ref("");
|
|
/** 必须显式选择是否退还回收物,用字符串承接单选值 */
|
|
const recycleReturnedText = ref("");
|
|
const stockReturned = ref(false);
|
|
const photoItems = ref<PhotoItem[]>([]);
|
|
const reasonPickerVisible = ref(false);
|
|
const reasonPickerDraft = ref<string[]>([]);
|
|
const requestNo = ref("");
|
|
|
|
const isRevoke = computed(() => props.action === "REVOKE");
|
|
const stockEnabled = computed(() => props.exchange.stockEnabledSnapshot === true);
|
|
const returnTipText = computed(() => `将退回客户 ${getRecycleQuantityText(props.exchange.recycleQuantity, props.exchange.recycleUnitSnapshot)}`);
|
|
const productText = computed(() => props.exchange.productNameSnapshot || props.exchange.skuNameSnapshot || "兑换商品");
|
|
const reasonOptions = computed(() => (isRevoke.value
|
|
? ["兑换商品退回", "兑换数量填写有误", "回收数量填写有误", "重复核销", "操作失误"]
|
|
: ["客户取消兑换", "回收数量填写有误", "兑换数量填写有误", "重复创建兑换单", "回收物与实物不符"]));
|
|
const reasonPickerColumns = computed(() => reasonOptions.value.map(item => ({ label: item, value: item })));
|
|
|
|
function resetForm(): void {
|
|
reason.value = "";
|
|
remark.value = "";
|
|
recycleReturnedText.value = "";
|
|
stockReturned.value = false;
|
|
photoItems.value = [];
|
|
reasonPickerVisible.value = false;
|
|
reasonPickerDraft.value = [];
|
|
requestNo.value = "";
|
|
}
|
|
|
|
function openReasonPicker(): void {
|
|
const currentReason = reasonOptions.value.includes(reason.value) ? reason.value : reasonOptions.value[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 buildAttachments(): Partial<Attachment>[] {
|
|
return photoItems.value.flatMap(item => item.tempFileId ? [{
|
|
tempFileId: item.tempFileId,
|
|
attachType: "PHOTO"
|
|
}] : []);
|
|
}
|
|
|
|
async function submit(): Promise<void> {
|
|
const exchangeId = props.exchange.id;
|
|
if (operating.value || !exchangeId) {
|
|
return;
|
|
}
|
|
if (isRevoke.value && !reason.value.trim()) {
|
|
Message.warning("冲正原因不能为空");
|
|
return;
|
|
}
|
|
if (!recycleReturnedText.value) {
|
|
Message.warning("请选择回收物是否退还客户");
|
|
return;
|
|
}
|
|
const attachmentList = buildAttachments();
|
|
if (isRevoke.value && stockEnabled.value) {
|
|
if (!stockReturned.value) {
|
|
Message.warning("请确认兑换商品已退回门店");
|
|
return;
|
|
}
|
|
if (!attachmentList.length) {
|
|
Message.warning("库存商品冲正必须上传退货凭证照片");
|
|
return;
|
|
}
|
|
}
|
|
// 内容变更后必须换新请求号;失败重试沿用同一个,服务端据此去重
|
|
if (!requestNo.value) {
|
|
requestNo.value = window.crypto.randomUUID();
|
|
}
|
|
operating.value = true;
|
|
try {
|
|
const request = {
|
|
exchangeId,
|
|
requestNo: requestNo.value,
|
|
reason: reason.value.trim() || undefined,
|
|
remark: remark.value || null,
|
|
recycleReturned: recycleReturnedText.value === "true",
|
|
stockReturned: stockReturned.value,
|
|
attachmentList
|
|
};
|
|
if (isRevoke.value) {
|
|
await RecycleAPI.revoke(request);
|
|
} else {
|
|
await RecycleAPI.cancel(request);
|
|
}
|
|
visible.value = false;
|
|
Message.success(isRevoke.value ? "兑换单已冲正" : "兑换单已撤销");
|
|
emit("success");
|
|
} catch (error) {
|
|
Message.error(getErrorMessage(error, `兑换单${isRevoke.value ? "冲正" : "撤销"}失败,重试会复用同一请求号`));
|
|
} finally {
|
|
operating.value = false;
|
|
}
|
|
}
|
|
|
|
watch(visible, value => {
|
|
if (value) {
|
|
resetForm();
|
|
} else {
|
|
reasonPickerVisible.value = false;
|
|
}
|
|
});
|
|
|
|
// 表单任意改动都要作废旧请求号,避免内容变了还撞上服务端的幂等摘要
|
|
watch([reason, remark, recycleReturnedText, stockReturned, photoItems], () => {
|
|
requestNo.value = "";
|
|
}, { deep: true });
|
|
</script>
|
|
|
|
<style scoped lang="less">
|
|
.action-form {
|
|
margin: 0;
|
|
padding-bottom: 1rem;
|
|
|
|
.reason {
|
|
gap: .5rem;
|
|
flex: 1;
|
|
display: flex;
|
|
min-width: 0;
|
|
align-items: flex-start;
|
|
|
|
.t-textarea {
|
|
flex: 1;
|
|
min-width: 0;
|
|
}
|
|
}
|
|
|
|
.tips {
|
|
color: var(--td-text-color-secondary);
|
|
font-size: .8125rem;
|
|
line-height: 1.5;
|
|
}
|
|
}
|
|
</style>
|