comment.vue 10 KB

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