// pages/merchant_page/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    foods: [{
        id: 0,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 1,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 10
      },
      {
        id: 2,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 3,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 4,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 5,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 6,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      },
      {
        id: 7,
        foodsImg: 'https://bpic.588ku.com/back_origin_min_pic/20/11/05/a7438bbf54ace893e790545815e14ef3.jpg',
        foodsName: '麻辣烫',
        foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
        initPrice: 28.80,
        nowPrice: 10.98,
        num : 0
      }
    ],
    show: false,
    totalPrice: 0,
    info: '',
    showList: []
  },
  onInput(e) {
    this.setData({
      info: e.detail.value
    })
  },
  onChange(e) {
    let id = e.currentTarget.dataset.id;
    let num = e.detail;
    // console.log(num); 
    let ans  = this.data.foods[0].num 
    console.log(ans);
    this.setData({
      [ans ]:'num'
    })
    // for( let i = 0 ; i < showList.length ;i ++ ) {
    //   showList[i].num 
    // }
    // for( let i = 0 ; i < showList.length ;i ++ ) {
    //   showList[i].
    // }
    // totalPrice
  },
  onSearch() {
    let list = this.data.foods;
    // 给你一个数组  里面包含a这个字的元素  将这些元素抛入新数组 
    let inputData = this.data.info
    let showList = [];
    for (let i = 0; i < list.length; i++) {
      let name = list[i].foodsName
      if (name.indexOf(inputData) >= 0) {
        showList.push(list[i]);
      }
    }
    console.log(showList);

    // showList
    if (showList.length != 0) {
      this.setData({
        show: false,
      })
    } else {
      this.setData({
        show: true,
      })
    }
    this.setData({
      showList,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      showList: this.data.foods
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})