|
@@ -1,85 +1,13 @@
|
|
|
// pages/merchant_page/index.js
|
|
|
-var sum=0;
|
|
|
+var sum = 0;
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
- foods: [{
|
|
|
- id: 0,
|
|
|
- foodsImg: 'https://ts1.cn.mm.bing.net/th/id/R-C.31b40d484fb6ce8489e9d41059da2287?rik=OtaZNWbOg00BnA&riu=http%3a%2f%2fi8.meishichina.com%2fattachment%2frecipe%2f2017%2f11%2f14%2f20171114151065744152710062141.jpg%40!p800&ehk=qILMoJbCdGAl68ppA0fZ9DOmh3i2AxL1P6s5XpyUS6I%3d&risl=&pid=ImgRaw&r=0',
|
|
|
- foodsName: '麻辣香锅',
|
|
|
- foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
|
- initPrice: 38.80,
|
|
|
- nowPrice: 20.98,
|
|
|
- num: 0
|
|
|
- },
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- foodsImg: 'https://pic3.zhimg.com/v2-dee617360db759cbe32851a80cfa34d7_r.jpg',
|
|
|
- foodsName: '麻辣拌',
|
|
|
- foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
|
- initPrice: 18.80,
|
|
|
- nowPrice: 10.98,
|
|
|
- num: 0
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- foodsImg: 'https://i3.meishichina.com/atta/recipe/2013/01/17/20130117165927356161752.jpg?x-oss-process=style/p800',
|
|
|
- foodsName: '烤冷面',
|
|
|
- foodsDesc: '包含香菜、菠菜、面、豆芽、海带',
|
|
|
- initPrice: 10.00,
|
|
|
- nowPrice: 6.98,
|
|
|
- num: 0
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- foodsImg: 'https://ts1.cn.mm.bing.net/th/id/R-C.88a2cba6e73706dfd9c0be2710f9eb76?rik=W7tpDQYqXcnUNQ&riu=http%3a%2f%2fpic34.photophoto.cn%2f20150114%2f0042040388971148_b.jpg&ehk=gkDGf3i9aRf1Y40phZWEoJ%2fZJ0OzU%2bL%2bfEzOOXtLaI8%3d&risl=&pid=ImgRaw&r=0',
|
|
|
- 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
|
|
|
- }
|
|
|
- ],
|
|
|
+
|
|
|
+ foods: [],
|
|
|
show: false,
|
|
|
totalPrice: 0,
|
|
|
info: '',
|
|
@@ -90,41 +18,40 @@ Page({
|
|
|
info: e.detail.value
|
|
|
})
|
|
|
},
|
|
|
- onMinus(e){
|
|
|
+ onMinus(e) {
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
- sum-=this.data.foods[id].nowPrice;
|
|
|
+ sum -= this.data.foods[id].nowPrice;
|
|
|
// console.log(sum.toFixed(2)+"---------");
|
|
|
this.setData({
|
|
|
- totalPrice:Math.abs(sum)
|
|
|
+ totalPrice: Math.abs(sum)
|
|
|
})
|
|
|
},
|
|
|
- onPlus(e){
|
|
|
+ onPlus(e) {
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
- sum+=this.data.foods[id].nowPrice;
|
|
|
+ sum += this.data.foods[id].nowPrice;
|
|
|
// console.log(sum.toFixed(2)+"+++++++++");
|
|
|
// console.log(typeof sum );
|
|
|
this.setData({
|
|
|
- totalPrice:Math.abs(sum)
|
|
|
+ totalPrice: Math.abs(sum)
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
onChange(e) {
|
|
|
- let id = e.currentTarget.dataset.id; //获取当前点击的Id
|
|
|
+ let id = e.currentTarget.dataset.id; //获取当前点击的Id
|
|
|
let num = e.detail; //获取当前步进器的值
|
|
|
//给当前的对象里面的属性绑定其步进器的值
|
|
|
- this.setData({
|
|
|
- ["foods["+id+"].num"]:num
|
|
|
- })
|
|
|
+ this.setData({
|
|
|
+ ["foods[" + id + "].num"]: num
|
|
|
+ })
|
|
|
|
|
|
- //接下来我们利用这个步进器的值,forEach遍历求和即可
|
|
|
+ //接下来我们利用这个步进器的值,forEach遍历求和即可
|
|
|
// console.log(sum);
|
|
|
-
|
|
|
+
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
onSearch() {
|
|
|
let list = this.data.foods;
|
|
|
- // 给你一个数组 里面包含a这个字的元素 将这些元素抛入新数组
|
|
|
- let inputData = this.data.info
|
|
|
+ let inputData = this.data.info;
|
|
|
let showList = [];
|
|
|
for (let i = 0; i < list.length; i++) {
|
|
|
let name = list[i].foodsName
|
|
@@ -132,7 +59,6 @@ Page({
|
|
|
showList.push(list[i]);
|
|
|
}
|
|
|
}
|
|
|
- // console.log(showList);
|
|
|
|
|
|
// showList
|
|
|
if (showList.length == 0) {
|
|
@@ -152,9 +78,21 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad() {
|
|
|
- this.setData({
|
|
|
- showList: this.data.foods
|
|
|
+ wx.request({
|
|
|
+ url: 'https://www.fastmock.site/mock/1f6ac0783b50c03f315fe6c001ca8dea/search/search',
|
|
|
+ success: (res) => {
|
|
|
+ let {
|
|
|
+ data
|
|
|
+ } = res.data;
|
|
|
+ // console.log(data);
|
|
|
+ this.setData({
|
|
|
+ foods: data.dishName,
|
|
|
+ showList: data.dishName
|
|
|
+ })
|
|
|
+ }
|
|
|
})
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|