detail.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar
  6. :command-list="commandList"
  7. :refresh-prev="refreshPrevPage"
  8. title="日志详情"
  9. @command="handleCommand" />
  10. <view class="container">
  11. <journal-item
  12. :journal-data="detailData"
  13. show-read-more
  14. is-detail
  15. @read-more="handleReadMore"
  16. @choose="handleChoose" />
  17. <add-comment
  18. ref="comment"
  19. v-model="content"
  20. :replay="replayInfo"
  21. :immediate-focus="immediateFocus"
  22. @change-user="changeUser"
  23. @submit="submit" />
  24. </view>
  25. </view>
  26. <uni-popup ref="popup" type="dialog">
  27. <uni-popup-dialog
  28. :content="dialogMsg"
  29. :duration="2000"
  30. type="warning"
  31. @confirm="deleteLog" />
  32. </uni-popup>
  33. </view>
  34. </template>
  35. <script>
  36. import { QueryById, DeleteById } from 'API/oa/journal'
  37. import { SetComment } from 'API/oa/comment'
  38. import JournalItem from './component/journalItem.vue'
  39. import AddComment from '@/components/base/add-comment.vue'
  40. export default {
  41. name: 'LogDetail',
  42. components: {
  43. JournalItem,
  44. AddComment
  45. },
  46. data() {
  47. return {
  48. id: null,
  49. detailData: {},
  50. commandList: [],
  51. content: '',
  52. replayInfo: null,
  53. dialogMsg: '',
  54. immediateFocus: false,
  55. refreshPage: false,
  56. refreshPrevPage: false
  57. }
  58. },
  59. onLoad(options) {
  60. this.id = options.id || null
  61. // this.immediateFocus = Boolean(options.action)
  62. this.getDetail()
  63. },
  64. onShow() {
  65. if (this.refreshPage) {
  66. this.refreshPage = false
  67. this.refreshPrevPage = true
  68. this.getDetail()
  69. }
  70. },
  71. onBackPress(evt) {
  72. if (evt.from === 'backbutton' && this.refreshPrevPage) {
  73. this.$refreshAndToPrev(this)
  74. return true // 返回值为 true 时,表示不执行默认的返回
  75. }
  76. return false
  77. },
  78. methods: {
  79. getDetail() {
  80. this.commandList = []
  81. QueryById({logId: this.id}).then(response => {
  82. this.detailData = response || {}
  83. const permission = response.permission
  84. if (permission.isUpdate === 1) {
  85. this.commandList.push({
  86. label: '编辑',
  87. value: 'edit',
  88. icon: 'wk-edit-pen',
  89. noCheck: true
  90. })
  91. }
  92. if (permission.isDelete === 1) {
  93. this.commandList.push({
  94. label: '删除',
  95. value: 'delete',
  96. icon: 'wk-bin',
  97. noCheck: true
  98. })
  99. }
  100. }).catch(() => {})
  101. },
  102. /**
  103. * 更多选项操作
  104. */
  105. handleCommand(command) {
  106. if (command.value === 'edit') {
  107. this.$Router.navigateTo({
  108. url: '/pages_log/add',
  109. query: {
  110. id: this.id,
  111. type: this.detailData.categoryId
  112. }
  113. })
  114. } else if (command.value === 'delete') {
  115. this.dialogMsg = '您确定要删除这条日志吗?'
  116. this.$refs.popup.open()
  117. }
  118. },
  119. deleteLog() {
  120. DeleteById({logId: this.id}).then(response => {
  121. this.$toast('删除成功')
  122. this.$refreshAndToPrev(this)
  123. }).catch()
  124. },
  125. /**
  126. * 选择回复人
  127. */
  128. handleChoose(user) {
  129. console.log('selected: ', user)
  130. if (this.replayInfo) {
  131. let str = `回复@${this.replayInfo.user.realname} `
  132. if (this.content.startsWith(str)) {
  133. this.content = this.content.replace(str, `回复@${user.user.realname} `)
  134. } else {
  135. this.content = `回复@${user.user.realname} ` + this.content
  136. }
  137. } else {
  138. this.content = `回复@${user.user.realname} ` + this.content
  139. }
  140. this.replayInfo = user
  141. this.$refs.comment.focus()
  142. },
  143. changeUser(data) {
  144. this.replayInfo = data
  145. },
  146. /**
  147. * 查看以往日志
  148. */
  149. handleReadMore(data) {
  150. this.$Router.navigateTo({
  151. url: '/pages_log/list',
  152. query: {
  153. userId: data.createUserId,
  154. title: data.realname + '的日志'
  155. }
  156. })
  157. },
  158. /**
  159. * 提交回复
  160. */
  161. submit() {
  162. let params = {
  163. type: 2,
  164. typeId: this.id,
  165. content: this.content
  166. }
  167. if (this.replayInfo) {
  168. params.pid = this.replayInfo.userId; // 被回复人的id
  169. params.mainId = this.replayInfo.mainId != 0 ? this.replayInfo.mainId : this.replayInfo.commentId; // 回复主id
  170. let str = `回复@${this.replayInfo.user.realname} `
  171. if (params.content.startsWith(str)) {
  172. params.content = params.content.replace(str, '')
  173. }
  174. }
  175. if (this.$isEmpty(params.content)) {
  176. this.$toast('回复内容不能为空')
  177. return
  178. }
  179. console.log('save: ', params)
  180. SetComment(params).then(() => {
  181. this.$toast('回复成功')
  182. this.content = ''
  183. this.replayInfo = null
  184. this.showEmoji = false
  185. this.$refreshAndToPrev(this, false)
  186. this.getDetail()
  187. }).catch()
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .main-container {
  194. display: flex;
  195. flex-direction: column;
  196. overflow: hidden;
  197. padding-bottom: 110rpx;
  198. .container {
  199. flex: 1;
  200. overflow: auto;
  201. }
  202. }
  203. </style>