"use strict";
const common_vendor = require("../../../common/vendor.js");
const pages_utils_emitter = require("../../utils/emitter.js");
require("../../../store/userStore.js");
const common_assets = require("../../../common/assets.js");
const api_request = require("../../../api/request.js");
if (!Array) {
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  _easycom_uni_popup2();
}
const _easycom_uni_popup = () => "../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (addressComponentVue + _easycom_uni_popup)();
}
const addressComponentVue = () => "../component/addressComponent.js";
const _sfc_main = {
  __name: "product-waitpay",
  setup(__props) {
    const num = common_vendor.ref(1);
    common_vendor.ref(138);
    const youhuijuan_num = common_vendor.ref(1);
    const manjian = common_vendor.ref(120);
    const manjian1 = common_vendor.ref(50);
    const sumprice = common_vendor.ref(88);
    const popup = common_vendor.ref(null);
    const addressRealInfo = common_vendor.ref({});
    const productObject = common_vendor.ref({});
    const labelList = common_vendor.ref([]);
    const userInfo = common_vendor.ref({});
    const totalAmount = common_vendor.ref(0);
    const orderItemList = common_vendor.ref([
      //订单中各种商品的详细信息
      {
        // orderId : 0,
        goodSnapshot: {},
        priceSnapshot: 0,
        //实付金额
        quantity: 0,
        itemTotalAmount: 0
      }
    ]);
    common_vendor.onMounted(() => {
      pages_utils_emitter.emitter.on("close", () => {
        close();
      });
      pages_utils_emitter.emitter.on("addressInfo", (val) => {
        addressRealInfo.value = val;
      });
      userInfo.value = common_vendor.wx$1.getStorageSync("userInfo");
    });
    common_vendor.onLoad((options) => {
      productObject.value = JSON.parse(options.product);
      labelList.value = productObject.value.label.split(";");
      labelList.value = labelList.value.filter((s) => {
        return s;
      });
      totalAmount.value = productObject.value.price;
      orderItemList.value[0].goodSnapshot = {
        //待优化  11.4
        name: productObject.value.name,
        type: productObject.value.type,
        price: productObject.value.price,
        goodImg: productObject.value.goodImg,
        festivalOrder: productObject.value.festivalOrder,
        reserveDate: productObject.value.reserveDate
      };
      orderItemList.value[0].priceSnapshot = productObject.value.price;
      orderItemList.value[0].quantity = 1;
      orderItemList.value[0].itemTotalAmount = orderItemList.value[0].quantity * orderItemList.value[0].priceSnapshot;
    });
    const close = () => {
      popup.value.close();
    };
    const loadPop = () => {
      popup.value.open("bottom");
    };
    const createOrder = async () => {
      console.log("商品对象==>", productObject.value);
      console.log("地址对象==>", addressRealInfo.value);
      console.log("用户信息==>", userInfo.value);
      console.log("订单明细-->", orderItemList.value);
      const resOrder = await common_vendor.index.request({
        url: api_request.baseUrl + "/order/add",
        method: "POST",
        data: {
          userId: userInfo.value.id,
          userName: userInfo.value.userName,
          orderNumber: "null",
          //订单编号暂存为null
          addressSnapshot: { ...addressRealInfo.value },
          //地址信息快照
          contactsSnapshot: { name: "null", phone: "null" },
          couponSnapshot: { name: "null", conditionAmount: "null" },
          //优惠卷信息快照
          totalAmount: totalAmount.value,
          //总价
          orderStatus: "待支付",
          //订单状态
          orderItemList: orderItemList.value
          // orderItemList: orderItemList.value.map(item =>({
          // 	goodSnapshot : item.goodSnapshot,
          // 	priceSnapshot : item.priceSnapshot,
          // 	quantity : item.quantity,
          // 	itemTotalAmount: item.itemTotalAmount
          // }))
        }
      });
      console.log("后台返回订单响应==>", resOrder);
      if (resOrder.data.code === 1) {
        common_vendor.index.navigateTo({
          url: "/pages/order/paysuccess/paysuccess"
        });
      } else {
        common_vendor.index.showToast({
          icon: "error",
          title: "购买失败，请求错误"
        });
        return;
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.t(addressRealInfo.value.region),
        b: common_vendor.unref(common_assets.dingwei$1),
        c: common_vendor.t(addressRealInfo.value.detailAddress),
        d: common_vendor.unref(common_assets.you_cheng),
        e: common_vendor.o(($event) => loadPop()),
        f: common_vendor.t(addressRealInfo.value.name),
        g: common_vendor.t(addressRealInfo.value.phone),
        h: productObject.value.goodImg,
        i: common_vendor.t(productObject.value.name),
        j: common_vendor.t(productObject.value.type),
        k: common_vendor.f(labelList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(labelList.value[index]),
            b: index
          };
        }),
        l: common_vendor.t(productObject.value.price),
        m: common_vendor.unref(common_assets.rmb_32),
        n: common_vendor.unref(common_assets.short$1),
        o: common_vendor.unref(common_assets.add$1),
        p: common_vendor.unref(common_assets.yiwen),
        q: common_vendor.t(num.value),
        r: common_vendor.unref(common_assets.rmb_36px),
        s: common_vendor.t(productObject.value.price),
        t: common_vendor.unref(common_assets.you_hei),
        v: common_vendor.t(youhuijuan_num.value),
        w: common_vendor.t(manjian.value),
        x: common_vendor.t(manjian1.value),
        y: common_vendor.unref(common_assets.rmb_cheng),
        z: common_vendor.t(manjian1.value),
        A: common_vendor.unref(common_assets.rmb_36px),
        B: common_vendor.t(productObject.value.price - 50),
        C: common_vendor.unref(common_assets.rmb_huang),
        D: common_vendor.t(sumprice.value),
        E: common_vendor.o(createOrder),
        F: common_vendor.sr(popup, "eda1e8f0-0", {
          "k": "popup"
        }),
        G: common_vendor.o(_ctx.change),
        H: common_vendor.p({
          ["background-color"]: "#fff"
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-eda1e8f0"], ["__file", "D:/jiangchengfeiyi-xiaochengxu/pages/order/product-waitpay/product-waitpay.vue"]]);
wx.createPage(MiniProgramPage);
