"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_global = require("../../../common/global.js");
const api_request = require("../../../api/request.js");
const _sfc_main = {
  __name: "product-paysuccess",
  setup(__props) {
    const orderObject = common_vendor.ref({});
    const addressInfo = common_vendor.ref({});
    const productList = common_vendor.ref([]);
    const stateObject = common_vendor.ref({});
    const bottomBtn = common_vendor.ref("去支付");
    const oid = common_vendor.ref(0);
    common_vendor.onLoad((options) => {
      oid.value = JSON.parse(options.oid);
      console.log("当前订单ID为", oid.value);
    });
    common_vendor.onShow(async () => {
      await getOrderItem();
      await setBottomText();
    });
    const getOrderItem = async () => {
      const res = await common_vendor.index.request({
        url: api_request.baseUrl + "/order/get/id",
        method: "POST",
        header: {
          "cookie": common_vendor.wx$1.getStorageSync("cookie")
        },
        data: { id: oid.value }
      });
      if (res.data.code === 1) {
        orderObject.value = res.data.data, addressInfo.value = res.data.data.addressSnapshot, productList.value = res.data.data.orderItemList;
        stateObject.value = common_global.stateMap.get(res.data.data.orderStatus);
      }
      console.log("地址信息--->", addressInfo.value);
      console.log("商品信息为--->", productList.value);
      console.log("此订单信息为", res.data);
      console.log("订单状态---->", stateObject.value);
    };
    const setBottomText = () => {
      switch (stateObject.value.state) {
        case "待支付":
          bottomBtn.value = "立即支付";
          break;
        case "待发货":
          bottomBtn.value = "联系客服";
          break;
        case "待收货":
          bottomBtn.value = "查看物流";
          break;
        case "已退款":
          bottomBtn.value = "删除订单";
          break;
        case "交易成功":
          bottomBtn.value = "删除订单";
          break;
        default:
          bottomBtn.value = "删除订单";
      }
    };
    const stateSubmit = (obj) => {
      if (bottomBtn.value === "立即支付") {
        wxPay(oid.value);
      } else if (bottomBtn.value === "删除订单") {
        console.log("订单被删除");
      } else if (bottomBtn.value === "查看物流") {
        viewLogistics(obj.id);
      }
    };
    const confirm = () => {
      console.log("确认收货方法");
    };
    const wxPay = async (oid2) => {
      try {
        const res = await common_vendor.index.request({
          url: api_request.baseUrl + "/wechat/payment/create",
          method: "POST",
          header: {
            "cookie": common_vendor.wx$1.getStorageSync("cookie")
          },
          data: { id: oid2 }
        });
        const paymentData = res.data.data;
        common_vendor.wx$1.requestPayment({
          appid: paymentData.appId,
          nonceStr: paymentData.nonceStr,
          package: paymentData.packageVal,
          paySign: paymentData.paySign,
          timeStamp: paymentData.timeStamp,
          signType: paymentData.signType,
          success(res2) {
            common_vendor.index.showModal({
              content: "支付成功",
              showCancel: false
            });
            buffer();
          },
          fail(e) {
            common_vendor.index.showModal({
              content: "支付失败，原因为:" + e.errMsg,
              showCancel: false
            });
          }
        });
      } catch (error) {
        console.error("支付请求失败", error);
        common_vendor.index.showModal({
          content: "支付请求失败,请重试。",
          showCancel: false
        });
      }
    };
    const buffer = async () => {
      await getOrderItem();
      await setBottomText();
    };
    const viewLogistics = (oid2) => {
      common_vendor.index.request({
        url: api_request.baseUrl + "/logistics/get/info",
        method: "POST",
        data: {
          id: oid2
        },
        header: {
          "cookie": common_vendor.wx$1.getStorageSync("cookie")
        },
        success: (res) => {
          console.log(res.data.data);
          waybillToken = res.data.data.waybill_token;
          plugin.openWaybillTracking({
            waybillToken
          });
        }
      });
    };
    const copy = (orderNumber) => {
      console.log("订单编号为--->", orderNumber);
      common_vendor.index.setClipboardData({
        data: orderNumber,
        success: () => {
          common_vendor.index.showToast({
            title: "成功复制到剪贴板"
          });
        }
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: stateObject.value.img,
        b: common_vendor.t(stateObject.value.msg),
        c: common_vendor.t(stateObject.value.tips),
        d: common_vendor.t(addressInfo.value.name),
        e: common_vendor.t(addressInfo.value.phone),
        f: common_vendor.t(addressInfo.value.region),
        g: common_vendor.t(addressInfo.value.detailAddress),
        h: common_vendor.f(productList.value, (item, index, i0) => {
          return {
            a: item.goodSnapshot.goodImg.split(";")[0],
            b: common_vendor.t(item.goodSnapshot.name),
            c: common_vendor.t(item.goodSnapshot.type),
            d: common_vendor.t(item.goodSnapshot.price),
            e: common_vendor.t(item.quantity),
            f: index
          };
        }),
        i: common_vendor.t(orderObject.value.note),
        j: common_vendor.o(($event) => copy(orderObject.value.orderNumber)),
        k: common_vendor.t(orderObject.value.orderNumber),
        l: common_vendor.t(orderObject.value.createTime),
        m: stateObject.value.state === "已退款"
      }, stateObject.value.state === "已退款" ? {
        n: common_vendor.t(orderObject.value.updateTime)
      } : {}, {
        o: stateObject.value.state === "待收货"
      }, stateObject.value.state === "待收货" ? {
        p: common_vendor.t(orderObject.value.trackingNumber)
      } : {}, {
        q: stateObject.value.state === "交易成功"
      }, stateObject.value.state === "交易成功" ? {
        r: common_vendor.t(orderObject.value.updateTime)
      } : {}, {
        s: stateObject.value.state != "交易成功"
      }, stateObject.value.state != "交易成功" ? common_vendor.e({
        t: common_vendor.t(orderObject.value.totalAmount),
        v: bottomBtn.value != "联系客服"
      }, bottomBtn.value != "联系客服" ? {
        w: common_vendor.t(bottomBtn.value),
        x: common_vendor.o(($event) => stateSubmit(orderObject.value))
      } : {}, {
        y: bottomBtn.value === "查看物流"
      }, bottomBtn.value === "查看物流" ? {
        z: common_vendor.o(($event) => confirm())
      } : {}, {
        A: bottomBtn.value === "联系客服"
      }, bottomBtn.value === "联系客服" ? {} : {}) : {});
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-e92dd7c8"], ["__file", "D:/微信小程序/课设整合/匠承非遗小程序端/jiangchengfeiyi-xiaochengxu/pages/order/product-paysuccess/product-paysuccess.vue"]]);
wx.createPage(MiniProgramPage);
