收藏
回答

RT,随机生成菜单判断逻辑无效,上代码

问题模块
API和组件

调试了1小时无果,求助大家,初步判断是if的判断代码无效。

wxml:

<view>
<input type="number" bindinput="getnum" placeholder="人数"/>
<input type="number" bindinput="getprc" placeholder="人均"/>
<input type="number" bindinput="getfood" placeholder="几个菜"/>
<button bindtap="changeMenu">Go</button>
<view>{{getfoodarr}}</view>
<view>{{pricesum}}</view>

JS:

Page({
    data: ({
        wow: "",
        getnum: "",
        getprc: "",
        getfood: "",
        pricesum: "",
        foodmenu: "",
        getfoodarr: ""
    }),
    getnum: function (e) {
        var num = parseInt(e.detail.value)
        this.setData({
            getnum: num
        })
    },
    getprc: function (e) {
        var prc = parseInt(e.detail.value)
 
        this.setData({
            getprc: prc
        })
    },
    getfood: function (e) {
        var food = parseInt(e.detail.value)
 
        this.setData({
            getfood: food
        })
    },
    changeMenu: function (e) {
        var that = this;
        var menu = [
            ["蒜泥青菜", 8],
            ["酸辣土豆丝", 9],
            ["油渣青菜", 10],
            ["蒜泥空心菜", 12],
            ["酸辣大白菜", 12],
            ["番茄炒蛋", 12],
            ["尖椒榨菜肉丝", 13],
            ["香干肉丝", 13],
            ["韭黄炒蛋", 15],
            ["尖椒炒蛋", 15],
            ["芹菜香干肉丝", 15],
            ["糖醋里脊", 15],
            ["雪菜炒蛋", 15],
            ["雪菜炒素几", 15],
            ["雪菜尖椒油渣", 15],
            ["尖椒页豆腐", 15],
            ["雪菜笋", 18],
            ["上汤娃娃菜", 18],
            ["小炒肉", 18],
            ["雪菜蘑菇肉片", 18],
            ["私房菜", 18],
            ["衢味笋", 18],
            ["雪菜鸡肫", 18],
            ["爆炒猪肝", 18],
            ["腊肉莴笋干", 20],
            ["干页豆腐", 20],
            ["蒜泥青菜", 8],
            ["萝卜丝牛肉", 22],
            ["白切肚头", 22],
            ["萝卜丝鸡肫", 22],
            ["红烧猪蹄", 24],
            ["葱油牛百叶", 25],
            ["笋子烧肉", 28],
            ["尖椒脆肠", 28],
            ["尖椒大肠", 28],
            ["红烧肉", 28],
            ["尖椒肚头", 28],
            ["红烧鸡块", 28],
            ["萝卜丝带鱼", 28],
            ["土豆鸡块", 28],
            ["红烧小排", 30],
            ["番茄牛腩", 30],
            ["芋艿牛腩", 30],
            ["爆炒腰花", 32],
            ["尖椒牛肚", 32],
            ["红烧小黄鱼", 32],
            ["土豆牛腩", 32],
            ["水煮肉片", 32],
            ["尖椒门腔", 32],
            ["小排土豆煲", 32],
            ["红烧小泥鳅", 35],
            ["酸菜鱼", 38],
            ["雪菜尖椒目鱼", 38],
            ["芹菜目鱼", 38],
            ["水煮牛百叶", 38],
            ["土烧包头鱼", 48],
            ["泥鳅烧芋艿(黄瓜)", 45],
            ["红烧鱼头", 58],
            ["爆炒鳝片", 58],
            ["香酥蹄髈", 58],
            ["黑椒牛排", 58],
            ["香菇炖鸡", 68]
        ]
 
        var y = 0;
        var kong = [];
        var menuarr = menu.length;
 
        function suiji() {
            return parseInt(Math.random() * menuarr);
        }
        var cai = menu[suiji()];
        for (var x = 0; x < kong.length; x++) {
            if (cai == kong[x]) {
                changeMenu();
            }
            kong.push(cai)
            var money = cai[1]; //二维数组的价格
            //for循环累加价格
            y += money;
        }
        if (y > that.getnum * that.getprc) {
            changeMenu()
        } else if (y >= (that.getnum * that.getprc - 5) && y <= that.getnum * that.getprc) {
            this.setData({
                getfoodarr: kong,
                pricesum: y
            })
        }else{
            changemenu();
        }
    }
})


最后一次编辑于  2017-01-03  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏关注问题回答