// packageE/memberorder/memberorder.js
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    },
    member_order: {
      type: null,
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
    active: "",
    U_memberorder: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberorderhotel: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSure",
      value: 0
    },
    {
      label: "waitEnter",
      value: 0
    },
    {
      label: "waitCheckOut",
      value: 0
    },
    ],
    U_memberorderrelease: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberordergroup: [{
      label: "",
      value: 0
    },
    {
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberordergrab: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberorderlive_install: [{
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    },
    {
      status: 3,
      value: 0
    },
    {
      status: 5,
      value: 0
    }
    ],
    U_memberorderlive_install_worker: [{
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    },
    {
      status: 3,
      value: 0
    },
    {
      status: 5,
      value: 0
    }
    ],
    U_memberordercps: [{
      status: -1,
      value: 0
    },
    {
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    }
    ],
    U_memberordernew_group: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      if (this.data.member_order && this.data.member_order.order) {
        for (let i = 0; i < this.data.member_order.order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = this.data.member_order.order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberorder[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorder[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorder[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorder[3].value"]: item.total,
            });
          }
        }
      }

      if (this.data.member_order && this.data.member_order.hotel_order) {
        this.data.member_order.hotel_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberorderhotel[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorderhotel[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorderhotel[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorderhotel[3].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.lease_order) {
        this.data.member_order.lease_order.forEach((item) => {
          if (item.status == "0") {
            this.setData({
              ["U_memberorderrelease[0].value"]: item.total,
            });
          } else if (item.status == "1") {
            this.setData({
              ["U_memberorderrelease[1].value"]: item.total,
            });
          } else if (item.status == "2") {
            this.setData({
              ["U_memberorderrelease[2].value"]: item.total,
            });
          } else if (item.status == "3") {
            this.setData({
              ["U_memberorderrelease[3].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.fight_groups_order) {
        this.data.member_order.fight_groups_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberordergroup[1].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordergroup[2].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordergroup[3].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordergroup[4].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.snatch_regiment_order
      ) {
        this.data.member_order.snatch_regiment_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberordergrab[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordergrab[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordergrab[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordergrab[3].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.live_install_order
      ) {
        this.data.member_order.live_install_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberorderlive_install[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorderlive_install[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorderlive_install[2].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_memberorderlive_install[4].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.live_install_work_order
      ) {
        this.data.member_order.live_install_work_order.forEach((item) => {
          if (item.status == 2) {
            this.setData({
              ["U_memberorderlive_install_worker[0].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_memberorderlive_install_worker[1].value"]: item.total,
            });
          } else if (item.status == 4) {
            this.setData({
              ["U_memberorderlive_install_worker[2].value"]: item.total,
            });
          } else if (item.status == 6) {
            this.setData({
              ["U_memberorderlive_install_worker[4].value"]: item.total,
            });
          }
        });
      } else {
        this.data.datas.list = this.data.datas.list.filter((item) => {
          return item.uikey != 'U_memberorderlive_install_worker';
        });
        this.setData({
          'datas.list': this.data.datas.list
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.aggregation_cps_order
      ) {
        this.data.member_order.aggregation_cps_order.forEach((item) => {
          if (item.status == 1) {
            this.setData({
              ["U_memberordercps[2].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordercps[3].value"]: item.total,
            });
          } else if (item.status == -1) {
            this.setData({
              ["U_memberordercps[0].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.group_work_order) {
        for (let i = 0; i < this.data.member_order.group_work_order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = this.data.member_order.group_work_order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberordernew_group[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordernew_group[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordernew_group[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordernew_group[3].value"]: item.total,
            });
          }
        }
      }

    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    bindTags(evt) {
      let index = evt.detail.index;
      this.setData({
        active: index,
      });
      if (this.data.datas.list[index].uikey == "U_memberorder_ys") {
        // 益生线下订单
        wx.navigateTo({
          url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=ysSystem",
        });
        return false;
      }
    },
    goAllOrderlist: function (e) {
      let ordertype = "";
      switch (this.data.datas.list[0].uikey) {
      case "U_memberorder":
        ordertype = "";
        break;
      case "U_memberorderhotel":
        ordertype = "hotel";
        break;
      case "U_memberorderrelease":
        ordertype = "lease_toy";
        break;
      case "U_memberordergroup":
        ordertype = "groups";
        break;
      case "U_memberordergrab":
        ordertype = "grabGroup";
        break;
      case "U_memberordernew_group":
        ordertype = "groupWork";
        break;
      case "U_memberorder_ys":
        ordertype = "ysSystem";
        break;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=" +
          ordertype,
      });
    },
    //跳到我的订单详情页面
    goorderlist: function (e) {
      //orderlist
      let status = e.currentTarget.dataset.status;
      if (status == 4) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" + status,
      });
    },
    gohotelOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=hotel",
      });
    },
    goleaseOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=lease_toy",
      });
    },
    gogroupOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      if (status == 5) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist?orderType=groups",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=groups",
      });
    },
    gograbOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=grabGroup",
      });
    },
    golive_installOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      wx.navigateTo({
        url: "/packageH/installationSever/installationSeverMemberHome/installationSeverMemberHome?status=" + status,
      });
    },
    golive_install_workOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      if (status == -1) {
        wx.navigateTo({
          url: "/packageH/installationSever/installationSeverHome/installationSeverHome?status=1",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageH/installationSever/installationSeverHome/installationSeverHome?status=" + status,
      });
    },
    gocpsOrderlist(e) {
      let status = e.currentTarget.dataset.status;
      if (status == 3) {
        wx.navigateTo({
          url: "/packageA/member/order/cpsCoupon/cpsCoupon",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/order/cpsOrder/cpsOrder?status=" + status,
      });
    },
    goGroupWorkorderlist: function (e) {
      //orderlist
      let status = e.currentTarget.dataset.status;
      if (status == 4) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" + status + "&orderType=groupWork",
      });
    },
  },
  observers: {
    "member_order.**": function (res) {
      // 每次 setData 都触发
      if (res) {
        for (let i = 0; i < res.order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = res.order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberorder[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorder[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorder[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorder[3].value"]: item.total,
            });
          }
        }
      }
    },
  },
});