// packageF/debt/debtor/debtorindex/debtorindex.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shoplist: [{
        name: "采购金",
        price: "8451.26"
      },
      {
        name: "网店收入",
        price: "8451.26"
      },
      {
        name: "已完成订单数",
        price: "896"
      },
      {
        name: "累计订单金额",
        price: "622556"
      }
    ],
    nume: [{
        icon: "icon-fontclass-dianpu1",
        color: '#fd6154',
        name: "进入店铺"
      },
      {
        icon: "icon-fontclass-erweima",
        color: '#0ed79b',
        name: "店铺二维码"
      },
      {
        icon: "icon-fontclass-huiyuandengji",
        color: '#ff961f',
        name: "会员管理"
      },
      {
        icon: "icon-fontclass-shangpindingdan",
        color: '#22a6ff',
        name: "网店订单"
      },
      {
        icon: "icon-fontclass-shangpindingdan",
        color: '#22a6ff',
        name: "采购订单"
      },
      {
        icon: "icon-fontclass-tichengmingxi",
        color: '#8562e6',
        name: "采购金明细"
      },
      {
        icon: "icon-fontclass-shenhe1",
        color: '#fd6154',
        name: "售后审核"
      },
      {
        icon: "icon-fontclass-wdeguanzhu",
        color: '#11da9f',
        name: "债务人申请"
      }
    ],
    info: [],
    debtor_id:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.setNavigationBarTitle({
      title: '债务人',
    })
  },
  tourl(e) {
    console.log(e)
    let name = e.currentTarget.dataset.item.name;
    if (name == '进入店铺') {
      if(!this.data.debtor_id){
        app.tips('你还不是债务人或者债务人身份已过期')
        return
      }
      wx.navigateTo({
        url: '/packageF/debt/debtor/debtorShop/debtorShop?kid='+this.data.debtor_id,
      })
    } else if (name == '店铺二维码') {
        wx.navigateTo({
          url: '/packageF/debt/debtShopCode/debtShopCode',
        })
    } else if (name == '会员管理') {
      wx.navigateTo({
        url: '/packageF/debt/userManagement/userManagement?type=2',
      })
    } else if (name == '网店订单') {
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?member_type=4',
      })
    } else if (name == '采购订单') {
      wx.navigateTo({
        url: '/packageA/member/myOrder_v2/myOrder_v2?member_type=2',
      })
    } else if (name == '采购金明细') {
      wx.navigateTo({
        url: '/packageF/debt/purchaseDetails/purchaseDetails',
      })
    } else if (name == '售后审核') {
      wx.navigateTo({
        url: '/packageF/debt/debtorAudit/debtorAudit',
      })
    } else if (name == '债务人申请') {
      wx.navigateTo({
        url: '/packageF/debt/debtapply/debtapply?type=2',
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  getData() {
    let urlStr = app.getNetAddresss('plugin.debt-shop.frontend.debt-member.getDebtData');
    app._getNetWork({
      url: urlStr,
      data: {
        member_type: 2
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            info: res.data,
            debtor_id:res.data.default_debtor_id
          })
          let info = this.data.info;
          this.data.shoplist.forEach((ele, index) => {
            console.log(ele.name)
            if (ele.name == '采购金') {
              ele.price = info.debtor_credit;
            } else if (ele.name == '网店收入') {
              ele.price = info.sum_debtor_income;
            } else if (ele.name == '已完成订单数') {
              ele.price = info.order_count;
            } else if (ele.name == '累计订单金额') {
              ele.price = info.order_price;
            }
          })
          this.setData({
            shoplist: this.data.shoplist,
            debtor_id:res.data.default_debtor_id
          })
        } else {
          wx.showToast({
            icon: 'none',
            title: res.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
})