| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- publisherId: '',
- questions: [],
- notAnswered: true,
- answered: false
- },
- updateFilter: function (e) {
- this.setData({
- notAnswered: e.detail.value.indexOf("0") !== -1,
- answered: e.detail.value.indexOf("1") !== -1
- })
- },
- 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({
- questions: this.data.questions
- })
- },
- togglePin: function (e) {
- const currentRank = this.data.questions[e.currentTarget.dataset.index].rank
- wx.showLoading({
- title: currentRank === 1 ? '正在置顶' : '取消置顶'
- })
- wx.cloud.callFunction({
- name: 'updateQuestion',
- data: {
- que_id: this.data.questions[e.currentTarget.dataset.index]._id,
- rank: currentRank === 1 ? 2 : 1
- }
- }).then(res => {
- wx.hideLoading()
- if (res.result.status !== 'OK') {
- wx.showToast({
- title: res.result.errMsg,
- icon: 'none'
- })
- return
- }
- wx.showToast({
- title: currentRank === 1 ? '置顶成功' : '取消置顶成功',
- icon: 'none'
- })
- this.data.questions[e.currentTarget.dataset.index].rank = currentRank === 1 ? 2 : 1
- this.setData({
- questions: this.data.questions
- })
- })
- },
- saveQuestion: function (e) {
- wx.showLoading({
- title: '正在保存'
- })
- wx.cloud.callFunction({
- name: 'updateQuestion',
- data: {
- que_id: this.data.questions[e.currentTarget.dataset.index]._id,
- answer: this.data.questions[e.currentTarget.dataset.index].answer
- }
- }).then(res => {
- wx.hideLoading()
- if (res.result.status !== 'OK') {
- wx.showToast({
- 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
- })
- })
- },
- removeQuestion: function (e) {
- wx.showModal({
- content: "确认删除提问?",
- confirmColor: "#009195"
- }).then(res => {
- if (res.confirm) {
- wx.showLoading({
- title: '正在删除'
- })
- wx.cloud.callFunction({
- name: 'deleteQuestion',
- data: {
- que_id: this.data.questions[e.currentTarget.dataset.index]._id
- }
- }).then(res => {
- wx.hideLoading()
- if (res.result.status !== 'OK') {
- wx.showToast({
- title: res.result.errMsg,
- icon: 'none'
- })
- return
- }
- wx.showToast({
- title: "删除成功",
- icon: 'none'
- })
- this.data.questions.splice(e.currentTarget.dataset.index, 1)
- this.setData({
- questions: this.data.questions
- })
- })
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- publisherId: options.id
- })
- wx.showNavigationBarLoading()
- wx.cloud.callFunction({
- name: 'listQuestions',
- data: {
- pub_id: this.data.publisherId,
- page_token: 0,
- page_size: 20
- }
- }).then(res => {
- wx.hideNavigationBarLoading()
- if (res.result.status !== 'OK') {
- wx.showToast({
- title: res.result.errMsg,
- icon: 'none'
- })
- return
- }
- for (let i = 0; i < res.result.list.length; i++) {
- res.result.list[i].saved = true
- }
- this.setData({
- questions: res.result.list
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|