//pages/myRelease/myRelease.js
var app =getApp();
Page({/**
* 页面的初始数据*/data: {
releases: [],
low_mon:0, //降价至
now_mon: 0, //现价
image: "", //降价图片
productID: 0,
limit:5,
release:false,
showMore:false,
showLowMoney:false,
lowMoney: [{
money:0,
tip:"打1折,极速卖"},
{
money:0,
tip:"打3折,出手快"},
{
money:0,
tip:"打5折,有竞争力"}, {
money:0,
tip:"打8折"}
],
lowind:0,
productState:false,
},/**
* 生命周期函数--监听页面显示*/onShow:function(options) {this.getMyRelease();
},/**
* 降价显示*/onClickShowMoney(e) {
let index=e.currentTarget.dataset.index;
let productID=e.currentTarget.dataset.productid;
let product= this.data.releases[index];
let one= "lowMoney[" + 0 + "].money";
let three= "lowMoney[" + 1 + "].money";
let five= "lowMoney[" + 2 + "].money";
let eight= "lowMoney[" + 3 + "].money";this.setData({
showLowMoney:!this.data.showLowMoney,
now_mon: product.currentPrice,
[one]: (product.currentPrice* 0.1).toFixed(2), //1折
[three]: (product.currentPrice * 0.3).toFixed(2), //3折
[five]: (product.currentPrice * 0.5).toFixed(2), //5折
[eight]: (product.currentPrice * 0.8).toFixed(2), //8折
low_mon: (product.currentPrice * 0.1).toFixed(2), //默认1折
productID: productID,
image: product.image
})
},/**
* 更多显示*/onClickShowMore(e) {this.setData({
showMore:!this.data.showMore,
productID: e.currentTarget.dataset.productid
});if (e.currentTarget.dataset.state === 0) {this.setData({
productState:true})
}else{this.setData({
productState:false})
}
},/**
* 降价&更多隐藏*/onClickHidden(e) {
let that= this;switch(e.currentTarget.dataset.id) {case '0':
that.setData({
showLowMoney:!this.data.showLowMoney,
lowind:0});break;case '1':
that.setData({
showMore:!this.data.showMore
});break;
}
},/**
* 修改价钱
* updatePrice*/updatePrice(e) {
let params={
userID: app.globalData.userID,
id:this.data.productID,
price:this.data.low_mon,
}
app.updatePrice(params).then(res=>{if (res.state === 1) {this.getMyRelease();this.setData({
showLowMoney:!this.data.showLowMoney,
lowind:0})
}
})
},/**
* 下架
* soldOut*/soldOut() {
let params={
userID: app.globalData.userID,
id:this.data.productID,
flag:this.data.productState
}
app.soldOut(params).then(res=>{if (res.state === 1) {
wx.showToast({
title:'已下架',
icon:"none",
duration:1000,
mask:true,
})this.getMyRelease();this.setData({
showMore:!this.data.showMore,
lowind:0})
}
})
},/**
* 上架
*putaway*/putaway() {
let params={
userID: app.globalData.userID,
id:this.data.productID,
flag:this.data.productState
}
app.soldOut(params).then(res=>{if (res.state === 1) {
wx.showToast({
title:'已上架',
icon:"none",
duration:1000,
mask:true,
})this.getMyRelease();this.setData({
showMore:!this.data.showMore,
lowind:0})
}
})
},/**
* 删除
* productDel*/productDel() {
let params={
userID: app.globalData.userID,
id:this.data.productID
}
app.productDel(params).then(res=>{if (res.state === 1) {this.getMyRelease();this.setData({
showMore:!this.data.showMore,
lowind:0})
}
})
},/**
* 选择打折力度*/clickLowMoney(e) {
let price= this.data.lowMoney[e.currentTarget.dataset.index].money;if (this.data.lowind ==e.currentTarget.dataset.index) {this.setData({
lowind:-1})
}else{this.setData({
lowind: e.currentTarget.dataset.index,
low_mon: price
})
}
},/**
* 编辑*/edit(e) {
let productID=e.currentTarget.dataset.productid
wx.navigateTo({
url:'../productReleased/productReleased?productID=' +productID,
})
},/**
* 新建我的发布*/newRelease() {
wx.navigateTo({
url:'../productReleased/productReleased?productID=' + 0,
})
},
productDetail(e) {
wx.navigateTo({
url:'../product/product?id=' +e.currentTarget.dataset.id,
})
},//上拉事件
onReachBottom: function() {this.data.limit = this.data.limit + 5
this.getMyRelease();
},/**
* 获取我的发布*/getMyRelease() {
let params={
userID: app.globalData.userID,
limit:this.data.limit,
offset:0,
}
app.getMyRelease(params).then(res=>{
let release=res.data.releasethis.setData({
releases: release
})
})
},
})