锦水居民端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
4.2 KiB

// subpages/heart/pages/groupBuyConfirmList/groupBuyConfirmList.js
const api = require('../../utils/api')
Page({
/**
* 页面的初始数据
*/
data: {
pageIndex: 1,
pageSize: 10,
nodata: false,
loadMoreType: 'none',
loadMoreVisible: false,
groupBuyId: '', //拼团购的ID
confirmlist:[],
_checklist:[],
allChecked: false,
dialogVisible: false, //提示框
dialogTitle: '', //提示内容
lock: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
groupBuyId: options.id
})
this.getConfirmList()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
// onShareAppMessage: function () {
// }
changeCheckValue (e) {
let index = e.currentTarget.dataset.index
let status = e.currentTarget.dataset.status
this.data.confirmlist[index].signUpStatus = (status == '0' ? '5' : '0')
this.setData({
confirmlist: this.data.confirmlist
})
for(let i=0; i<this.data._checklist.length; i++) {
if (this.data._checklist[i].id == this.data.confirmlist[index].id) {
this.data._checklist[i].signUpStatus = this.data.confirmlist[index].signUpStatus
return
}
}
let check = {
id: this.data.confirmlist[index].id,
signUpStatus: this.data.confirmlist[index].signUpStatus
}
this.data._checklist.push(check)
console.log(this.data._checklist)
},
changeAllCheck () {
this.data._checklist = []
this.data.allChecked = !this.data.allChecked
this.data.confirmlist.forEach(item => {
item.signUpStatus = this.data.allChecked ? '5' : '0'
let val = {
id: item.id,
signUpStatus: item.signUpStatus
}
this.data._checklist.push(val)
})
this.setData({
allChecked: this.data.allChecked,
confirmlist: this.data.confirmlist
})
console.log(this.data._checklist)
},
submitConfirm () {
if (this.data.lock) {
return
}
console.log('tradeConfirmationList', this.data._checklist)
if (this.data._checklist.length > 0) {
const para = {
tradeConfirmationList: this.data._checklist
}
this.setData({
lock: true
})
api.tradeConfirmation(para).then(res => {
console.log(res.data)
this.setData({
allChecked: false,
confirmlist: [],
_checklist: [],
pageIndex: 1,
dialogVisible: true,
dialogTitle: '提交成功',
lock: false
})
this.getConfirmList()
}).catch(err => {
this.setData({
lock: false
})
})
}
},
//获取列表
getConfirmList () {
const para = {
id: this.data.groupBuyId,
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize
}
api.getGroupBuySignUpList(para).then(res => {
console.log(res)
this.setData({
confirmlist: [...this.data.confirmlist,...res.data],
loadMoreType: res.data.length === this.data.pageSize ? 'loading' : 'none',
loadMoreVisible: res.data.length === this.data.pageSize ? false : true,
nodata: false,
})
if (this.data.confirmlist.length == 0) {
this.setData({
nodata: true,
loadMoreType: 'none',
loadMoreVisible: false,
})
}
}).catch(err => {
this.setData({
confirmlist: [],
nodata: true,
loadMoreType: 'none',
loadMoreVisible: false,
})
console.log(err)
})
},
// 关闭弹框
closeDialog () {
this.setData({
dialogVisible: false
})
},
})