"use strict";
const common_vendor = require("../../common/vendor.js");
const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
const sheep_index = require("../../sheep/index.js");
require("../../sheep/url/index.js");
require("../../sheep/store/index.js");
require("../../sheep/store/app.js");
require("../../sheep/api/promotion/diy.js");
require("../../sheep/request/index.js");
require("../../sheep/config/index.js");
require("../../sheep/platform/index.js");
require("../../sheep/platform/provider/wechat/index.js");
require("../../sheep/platform/provider/wechat/miniProgram.js");
require("../../sheep/api/member/auth.js");
require("../../sheep/api/member/social.js");
require("../../sheep/api/member/user.js");
require("../../sheep/platform/provider/apple/index.js");
require("../../sheep/platform/share.js");
require("../../sheep/router/index.js");
require("../../sheep/hooks/useModal.js");
require("../../sheep/helper/index.js");
require("../../sheep/helper/test.js");
require("../../sheep/helper/digit.js");
require("../../sheep/api/member/signin.js");
require("../../sheep/helper/throttle.js");
require("../../sheep/platform/pay.js");
require("../../sheep/api/pay/order.js");
require("../../sheep/store/user.js");
require("../../sheep/store/cart.js");
require("../../sheep/api/trade/cart.js");
require("../../sheep/api/pay/wallet.js");
require("../../sheep/api/trade/order.js");
require("../../sheep/api/promotion/coupon.js");
require("../../sheep/store/sys.js");
require("../../sheep/store/modal.js");
require("../../sheep/util/index.js");
require("../../sheep/api/index.js");
require("../../sheep/api/distri/score.js");
require("../../sheep/api/distri/share.js");
require("../../sheep/api/distri/team.js");
require("../../sheep/api/infra/file.js");
require("../../sheep/api/member/address.js");
require("../../sheep/api/member/point.js");
require("../../sheep/api/migration/app.js");
require("../../sheep/api/migration/chat.js");
require("../../sheep/api/migration/index.js");
require("../../sheep/api/migration/third.js");
require("../../sheep/api/pay/channel.js");
require("../../sheep/api/product/category.js");
require("../../sheep/api/product/comment.js");
require("../../sheep/api/product/favorite.js");
require("../../sheep/api/product/history.js");
require("../../sheep/api/product/spu.js");
require("../../sheep/api/promotion/activity.js");
require("../../sheep/api/promotion/article.js");
require("../../sheep/api/promotion/bargain.js");
require("../../sheep/api/promotion/combination.js");
require("../../sheep/api/promotion/rewardActivity.js");
require("../../sheep/api/promotion/seckill.js");
require("../../sheep/api/system/area.js");
require("../../sheep/api/system/voice.js");
require("../../sheep/api/trade/afterSale.js");
require("../../sheep/api/trade/brokerage.js");
require("../../sheep/api/trade/config.js");
require("../../sheep/api/trade/delivery.js");
require("../../sheep/config/zIndex.js");
if (!Array) {
  const _easycom_su_tabs2 = common_vendor.resolveComponent("su-tabs");
  const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
  const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  const _easycom_s_goods_item2 = common_vendor.resolveComponent("s-goods-item");
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  (_easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_s_empty2 + _easycom_s_goods_item2 + _easycom_uni_load_more2 + _easycom_s_layout2)();
}
const _easycom_su_tabs = () => "../../sheep/ui/su-tabs/su-tabs.js";
const _easycom_su_sticky = () => "../../sheep/ui/su-sticky/su-sticky.js";
const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
const _easycom_s_goods_item = () => "../../sheep/components/s-goods-item/s-goods-item.js";
const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
if (!Math) {
  (_easycom_su_tabs + _easycom_su_sticky + _easycom_s_empty + _easycom_s_goods_item + _easycom_uni_load_more + _easycom_s_layout)();
}
const _sfc_main = {
  __name: "otherlist",
  setup(__props) {
    const tradeManaged = common_vendor.computed(() => sheep_index.sheep.$store("app").has_wechat_trade_managed);
    const pagination = {
      data: [],
      current_page: 1,
      total: 1,
      last_page: 1
    };
    const state = common_vendor.reactive({
      currentTab: 0,
      pagination: {
        data: [],
        current_page: 1,
        total: 1,
        last_page: 1
      },
      loadStatus: "",
      deleteOrderId: 0,
      error: 0
    });
    const tabMaps = [
      {
        name: "全部",
        value: "all"
      },
      {
        name: "待付款",
        value: "unpaid"
      },
      {
        name: "待发货",
        value: "nosend"
      },
      {
        name: "待收货",
        value: "noget"
      },
      {
        name: "待评价",
        value: "nocomment"
      }
    ];
    function onTabsChange(e) {
      if (state.currentTab === e.index)
        return;
      state.pagination = pagination;
      state.currentTab = e.index;
      getOrderList();
    }
    function onOrderDetail(orderSN) {
      sheep_index.sheep.$router.go("/pages/order/detail", {
        orderSN
      });
    }
    function onOrderGroupon(order) {
      sheep_index.sheep.$router.go("/pages/activity/groupon/detail", {
        id: order.ext.groupon_id
      });
    }
    function onOrderInvoice(invoiceId) {
      sheep_index.sheep.$router.go("/pages/order/invoice", {
        invoiceId
      });
    }
    function onPay(orderSN) {
      sheep_index.sheep.$router.go("/pages/pay/index", {
        orderSN
      });
    }
    function onComment(orderSN) {
      sheep_index.sheep.$router.go("/pages/goods/comment/add", {
        orderSN
      });
    }
    async function onConfirm(order, ignore = false) {
      if (sheep_index.sheep.$platform.name === "WechatMiniProgram" && !common_vendor.lodashExports.isEmpty(order.wechat_extra_data) && tradeManaged.value === 1 && !ignore) {
        mpConfirm(order);
        return;
      }
      const { error } = await sheep_index.sheep.$api.order.confirm(order.id);
      if (error === 0) {
        state.pagination = pagination;
        getOrderList();
      }
    }
    function mpConfirm(order) {
      if (!common_vendor.wx$1.openBusinessView) {
        sheep_index.sheep.$helper.toast(`请升级微信版本`);
        return;
      }
      common_vendor.wx$1.openBusinessView({
        businessType: "weappOrderConfirm",
        extraData: {
          merchant_trade_no: order.wechat_extra_data.merchant_trade_no,
          transaction_id: order.wechat_extra_data.transaction_id
        },
        success(response) {
          console.log("success:", response);
          if (response.errMsg === "openBusinessView:ok") {
            if (response.extraData.status === "success") {
              onConfirm(order, true);
            }
          }
        },
        fail(error) {
          console.log("error:", error);
        },
        complete(result) {
          console.log("result:", result);
        }
      });
    }
    async function onExpress(orderId) {
      sheep_index.sheep.$router.go("/pages/order/express/list", {
        orderId
      });
    }
    async function onCancel(orderId) {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要取消订单吗?",
        success: async function(res) {
          if (res.confirm) {
            const { error, data } = await sheep_index.sheep.$api.order.cancel(orderId);
            if (error === 0) {
              let index = state.pagination.data.findIndex((order) => order.id === orderId);
              state.pagination.data[index] = data;
            }
          }
        }
      });
    }
    function onDelete(orderId) {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要删除订单吗?",
        success: async function(res) {
          if (res.confirm) {
            const { error, data } = await sheep_index.sheep.$api.order.delete(orderId);
            if (error === 0) {
              let index = state.pagination.data.findIndex((order) => order.id === orderId);
              state.pagination.data.splice(index, 1);
            }
          }
        }
      });
    }
    async function onRefund(orderId) {
      common_vendor.index.showModal({
        title: "提示",
        content: "确定要申请退款吗?",
        success: async function(res) {
          if (res.confirm) {
            sheep_index.sheep.$platform.useProvider("wechat").subscribeMessage("order_refund");
            const { error, data } = await sheep_index.sheep.$api.order.applyRefund(orderId);
            if (error === 0) {
              let index = state.pagination.data.findIndex((order) => order.id === orderId);
              state.pagination.data[index] = data;
            }
          }
        }
      });
    }
    async function getOrderList(page = 1, list_rows = 5) {
      state.loadStatus = "loading";
      let res = await sheep_index.sheep.$api.order.list({
        type: tabMaps[state.currentTab].value,
        list_rows,
        page
      });
      state.error = res.error;
      if (res.error === 0) {
        let orderList = common_vendor._.concat(state.pagination.data, res.data.data);
        state.pagination = {
          ...res.data,
          data: orderList
        };
        if (state.pagination.current_page < state.pagination.last_page) {
          state.loadStatus = "more";
        } else {
          state.loadStatus = "noMore";
        }
      }
    }
    common_vendor.onLoad(async (options) => {
      if (options.type) {
        state.currentTab = options.type;
      }
      getOrderList();
    });
    function loadmore() {
      if (state.loadStatus !== "noMore") {
        getOrderList(state.pagination.current_page + 1);
      }
    }
    common_vendor.onReachBottom(() => {
      loadmore();
    });
    common_vendor.onPullDownRefresh(() => {
      state.pagination = pagination;
      getOrderList();
      setTimeout(function() {
        common_vendor.index.stopPullDownRefresh();
      }, 800);
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(onTabsChange),
        b: common_vendor.p({
          list: tabMaps,
          scrollable: false,
          current: state.currentTab
        }),
        c: common_vendor.p({
          bgColor: "#fff"
        }),
        d: state.pagination.total === 0
      }, state.pagination.total === 0 ? {
        e: common_vendor.p({
          icon: "/static/order-empty.png",
          text: "暂无订单"
        })
      } : {}, {
        f: state.pagination.total > 0
      }, state.pagination.total > 0 ? {
        g: common_vendor.f(state.pagination.data, (order, k0, i0) => {
          return common_vendor.e({
            a: common_vendor.t(order.order_sn),
            b: common_vendor.t(order.status_text),
            c: common_vendor.n(common_vendor.unref(sheep_hooks_useGoods.formatOrderColor)(order.status_code)),
            d: common_vendor.f(order.items, (item, k1, i1) => {
              return common_vendor.e({
                a: item.btns.includes("aftersale")
              }, item.btns.includes("aftersale") ? {
                b: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/order/aftersale/apply", {
                  item: JSON.stringify(item)
                }), item.id)
              } : {}, {
                c: item.btns.includes("re_aftersale")
              }, item.btns.includes("re_aftersale") ? {
                d: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/order/aftersale/apply", {
                  item: JSON.stringify(item)
                }), item.id)
              } : {}, {
                e: item.btns.includes("aftersale_info")
              }, item.btns.includes("aftersale_info") ? {
                f: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/order/aftersale/detail", {
                  id: item.ext.aftersale_id
                }), item.id)
              } : {}, {
                g: item.btns.includes("buy_again")
              }, item.btns.includes("buy_again") ? {
                h: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
                  id: item.goods_id
                }), item.id)
              } : {}, {
                i: "ad14ec43-4-" + i0 + "-" + i1 + ",ad14ec43-0",
                j: common_vendor.p({
                  img: item.goods_image,
                  title: item.goods_title,
                  skuText: item.goods_sku_text,
                  price: item.goods_price,
                  score: order.score_amount,
                  num: item.goods_num
                }),
                k: item.id
              });
            }),
            e: order.total_discount_fee > 0
          }, order.total_discount_fee > 0 ? {
            f: common_vendor.t(order.total_discount_fee)
          } : {}, {
            g: common_vendor.t(order.dispatch_amount),
            h: common_vendor.t(order.order_amount),
            i: order.score_amount
          }, order.score_amount ? {} : {}, {
            j: order.score_amount
          }, order.score_amount ? {
            k: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/score1.svg"),
            l: common_vendor.t(order.score_amount)
          } : {}, {
            m: order.btns.includes("groupon")
          }, order.btns.includes("groupon") ? {
            n: common_vendor.t(order.status_code === "groupon_ing" ? "邀请拼团" : "拼团详情"),
            o: common_vendor.o(($event) => onOrderGroupon(order), order.id)
          } : {}, {
            p: order.btns.includes("invoice")
          }, order.btns.includes("invoice") ? {
            q: common_vendor.o(($event) => {
              var _a;
              return onOrderInvoice((_a = order.invoice) == null ? void 0 : _a.id);
            }, order.id)
          } : {}, {
            r: order.btns.length === 0
          }, order.btns.length === 0 ? {
            s: common_vendor.o(($event) => onOrderDetail(order.order_sn), order.id)
          } : {}, {
            t: order.btns.includes("confirm")
          }, order.btns.includes("confirm") ? {
            v: common_vendor.o(($event) => onConfirm(order), order.id)
          } : {}, {
            w: order.btns.includes("express")
          }, order.btns.includes("express") ? {
            x: common_vendor.o(($event) => onExpress(order.id), order.id)
          } : {}, {
            y: order.btns.includes("apply_refund")
          }, order.btns.includes("apply_refund") ? {
            z: common_vendor.o(($event) => onRefund(order.id), order.id)
          } : {}, {
            A: order.btns.includes("re_apply_refund")
          }, order.btns.includes("re_apply_refund") ? {
            B: common_vendor.o(($event) => onRefund(order.id), order.id)
          } : {}, {
            C: order.btns.includes("cancel")
          }, order.btns.includes("cancel") ? {
            D: common_vendor.o(($event) => onCancel(order.id), order.id)
          } : {}, {
            E: order.btns.includes("comment")
          }, order.btns.includes("comment") ? {
            F: common_vendor.o(($event) => onComment(order.order_sn), order.id)
          } : {}, {
            G: order.btns.includes("delete")
          }, order.btns.includes("delete") ? {
            H: common_vendor.o(($event) => onDelete(order.id), order.id)
          } : {}, {
            I: order.btns.includes("pay")
          }, order.btns.includes("pay") ? {
            J: common_vendor.o(($event) => onPay(order.order_sn), order.id)
          } : {}, {
            K: common_vendor.n(order.btns.length > 3 ? "ss-row-between" : "ss-row-right"),
            L: order.id,
            M: common_vendor.o(($event) => onOrderDetail(order.order_sn), order.id)
          });
        })
      } : {}, {
        h: state.pagination.total > 0
      }, state.pagination.total > 0 ? {
        i: common_vendor.o(loadmore),
        j: common_vendor.p({
          status: state.loadStatus,
          ["content-text"]: {
            contentdown: "上拉加载更多"
          }
        })
      } : {}, {
        k: common_vendor.p({
          title: "我的订单"
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-ad14ec43"], ["__file", "D:/zx/mall-front-app/pages/order/otherlist.vue"]]);
wx.createPage(MiniProgramPage);
