comment.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <!--评论模块-->
  2. <template>
  3. <view class="container">
  4. <view class="comment" v-for="(item, index) in contactDynamicsList" :key="index">
  5. <view class="info">
  6. <image class="avatar" :src="item.fromAvatar" style="width: 64rpx; height: 64rpx;" />
  7. <view class="right">
  8. <view class="name">{{ item.fromName }}</view>
  9. <view class="date">{{ item.date }}</view>
  10. </view>
  11. </view>
  12. <view class="content">{{ item.content }}</view>
  13. <u-album :urls="item.imgs" :multipleSize="120"></u-album>
  14. <view class="control">
  15. <!-- <text class="like" :class="{active: item.isLike}" @click="likeClick(item)">
  16. <i class="iconfont icon-like"></i>
  17. <text class="like-num">{{item.likeNum > 0 ? item.likeNum + '人赞' : '赞'}}</text>
  18. </text> -->
  19. <text class="comment-reply" @click="showCommentInput(item)">
  20. <text>评论</text>
  21. </text>
  22. </view>
  23. <view class="reply">
  24. <view class="item" v-for="reply in item.reply" :key="reply.id">
  25. <view class="reply-content">
  26. <text class="from-name">{{ reply.fromName }}</text><text>: </text>
  27. <text class="to-name">{{ reply.toName&&'@'+reply.toName }}</text>
  28. <text>{{ reply.content }}</text>
  29. </view>
  30. <view class="reply-bottom">
  31. <text>{{ reply.date }}</text>
  32. <text class="reply-text" @click="showCommentInput(item, reply)">
  33. <text>回复</text>
  34. </text>
  35. </view>
  36. </view>
  37. <!-- <view
  38. class="write-reply"
  39. v-if="item.reply.length > 0"
  40. @click="showCommentInput(item)"
  41. >
  42. <i class="el-icon-edit"></i>
  43. <text class="add-comment">添加新评论</text>
  44. </view> -->
  45. <!-- <transition name="fade"> -->
  46. <view class="input-wrapper" v-if="item.id && showItemId === item.id">
  47. <u--textarea class="gray-bg-input" placeholder="写下你的评论" border="surround"
  48. v-model="inputComment"></u--textarea>
  49. <view class="btn-control">
  50. <text class="cancel" @click="cancel">取消</text>
  51. <text class="btn" type="success" round @click="commitComment">确定</text>
  52. <!-- <u-button type="primary" @click="commitComment" text="确定"></u-button> -->
  53. </view>
  54. </view>
  55. <!-- </transition> -->
  56. </view>
  57. </view>
  58. <u-modal :show="show" @cancel="cancel1" :showCancelButton="true" :closeOnClickOverlay="true"
  59. @confirm="updateContactDynamics" :title="'发布动态'">
  60. <view style="dia">
  61. <u--textarea class="gray-bg-input" placeholder="动态内容" border="surround" v-model="content"></u--textarea>
  62. </view>
  63. <view @click="chooseImage" style="display: flex;">
  64. <text>现场照片:</text>
  65. <u-button type="primary" style="width: 150rpx;" size="small" text="点击上传"></u-button>
  66. </view>
  67. <view>
  68. <u-album :urls="imgs" :singleSize="180" :multipleSize="180"></u-album>
  69. </view>
  70. </u-modal>
  71. <view class="add" @click="show=true">
  72. <u-icon name="plus" color="#fff"></u-icon>
  73. </view>
  74. </view>
  75. </template>
  76. <script>
  77. import {
  78. updateContactComment,
  79. contactDetail,
  80. updateContactDynamics
  81. } from '@/api/saleManage/contact/index.js'
  82. export default {
  83. components: {},
  84. data() {
  85. return {
  86. show: false,
  87. inputComment: '',
  88. showItemId: '',
  89. contactDynamicsList: [],
  90. row: {},
  91. item: {},
  92. reply: {},
  93. userInfo: {},
  94. content: '',
  95. imgs: []
  96. };
  97. },
  98. created() {
  99. this.userInfo = uni.getStorageSync('userInfo')
  100. },
  101. methods: {
  102. chooseImage() {
  103. const _this = this
  104. const token = uni.getStorageSync("token"); //取存本地的token
  105. uni.chooseImage({
  106. count: 9, //默认9
  107. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  108. sourceType: ['camera'], //从相册选择
  109. success: function(res) {
  110. const tempFilePaths = res.tempFilePaths;
  111. tempFilePaths.forEach(item => {
  112. uni.uploadFile({
  113. url: _this.apiUrl + '/main/file/upload',
  114. filePath: item,
  115. name: 'multiPartFile',
  116. header: {
  117. authorization: token
  118. },
  119. success: (uploadFileRes) => {
  120. let data = JSON.parse(uploadFileRes.data)
  121. if (data?.data) {
  122. let fileNames = data?.data.storePath.split('/')
  123. let url = _this.apiUrl +
  124. '/main/file/getFile?objectName=' + data?.data
  125. .storePath +
  126. '&fullfilename=' + fileNames[fileNames.length -
  127. 1]
  128. _this.imgs.push(url)
  129. }
  130. console.log(_this.imgs, '_this.imgs')
  131. }
  132. });
  133. })
  134. }
  135. });
  136. },
  137. /**
  138. * 点击取消按钮
  139. */
  140. cancel() {
  141. this.showItemId = '';
  142. },
  143. cancel1() {
  144. this.show = false
  145. this.imgs = []
  146. this.content = ''
  147. },
  148. confirm() {
  149. this.show = false
  150. },
  151. /**
  152. * 提交评论
  153. */
  154. async commitComment() {
  155. await updateContactComment({
  156. id: this.row.id,
  157. contactDynamicsList: [{
  158. id: '', //主键id
  159. date: '', //评论时间
  160. commentId: this.item.id,
  161. fromId: this.userInfo.userId, //评论者id
  162. fromName: this.userInfo.name, //评论者昵称
  163. fromAvatar: this.userInfo.avatar && this.userInfo.avatar[0]?.url, //评论者头像
  164. toId: this.reply.fromId, //被评论者id
  165. toName: this.reply.fromName, //被评论者昵称
  166. toAvatar: this.reply.fromAvatar, //被评论者头像
  167. content: this.inputComment, //评论内容
  168. }]
  169. });
  170. this.showItemId = '';
  171. uni.$emit('setContact', {
  172. key: 'form',
  173. data: this.form
  174. })
  175. const data = await contactDetail(this.row.id);
  176. this.init(data.base);
  177. },
  178. //发布动态
  179. async updateContactDynamics() {
  180. this.show = false;
  181. await updateContactDynamics({
  182. id: this.row.id,
  183. contactDynamicsList: [{
  184. id: '', //主键id
  185. date: '', //评论时间
  186. ownerId: '', //文章的id
  187. fromId: this.userInfo.userId, //评论者id
  188. fromName: this.userInfo.name, //评论者昵称
  189. fromAvatar: this.userInfo.avatar && this.userInfo.avatar[0]?.url, //评论者头像
  190. content: this.content, //评论内容
  191. imgs: this.imgs, //现场图
  192. reply: [
  193. //回复,或子评论
  194. ]
  195. }]
  196. });
  197. const data = await contactDetail(this.row.id);
  198. this.content = ''
  199. this.init(data.base);
  200. },
  201. /**
  202. * 点击评论按钮显示输入框
  203. * item: 当前大评论
  204. * reply: 当前回复的评论
  205. */
  206. showCommentInput(item, reply) {
  207. this.inputComment = ''
  208. this.item = item;
  209. this.reply = reply || {};
  210. this.showItemId = item.id;
  211. },
  212. init(row) {
  213. this.row = row;
  214. this.contactDynamicsList = row.contactDynamicsList
  215. this.$forceUpdate()
  216. }
  217. }
  218. }
  219. </script>
  220. <style scoped lang="scss">
  221. .add {
  222. width: 96rpx;
  223. height: 96rpx;
  224. border-radius: 48rpx;
  225. background: #3c9cff;
  226. position: fixed;
  227. bottom: 100rpx;
  228. right: 24rpx;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. z-index: 99;
  233. }
  234. .container {
  235. padding: 0 16rpx;
  236. box-sizing: border-box;
  237. .comment {
  238. display: flex;
  239. flex-direction: column;
  240. padding: 16rpx;
  241. border-bottom: 1rpx solid #F2F6FC;
  242. .info {
  243. display: flex;
  244. align-items: center;
  245. .avatar {
  246. border-radius: 50%;
  247. }
  248. .right {
  249. display: flex;
  250. flex-direction: column;
  251. margin-left: 16rpx;
  252. .name {
  253. font-size: 28rpx;
  254. color: #303133;
  255. margin-bottom: 16rpx;
  256. font-weight: 500;
  257. }
  258. .date {
  259. font-size: 24rpx;
  260. color: #909399;
  261. }
  262. }
  263. }
  264. .content {
  265. font-size: 28rpx;
  266. color: #303133;
  267. line-height: 18rpx;
  268. padding: 18rpx 0;
  269. }
  270. .control {
  271. display: flex;
  272. align-items: center;
  273. font-size: 26rpx;
  274. color: #909399;
  275. .like {
  276. display: flex;
  277. align-items: center;
  278. margin-right: 32rpx;
  279. cursor: pointer;
  280. &.active,
  281. &:hover {
  282. color: #409EFF;
  283. }
  284. .iconfont {
  285. font-size: 26rpx;
  286. margin-right: 16rpx;
  287. }
  288. }
  289. .comment-reply {
  290. display: flex;
  291. align-items: center;
  292. cursor: pointer;
  293. &:hover {
  294. color: #333;
  295. }
  296. .iconfont {
  297. font-size: 28rpx;
  298. margin-right: 16rpx;
  299. }
  300. }
  301. }
  302. .reply {
  303. margin: 28rpx 0;
  304. border-left: 4rpx solid #DCDFE6;
  305. .item {
  306. margin: 0 18rpx;
  307. padding: 18rpx 0;
  308. border-bottom: 1rpx dashed #EBEEF5;
  309. .reply-content {
  310. display: flex;
  311. align-items: center;
  312. font-size: 26rpx;
  313. color: #303133;
  314. .from-name {
  315. color: #409EFF;
  316. }
  317. .to-name {
  318. color: #409EFF;
  319. margin-left: 16rpx;
  320. margin-right: 16rpx;
  321. }
  322. }
  323. .reply-bottom {
  324. display: flex;
  325. align-items: center;
  326. margin-top: 16rpx;
  327. font-size: 24rpx;
  328. color: #909399;
  329. .reply-text {
  330. display: flex;
  331. align-items: center;
  332. margin-left: 18rpx;
  333. cursor: pointer;
  334. &:hover {
  335. color: #333;
  336. }
  337. .icon-comment {
  338. margin-right: 16rpx;
  339. }
  340. }
  341. }
  342. }
  343. .write-reply {
  344. display: flex;
  345. align-items: center;
  346. font-size: 26rpx;
  347. color: #909399;
  348. padding: 18rpx;
  349. cursor: pointer;
  350. &:hover {
  351. color: #303133;
  352. }
  353. .el-icon-edit {
  354. margin-right: 16rpx;
  355. }
  356. }
  357. .fade-enter-active,
  358. fade-leave-active {
  359. transition: opacity 0.5s;
  360. }
  361. .fade-enter,
  362. .fade-leave-to {
  363. opacity: 0;
  364. }
  365. .input-wrapper {
  366. padding: 18rpx;
  367. .gray-bg-input,
  368. .el-input__inner {
  369. /*background-color: #67C23A;*/
  370. }
  371. .btn-control {
  372. display: flex;
  373. justify-content: flex-end;
  374. align-items: center;
  375. padding-top: 18rpx;
  376. .cancel {
  377. font-size: 28rpx;
  378. color: #606266;
  379. margin-right: 32rpx;
  380. cursor: pointer;
  381. &:hover {
  382. color: #333;
  383. }
  384. }
  385. .confirm {
  386. font-size: 28rpx;
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. /deep/.u-modal__content {
  394. flex-direction: column;
  395. }
  396. /deep/.u-album__row__wrapper {
  397. uni-image {
  398. width: 180rpx !important;
  399. height: 180rpx !important;
  400. }
  401. }
  402. </style>