"use strict";
const common_vendor = require("../../common/vendor.js");
const _sfc_main = {
  data() {
    return {
      isAuthorized: false,
      selectedModels: []
    };
  },
  computed: {
    totalCount() {
      return this.selectedModels.reduce((sum, item) => sum + parseInt(item.count || 0), 0);
    }
  },
  onLoad() {
    common_vendor.index.$on("add_order_item", (data) => {
      this.selectedModels.push(data);
      common_vendor.index.showToast({ title: "添加成功", icon: "success" });
    });
    common_vendor.index.$on("update_order_item", (res) => {
      if (res.index > -1) {
        this.$set(this.selectedModels, res.index, res.data);
        common_vendor.index.showToast({ title: "修改成功", icon: "success" });
      }
    });
  },
  onUnload() {
    common_vendor.index.$off("add_order_item");
    common_vendor.index.$off("update_order_item");
  },
  methods: {
    contactAdmin() {
      common_vendor.index.showModal({ title: "联系管理员", content: "管理员电话：138-0000-0000", showCancel: false, confirmColor: "#C1001C" });
    },
    goToAddModel() {
      common_vendor.index.navigateTo({
        url: "/pages/order/add_model"
      });
    },
    editItem(index, item) {
      common_vendor.index.navigateTo({
        url: `/pages/order/edit_model?index=${index}&data=${encodeURIComponent(JSON.stringify(item))}`
      });
    },
    removeItem(index) {
      const self = this;
      common_vendor.index.showModal({
        title: "提示",
        content: "确定移除该型号吗？",
        success: (res) => {
          if (res.confirm) {
            self.selectedModels.splice(index, 1);
          }
        }
      });
    },
    submitFinalOrder() {
      if (this.selectedModels.length === 0)
        return;
      common_vendor.index.showLoading({ title: "正在提交结果", mask: true });
      setTimeout(() => {
        common_vendor.index.hideLoading();
        common_vendor.index.navigateTo({
          url: "/pages/order/success"
        });
      }, 1500);
    }
  }
};
if (!Array) {
  const _easycom_erp_tab_bar2 = common_vendor.resolveComponent("erp-tab-bar");
  _easycom_erp_tab_bar2();
}
const _easycom_erp_tab_bar = () => "../../components/erp-tab-bar/erp-tab-bar.js";
if (!Math) {
  _easycom_erp_tab_bar();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: !$data.isAuthorized
  }, !$data.isAuthorized ? {
    b: common_vendor.o((...args) => $options.contactAdmin && $options.contactAdmin(...args), "d8"),
    c: common_vendor.o(($event) => $data.isAuthorized = true, "35")
  } : common_vendor.e({
    d: $data.selectedModels.length > 0
  }, $data.selectedModels.length > 0 ? {} : {}, {
    e: $data.selectedModels.length > 0
  }, $data.selectedModels.length > 0 ? {
    f: common_vendor.f($data.selectedModels, (item, index, i0) => {
      return {
        a: common_vendor.o(($event) => $options.removeItem(index), index),
        b: common_vendor.t(item.type),
        c: common_vendor.t(item.count),
        d: common_vendor.t(item.surfaceName),
        e: index,
        f: common_vendor.o(($event) => $options.editItem(index, item), index)
      };
    })
  } : {
    g: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "65")
  }, {
    h: $data.selectedModels.length > 0
  }, $data.selectedModels.length > 0 ? {
    i: common_vendor.o((...args) => $options.goToAddModel && $options.goToAddModel(...args), "31")
  } : {}, {
    j: $data.selectedModels.length > 0
  }, $data.selectedModels.length > 0 ? {
    k: common_vendor.t($data.selectedModels.length),
    l: common_vendor.t($options.totalCount),
    m: $data.selectedModels.length === 0,
    n: common_vendor.o((...args) => $options.submitFinalOrder && $options.submitFinalOrder(...args), "fd")
  } : {}), {
    o: common_vendor.p({
      active: "order"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-93207a4f"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/order.js.map
