afterSaleDetail.js 4.9 KB
import {
  getAfterSaleDetail,
  calcOrderProp,
  getOrder,
  API_Methods,
  APIS,
} from "~/packageMine/pages/order/utils";
import { ORDER_STATUS, OrderStatusEnum } from "~/constants/mine.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    order: {
      express_no: "",
    },
    orderInfo: {},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.p.router.getRouterParams(options).then((params) => {
      if (params) {
        this.setData({
          ...params,
        });
        this.getOrderAfterSaleDetail(params.subOrderCode);
      }
    });
  },
  submitlogistics() {
    this.getOrderAfterSaleDetail();
  },
  getOrderAfterSaleDetail() {
    wx.p.wxApi.showLoading("加载中...");
    let { goodsSource, tparReturnOrderCode, subOrderCode, goodsSkuCode } =
      this.data;
    // Methods = goodsSource == 2 ? "afterSaleDetail" : "platformSaleDetail";
    API_Methods[goodsSource][APIS.AFTER_SALE_DETAIL]({
      subOrderCode,
      tparReturnOrderCode,
      goodsSkuCode,
    })
      .then((res) => {
        // let status = 0
        // if (res.returnOrderStatus == 1000 || res.returnOrderStatus == 1002 || res.returnOrderStatus == 1001 || res.returnOrderStatus == 1004 || (res.returnOrderStatus == 1003 && res.outRefundType == 2)) {
        //   status = 0
        // } else if (res.returnOrderStatus == 1003 && res.outRefundType == 0) {
        //   status = 1
        // } else if (res.returnOrderStatus == 1005 || (res.returnOrderStatus == 1003 && res.outRefundType == 3) || (res.returnOrderStatus == 1003 && res.outRefundType == 1)) {
        //   status = 2
        // }
        // const { returnOrderStatus } = res;
        const status = getOrder(res); //getAfterSaleDetail({ returnOrderStatus });
        const button = status.detail.buttons?.[goodsSource][0] || {}; //status.buttons?.[goodsSource][0];
        // button.action = this[button.handler]
        let str = "";
        if (res.sendbackAddressModel) {
          const { sendbackAddressModel } = res;
          str = `${sendbackAddressModel.provinceName}${sendbackAddressModel.cityName}${sendbackAddressModel.countyName}${sendbackAddressModel.address}`;
        }
        res.addressInfo = str;
        const { ___qty, ___price, ___totalPrice } = calcOrderProp(
          res.orderGoods
        );
        Object.assign(res.orderGoods, { ___qty, ___price, ___totalPrice });
        this.setData({
          orderInfo: res,
          status,
          button,
        });
      }).catch((err) => {
        wx.p.sentry.reportError(`售后详情异常:${err.message}`, {...this.data,err});
      })
      .finally(() => {
        wx.hideLoading();
      });
  },

  confirm() {
    // const { status, orderInfo } = this.data;
    // if (status == 0) {
    //   this.cancelSaleApply();
    // } else if (status == 2) {
    //   wx.p.router.go(
    //     "/packageMine/pages/order/afterSale_step_two/afterSale_step_two",
    //     orderInfo
    //   );
    // }
    // this.cancelSaleApply()
    // console.log('this.button', this.data.button)
    this[this.data.button.handler]();
    // this.toAfterSale();
  },
  toAfterSale() {
    const { orderInfo } = this.data;
    // const { orderGoods, imgUrlList, ...rest } = orderInfo;
    // const order = Object.assign({ imgList: imgUrlList }, orderGoods, rest);
    wx.p.router.go(
      "/packageMine/pages/order/afterSale_step_two/afterSale_step_two",
      orderInfo
    );
  },
  /**撤销申请 */
  cancelSaleApply() {
    const { orderInfo } = this.data;
    let para = {
      tparReturnOrderCode: orderInfo.tparReturnOrderCode,
    };
    wx.showModal({
      title: "提示",
      content: `请确认是否撤销申请`,
      confirmColor: "#F13C3D",
    })
      .then((res) => {
        if (res.confirm) {
          wx.p.wxApi.showLoading("提交中");
          const URLNAME = "platformEditSale";
          wx.p.api.shopmallApi[URLNAME](para).then((res) => {
            if (res) {
              wx.p.wxApi.showToast("撤销成功");
              wx.p.router.go("/packageMine/pages/order/index/index", {
                tab: ORDER_STATUS[OrderStatusEnum.COMPLETED],
              });
            }
          }).catch((err) => {
            wx.p.sentry.reportError(`撤销售后:${err.message}`, {...this.data.orderInfo,err});
          });
        }
      })
      .catch((err) => {
        wx.p.sentry.reportError(`撤销售后Modal:${err.message}`, {...this.data.orderInfo,err});
        wx.p.wxApi.showToast("已取消");
      })
      .finally(() => {
        setTimeout(() => {
          wx.hideLoading();
        }, 500);
      });
  },
  previewImage(e) {
    let params = e.detail; // 从组件传递的数据
    wx.p.wxApi.previewImage(params);
  },

  onExpressNoInput(e) {
    const { value } = e.detail;
    this.setData({
      "order.express_no": value,
    });
  },

  onSubmitLogistics() {
    // 提交物流信息的处理逻辑
    console.log("提交物流信息");
  },
});