ソースを参照

ADD

回答与置顶功能对接
RegMs If 4 年 前
コミット
e30208de10
30 ファイル変更268 行追加111 行削除
  1. 1 1
      cloudfunctions/deleteFavorite/index.js
  2. 1 1
      cloudfunctions/deleteFollow/index.js
  3. 1 1
      cloudfunctions/deleteMessage/index.js
  4. 1 1
      cloudfunctions/deleteQuestion/index.js
  5. 2 1
      cloudfunctions/listQuestions/index.js
  6. 3 10
      cloudfunctions/updateMessage/index.js
  7. 6 0
      cloudfunctions/updateQuestion/config.json
  8. 88 0
      cloudfunctions/updateQuestion/index.js
  9. 14 0
      cloudfunctions/updateQuestion/package.json
  10. 1 1
      cloudfunctions/updateUser/index.js
  11. 4 1
      miniprogram/components/itemActivityComment/itemActivityComment.wxml
  12. 2 2
      miniprogram/components/itemmyLikeMessage/itemmyLikeMessage.js
  13. 2 2
      miniprogram/components/itemmyLikePublisher/itemmyLikePublisher.js
  14. BIN
      miniprogram/images/publisher/delete.png
  15. 1 1
      miniprogram/pages/aboutUs/aboutUs.js
  16. 14 8
      miniprogram/pages/activity/activity.js
  17. 7 3
      miniprogram/pages/activity/activity.wxml
  18. 2 2
      miniprogram/pages/activityPublish/activityPublish.js
  19. 12 1
      miniprogram/pages/main/main.js
  20. 6 11
      miniprogram/pages/myQuestion/myQuestion.js
  21. 3 3
      miniprogram/pages/myQuestion/myQuestion.wxml
  22. 10 4
      miniprogram/pages/publisher/publisher.js
  23. 1 1
      miniprogram/pages/publisherDetail/publisherDetail.js
  24. 1 1
      miniprogram/pages/publisherPage/publisherPage.js
  25. 2 2
      miniprogram/pages/publisherPage/publisherPage.wxml
  26. 67 36
      miniprogram/pages/publisherQuestion/publisherQuestion.js
  27. 13 11
      miniprogram/pages/publisherQuestion/publisherQuestion.wxml
  28. 1 4
      miniprogram/pages/publisherQuestion/publisherQuestion.wxss
  29. 1 1
      miniprogram/pages/search/search.js
  30. 1 1
      miniprogram/pages/user/user.js

+ 1 - 1
cloudfunctions/deleteFavorite/index.js

@@ -31,7 +31,7 @@ exports.main = async (event, context) => {
     .remove()
 
   return {
-    removed: favorite.removed,
+    stats: favorite.stats,
     status: 'OK'
   }
 }

+ 1 - 1
cloudfunctions/deleteFollow/index.js

@@ -31,7 +31,7 @@ exports.main = async (event, context) => {
     .remove()
 
   return {
-    removed: follow.removed,
+    stats: follow.stats,
     status: 'OK'
   }
 }

+ 1 - 1
cloudfunctions/deleteMessage/index.js

@@ -46,7 +46,7 @@ exports.main = async (event, context) => {
     .remove()
 
   return {
-    removed: message.removed,
+    stats: message.stats,
     status: 'OK'
   }
 }

+ 1 - 1
cloudfunctions/deleteQuestion/index.js

@@ -57,7 +57,7 @@ exports.main = async (event, context) => {
     .remove()
 
   return {
-    removed: question.removed,
+    stats: question.stats,
     status: 'OK'
   }
 }

+ 2 - 1
cloudfunctions/listQuestions/index.js

@@ -19,7 +19,8 @@ exports.main = async (event, context) => {
         answer: _.neq('')
       })
       .sort({
-        rank: -1
+        rank: -1,
+        answer_time: -1
       })
       .skip(event.page_token)
       .limit(event.page_size)

+ 3 - 10
cloudfunctions/updateMessage/index.js

@@ -12,7 +12,7 @@ exports.main = async (event, context) => {
 
   const message_check = await db.collection('message')
     .where({
-      _id: event.msg_id
+      _id: event.msg_id || ''
     })
     .get()
   if (message_check.data.length === 0) {
@@ -34,16 +34,10 @@ exports.main = async (event, context) => {
       status: 'ERR'
     }
   }
-  if (manager_check.data[0].role !== '所有者' && manager_check.data[0].role !== '管理者') {
-    return {
-      errMsg: '没有修改权限',
-      status: 'ERR'
-    }
-  }
 
   if (event.type === '纳新') {
     const publisher = await db.collection('publisher')
-      .doc(event.pub_id)
+      .doc(message_check.data[0].pub_id)
       .get()
     event.type = publisher.data.type + '纳新'
   }
@@ -52,7 +46,6 @@ exports.main = async (event, context) => {
     .doc(event.msg_id)
     .update({
       data: {
-        user_id: OPENID,
         name: event.name,
         type: event.type,
         brief: event.brief,
@@ -69,7 +62,7 @@ exports.main = async (event, context) => {
     })
 
   return {
-    updated: message.updated,
+    stats: message.stats,
     status: 'OK'
   }
 }

+ 6 - 0
cloudfunctions/updateQuestion/config.json

@@ -0,0 +1,6 @@
+{
+  "permissions": {
+    "openapi": [
+    ]
+  }
+}

+ 88 - 0
cloudfunctions/updateQuestion/index.js

@@ -0,0 +1,88 @@
+// 云函数入口文件
+const cloud = require('wx-server-sdk')
+
+cloud.init()
+const db = cloud.database()
+
+// 云函数入口函数
+exports.main = async (event, context) => {
+  const {
+    OPENID
+  } = cloud.getWXContext()
+
+  const question_check = await db.collection('question')
+    .where({
+      _id: event.que_id || ''
+    })
+    .get()
+  if (question_check.data.length === 0) {
+    return {
+      errMsg: '提问不存在',
+      status: 'ERR'
+    }
+  }
+
+  const manager_check = await db.collection('question')
+    .aggregate()
+    .match({
+      _id: event.que_id
+    })
+    .lookup({
+      from: 'message',
+      localField: 'msg_id',
+      foreignField: '_id',
+      as: 'message'
+    })
+    .unwind('$message')
+    .lookup({
+      from: 'manager',
+      localField: 'message.pub_id',
+      foreignField: 'pub_id',
+      as: 'manager'
+    })
+    .unwind('$manager')
+    .match({
+      'manager.user_id': OPENID
+    })
+    .end()
+  if (manager_check.list.length === 0) {
+    return {
+      errMsg: '只有管理员可以修改',
+      status: 'ERR'
+    }
+  }
+
+  if (event.answer) {
+    const question = await db.collection('question')
+      .doc(event.que_id)
+      .update({
+        data: {
+          answer: event.answer,
+          a_time: new Date()
+        }
+      })
+
+    return {
+      stats: question.stats,
+      status: 'OK'
+    }
+  } else if (event.rank) {
+    const question = await db.collection('question')
+      .doc(event.que_id)
+      .update({
+        data: {
+          rank: event.rank
+        }
+      })
+
+    return {
+      stats: question.stats,
+      status: 'OK'
+    }
+  }
+
+  return {
+    errMsg: '未知操作',
+    status: 'ERR'
+  }
+}

+ 14 - 0
cloudfunctions/updateQuestion/package.json

@@ -0,0 +1,14 @@
+{
+  "name": "updateQuestion",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "wx-server-sdk": "~2.4.0"
+  }
+}

+ 1 - 1
cloudfunctions/updateUser/index.js

@@ -22,7 +22,7 @@ exports.main = async (event, context) => {
       })
 
     return {
-      updated: user.updated,
+      stats: user.stats,
       status: 'OK'
     }
   } catch (err) {

+ 4 - 1
miniprogram/components/itemActivityComment/itemActivityComment.wxml

@@ -1,3 +1,6 @@
-<view class="qa-text primary-text-color">{{comment.a_time}}</view>
+<view class="qa-text" style="display: flex;">
+  <view class="primary-text-color" style="margin-right: 30rpx;">{{comment.a_time}}</view>
+  <view class="secondary-text-color">{{comment.rank ? '置顶' : ''}}</view>
+</view>
 <view class="qa-text">Q: {{comment.question}}</view>
 <view class="qa-text">A: {{comment.answer}}</view>

+ 2 - 2
miniprogram/components/itemmyLikeMessage/itemmyLikeMessage.js

@@ -41,11 +41,11 @@ Component({
     },
 
     toggleLike: function () {
-      if (this.data.likeDisabled) {
+      if (this.data.loading) {
         return
       }
       wx.showLoading({
-        title: this.data.like ? '取消收藏' : '收藏'
+        title: this.data.like ? '取消收藏' : '正在收藏'
       })
       wx.cloud.callFunction({
         name: this.data.like ? 'deleteFavorite' : 'createFavorite',

+ 2 - 2
miniprogram/components/itemmyLikePublisher/itemmyLikePublisher.js

@@ -23,11 +23,11 @@ Component({
     },
 
     toggleLike: function () {
-      if (this.data.likeDisabled) {
+      if (this.data.loading) {
         return
       }
       wx.showLoading({
-        title: this.data.like ? '取消关注' : '关注'
+        title: this.data.like ? '取消关注' : '正在关注'
       })
       wx.cloud.callFunction({
         name: this.data.like ? 'deleteFollow' : 'createFollow',

BIN
miniprogram/images/publisher/delete.png


+ 1 - 1
miniprogram/pages/aboutUs/aboutUs.js

@@ -105,7 +105,7 @@ Page({
               return
             }
             wx.showLoading({
-              title: "入驻"
+              title: "正在入驻"
             })
             wx.cloud.uploadFile({
               cloudPath: "publisherAvater/" + this.data.publisherName + '.jpg',

+ 14 - 8
miniprogram/pages/activity/activity.js

@@ -11,7 +11,7 @@ Page({
     messageId: '',
     activityInfo: {},
     like: false,
-    likeDisabled: true,
+    loading: true,
     showEdit: false,
     pageToken: 0,
     activityComment: [],
@@ -42,7 +42,7 @@ Page({
     }).then(res => {
       if (res.confirm) {
         wx.showLoading({
-          title: '删除'
+          title: '正在删除'
         })
         wx.cloud.callFunction({
           name: 'deleteMessage',
@@ -59,19 +59,19 @@ Page({
             return
           }
           wx.navigateBack()
-          const eventChannel = this.getOpenerEventChannel()
-          eventChannel.emit('deleteMessage')
           wx.showToast({
             title: "删除成功",
             icon: 'none'
           })
+          const eventChannel = this.getOpenerEventChannel()
+          eventChannel.emit('deleteMessage')
         })
       }
     })
   },
 
   toggleLike: function () {
-    if (this.data.likeDisabled) {
+    if (this.data.loading) {
       return
     }
     wx.showLoading({
@@ -109,7 +109,7 @@ Page({
       })
     } else {
       wx.showLoading({
-        title: '发送'
+        title: '正在发送'
       })
       wx.cloud.callFunction({
         name: 'createQuestion',
@@ -151,6 +151,9 @@ Page({
   },
 
   loadExtraData: function () {
+    this.setData({
+      loading: true
+    })
     wx.showNavigationBarLoading()
     const arr = []
     arr.push(wx.cloud.callFunction({
@@ -183,7 +186,7 @@ Page({
         activityComment: this.data.activityComment.concat(res[0].result.list),
         pageToken: res[0].result.next_page_token,
         like: res[1].result.total === 1,
-        likeDisabled: false
+        loading: false
       })
     })
   },
@@ -200,7 +203,7 @@ Page({
         messageId: options.id
       })
       wx.showLoading({
-        title: '加载'
+        title: '正在加载'
       })
       wx.cloud.callFunction({
         name: 'getMessage',
@@ -277,6 +280,9 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
+    if (this.data.loading) {
+      return
+    }
     this.loadExtraData()
   },
 

+ 7 - 3
miniprogram/pages/activity/activity.wxml

@@ -39,9 +39,13 @@
     </view>
 
     <view class="bottom" wx:if="{{showEdit}}">
-      <view class="btn accent-background-color white-text-color" bindtap="deleteActivity">删除</view>
+      <view class="btn accent-background-color" bindtap="deleteActivity">
+        <image class="btn-icon" mode="aspectFit" src="/images/publisher/delete.png">
+        </image>
+        <view class="white-text-color">删除</view>
+      </view>
       <view class="btn primary-background-color" bindtap="editActivity">
-        <image class="btn-icon primary-background-color" mode="aspectFit" src="/images/publisher/publish2.png">
+        <image class="btn-icon" mode="aspectFit" src="/images/publisher/publish2.png">
         </image>
         <view class="white-text-color">修改</view>
       </view>
@@ -50,7 +54,7 @@
 
   <view class="message-block">
     <view style="display: flex; justify-content: space-between;">
-      <view class="title2">{{activityComment.length === 0 ? "暂无问答" : "答疑区:"}}</view>
+      <view class="title2">{{activityComment.length === 0 ? "暂无问答" : "答疑区"}}</view>
       <image wx:if="{{hasUserInfo}}" class="like" src="/images/like/{{like ? 'heart' : 'hollowheart'}}.png"
         catchtap="toggleLike" />
     </view>

+ 2 - 2
miniprogram/pages/activityPublish/activityPublish.js

@@ -137,7 +137,7 @@ Page({
     Promise.all(arr).then(res => {
       wx.hideLoading()
       wx.showLoading({
-        title: '正在发布'
+        title: '正在' + (this.data.messageId === '' ? '发布' : '修改')
       })
       if (this.data.messageId === '') {
         value.pub_id = this.data.publisherId
@@ -197,7 +197,7 @@ Page({
         currentTab: -1
       })
       wx.showLoading({
-        title: '加载'
+        title: '正在加载'
       })
       wx.cloud.callFunction({
         name: 'getMessage',

+ 12 - 1
miniprogram/pages/main/main.js

@@ -8,6 +8,7 @@ Page({
   data: {
     pageToken: 0,
     mainDatas: [],
+    loading: true,
     toggleEnable: true,
     filterList: 0,
     filterItem: ['', '', '', ''],
@@ -163,6 +164,9 @@ Page({
   },
 
   loadMessageData: function (refresh) {
+    this.setData({
+      loading: true
+    })
     wx.showNavigationBarLoading()
     wx.cloud.callFunction({
       name: 'listMessages',
@@ -185,7 +189,8 @@ Page({
       }
       this.setData({
         mainDatas: refresh ? res.result.list : this.data.mainDatas.concat(res.result.list),
-        pageToken: res.result.next_page_token
+        pageToken: res.result.next_page_token,
+        loading: false
       })
       this.updateData()
     })
@@ -230,6 +235,9 @@ Page({
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh: function () {
+    if (this.data.loading) {
+      return
+    }
     this.loadMessageData(true)
   },
 
@@ -237,6 +245,9 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
+    if (this.data.loading) {
+      return
+    }
     this.loadMessageData(false)
   },
 

+ 6 - 11
miniprogram/pages/myQuestion/myQuestion.js

@@ -15,12 +15,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()
@@ -31,19 +31,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
+          })
         })
       }
     })

+ 3 - 3
miniprogram/pages/myQuestion/myQuestion.wxml

@@ -1,12 +1,12 @@
 <!--为我的-我的提问页面-->
 <view wx:if="{{!questions.length}}" class="empty-text primary-text-color">这里空空如也</view>
-<view wx:for="{{questions}}" wx:for-item="item" wx:key="_id">
+<view wx:for="{{questions}}" wx:for-item="item" wx:for-index="index" wx:key="_id">
   <view class="card">
     <view class="title">{{item.message.name}}</view>
     <view class="question">提出的问题:{{item.question}}</view>
     <view class="{{'answer ' + (item.answer ? 'primary' : 'secondary') + '-text-color'}}">{{item.answer ? '收到的回复:' +
       item.answer : '暂未收到回复'}}</view>
-    <icon style="position: absolute; top: 20rpx; right: 20rpx; " type="cancel" size="20" data-id="{{item._id}}"
-      catchtap="removeQuestion"></icon>
+    <icon wx:if="{{!item.answer}}" style="position: absolute; top: 20rpx; right: 20rpx; " type="cancel" size="20"
+      data-index="{{index}}" catchtap="removeQuestion"></icon>
   </view>
 </view>

+ 10 - 4
miniprogram/pages/publisher/publisher.js

@@ -11,7 +11,7 @@ Page({
     publisherId: '',
     publisherInfo: {},
     like: false,
-    likeDisabled: true,
+    loading: true,
     pageToken: 0,
     mainDatas: []
   },
@@ -33,7 +33,7 @@ Page({
   },
 
   toggleLike: function () {
-    if (this.data.likeDisabled) {
+    if (this.data.loading) {
       return
     }
     wx.showLoading({
@@ -64,6 +64,9 @@ Page({
   },
 
   loadExtraData: function () {
+    this.setData({
+      loading: true
+    })
     wx.showNavigationBarLoading()
     const arr = []
     arr.push(wx.cloud.callFunction({
@@ -97,7 +100,7 @@ Page({
         mainDatas: this.data.mainDatas.concat(res[0].result.list),
         pageToken: res[0].result.next_page_token,
         like: res[1].result.total === 1,
-        likeDisabled: false
+        loading: false
       })
     })
   },
@@ -114,7 +117,7 @@ Page({
         publisherId: options.id
       })
       wx.showLoading({
-        title: "加载"
+        title: "正在加载"
       })
       wx.cloud.callFunction({
         name: 'getPublisher',
@@ -186,6 +189,9 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
+    if (this.data.loading) {
+      return
+    }
     this.loadMessageData()
   },
 

+ 1 - 1
miniprogram/pages/publisherDetail/publisherDetail.js

@@ -16,7 +16,7 @@ Page({
         publisherId: options.id
       })
       wx.showLoading({
-        title: "加载"
+        title: "正在加载"
       })
       wx.cloud.callFunction({
         name: 'getPublisher',

+ 1 - 1
miniprogram/pages/publisherPage/publisherPage.js

@@ -7,7 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
-    pubInfo: null,
+    pubInfo: [],
     hasPubInfo: false,
     pubName: [],
     pubIndex: 0

+ 2 - 2
miniprogram/pages/publisherPage/publisherPage.wxml

@@ -29,7 +29,7 @@
   <view class="btn-arrow secondary-text">></view>
 </view>
 
-<view class="block" hover-class="btn-hover" bindtap="administratorSetting">
+<view wx:if="{{pubInfo[pubIndex].role === '所有者'}}" class="block" hover-class="btn-hover" bindtap="administratorSetting">
   <view class="left">
     <image class="btn-icon" mode="aspectFit" src="/images/publisher/setting.png"></image>
     <view class="btn-text primary-text">管理员资格设置</view>
@@ -37,7 +37,7 @@
   <view class="btn-arrow secondary-text">></view>
 </view>
 
-<view class="block2" hover-class="btn-hover" bindtap="publisherInfoChange">
+<view wx:if="{{pubInfo[pubIndex].role === '所有者'}}" class="block2" hover-class="btn-hover" bindtap="publisherInfoChange">
   <view class="left">
     <image class="btn-icon" mode="aspectFit" src="/images/publisher/adjust.png"></image>
     <view class="btn-text primary-text">社团组织信息修改</view>

+ 67 - 36
miniprogram/pages/publisherQuestion/publisherQuestion.js

@@ -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
       })

+ 13 - 11
miniprogram/pages/publisherQuestion/publisherQuestion.wxml

@@ -1,29 +1,31 @@
 <!--为发布者-收到的提问页面-->
-<view wx:if="{{questions.length == 0}}" class="title primary-text-color" style="text-align: center;">这里空空如也哦</view>
-
-<checkbox-group wx:if="{{questions.length != 0}}" class="checkbox-group" bindchange="updateFilter">
+<view wx:if="{{!questions.length}}" class="title primary-text-color" style="text-align: center;">这里空空如也</view>
+<checkbox-group wx:else class="checkbox-group" bindchange="updateFilter">
   <view>
     <checkbox class="checkbox" value="0" checked color="#009195">未回答</checkbox>
   </view>
   <view>
-    <checkbox class="checkbox" value="1" checked color="#009195">已回答</checkbox>
+    <checkbox class="checkbox" value="1" color="#009195">已回答</checkbox>
   </view>
 </checkbox-group>
 
 <view wx:for="{{questions}}" wx:for-item="item" wx:for-index="index" wx:key="_id">
-  <view wx:if="{{notAnswered && item.answer == '' || answered && item.answer != ''}}" class="card">
-    <view class="title">{{item.title}}</view>
+  <view wx:if="{{!item.saved || notAnswered && !item.answer || answered && item.answer}}" class="card">
+    <view class="title">{{item.message.name}}</view>
     <view class="question primary-text-color">问:{{item.question}}</view>
     <textarea class="answer block-background-color" value="{{item.answer}}" placeholder="填写回答" data-index="{{index}}"
       bindinput="updateText"></textarea>
     <view class="btn">
-      <view class="save-btn primary-background-color white-text-color" data-id="{{item._id}}"
-        data-answer="{{item.answer}}" bindtap="saveQuestion">保存</view>
-      <view wx:if="{{top == false}}" class="top-btn primary-background-color white-text-color" bindtap="top">置顶提问</view>
-      <view wx:if="{{top == true}}" class="top-btn third-background-color white-text-color" bindtap="top">取消置顶
+      <view wx:if="{{!item.saved}}" class="save-btn primary-background-color white-text-color" data-index="{{index}}"
+        bindtap="saveQuestion">保存</view>
+      <view wx:else class="save-btn third-background-color white-text-color">保存</view>
+      <view wx:if="{{!item.rank}}" class="top-btn primary-background-color white-text-color" data-index="{{index}}"
+        bindtap="togglePin">置顶提问</view>
+      <view wx:else class="top-btn third-background-color white-text-color" data-index="{{index}}" bindtap="togglePin">
+        取消置顶
       </view>
     </view>
-    <icon style="position: absolute; top: 20rpx; right: 20rpx;" type="cancel" size="20" data-id="{{item._id}}"
+    <icon style="position: absolute; top: 20rpx; right: 20rpx;" type="cancel" size="20" data-index="{{index}}"
       catchtap="removeQuestion"></icon>
   </view>
 </view>

+ 1 - 4
miniprogram/pages/publisherQuestion/publisherQuestion.wxss

@@ -48,16 +48,13 @@
   padding: 10rpx 20rpx;
   border-radius: 20rpx;
   font-size: 35rpx;
-  align-self: center;
   margin-right: 20rpx;
 }
 
 .top-btn {
-  margin: 0rpx !important;
-  padding: 10rpx 20rpx !important;
+  padding: 10rpx 20rpx;
   border-radius: 20rpx;
   font-size: 35rpx;
-  font-weight: normal !important;
 }
 
 .btn {

+ 1 - 1
miniprogram/pages/search/search.js

@@ -76,7 +76,7 @@ Page({
       data: history
     })
     wx.showLoading({
-      title: '搜索'
+      title: '正在搜索'
     })
     wx.cloud.callFunction({
       name: 'listMessages',

+ 1 - 1
miniprogram/pages/user/user.js

@@ -7,7 +7,7 @@ Page({
    * 页面的初始数据
    */
   data: {
-    userInfo: null,
+    userInfo: {},
     hasUserInfo: false,
     pubInfo: []
   },