myOrder.js 1.6 KB
// pages/tab/mine/components/myOrder/myOrder.js
import { ORDER_STATUS, OrderStatusTypes } from "~/constants/mine.js";

Component({
  /**
   * 组件的初始数据
   */
  data: {
    orderList: Object.freeze(
      Object.values(ORDER_STATUS).filter(
        (item) => item.type == OrderStatusTypes.MY_ORDER
      )
    ),
  },
  /**
   * 组件生命周期
   */
  lifetimes: {
    attached() {
      // 获取订单状态对应的图片
      this.getOrderNumberList();
    },
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示时执行
      this.getOrderNumberList();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goOrder(e) {
      // 直接使用 ORDER_LIST 中的索引作为 tabIndex
      const item = e.currentTarget.dataset.item;
      wx.p.router.go("/packageMine/pages/order/index/index", {
        tab: item,
      });
    },

    getOrderNumberList() {
      const loginStatus = !wx.p.isLogin;
      if (loginStatus) return;
      const userInfo = wx.p.storage.get("userInfo") || {};
      let { merchantId, channelSource,phone } = userInfo;
      const params = {
        merchantId,
        pageSize: 1,
        currentPage: 1,
        scoreSource: channelSource,
        phone
      };
      const orderList = this.data.orderList;
      orderList.forEach((item) => {
        const p = { ...params, requestType: item.requestType };
        wx.p.api.mineApi[item.requestMethod](p).then((data) => {
          if(data.total){
            item.___count = data.total;
            this.setData({
              orderList,
            });
          }
        });
      });
    },
  },
});