| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { Get } from "../../../../lib/request/method";
- Component({
- properties: {
- visible: { type: Boolean, value: false },
- goodsName: { type: String, value: "" },
- goodsImage: { type: String, value: "" },
- goodsPrice: { type: String, value: "" },
- goodsMeta1: { type: String, value: "" },
- goodsMeta2: { type: String, value: "" },
- refundReason: { type: String, value: "" },
- refundStatus: { type: String, value: "" },
- refundAmount: { type: Number, value: 0 },
- maxAmount: { type: Number, value: 0 },
- proofImages: { type: Array, value: [] },
- showReceiptStatus: { type: Boolean, value: true },
- },
- data: {
- statusPickerVisible: false,
- statusPickerOptions: [] as Array<{ label: string; value: string }>,
- statusPickerValue: [] as string[],
- statusLabel: "",
- // 退款金额编辑器(整屏弹窗)
- amountEditorVisible: false,
- amountInput: "",
- },
- observers: {
- refundStatus(v: string) {
- const options = (this as any).data?.statusPickerOptions || [];
- const matched = options.find((item: any) => item.value === v);
- if (matched) {
- (this as any).setData({
- statusPickerValue: [v],
- statusLabel: matched.label,
- });
- }
- },
- visible(v: boolean) {
- if (v && (this as any).data?.statusPickerOptions?.length) {
- const currentValue = (this as any).data?.statusPickerValue?.[0];
- if (currentValue) {
- (this as any).triggerEvent("changeStatus", { status: currentValue });
- }
- }
- },
- },
- lifetimes: {
- attached() {
- (this as any).fetchStatusOptions();
- },
- },
- methods: {
- getStatusLabel(value: string): string {
- const options = (this as any).data?.statusPickerOptions || [];
- return options.find((item: any) => item.value === value)?.label || "";
- },
- async fetchStatusOptions() {
- try {
- const res = await Get<any[]>("/dict/getDicts");
- const dict = (res as any)?.data?.find(
- (item: any) => item.dictType === "aftersale_receipt_status"
- );
- if (dict?.items?.length) {
- const options = dict.items.map((item: any) => ({
- label: item.dictLabel,
- value: item.dictValue,
- }));
- // 默认选中最后一个(未收到货)
- const lastOption = options[options.length - 1];
- const current = (this as any).data?.refundStatus;
- const matched = options.find((item: any) => item.value === current);
- const value = matched ? current : lastOption.value;
- const label = matched ? matched.label : lastOption.label;
- (this as any).setData({
- statusPickerOptions: options,
- statusPickerValue: [value],
- statusLabel: label,
- });
- // 回传默认值给父页面
- (this as any).triggerEvent("changeStatus", { status: value });
- }
- } catch {
- wx.showToast({ title: "获取商品状态失败", icon: "none" });
- }
- },
- onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
- if (!e?.detail?.visible) {
- (this as any).triggerEvent("close");
- }
- },
- onAmountPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
- if (!e?.detail?.visible) {
- (this as any).setData({ amountEditorVisible: false });
- }
- },
- onClose() {
- (this as any).triggerEvent("close");
- },
- onOpenStatusPicker() {
- (this as any).setData({ statusPickerVisible: true });
- },
- onStatusPickerChange(e: any) {
- const valueArr = e?.detail?.value as Array<string | number> | undefined;
- const status = String(valueArr?.[0] ?? "");
- (this as any).triggerEvent("changeStatus", { status });
- (this as any).setData({ statusPickerVisible: false });
- },
- onStatusPickerClose() {
- (this as any).setData({ statusPickerVisible: false });
- },
- onEditReason() {
- (this as any).triggerEvent("editReason");
- },
- onEditAmount() {
- const cur = Number((this as any).data?.refundAmount ?? 0);
- (this as any).setData({ amountInput: cur ? String(cur) : "0", amountEditorVisible: true });
- },
- onEditProof() {
- (this as any).triggerEvent("editProof");
- },
- onAmountInput(e: WechatMiniprogram.Input) {
- const raw = e.detail?.value || "";
- // 保留数字与小数点
- const cleaned = raw.replace(/[^\d.]/g, "");
- (this as any).setData({ amountInput: cleaned });
- },
- onAmountClose() {
- (this as any).setData({ amountEditorVisible: false });
- },
- onAmountConfirm() {
- const maxAmount = Number((this as any).data?.maxAmount ?? 0);
- const amount = Number((this as any).data?.amountInput ?? 0);
- if (!amount || Number.isNaN(amount)) {
- wx.showToast({ title: "请输入退款金额", icon: "none" });
- return;
- }
- if (maxAmount && amount > maxAmount) {
- wx.showToast({ title: "不能超过最高可退金额", icon: "none" });
- return;
- }
- const fixed = Number(amount.toFixed(2));
- (this as any).triggerEvent("amountConfirm", { amount: fixed });
- (this as any).setData({ amountEditorVisible: false });
- },
- onSubmit() {
- (this as any).triggerEvent("submit");
- },
- },
- });
|