answerBox.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="Answering">
  3. <view v-for="(item, index) in answerList" :key="index" style="background-color: #ffffff" class="answer_item">
  4. <view class="chat_box" @click.stop="clearCtx">
  5. <view style="display: flex; flex: 1">
  6. <view>
  7. <image :src="
  8. item.assignUserId > 0 && !item.realname
  9. ? '/static/logo_xcx.png'
  10. : $method.splitImgHost(item.avatar)
  11. " style="width: 64rpx; height: 64rpx"></image>
  12. </view>
  13. <view style="margin-left: 15rpx">
  14. <view class="chat1">{{
  15. item.assignUserId > 0 && !item.realname
  16. ? "祥粤老师"
  17. : item.realname
  18. }}</view>
  19. <view class="chat2">{{
  20. $method.timestampToTime(item.createTime, false)
  21. }}</view>
  22. <view class="chat3">
  23. <text v-if="item.assignUserId > 0">回复</text>
  24. <text v-if="item.assignUserId > 0" style="color: #007aff">@{{ item.assignRealname }}</text>
  25. <view style="word-break: break-all">{{ item.answerText }}</view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="btnReply" @click.stop="replyContent(item)" v-if="item.userId != userId">回复</view>
  30. <view v-else class="btnDel" @click.stop="delAnswer(item.answerId)">删除</view>
  31. </view>
  32. <u-line color="#D6D6DB" />
  33. </view>
  34. <view v-if="answerList.length == 0" style="text-align: center">暂无记录</view>
  35. <view class="inputBottom" :style="{ bottom: bottomHeight + 'px' }">
  36. <view class="flex_auto">
  37. <input v-model="ctxValue" height="60" fixed="true" :focus="isFocus" :placeholder="placeholder"
  38. type="text" :custom-style="inputStyle" :adjust-position="false" class="input" @focus="focusNote"
  39. @blur="blur" />
  40. </view>
  41. <view class="btn" @click="postContent">提交</view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. name: "SaasMiniprogramAnswerBox",
  48. props: {
  49. userId: {
  50. type: Number,
  51. defaule: 0,
  52. },
  53. },
  54. inject: ["paramsFn"],
  55. data() {
  56. return {
  57. answerList: [],
  58. ctxValue: "",
  59. isFocus: false,
  60. placeholder: "您可以在这里输入答疑内容",
  61. inputStyle: {
  62. background: "rgba(244, 244, 244, 0.98)",
  63. borderRadius: "24rpx",
  64. padding: "8rpx",
  65. marginBottom: "10rpx",
  66. },
  67. bottomHeight: 0,
  68. assignUserId: 0,
  69. };
  70. },
  71. mounted() {
  72. this.getAnswerList();
  73. },
  74. methods: {
  75. postContent() {
  76. if (!this.ctxValue || this.ctxValue == "") {
  77. this.$u.toast("请输入内容");
  78. return;
  79. }
  80. this.postAnswer();
  81. },
  82. blur() {
  83. this.bottomHeight = 0;
  84. this.clearTimer = setTimeout(() => {
  85. this.ctxValue = "";
  86. this.isFocus = false;
  87. this.assignUserId = 0;
  88. this.placeholder = "您可以在这里输入答疑内容";
  89. }, 2000);
  90. },
  91. focusNote(event) {
  92. this.bottomHeight = event.detail.height;
  93. },
  94. getAnswerList() {
  95. this.$api.answerList(this.params).then((res) => {
  96. if (res.data.code == 200) {
  97. this.answerList = res.data.rows;
  98. }
  99. });
  100. },
  101. postAnswer() {
  102. let self = this;
  103. let data = {
  104. answerText: this.ctxValue,
  105. ...this.params,
  106. };
  107. if (this.assignUserId > 0) {
  108. data.assignUserId = this.assignUserId;
  109. }
  110. this.$api.postAnswer(data).then((res) => {
  111. if (res.data.code == 200) {
  112. this.$u.toast("发布成功");
  113. self.getAnswerList();
  114. this.isFocus = false;
  115. this.placeholder = "您可以在这里输入答疑内容";
  116. this.ctxValue = "";
  117. this.assignUserId = 0;
  118. }
  119. });
  120. },
  121. delAnswer(answerId) {
  122. this.$api
  123. .delAnswer({
  124. answerId: answerId,
  125. status: -1,
  126. orderGoodsId: this.params.orderGoodsId,
  127. })
  128. .then((res) => {
  129. if (res.data.code == 200) {
  130. this.getAnswerList();
  131. }
  132. });
  133. },
  134. clearCtx() {
  135. this.placeholder = "您可以在这里输入答疑内容";
  136. this.ctxValue = "";
  137. this.assignUserId = 0;
  138. },
  139. replyContent(item) {
  140. this.isFocus = true;
  141. this.assignUserId = item.userId;
  142. this.placeholder = "@" + item.realname;
  143. },
  144. },
  145. computed: {
  146. params() {
  147. return this.paramsFn(["orderGoodsId", "goodsId", "courseId", "gradeId", "moduleId", "chapterId",
  148. "sectionId"
  149. ])
  150. },
  151. },
  152. };
  153. </script>
  154. <style lang="scss" scoped>
  155. .Answering {
  156. .answer_item {
  157. &:nth-child(2) {
  158. border-radius: 16rpx 16rpx 0rpx 0rpx;
  159. }
  160. &:nth-last-child(1) {
  161. border-radius: 0rpx 0rpx 16rpx 16rpx;
  162. }
  163. }
  164. }
  165. .chat_box {
  166. display: flex;
  167. padding: 20rpx;
  168. justify-content: space-between;
  169. }
  170. .chat3 {
  171. font-size: 30rpx;
  172. font-family: PingFang SC;
  173. font-weight: 500;
  174. color: #666666;
  175. margin-top: 10rpx;
  176. }
  177. .chat2 {
  178. font-size: 20rpx;
  179. font-family: PingFang SC;
  180. font-weight: 500;
  181. color: #999999;
  182. margin-top: 10rpx;
  183. }
  184. .chat1 {
  185. font-size: 24rpx;
  186. font-family: PingFang SC;
  187. font-weight: 500;
  188. color: #333333;
  189. }
  190. .btnReply {
  191. width: 80rpx;
  192. height: 40rpx;
  193. background: #e3f0ff;
  194. border-radius: 16rpx;
  195. text-align: center;
  196. color: #007aff;
  197. }
  198. .btnDel {
  199. width: 80rpx;
  200. height: 40rpx;
  201. background: #ffedf0;
  202. border-radius: 16rpx;
  203. text-align: center;
  204. color: #ff2d55;
  205. }
  206. .btnReply {
  207. width: 80rpx;
  208. height: 40rpx;
  209. background: #e3f0ff;
  210. border-radius: 16rpx;
  211. font-size: 24rpx;
  212. }
  213. .inputBottom {
  214. position: fixed;
  215. left: 0;
  216. bottom: 0;
  217. background: #ffffff;
  218. height: 98rpx;
  219. display: flex;
  220. align-items: center;
  221. width: 100%;
  222. .flex_auto {
  223. flex: 1;
  224. margin-left: 10%;
  225. word-break: break-all;
  226. // .input {
  227. // height: 60rpx;
  228. // }
  229. }
  230. .btn {
  231. color: #007aff;
  232. font-size: 30rpx;
  233. font-weight: bold;
  234. width: 15%;
  235. text-align: center;
  236. }
  237. .input {
  238. background: rgba(244, 244, 244, 0.98);
  239. height: 60rpx;
  240. border-radius: 24rpx;
  241. margin-top: 12rpx;
  242. }
  243. }
  244. </style>