|
|
@@ -7,49 +7,82 @@ Page({
|
|
|
publisherId: '',
|
|
|
questions: [],
|
|
|
notAnswered: true,
|
|
|
- answered: true,
|
|
|
- top: false,
|
|
|
+ answered: false
|
|
|
},
|
|
|
|
|
|
- updateText: function (e) {
|
|
|
- var arr = this.data.questions
|
|
|
- arr[e.target.dataset.index].answer = e.detail.value
|
|
|
+ updateFilter: function (e) {
|
|
|
this.setData({
|
|
|
- questions: arr
|
|
|
+ notAnswered: e.detail.value.indexOf("0") !== -1,
|
|
|
+ answered: e.detail.value.indexOf("1") !== -1
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- updateFilter: function (e) {
|
|
|
- var check0 = false
|
|
|
- var check1 = false
|
|
|
- for (let i = 0; i < e.detail.value.length; i++) {
|
|
|
- if (e.detail.value[i] == 0) check0 = true
|
|
|
- if (e.detail.value[i] == 1) check1 = true
|
|
|
- }
|
|
|
+ updateText: function (e) {
|
|
|
+ this.data.questions[e.currentTarget.dataset.index].answer = e.detail.value
|
|
|
+ this.data.questions[e.currentTarget.dataset.index].saved = false
|
|
|
this.setData({
|
|
|
- notAnswered: check0,
|
|
|
- answered: check1
|
|
|
+ questions: this.data.questions
|
|
|
})
|
|
|
},
|
|
|
|
|
|
- top: function () {
|
|
|
- this.setData({
|
|
|
- top: !this.data.top
|
|
|
+ togglePin: function (e) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: this.data.questions[e.currentTarget.dataset.index].rank ? '取消置顶' : '正在置顶'
|
|
|
+ })
|
|
|
+ wx.cloud.callFunction({
|
|
|
+ name: 'updateQuestion',
|
|
|
+ data: {
|
|
|
+ que_id: this.data.questions[e.currentTarget.dataset.index]._id,
|
|
|
+ rank: !this.data.questions[e.currentTarget.dataset.index].rank
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
+ wx.showToast({
|
|
|
+ title: res.result.errMsg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wx.showToast({
|
|
|
+ title: this.data.questions[e.currentTarget.dataset.index].rank ? '取消置顶成功' : '置顶成功',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ this.data.questions[e.currentTarget.dataset.index].rank = !this.data.questions[e.currentTarget.dataset.index].rank
|
|
|
+ this.setData({
|
|
|
+ questions: this.data.questions
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
|
|
|
saveQuestion: function (e) {
|
|
|
- const db = wx.cloud.database()
|
|
|
- db.collection("qaData").doc(e.target.dataset.id).update({
|
|
|
+ wx.showLoading({
|
|
|
+ title: '正在保存'
|
|
|
+ })
|
|
|
+ wx.cloud.callFunction({
|
|
|
+ name: 'updateQuestion',
|
|
|
data: {
|
|
|
- answer: e.target.dataset.answer,
|
|
|
- answerTime: new Date()
|
|
|
- },
|
|
|
- success: function () {
|
|
|
+ que_id: this.data.questions[e.currentTarget.dataset.index]._id,
|
|
|
+ answer: this.data.questions[e.currentTarget.dataset.index].answer
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ wx.hideLoading()
|
|
|
+ if (res.result.status !== 'OK') {
|
|
|
wx.showToast({
|
|
|
- title: "保存成功",
|
|
|
+ title: res.result.errMsg,
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存成功',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ this.data.questions[e.currentTarget.dataset.index].saved = true
|
|
|
+ this.setData({
|
|
|
+ questions: this.data.questions
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
|
|
|
@@ -60,12 +93,12 @@ Page({
|
|
|
}).then(res => {
|
|
|
if (res.confirm) {
|
|
|
wx.showLoading({
|
|
|
- title: '删除中'
|
|
|
+ title: '正在删除'
|
|
|
})
|
|
|
wx.cloud.callFunction({
|
|
|
name: 'deleteQuestion',
|
|
|
data: {
|
|
|
- que_id: e.currentTarget.dataset.id
|
|
|
+ que_id: this.data.questions[e.currentTarget.dataset.index]._id
|
|
|
}
|
|
|
}).then(res => {
|
|
|
wx.hideLoading()
|
|
|
@@ -76,19 +109,14 @@ Page({
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- for (let i = 0; i < this.data.questions.length; i++) {
|
|
|
- if (this.data.questions[i]._id === e.currentTarget.dataset.id) {
|
|
|
- this.data.questions.splice(i, 1)
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- questions: this.data.questions
|
|
|
- })
|
|
|
wx.showToast({
|
|
|
title: "删除成功",
|
|
|
icon: 'none'
|
|
|
})
|
|
|
+ this.data.questions.splice(e.currentTarget.dataset.index, 1)
|
|
|
+ this.setData({
|
|
|
+ questions: this.data.questions
|
|
|
+ })
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
@@ -118,6 +146,9 @@ Page({
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
+ for (let i = 0; i < res.result.list.length; i++) {
|
|
|
+ res.result.list[i].saved = true
|
|
|
+ }
|
|
|
this.setData({
|
|
|
questions: res.result.list
|
|
|
})
|