const app = getApp();
Page({
  data: {
    params: null,
    data_list_loding_status: 1,
    data_list_loding_msg: '',
    data_bottom_line_status: false,

    detail: null,
    detail_list: []
  },

  onLoad(params) {
    //params['id'] = 1;
    this.setData({ params: params });
    this.init();
  },

  onShow() {},

  init() {
    var self = this;
    swan.showLoading({ title: "加载中..." });
    this.setData({
      data_list_loding_status: 1
    });

    swan.request({
      url: app.get_request_url("detail", "order", "distribution"),
      method: "POST",
      data: {
        id: this.data.params.id
      },
      dataType: "json",
      success: res => {
        swan.hideLoading();
        swan.stopPullDownRefresh();
        if (res.data.code == 0) {
          var data = res.data.data;
          self.setData({
            detail: data.data,
            detail_list: [{ name: "用户昵称", value: data.data.user_name_view || '' }, { name: "订单金额", value: data.data.total_price + ' 元' || '' }, { name: "退款金额", value: data.data.refund_price + ' 元' || '' }, { name: "订单状态", value: data.data.order_status_name || '' }, { name: "支付状态", value: data.data.order_pay_status_name || '' }, { name: "来源终端", value: data.data.order_client_type_name || '' }, { name: "下单时间", value: data.data.add_time_time || '' }],

            data_list_loding_status: 3,
            data_bottom_line_status: true,
            data_list_loding_msg: ''
          });
        } else {
          self.setData({
            data_list_loding_status: 2,
            data_bottom_line_status: false,
            data_list_loding_msg: res.data.msg
          });
          if (app.is_login_check(res.data, self, 'init')) {
            app.showToast(res.data.msg);
          }
        }
      },
      fail: () => {
        swan.hideLoading();
        swan.stopPullDownRefresh();
        self.setData({
          data_list_loding_status: 2,
          data_bottom_line_status: false,
          data_list_loding_msg: '服务器请求出错'
        });

        app.showToast("服务器请求出错");
      }
    });
  },

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

  // 头像查看
  avatar_event(e) {
    var value = e.currentTarget.dataset.value || null;
    if (value != null) {
      swan.previewImage({
        current: value,
        urls: [value]
      });
    } else {
      app.showToast('头像地址有误');
    }
  }

});