user.js 5.4 KB
Newer Older
D
devil_gong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
const app = getApp();
Page({
  data: {
    avatar: app.data.default_user_head_src,
    nickname: "用户名",
    customer_service_tel: null,
    common_user_center_notice: null,
    message_total: 0,
    head_nav_list: [
      { name: "订单总数", url: "user-order", count: 0 },
      { name: "商品收藏", url: "user-faovr", count: 0 },
      { name: "我的足迹", url: "user-goods-browse", count: 0 },
      { name: "我的积分", url: "user-integral", count: 0 },
    ],
    user_order_status_list: [
D
Devil 已提交
16 17 18 19 20
      { name: "待付款", status: 1, count: 0, url: "/pages/user-order/user-order?status=1" },
      { name: "待发货", status: 2, count: 0, url: "/pages/user-order/user-order?status=2" },
      { name: "待收货", status: 3, count: 0, url: "/pages/user-order/user-order?status=3" },
      { name: "已完成", status: 4, count: 0, url: "/pages/user-order/user-order?status=4" },
      { name: "退款/售后", status: 101, count: 0, url: "/pages/user-orderaftersale/user-orderaftersale" },
D
devil_gong 已提交
21 22 23 24 25 26 27
    ],
    nav_lists: [
      {
        url: "user-order",
        icon: "user-nav-order-icon",
        name: "我的订单",
      }
D
devil_gong 已提交
28 29 30 31
    ],

    // 远程自定义导航
    navigation: [],
G
gongfuxiang 已提交
32 33

    common_app_is_online_service: 0,
D
devil_gong 已提交
34 35 36
  },

  onShow() {
G
gongfuxiang 已提交
37
    wx.setNavigationBarTitle({title: app.data.common_pages_title.user});
D
devil_gong 已提交
38 39 40 41
    this.init();
  },

  init(e) {
D
devil_gong 已提交
42 43 44
    var user = app.get_user_cache_info(this, "init"),
        self = this;
    // 用户未绑定用户则转到登录页面
D
xcx  
devil_gong 已提交
45
    var msg = (user == false) ? '授权用户信息' : '绑定手机号码';
D
1.6  
devil_gong 已提交
46
    if (app.user_is_need_login(user)) {
D
devil_gong 已提交
47 48
      wx.showModal({
        title: '温馨提示',
D
xcx  
devil_gong 已提交
49
        content: msg,
D
devil_gong 已提交
50 51 52
        confirmText: '确认',
        cancelText: '暂不',
        success: (result) => {
D
devil_gong 已提交
53
          wx.stopPullDownRefresh();
D
devil_gong 已提交
54 55 56
          if(result.confirm) {
            wx.navigateTo({
              url: "/pages/login/login?event_callback=init"
D
devil_gong 已提交
57
            });
D
devil_gong 已提交
58 59 60
          }
          self.setData({
            avatar: user.avatar || app.data.default_user_head_src,
D
devil_gong 已提交
61
            nickname: user.user_name_view || '用户名',
D
devil_gong 已提交
62 63 64 65 66
          });
        },
      });
    } else {
      self.get_data();
D
devil_gong 已提交
67 68 69 70 71 72
    }
  },

  // 获取数据
  get_data() {
    wx.request({
D
devil_gong 已提交
73
      url: app.get_request_url("center", "user"),
D
devil_gong 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
      method: "POST",
      data: {},
      dataType: "json",
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: res => {
        wx.stopPullDownRefresh();
        if (res.data.code == 0) {
          var data = res.data.data;

          // 订单数量处理
          var temp_user_order_status_list = this.data.user_order_status_list;
          if ((data.user_order_status || null) != null && data.user_order_status.length > 0) {
            for (var i in temp_user_order_status_list) {
              for (var t in data.user_order_status) {
                if (temp_user_order_status_list[i]['status'] == data.user_order_status[t]['status']) {
                  temp_user_order_status_list[i]['count'] = data.user_order_status[t]['count'];
                  break;
                }
              }
            }
          }

          // 头部导航总数
          var temp_head_nav_list = this.data.head_nav_list;
          temp_head_nav_list[0]['count'] = ((data.user_order_count || 0) == 0) ? 0 : data.user_order_count;
          temp_head_nav_list[1]['count'] = ((data.user_goods_favor_count || 0) == 0) ? 0 : data.user_goods_favor_count;
          temp_head_nav_list[2]['count'] = ((data.user_goods_browse_count || 0) == 0) ? 0 : data.user_goods_browse_count;
          temp_head_nav_list[3]['count'] = ((data.integral || 0) == 0) ? 0 : data.integral;

          this.setData({
            user_order_status_list: temp_user_order_status_list,
            customer_service_tel: data.customer_service_tel || null,
            common_user_center_notice: data.common_user_center_notice || null,
            avatar: (data.avatar != null) ? data.avatar : ((this.data.avatar || null) == null ? app.data.default_user_head_src : this.data.avatar),
            nickname: (data.nickname != null) ? data.nickname : this.data.nickname,
            message_total: ((data.common_message_total || 0) == 0) ? 0 : data.common_message_total,
            head_nav_list: temp_head_nav_list,
D
devil_gong 已提交
111
            navigation: data.navigation || [],
G
gongfuxiang 已提交
112
            common_app_is_online_service: data.common_app_is_online_service || 0,
D
devil_gong 已提交
113 114
          });
        } else {
D
devil_gong 已提交
115
          app.showToast(res.data.msg);
D
devil_gong 已提交
116 117 118 119
        }
      },
      fail: () => {
        wx.stopPullDownRefresh();
D
devil_gong 已提交
120
        app.showToast("服务器请求出错");
D
devil_gong 已提交
121 122 123 124 125 126 127
      }
    });
  },

  // 清除缓存
  clear_storage(e) {
    wx.clearStorage()
G
gongfuxiang 已提交
128
    app.showToast("清除缓存成功", "success");
D
devil_gong 已提交
129 130 131 132 133 134
  },

  // 客服电话
  call_event() {
    if(this.data.customer_service_tel == null)
    {
D
devil_gong 已提交
135
      app.showToast("客服电话有误");
D
devil_gong 已提交
136
    } else {
G
gongfuxiang 已提交
137
      wx.makePhoneCall({ phoneNumber: this.data.customer_service_tel });
D
devil_gong 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150
    }
  },

  // 下拉刷新
  onPullDownRefresh(e) {
    this.init(e);
  },

  // 头像查看
  preview_event() {
    if(app.data.default_user_head_src != this.data.avatar)
    {
      wx.previewImage({
D
devil_gong 已提交
151
        current: this.data.avatar,
D
devil_gong 已提交
152 153 154 155 156 157 158 159 160
        urls: [this.data.avatar]
      });
    }
  },

  // 头像加载错误
  user_avatar_error(e) {
    this.setData({avatar: app.data.default_user_head_src});
  },
D
devil_gong 已提交
161 162 163 164 165

  // 远程自定义导航事件
  navigation_event(e) {
    app.operation_event(e);
  },
D
devil_gong 已提交
166
});