123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- // pages/merchant_page/index.js
- var sum=0;
- 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: 0
- },
- {
- 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
- })
- },
- onMinus(e){
- var id = e.currentTarget.dataset.id;
- sum-=this.data.foods[id].nowPrice;
- // console.log(sum.toFixed(2)+"---------");
- this.setData({
- totalPrice:Math.abs(sum)
- })
- },
- onPlus(e){
- var id = e.currentTarget.dataset.id;
- sum+=this.data.foods[id].nowPrice;
- // console.log(sum.toFixed(2)+"+++++++++");
- // console.log(typeof sum );
- this.setData({
- totalPrice:Math.abs(sum)
- })
-
- },
- onChange(e) {
- let id = e.currentTarget.dataset.id; //获取当前点击的Id
- let num = e.detail; //获取当前步进器的值
- //给当前的对象里面的属性绑定其步进器的值
- this.setData({
- ["foods["+id+"].num"]:num
- })
- //接下来我们利用这个步进器的值,forEach遍历求和即可
- // console.log(sum);
-
- },
-
- 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: true,
- })
- } else {
- this.setData({
- show: false,
- })
- }
- this.setData({
- showList,
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- this.setData({
- showList: this.data.foods
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|