"use strict";
const common_vendor = require("../../common/vendor.js");
const ErpTabBar = () => "../../components/erp-tab-bar/erp-tab-bar.js";
const _sfc_main = {
  components: {
    ErpTabBar
  },
  data() {
    return {
      statusBarHeight: 20,
      navBarHeight: 44,
      tabBarHeight: 50,
      // 对应 100rpx
      currentTab: 0,
      loading: false,
      noMore: false,
      tabs: ["全部", "待审核", "待签批", "生产中", "已完成"],
      allOrders: [
        {
          orderNo: "ORD20240428001",
          models: [
            { type: "TY0019", length: "6000", surface: "阳极氧化", count: "100" },
            { type: "TY0018", length: "6000", surface: "PL坯料", count: "50" }
          ],
          totalCount: 150,
          status: 1,
          statusName: "待审核",
          statusType: "pending",
          time: "2024-04-28 10:20"
        },
        {
          orderNo: "ORD20240428002",
          models: [
            { type: "TY0020", length: "5800", surface: "粉末喷涂", count: "80" }
          ],
          totalCount: 80,
          status: 2,
          statusName: "待签批",
          statusType: "process",
          time: "2024-04-28 09:15"
        },
        {
          orderNo: "ORD20240427088",
          models: [
            { type: "TY0018", length: "6000", surface: "PL坯料", count: "300" }
          ],
          totalCount: 300,
          status: 4,
          statusName: "已完成",
          statusType: "finish",
          time: "2024-04-27 15:40"
        },
        {
          orderNo: "ORD20240427045",
          models: [
            { type: "TY0021", length: "3000", surface: "电泳涂漆", count: "50" },
            { type: "TY0022", length: "4000", surface: "木纹转印", count: "40" },
            { type: "TY0023", length: "5000", surface: "氟碳喷涂", count: "30" }
          ],
          totalCount: 120,
          status: 3,
          statusName: "生产中",
          statusType: "making",
          time: "2024-04-27 11:05"
        }
      ],
      displayList: []
    };
  },
  computed: {
    scrollHeight() {
      return `calc(100vh - ${this.statusBarHeight + this.navBarHeight + this.tabBarHeight}px)`;
    }
  },
  onLoad(options) {
    const info = common_vendor.index.getSystemInfoSync();
    this.statusBarHeight = info.statusBarHeight;
    this.tabBarHeight = info.windowWidth / 750 * 110;
    if (options.tab)
      this.currentTab = parseInt(options.tab);
    this.refresh();
  },
  methods: {
    goBack() {
      common_vendor.index.navigateBack();
    },
    switchTab(i) {
      this.currentTab = i;
      this.refresh();
    },
    refresh() {
      this.displayList = [];
      this.noMore = false;
      this.loadData();
    },
    onReachEnd() {
      if (!this.loading && !this.noMore)
        this.loadData();
    },
    loadData() {
      this.loading = true;
      setTimeout(() => {
        let raw = this.currentTab === 0 ? this.allOrders : this.allOrders.filter((o) => o.status === this.currentTab);
        this.displayList = [...this.displayList, ...raw];
        this.noMore = true;
        this.loading = false;
      }, 500);
    },
    onCancel(item) {
      common_vendor.index.showModal({
        title: "确认撤销",
        content: `确认要撤销订单：${item.orderNo} 吗？`,
        confirmColor: "#ff4d4f",
        success: (res) => {
          if (res.confirm) {
            common_vendor.index.showLoading({ title: "撤销中" });
            setTimeout(() => {
              common_vendor.index.hideLoading();
              common_vendor.index.showToast({ title: "已撤销" });
              const target = this.allOrders.find((o) => o.orderNo === item.orderNo);
              if (target) {
                target.status = 0;
                target.statusName = "已撤销";
                target.statusType = "expired";
              }
              this.refresh();
            }, 800);
          }
        }
      });
    },
    goDetail(item) {
      const dataStr = encodeURIComponent(JSON.stringify(item));
      common_vendor.index.navigateTo({
        url: `/pages/order/detail?data=${dataStr}`
      });
    }
  }
};
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: common_vendor.o((...args) => $options.goBack && $options.goBack(...args), "a8"),
    b: $data.statusBarHeight + "px",
    c: common_vendor.f($data.tabs, (tab, index, i0) => {
      return {
        a: common_vendor.t(tab),
        b: index,
        c: $data.currentTab === index ? 1 : "",
        d: common_vendor.o(($event) => $options.switchTab(index), index)
      };
    }),
    d: "translateX(" + $data.currentTab * 100 + "%)",
    e: common_vendor.f($data.displayList, (item, index, i0) => {
      return common_vendor.e({
        a: common_vendor.t(item.orderNo),
        b: common_vendor.t(item.statusName),
        c: common_vendor.n(item.statusType),
        d: common_vendor.f(item.models.slice(0, 2), (model, mIdx, i1) => {
          return {
            a: common_vendor.t(model.type),
            b: common_vendor.t(model.surface),
            c: common_vendor.t(model.length),
            d: common_vendor.t(model.count),
            e: mIdx
          };
        }),
        e: item.models.length > 2
      }, item.models.length > 2 ? {
        f: common_vendor.t(item.models.length - 2)
      } : {}, {
        g: common_vendor.t(item.models.length),
        h: common_vendor.t(item.totalCount),
        i: common_vendor.t(item.time),
        j: item.status === 1
      }, item.status === 1 ? {
        k: common_vendor.o(($event) => $options.onCancel(item), index)
      } : {}, {
        l: common_vendor.o(($event) => $options.goDetail(item), index),
        m: index,
        n: common_vendor.o(($event) => $options.goDetail(item), index)
      });
    }),
    f: $data.displayList.length > 0
  }, $data.displayList.length > 0 ? common_vendor.e({
    g: $data.loading
  }, $data.loading ? {} : {}, {
    h: $data.noMore
  }, $data.noMore ? {} : {}) : {}, {
    i: $data.displayList.length === 0 && !$data.loading
  }, $data.displayList.length === 0 && !$data.loading ? {} : {}, {
    j: $options.scrollHeight,
    k: common_vendor.o((...args) => $options.onReachEnd && $options.onReachEnd(...args), "ea"),
    l: common_vendor.p({
      active: "order"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-456ecf67"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/order/list.js.map
