云函数使用switch()函数报错
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
switch (req_type) {
case 'Add': {
return await db.collection('RepairOrder').add({
data: {
date: event.date,
time: event.time,
communityId: event.communityId,
orderType: event.orderType,
orderProgress: event.orderProgress,
projectName: event.projectName,
projectType: event.projectType,
projectPrice: event.projectPrice,
descValue: event.descValue,
address: event.address,
contactInfo: event.contactInfo,
status: event.status,
userId: wxContext.OPENID,
userInfo: event.userInfo,
createAt: new Date()
}
}).then( res => {
console.log(res)
return res
})
}
case 'Recall' : {
return await db.collection('RepairOrder').where({
_id: event._id
})
.update({
data: {
status: event.status,
deleteAt: new Date()
}
}).then( res => {
console.log(res)
return res
})
}
case 'Repairman' : {
return await db.collection('RepairOrder').where({
_id: event._id
})
.update({
data: {
orderProgress: _.push(event.progressItem),
}
}).then( res => {
console.log(res)
return res
})
}
default: {
return
}
}
js文件
wx.cloud.callFunction({
name: 'add_RepairOrder',
data: {
req_type: 'Add',
date: this.data.date,
time: this.data.time,
communityId: this.data.communityId,
orderType: this.data.orderType,
orderProgress: this.data.orderProgress,
projectName: this.data.projectName,
projectType: this.data.projectType,
projectPrice: this.data.projectPrice,
descValue: this.data.descValue,
address: this.data.address,
contactInfo: this.data.contactInfo,
status: this.data.status,
userInfo: app.globalData.userInfo
}
}).then( res => {
console.log(res)
// 强制刷新上一页
var pages = getCurrentPages(); // 获取页面栈
var prevPage = pages[pages.length - 2]; // 上一个页面
prevPage.setData({
update: true
})
wx.hideLoading()
wx.navigateBack({
delta: 1
})
})
const wxContext = cloud.getWXContext() // 在这里加一句 const req_type = event.req_type