comment.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. uni.chooseImage({
  105. count: 9, //默认9
  106. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  107. sourceType: ['camera'], //从相册选择
  108. success: function(res) {
  109. uni.showLoading({
  110. title: '加载中'
  111. })
  112. _this.uploadFile(res.tempFilePaths).then(res => {
  113. res.forEach(item => {
  114. let fileNames = item.storePath.split('/')
  115. let url = _this.apiUrl +
  116. '/main/file/getFile?objectName=' + item.storePath+
  117. '&fullfilename=' + fileNames[fileNames.length -
  118. 1]
  119. _this.imgs.push(url)
  120. })
  121. uni.hideLoading()
  122. })
  123. // tempFilePaths.forEach(item => {
  124. // uni.uploadFile({
  125. // url: _this.apiUrl + '/main/file/upload',
  126. // filePath: item,
  127. // name: 'multiPartFile',
  128. // header: {
  129. // authorization: token
  130. // },
  131. // success: (uploadFileRes) => {
  132. // let data = JSON.parse(uploadFileRes.data)
  133. // if (data?.data) {
  134. // let fileNames = data?.data.storePath.split('/')
  135. // let url = _this.apiUrl +
  136. // '/main/file/getFile?objectName=' + data?.data
  137. // .storePath +
  138. // '&fullfilename=' + fileNames[fileNames.length -
  139. // 1]
  140. // _this.imgs.push(url)
  141. // }
  142. // console.log(_this.imgs, '_this.imgs')
  143. // }
  144. // });
  145. // })
  146. }
  147. });
  148. },
  149. uploadFile(list) {
  150. let PromiseAll = []
  151. const apiUrl = this.apiUrl
  152. const token = uni.getStorageSync("token"); //取存本地的token
  153. list.forEach(item => {
  154. PromiseAll.push(
  155. new Promise((resolve, reject) => {
  156. uni.uploadFile({
  157. url: apiUrl + '/main/file/upload',
  158. filePath: item,
  159. name: 'multiPartFile',
  160. header: {
  161. authorization: token
  162. },
  163. success: (uploadFileRes) => {
  164. let data = JSON.parse(uploadFileRes.data)
  165. resolve(data.data)
  166. }
  167. });
  168. }),
  169. )
  170. })
  171. return Promise.all(PromiseAll)
  172. },
  173. /**
  174. * 点击取消按钮
  175. */
  176. cancel() {
  177. this.showItemId = '';
  178. },
  179. cancel1() {
  180. this.show = false
  181. this.imgs = []
  182. this.content = ''
  183. },
  184. confirm() {
  185. this.show = false
  186. },
  187. /**
  188. * 提交评论
  189. */
  190. async commitComment() {
  191. await updateContactComment({
  192. id: this.row.id,
  193. contactDynamicsList: [{
  194. id: '', //主键id
  195. date: '', //评论时间
  196. commentId: this.item.id,
  197. fromId: this.userInfo.userId, //评论者id
  198. fromName: this.userInfo.name, //评论者昵称
  199. fromAvatar: this.userInfo.avatar && this.userInfo.avatar[0]?.url, //评论者头像
  200. toId: this.reply.fromId, //被评论者id
  201. toName: this.reply.fromName, //被评论者昵称
  202. toAvatar: this.reply.fromAvatar, //被评论者头像
  203. content: this.inputComment, //评论内容
  204. }]
  205. });
  206. this.showItemId = '';
  207. uni.$emit('setContact', {
  208. key: 'form',
  209. data: this.form
  210. })
  211. const data = await contactDetail(this.row.id);
  212. this.init(data.base);
  213. },
  214. //发布动态
  215. async updateContactDynamics() {
  216. await updateContactDynamics({
  217. id: this.row.id,
  218. contactDynamicsList: [{
  219. id: '', //主键id
  220. date: '', //评论时间
  221. ownerId: '', //文章的id
  222. fromId: this.userInfo.userId, //评论者id
  223. fromName: this.userInfo.name, //评论者昵称
  224. fromAvatar: this.userInfo.avatar && this.userInfo.avatar[0]?.url, //评论者头像
  225. content: this.content, //评论内容
  226. imgs: this.imgs, //现场图
  227. reply: [
  228. //回复,或子评论
  229. ]
  230. }]
  231. });
  232. const data = await contactDetail(this.row.id);
  233. this.cancel1()
  234. this.init(data.base);
  235. },
  236. /**
  237. * 点击评论按钮显示输入框
  238. * item: 当前大评论
  239. * reply: 当前回复的评论
  240. */
  241. showCommentInput(item, reply) {
  242. this.inputComment = ''
  243. this.item = item;
  244. this.reply = reply || {};
  245. this.showItemId = item.id;
  246. },
  247. init(row) {
  248. this.row = row;
  249. this.contactDynamicsList = row.contactDynamicsList
  250. this.$forceUpdate()
  251. }
  252. }
  253. }
  254. </script>
  255. <style scoped lang="scss">
  256. .add {
  257. width: 96rpx;
  258. height: 96rpx;
  259. border-radius: 48rpx;
  260. background: #3c9cff;
  261. position: fixed;
  262. bottom: 100rpx;
  263. right: 24rpx;
  264. display: flex;
  265. align-items: center;
  266. justify-content: center;
  267. z-index: 99;
  268. }
  269. .container {
  270. padding: 0 16rpx;
  271. box-sizing: border-box;
  272. .comment {
  273. display: flex;
  274. flex-direction: column;
  275. padding: 16rpx;
  276. border-bottom: 1rpx solid #F2F6FC;
  277. .info {
  278. display: flex;
  279. align-items: center;
  280. .avatar {
  281. border-radius: 50%;
  282. }
  283. .right {
  284. display: flex;
  285. flex-direction: column;
  286. margin-left: 16rpx;
  287. .name {
  288. font-size: 28rpx;
  289. color: #303133;
  290. margin-bottom: 16rpx;
  291. font-weight: 500;
  292. }
  293. .date {
  294. font-size: 24rpx;
  295. color: #909399;
  296. }
  297. }
  298. }
  299. .content {
  300. font-size: 28rpx;
  301. color: #303133;
  302. line-height: 18rpx;
  303. padding: 18rpx 0;
  304. }
  305. .control {
  306. display: flex;
  307. align-items: center;
  308. font-size: 26rpx;
  309. color: #909399;
  310. .like {
  311. display: flex;
  312. align-items: center;
  313. margin-right: 32rpx;
  314. cursor: pointer;
  315. &.active,
  316. &:hover {
  317. color: #409EFF;
  318. }
  319. .iconfont {
  320. font-size: 26rpx;
  321. margin-right: 16rpx;
  322. }
  323. }
  324. .comment-reply {
  325. display: flex;
  326. align-items: center;
  327. cursor: pointer;
  328. &:hover {
  329. color: #333;
  330. }
  331. .iconfont {
  332. font-size: 28rpx;
  333. margin-right: 16rpx;
  334. }
  335. }
  336. }
  337. .reply {
  338. margin: 28rpx 0;
  339. border-left: 4rpx solid #DCDFE6;
  340. .item {
  341. margin: 0 18rpx;
  342. padding: 18rpx 0;
  343. border-bottom: 1rpx dashed #EBEEF5;
  344. .reply-content {
  345. display: flex;
  346. align-items: center;
  347. font-size: 26rpx;
  348. color: #303133;
  349. .from-name {
  350. color: #409EFF;
  351. }
  352. .to-name {
  353. color: #409EFF;
  354. margin-left: 16rpx;
  355. margin-right: 16rpx;
  356. }
  357. }
  358. .reply-bottom {
  359. display: flex;
  360. align-items: center;
  361. margin-top: 16rpx;
  362. font-size: 24rpx;
  363. color: #909399;
  364. .reply-text {
  365. display: flex;
  366. align-items: center;
  367. margin-left: 18rpx;
  368. cursor: pointer;
  369. &:hover {
  370. color: #333;
  371. }
  372. .icon-comment {
  373. margin-right: 16rpx;
  374. }
  375. }
  376. }
  377. }
  378. .write-reply {
  379. display: flex;
  380. align-items: center;
  381. font-size: 26rpx;
  382. color: #909399;
  383. padding: 18rpx;
  384. cursor: pointer;
  385. &:hover {
  386. color: #303133;
  387. }
  388. .el-icon-edit {
  389. margin-right: 16rpx;
  390. }
  391. }
  392. .fade-enter-active,
  393. fade-leave-active {
  394. transition: opacity 0.5s;
  395. }
  396. .fade-enter,
  397. .fade-leave-to {
  398. opacity: 0;
  399. }
  400. .input-wrapper {
  401. padding: 18rpx;
  402. .gray-bg-input,
  403. .el-input__inner {
  404. /*background-color: #67C23A;*/
  405. }
  406. .btn-control {
  407. display: flex;
  408. justify-content: flex-end;
  409. align-items: center;
  410. padding-top: 18rpx;
  411. .cancel {
  412. font-size: 28rpx;
  413. color: #606266;
  414. margin-right: 32rpx;
  415. cursor: pointer;
  416. &:hover {
  417. color: #333;
  418. }
  419. }
  420. .confirm {
  421. font-size: 28rpx;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. }
  428. /deep/.u-modal__content {
  429. flex-direction: column;
  430. }
  431. /deep/.u-album__row__wrapper {
  432. uni-image {
  433. width: 180rpx !important;
  434. height: 180rpx !important;
  435. }
  436. }
  437. </style>