index.vue 8.9 KB

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