first commit
This commit is contained in:
77
衣莎项目/源码/YiShaXiYi/mall/index/index.js
Normal file
77
衣莎项目/源码/YiShaXiYi/mall/index/index.js
Normal file
@@ -0,0 +1,77 @@
|
||||
// mall/index/index.js
|
||||
const app = getApp();
|
||||
const regeneratorRuntime = app.loadAsync()
|
||||
const model = app.loadModel("index")
|
||||
const http = app.loadHttp()
|
||||
const util = app.loadUtils("util")
|
||||
Component({
|
||||
/**
|
||||
* 组件的属性列表
|
||||
*/
|
||||
properties: {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
system: app.globalData.system, //设备相关信息
|
||||
pageTitle: "商城", //头部标题
|
||||
isBack: false,//显示返回
|
||||
titleColor: { //头部背景和文字颜色
|
||||
bColor: "#1dbf53",
|
||||
tColor: "#ffffff"
|
||||
},
|
||||
TabCur: 0,
|
||||
scrollLeft: 0,
|
||||
category: [],// 商品大分类
|
||||
product: [],//大分类下的商品
|
||||
},
|
||||
created() {
|
||||
this.storeCategory()
|
||||
},
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
// tab
|
||||
tabSelect(e) {
|
||||
this.setData({
|
||||
TabCur: e.currentTarget.dataset.id,
|
||||
scrollLeft: (e.currentTarget.dataset.id - 1) * 60,
|
||||
product: []
|
||||
})
|
||||
this.storeProduct()
|
||||
},
|
||||
// 获取商城分类获取
|
||||
async storeCategory() {
|
||||
let res = await http.http.request1({ url: `${http.api.storeCategory}`, method: "GET" })
|
||||
this.setData({
|
||||
category: res.data.data,
|
||||
TabCur: res.data.data[0].id
|
||||
})
|
||||
this.storeProduct()
|
||||
},
|
||||
// 获取分类下商品
|
||||
async storeProduct() {
|
||||
let res = await http.http.request1({ url: `${http.api.storeProduct}/${this.data.TabCur}`, method: "GET" })
|
||||
this.setData({
|
||||
product: res.data.data
|
||||
})
|
||||
},
|
||||
// 添加商品到购物车
|
||||
async addCart(e) {
|
||||
let item = e.currentTarget.dataset.item
|
||||
item.num = 0
|
||||
item.attr = []
|
||||
model.shopCart.setCart(item)
|
||||
},
|
||||
// 去详情
|
||||
goInfo(e) {
|
||||
wx.navigateTo({
|
||||
url: "/mall/index/shopInfo/shopInfo?id=" + e.currentTarget.dataset.id
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user