359 lines
8.5 KiB
JavaScript
359 lines
8.5 KiB
JavaScript
// components/inform/inform.js
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
pageName:'',
|
||
pagetype:1,
|
||
userInfoDetail:null,
|
||
inputList:{},
|
||
list:null,
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad: function (options) {
|
||
wx.cloud.init();
|
||
this.processMsg(options.pagetype);
|
||
wx.hideShareMenu();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
if(this.data.pagetype == 4) this.getExamineList();
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom: function () {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage: function () {
|
||
|
||
},
|
||
processMsg(pagetype) {
|
||
var pageName = "";
|
||
if(pagetype == 1 ) pageName = "我的发布";
|
||
if(pagetype == 2 ) pageName = "我的收藏";
|
||
if(pagetype == 3 ) pageName = "我的消息";
|
||
if(pagetype == 4 ) pageName = "待审核";
|
||
var userInfoDetail = wx.getStorageSync('userInfoDetail')
|
||
userInfoDetail.unreadMsg.reverse();
|
||
this.setData({
|
||
pageName:pageName,
|
||
pagetype:pagetype,
|
||
userInfoDetail:userInfoDetail,
|
||
})
|
||
wx.hideLoading();
|
||
if(pagetype == 4) this.getExamineList();
|
||
},
|
||
|
||
input(e) {
|
||
if(e.detail.value) {
|
||
this.data.inputList[e.target.dataset.inputnum] = e.detail.value;
|
||
} else {
|
||
this.data.inputList[e.target.dataset.inputnum] = null;
|
||
}
|
||
},
|
||
|
||
//修改价格
|
||
changePrice(e) {
|
||
var index = e.target.dataset.index;
|
||
if(this.data.inputList[index]==0) {
|
||
var newisFree = true
|
||
} else if(this.data.inputList[index]){
|
||
var newisFree = false
|
||
} else { //没填钱数
|
||
wx.showToast({
|
||
title: '请输入内容',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
return
|
||
}
|
||
wx.showLoading({
|
||
title:'操作中',
|
||
mask:true,
|
||
})
|
||
var data = {
|
||
productId:this.data.userInfoDetail.issue[index].id,
|
||
newPrice: this.data.inputList[index],
|
||
newisFree:newisFree,
|
||
}
|
||
wx.cloud.callFunction({
|
||
name: 'sM_rewriteProduct',
|
||
data: data
|
||
}).then(res => {
|
||
wx.hideLoading();
|
||
if(res.result.errCode !== 200) {
|
||
wx.showToast({
|
||
title:'错误码:'+res.result.errCode,
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
} else {
|
||
wx.showToast({
|
||
title: '操作成功',
|
||
duration: 1000,
|
||
})
|
||
wx.setStorageSync('refreshMain',true)
|
||
}
|
||
}).catch(err => {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title:'操作失败,请重试',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
console.log(err)
|
||
})
|
||
},
|
||
|
||
//点击卖出
|
||
bindtapSale(e) {
|
||
//由于只是改了一下isSall的参数,所以理论上是可以复原的,以后作为更新再写吧
|
||
var that = this;
|
||
wx.showModal({
|
||
title: '警告',
|
||
content: '此操作不可恢复,是否继续',
|
||
confirmText:'继续',
|
||
success (res) {
|
||
if (res.confirm) {//确定
|
||
wx.showLoading({
|
||
title:'操作中',
|
||
mask:true,
|
||
})
|
||
that.hasSale(e.target.dataset.index);
|
||
} else if (res.cancel) { //取消
|
||
return
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
//卖出操作
|
||
hasSale(index) {
|
||
var that = this;
|
||
var data = {
|
||
productId : this.data.userInfoDetail.issue[index].id,
|
||
isSall:true,
|
||
userId : this.data.userInfoDetail._id
|
||
}
|
||
wx.cloud.callFunction({
|
||
name: 'sM_rewriteProduct',
|
||
data: data
|
||
}).then(res => {
|
||
console.log(res.result)
|
||
wx.hideLoading();
|
||
if(res.result.errCode !== 200) {
|
||
wx.showToast({
|
||
title:'错误码:'+res.result.errCode,
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
} else {
|
||
wx.showToast({
|
||
title: '操作成功',
|
||
duration: 1000,
|
||
})
|
||
wx.setStorageSync('refreshMain',true)
|
||
wx.setStorageSync('refreshMine',true)
|
||
wx.navigateBack({
|
||
delta: 1
|
||
});
|
||
}
|
||
}).catch(err => {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title:'操作失败,请重试',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
console.log(err)
|
||
})
|
||
},
|
||
|
||
//点击取消收藏
|
||
bindCancalWant(e) {
|
||
var that = this;
|
||
wx.showModal({
|
||
title: '警告',
|
||
content: '您确定要继续操作吗?',
|
||
confirmText:'继续',
|
||
success (res) {
|
||
if (res.confirm) {//确定
|
||
wx.showLoading({
|
||
title:'操作中',
|
||
mask:true,
|
||
})
|
||
that.cancalWant(e.target.dataset.productid);
|
||
} else if (res.cancel) { //取消
|
||
return
|
||
}
|
||
}
|
||
})
|
||
},
|
||
//取消收藏
|
||
//因为就算商品卖出了也只是改了一个参数,所以用户取消收藏也可以正常进行,否则卖出商品的时候一个一个人的删除收藏开销太大;
|
||
cancalWant(productId) {
|
||
wx.cloud.callFunction({
|
||
name: 'sM_want',
|
||
data: {
|
||
isWant:false,
|
||
productId:productId,
|
||
userInfos:this.data.userInfoDetail,
|
||
}
|
||
}).then(res => {
|
||
console.log(res.result)
|
||
if(res.result.errCode!== 200) { //报错
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '错误码:'+ res.result.errCode,
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
} else { //正常
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '操作成功',
|
||
icon: 'success',
|
||
duration: 2000
|
||
})
|
||
wx.setStorageSync('refreshMain',true)
|
||
wx.setStorageSync('refreshMine',true)
|
||
wx.navigateBack({
|
||
delta: 1
|
||
});
|
||
}
|
||
}).catch(err => {
|
||
console.log(err);
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '操作失败',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
})
|
||
},
|
||
|
||
//点击商品跳转详情
|
||
jumpToDetail(event) {
|
||
var url = '../details/details?productId='+event.currentTarget.dataset.productid;
|
||
wx.navigateTo({
|
||
url: url
|
||
})
|
||
},
|
||
|
||
|
||
//点击清空消息
|
||
bindclearMsg() {
|
||
var that = this;
|
||
wx.showModal({
|
||
title: '警告',
|
||
content: '您确定要继续操作吗?',
|
||
confirmText:'继续',
|
||
success (res) {
|
||
if (res.confirm) {//确定
|
||
wx.showLoading({
|
||
title:'操作中',
|
||
mask:true,
|
||
})
|
||
that.clearMsg();
|
||
} else if (res.cancel) { //取消
|
||
return
|
||
}
|
||
}
|
||
})
|
||
},
|
||
|
||
clearMsg() {
|
||
const db = wx.cloud.database();
|
||
db.collection('sM_userInfo').doc(this.data.userInfoDetail._id).update({
|
||
data:{
|
||
unreadMsg:db.command.set(new Array())
|
||
}
|
||
}).then(res=> {
|
||
if(res.stats.updated == 1) {
|
||
//成功
|
||
wx.showToast({
|
||
title: '操作成功',
|
||
icon: 'success',
|
||
duration: 2000
|
||
})
|
||
wx.setStorageSync('refreshMain',true)
|
||
wx.setStorageSync('refreshMine',true)
|
||
wx.navigateBack({
|
||
delta: 1
|
||
});
|
||
} else {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '操作失败',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
}
|
||
}).catch(err=> {
|
||
wx.hideLoading();
|
||
wx.showToast({
|
||
title: '操作失败',
|
||
image:'../../images/info.png',
|
||
duration: 2000
|
||
})
|
||
})
|
||
},
|
||
|
||
getExamineList() {
|
||
const db = wx.cloud.database();
|
||
db.collection('sM_examine').get().then(res => {
|
||
this.setData({
|
||
list:res.data
|
||
})
|
||
})
|
||
},
|
||
|
||
jumpToExamine(event) {
|
||
var url = '../examine/examine?id='+event.currentTarget.dataset.productid+'&fromapp=true';
|
||
wx.navigateTo({
|
||
url: url
|
||
})
|
||
}
|
||
}) |