answerBox.vue 6.3 KB

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