// pages/serch/serch.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    money: 9.9,
    Integral: 20,
    allMoney: 0,
    allIntegral: 0,
    number: 0,
    list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.request({
      url:
        "https://www.fastmock.site/mock/883cd62177ae0a3a79638beccc3349da/api/order/list",
      success: (e) => {
        let { data } = e.data;
        this.setData({
          list: data.list,
        });
      },
    });
  },
  onChange(e) {
    this.setData({
      number: e.detail,
    });
  },
  prev(e) {
    var id = e.currentTarget.dataset.id;
    console.log(id);
    this.setData({
      allMoney: this.data.allMoney - this.data.money,
      allIntegral: this.data.allIntegral - this.data.Integral,
    });
  },
  plus() {
    this.setData({
      allMoney: this.data.allMoney + this.data.money,
      allIntegral: this.data.allIntegral + this.data.Integral,
    });
  },
  OnInput(e) {
    var list = this.data.list;
    var value = e.detail.value;
    var id = e.currentTarget.dataset.id;
    this.data.allMoney = 0;
    this.data.allIntegral = 0;
    for (var i = 0; i < list.length; i++) {
      if (id == list[i].id) {
        list[i].status = value
      }
      this.data.allMoney += (list[i].status * this.data.money);
      this.data.allIntegral += (list[i].status * this.data.Integral);
    }
    this.setData({
      allMoney: this.data.allMoney,
      allIntegral: this.data.allIntegral,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

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

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

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

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

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

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