index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 ref="msgListRef" @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 { onBeforeMount, 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. onBeforeMount(()=>{
  56. })
  57. onMounted(() => {
  58. showTarBarBadge();
  59. })
  60. // 跳转打卡页
  61. function toClockIn() {
  62. // 确认是否跳转打卡页
  63. $modal.confirm('当前未打卡,是否前往打卡').then(() => {
  64. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  65. })
  66. }
  67. //子组件
  68. const msgListRef=ref(null)
  69. //设置消息已读
  70. function setMsgRead() {
  71. const params = {
  72. currentUser: userStore.user.useId,
  73. isRead: "0",
  74. pSize: unReadNum.value,
  75. type: "",
  76. p: 1,
  77. }
  78. getMessageList(params).then(({ returnParams }) => {
  79. const unReadMsgIds= returnParams.ids === "" ? "" : returnParams.ids + ",";
  80. setMsgIsRead(unReadMsgIds).then((res) => {
  81. if (Number.isInteger(res)) {
  82. switch (res) {
  83. case -1:
  84. $modal.msgError('操作失败')
  85. break
  86. case -2:
  87. case 0:
  88. $modal.msg('不存在未读消息')
  89. break
  90. default:
  91. $modal.msgSuccess('操作成功')
  92. //刷新页面
  93. msgListRef.value.reload();// 调用子组件刷新数据
  94. showTarBarBadge();
  95. }
  96. } else {
  97. $modal.msgError('jssesionid失效')
  98. }
  99. })
  100. })
  101. }
  102. // 待办列表
  103. const processes = ref([])
  104. // 获取待办消息列表数据
  105. function getProcessData({ pSize, pageNo }, callback) {
  106. const params = {
  107. staffId: userStore.user.useId,
  108. page: pageNo,
  109. pageNum: pSize,
  110. modelId: "",
  111. control: 1
  112. }
  113. getUserProcess(params).then(({ returnParams }) => {
  114. if (returnParams == undefined) {
  115. processes.value = []
  116. return
  117. }
  118. processes.value = returnParams.list;
  119. callback(returnParams.list, returnParams.total, pageNo)
  120. });
  121. }
  122. // 分页获取待办消息列表数据
  123. function getProcessPage({ pSize, pageNo }, callback) {
  124. const params = {
  125. staffId: userStore.user.useId,
  126. page: pageNo,
  127. pageNum: pSize,
  128. modelId: "",
  129. control: 1
  130. }
  131. getUserProcess(params).then(({ returnParams }) => {
  132. processes.value.push(...returnParams.list)
  133. callback(returnParams.list, returnParams.total, pageNo)
  134. });
  135. }
  136. // 点击待办消息列表项
  137. function handleToProcessDetail({ insId, insName }) {
  138. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&insName=' + insName)
  139. }
  140. // 公告列表
  141. const notices = ref([])
  142. // 获取公告列表数据
  143. function getNoticeData({ pSize, pageNo }, callback) {
  144. const params = {
  145. notice_title: "",
  146. p: pageNo,
  147. pSize,
  148. userId: userStore.user.useId,
  149. unitId: userStore.user.unitId,
  150. }
  151. getNoticeList(params).then(({ returnParams }) => {
  152. notices.value = returnParams.noticelist.list
  153. // 通知子组件加载完成
  154. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  155. })
  156. }
  157. // 分页获取公告数据
  158. function getNoticePage({ pSize, pageNo }, callback) {
  159. const params = {
  160. notice_title: "",
  161. p: pageNo,
  162. pSize,
  163. userId: userStore.user.useId,
  164. unitId: userStore.user.unitId,
  165. }
  166. getNoticeList(params).then(({ returnParams }) => {
  167. // 更新数据
  168. notices.value.push(...returnParams.noticelist.list)
  169. // 通知子组件加载完成
  170. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  171. })
  172. }
  173. // 点击公告列表项
  174. function handleToNoticeDetail(notice) {
  175. $tab.navigateTo('/pages/message/detail/index?noticeId=' + notice.id)
  176. }
  177. // 消息列表
  178. const messages = ref([])
  179. // 获取消息列表数据
  180. function getMessageData({ pSize, pageNo, type, segmentValue }, callback) {
  181. const params = {
  182. currentUser: userStore.user.useId,
  183. isRead: segmentValue,
  184. pSize: pSize,
  185. type: type,
  186. p: pageNo,
  187. }
  188. getMessageList(params).then(({ returnParams }) => {
  189. returnParams.list.forEach(item => {
  190. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  191. item.title = '(流程提醒)' + item.title.slice(12)
  192. }
  193. // return item
  194. })
  195. messages.value = returnParams.list;
  196. // 通知子组件加载完成
  197. callback(returnParams.list, returnParams.total, pageNo)
  198. })
  199. }
  200. // 分页获取消息数据
  201. function getMessagePage({ pSize, pageNo, type, segmentValue }, callback) {
  202. const params = {
  203. currentUser: userStore.user.useId,
  204. isRead: segmentValue,
  205. pSize: pSize,
  206. type: type,
  207. p: pageNo,
  208. }
  209. getMessageList(params).then(({ returnParams }) => {
  210. returnParams.list.forEach(item => {
  211. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  212. item.title = '(流程提醒)' + item.title.slice(12)
  213. }
  214. // return item
  215. })
  216. // 更新数据
  217. messages.value.push(...returnParams.list)
  218. // 通知子组件加载完成
  219. callback(returnParams.list, returnParams.total, pageNo)
  220. })
  221. }
  222. // 点击消息列表项
  223. function handleToMessageDetail({ messageid, universalid }) {
  224. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  225. }
  226. // AI咨询按钮
  227. function clickFabButton() {
  228. console.log('clickFabButton');
  229. $tab.navigateTo('/pages/message/chat/index')
  230. }
  231. //待办流程数
  232. const unProcessNum = ref(0)
  233. //未读消息数
  234. const unReadNum = ref(0)
  235. //待阅消息数+待办流程数(用于tarbar导航栏)
  236. const unReadMsgNum = ref(0)
  237. function showTarBarBadge() {
  238. getUnProcessNum(userStore.user.useId, "").then(res => {
  239. if ("failed" == res.returnMsg) {
  240. $modal.msgError('待办流程数获取失败')
  241. return
  242. } else {
  243. unProcessNum.value = parseInt(res.returnParams.total, 10);
  244. }
  245. getUnReadMessageNum(userStore.user.useId).then(res => {
  246. unReadNum.value = parseInt(res.returnParams, 10);
  247. unReadMsgNum.value = unReadNum.value + unProcessNum.value;
  248. if (unReadMsgNum.value == 0) {
  249. uni.removeTabBarBadge({
  250. index: 0
  251. })
  252. } else {
  253. uni.setTabBarBadge({
  254. index: 0,
  255. text: unReadMsgNum.value > 99 ? '99+' : String(unReadMsgNum.value)
  256. })
  257. }
  258. })
  259. })
  260. }
  261. </script>
  262. <style lang="scss">
  263. @import "@/static/font/ygoa/iconfont.css";
  264. .text {
  265. text-align: center;
  266. font-size: 26rpx;
  267. margin-top: 10rpx;
  268. }
  269. ::v-deep .uni-section-header__content {
  270. max-width: 3rem;
  271. }
  272. </style>