index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <view class="index_container">
  3. <uni-nav-bar dark :border="false" :fixed="true" title="宇光同行">
  4. </uni-nav-bar>
  5. <uni-collapse>
  6. <uni-collapse-item title-border="show" :border="true" :show-animation="true" :open="false">
  7. <template v-slot:title>
  8. <uni-section title="待办" type="line" titleFontSize="1.3rem">
  9. <template v-slot:right>
  10. <uni-badge :text="unProcessNum" style="margin-left: -10px;"
  11. v-if="unProcessNum>0"></uni-badge>
  12. </template>
  13. </uni-section>
  14. </template>
  15. <view class="process_container">
  16. <view class="process_list">
  17. <process-list :list="processes" @clickSegment="getProcessData"
  18. @clickItem="handleToProcessDetail" @scrollToBottom="getProcessPage" :current="0" :pSize="5"
  19. :pageNo="1" contentHeight="69.5vh"></process-list>
  20. </view>
  21. </view>
  22. </uni-collapse-item>
  23. </uni-collapse>
  24. <!-- 公告列表 -->
  25. <message-list :list="notices" @clickSegment="getNoticeData" @clickItem="handleToNoticeDetail"
  26. @scrollToBottom="getNoticePage" :pSize="5" :pageNo="1" :anime="true" :open="false"
  27. title="公告"></message-list>
  28. <!-- 消息列表 -->
  29. <message-list @readMsg="setMsgRead" :unReadNum="unReadNum" :list="messages" @clickSegment="getMessageData"
  30. @clickItem="handleToMessageDetail" @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5"
  31. :pageNo="1" :anime="true" :open="true" :segments="{ '全部': '', '未读': '0', '已读': '1' }"
  32. title="消息"></message-list>
  33. <!-- AI咨询按钮 -->
  34. <view class="fab_button">
  35. <uni-fab :pattern="{ icon: 'headphones' }" :popMenu="false" horizontal="right"
  36. @fabClick="clickFabButton"></uni-fab>
  37. </view>
  38. </view>
  39. </template>
  40. <script setup lang="ts">
  41. import { onMounted, ref } from 'vue';
  42. import { onLoad } from '@dcloudio/uni-app'
  43. import { getMessageList, getNoticeList, getUnReadMessageNum, setMsgIsRead } from '@/api/message.js';
  44. import { getUserProcess, getUnProcessNum } from '@/api/process';
  45. import $tab from '@/plugins/tab.js';
  46. import $modal from '@/plugins/modal.js';
  47. import processList from '@/components/ygoa/processList.vue'
  48. import messageList from '@/components/ygoa/messageList.vue'
  49. import { useUserStore } from '@/store/user.js'
  50. const userStore = useUserStore()
  51. onLoad((options) => {
  52. // 是否跳转打卡页
  53. if (options.to == 'clockIn') toClockIn()
  54. })
  55. onMounted(() => {
  56. showTarBarBadge();
  57. })
  58. // 跳转打卡页
  59. function toClockIn() {
  60. // 确认是否跳转打卡页
  61. $modal.confirm('当前未打卡,是否前往打卡').then(() => {
  62. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  63. })
  64. }
  65. //所有未读消息的ids
  66. const unReadMsgIds = ref('')
  67. //设置消息已读
  68. function setMsgRead() {
  69. setMsgIsRead(unReadMsgIds.value).then((res) => {
  70. if (Number.isInteger(res)) {
  71. switch (res) {
  72. case -1:
  73. $modal.msgError('操作失败')
  74. break
  75. case -2:
  76. $modal.msg('不存在未读消息')
  77. break
  78. default:
  79. $modal.msgSuccess('操作成功')
  80. //刷新页面
  81. setTimeout(() => {
  82. $tab.reLaunch('/pages/message/index')
  83. }, 1000)
  84. }
  85. } else {
  86. $modal.msgError('jssesionid失效,请重新登录')
  87. }
  88. })
  89. }
  90. // 待办列表
  91. const processes = ref([])
  92. // 获取待办消息列表数据
  93. function getProcessData({ pSize, pageNo }, callback) {
  94. const params = {
  95. staffId: userStore.user.useId,
  96. page: pageNo,
  97. pageNum: pSize,
  98. modelId: "",
  99. control: 1
  100. }
  101. getUserProcess(params).then(({ returnParams }) => {
  102. if (returnParams == undefined) {
  103. processes.value = []
  104. return
  105. }
  106. processes.value = returnParams.list;
  107. callback(returnParams.list, returnParams.total, pageNo)
  108. });
  109. }
  110. // 分页获取待办消息列表数据
  111. function getProcessPage({ pSize, pageNo }, callback) {
  112. const params = {
  113. staffId: userStore.user.useId,
  114. page: pageNo,
  115. pageNum: pSize,
  116. modelId: "",
  117. control: 1
  118. }
  119. getUserProcess(params).then(({ returnParams }) => {
  120. processes.value.push(...returnParams.list)
  121. callback(returnParams.list, returnParams.total, pageNo)
  122. });
  123. }
  124. // 点击待办消息列表项
  125. function handleToProcessDetail({ insId, insName }) {
  126. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&insName=' + insName)
  127. }
  128. // 公告列表
  129. const notices = ref([])
  130. // 获取公告列表数据
  131. function getNoticeData({ pSize, pageNo }, callback) {
  132. const params = {
  133. notice_title: "",
  134. p: pageNo,
  135. pSize,
  136. userId: userStore.user.useId,
  137. unitId: userStore.user.unitId,
  138. }
  139. getNoticeList(params).then(({ returnParams }) => {
  140. notices.value = returnParams.noticelist.list
  141. // 通知子组件加载完成
  142. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  143. })
  144. }
  145. // 分页获取公告数据
  146. function getNoticePage({ pSize, pageNo }, callback) {
  147. const params = {
  148. notice_title: "",
  149. p: pageNo,
  150. pSize,
  151. userId: userStore.user.useId,
  152. unitId: userStore.user.unitId,
  153. }
  154. getNoticeList(params).then(({ returnParams }) => {
  155. // 更新数据
  156. notices.value.push(...returnParams.noticelist.list)
  157. // 通知子组件加载完成
  158. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  159. })
  160. }
  161. // 点击公告列表项
  162. function handleToNoticeDetail(notice) {
  163. $tab.navigateTo('/pages/message/detail/index?noticeId=' + notice.id)
  164. }
  165. // 消息列表
  166. const messages = ref([])
  167. // 获取消息列表数据
  168. function getMessageData({ pSize, pageNo, type, segmentValue }, callback) {
  169. const params = {
  170. currentUser: userStore.user.useId,
  171. isRead: segmentValue,
  172. pSize: pSize,
  173. type: type,
  174. p: pageNo,
  175. }
  176. getMessageList(params).then(({ returnParams }) => {
  177. returnParams.list.forEach(item => {
  178. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  179. item.title = '(流程提醒)' + item.title.slice(12)
  180. }
  181. // return item
  182. })
  183. messages.value = returnParams.list;
  184. unReadMsgIds.value = returnParams.ids === "" ? "" : returnParams.ids + ",";
  185. // 通知子组件加载完成
  186. callback(returnParams.list, returnParams.total, pageNo)
  187. })
  188. }
  189. // 分页获取消息数据
  190. function getMessagePage({ pSize, pageNo, type, segmentValue }, callback) {
  191. const params = {
  192. currentUser: userStore.user.useId,
  193. isRead: segmentValue,
  194. pSize: pSize,
  195. type: type,
  196. p: pageNo,
  197. }
  198. getMessageList(params).then(({ returnParams }) => {
  199. returnParams.list.forEach(item => {
  200. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  201. item.title = '(流程提醒)' + item.title.slice(12)
  202. }
  203. // return item
  204. })
  205. // 更新数据
  206. messages.value.push(...returnParams.list)
  207. // 通知子组件加载完成
  208. callback(returnParams.list, returnParams.total, pageNo)
  209. })
  210. }
  211. // 点击消息列表项
  212. function handleToMessageDetail({ messageid, universalid }) {
  213. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  214. }
  215. // AI咨询按钮
  216. function clickFabButton() {
  217. console.log('clickFabButton');
  218. $tab.navigateTo('/pages/message/chat/index')
  219. }
  220. //待办流程数
  221. const unProcessNum = ref(0)
  222. //未读消息数
  223. const unReadNum = ref(0)
  224. //待阅消息数+待办流程数(用于tarbar导航栏)
  225. const unReadMsgNum = ref(0)
  226. function showTarBarBadge() {
  227. getUnProcessNum(userStore.user.useId, "").then(res => {
  228. if ("failed" == res.returnMsg) {
  229. $modal.msgError('待办流程数获取失败')
  230. return
  231. } else {
  232. unProcessNum.value = parseInt(res.returnParams.total, 10);
  233. }
  234. getUnReadMessageNum(userStore.user.useId).then(res => {
  235. unReadNum.value = parseInt(res.returnParams, 10);
  236. unReadMsgNum.value = unReadNum.value + unProcessNum.value;
  237. if (unReadMsgNum.value == 0) {
  238. uni.removeTabBarBadge({
  239. index: 0
  240. })
  241. } else {
  242. uni.setTabBarBadge({
  243. index: 0,
  244. text: unReadMsgNum.value > 99 ? '99+' : String(unReadMsgNum.value)
  245. })
  246. }
  247. })
  248. })
  249. }
  250. </script>
  251. <style lang="scss">
  252. @import "@/static/font/ygoa/iconfont.css";
  253. .text {
  254. text-align: center;
  255. font-size: 26rpx;
  256. margin-top: 10rpx;
  257. }
  258. ::v-deep .uni-section-header__content {
  259. max-width: 3rem;
  260. }
  261. </style>