| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { Get } from "../../../../lib/request/method";
- Component({
- properties: {
- visible: { type: Boolean, value: false },
- initialReason: { type: String, value: "" },
- },
- data: {
- selectedReason: "",
- reasons: [] as Array<{ label: string; value: string }>,
- },
- observers: {
- visible(v: boolean) {
- if (v) {
- this.setData({ selectedReason: this.data.initialReason || "" });
- }
- },
- },
- lifetimes: {
- attached() {
- this.fetchReasons();
- },
- },
- methods: {
- async fetchReasons() {
- try {
- const res = await Get<any[]>("/dict/getDicts");
- const dict = (res as any)?.data?.find(
- (item: any) => item.dictType === "aftersale_reason"
- );
- if (dict?.items?.length) {
- this.setData({
- reasons: dict.items.map((item: any) => ({
- label: item.dictLabel,
- value: item.dictValue,
- })),
- });
- }
- } catch {
- wx.showToast({ title: "获取退款原因失败", icon: "none" });
- }
- },
- onPopupVisibleChange(e: WechatMiniprogram.CustomEvent<{ visible: boolean }>) {
- if (!e?.detail?.visible) {
- this.triggerEvent("close");
- }
- },
- onClose() {
- this.triggerEvent("close");
- },
- onSelectReason(e: any) {
- const reason = e.detail?.value;
- if (reason) {
- this.setData({ selectedReason: reason });
- }
- },
- onNext() {
- const reason = this.data.selectedReason;
- if (!reason) {
- wx.showToast({ title: "请选择退款原因", icon: "none" });
- return;
- }
- this.triggerEvent("next", { reason });
- },
- },
- });
|