129 lines
4.0 KiB
JavaScript
129 lines
4.0 KiB
JavaScript
// subpages/goodsdetail/goodsdetail.js
|
|
var app = getApp();
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
goodsId: "",
|
|
isHidePageloading: false,
|
|
detailBean: {},
|
|
currentStandard: {},
|
|
standardList: [],
|
|
curStandardIndex: 0,
|
|
imgUrl: app.shopImgUrl,
|
|
carList: [],
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
goodsId: options.id
|
|
})
|
|
this.getGoodsDetail();
|
|
|
|
},
|
|
//获取商品详情
|
|
getGoodsDetail() {
|
|
var _self = this
|
|
app.restAjax.get(app.restAjax.path('{shopUrl}/app/shopgoods/getrelease/{goodsId}',
|
|
[app.shopUrl, _self.data.goodsId]),
|
|
null,
|
|
null,
|
|
function (code, data) {
|
|
if (data) {
|
|
if (data.goodsPhotos.length > 0) {
|
|
var photos = data.goodsPhotos.split(',');
|
|
data.photoList = photos;
|
|
} else {
|
|
data.photoList = []
|
|
}
|
|
data.goodsPrice = 0;
|
|
data.goodsStandarName = "";
|
|
data.goodsStandarId = "";
|
|
data.isCheck = false;
|
|
data.carAmount = 0;
|
|
_self.setData({
|
|
detailBean: data,
|
|
})
|
|
}
|
|
},
|
|
function (code, data) {
|
|
app.dialog.msg(data.msg);
|
|
},
|
|
function () {
|
|
_self.getGoodsStandardList();
|
|
})
|
|
},
|
|
// carAmount;
|
|
// goodsPrice;
|
|
// goodsStandarId;
|
|
// goodsStandarName;
|
|
// isCheck;
|
|
//获取商品附加信息
|
|
getGoodsStandardList() {
|
|
var _self = this
|
|
_self.data.detailBean.goodsPrice = 0;
|
|
_self.data.detailBean.goodsStandarName = "";
|
|
_self.data.detailBean.goodsStandarId = "";
|
|
_self.data.detailBean.isCheck = false;
|
|
_self.data.detailBean.carAmount = 0;
|
|
|
|
app.restAjax.get(app.restAjax.path('{shopUrl}/app/shopgoodsitem/listrelease/{goodsId}',
|
|
[app.shopUrl, _self.data.goodsId]),
|
|
null,
|
|
null,
|
|
function (code, data) {
|
|
if (data && data.length > 0) {
|
|
_self.data.detailBean.goodsPrice = data[0].goodsItemUnitPrice;
|
|
_self.data.detailBean.goodsStandarName = data[0].goodsItemName;
|
|
_self.data.detailBean.goodsStandarId = data[0].goodsItemId;
|
|
_self.setData({
|
|
standardList: data,
|
|
currentStandard: data[0],
|
|
isHidePageloading: true,
|
|
detailBean: _self.data.detailBean
|
|
})
|
|
} else {
|
|
_self.setData({
|
|
isHidePageloading: true
|
|
})
|
|
}
|
|
},
|
|
function (code, data) {
|
|
app.dialog.msg(data.msg);
|
|
_self.setData({
|
|
isHidePageloading: true
|
|
})
|
|
},
|
|
function () {
|
|
_self.setData({
|
|
isHidePageloading: true
|
|
})
|
|
})
|
|
},
|
|
doSelStandard(e) {
|
|
var item = e.currentTarget.dataset.item;
|
|
var index = e.currentTarget.dataset.index;
|
|
this.data.detailBean.goodsPrice = item.goodsItemUnitPrice;
|
|
this.data.detailBean.goodsStandarName = item.goodsItemName;
|
|
this.data.detailBean.goodsStandarId = item.goodsItemId;
|
|
this.setData({
|
|
currentStandard: item,
|
|
curStandardIndex: index,
|
|
detailBean: this.data.detailBean
|
|
})
|
|
},
|
|
// 添加购物车
|
|
addToCar() {
|
|
//判断购物车中是否存在该商品
|
|
var _self = this;
|
|
for (let i = 0; i < _self.data.carList.length; i++) {
|
|
var item = _self.data.carList[i];
|
|
|
|
}
|
|
}
|
|
}) |