index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <page-meta root-font-size="system" />
  3. <view class="index_container">
  4. <uni-nav-bar dark :border="false" :fixed="true" :title="config.companyName">
  5. </uni-nav-bar>
  6. <!-- 待办消息列表 -->
  7. <uni-collapse :accordion="true">
  8. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  9. :open="unProcessNum > 0 || false">
  10. <template v-slot:title>
  11. <uni-section title="待办" type="line" titleFontSize="1.3rem">
  12. <template v-slot:right>
  13. <uni-badge :text="unProcessNum" class="unReadBadge" v-if="unProcessNum > 0"></uni-badge>
  14. </template>
  15. </uni-section>
  16. </template>
  17. <view class="process_container">
  18. <view class="process_list">
  19. <process-list ref="processListRef" @clickSegment="getProcessData"
  20. @clickItem="handleToProcessDetail" @scrollToBottom="getProcessPage" :current="0" :pSize="5"
  21. :pageNo="1" contentHeight="63.5vh"></process-list>
  22. </view>
  23. </view>
  24. </uni-collapse-item>
  25. <!-- 公告列表 -->
  26. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  27. :open="unReadMsgNum > 0 || false">
  28. <template v-slot:title>
  29. <uni-section title="公告" type="line" titleFontSize="1.3rem">
  30. </uni-section>
  31. </template>
  32. <view class="notice_list">
  33. <message-list @clickSegment="getNoticeData" @clickItem="handleToNoticeDetail"
  34. @scrollToBottom="getNoticePage" :pSize="5" :pageNo="1" :anime="true"
  35. :open="false"></message-list>
  36. </view>
  37. </uni-collapse-item>
  38. <!-- 消息列表 -->
  39. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  40. :open="unReadMsgNum > 0 || false">
  41. <template v-slot:title>
  42. <uni-section title="消息" type="line" titleFontSize="1.3rem">
  43. <template v-slot:right>
  44. <uni-badge :text="unReadMsgNum"
  45. v-if="unReadMsgNum !== undefined && unReadMsgNum > 0"></uni-badge>
  46. <button @click.stop="setAllMsgRead" class="read_button" v-if="unReadMsgNum !== undefined" :disabled="unReadMsgNum === 0">一键阅读</button>
  47. </template>
  48. </uni-section>
  49. </template>
  50. <view class="message_list">
  51. <message-list ref="msgListRef" @clickSegment="getMessageData" @clickItem="handleToMessageDetail"
  52. @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5" :pageNo="1"
  53. :segments="{ '全部': '', '未读': '0', '已读': '1' }"></message-list>
  54. </view>
  55. </uni-collapse-item>
  56. </uni-collapse>
  57. <!-- 跳转打卡页按钮 -->
  58. <view class="fab_button">
  59. <view class="toClockInBtn">
  60. <uni-fab :pattern="{ icon: 'map-pin-ellipse' }" :popMenu="false" horizontal="right"
  61. @fabClick="toClockInBtn"></uni-fab>
  62. </view>
  63. <!-- AI咨询按钮 -->
  64. <view>
  65. <uni-fab :pattern="{ icon: 'headphones' }" :popMenu="false" horizontal="right" @fabClick="clickFabButton"></uni-fab>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script setup lang="ts">
  71. import { onBeforeMount, onMounted, onUpdated, ref } from 'vue';
  72. import { onLoad, onShow } from '@dcloudio/uni-app'
  73. import { getMessageList, getNoticeList, getUnReadMessageNum, setMsgIsRead } from '@/api/message.js';
  74. import { getUserProcess, getUnProcessNum } from '@/api/process';
  75. import $tab from '@/plugins/tab.js';
  76. import $modal from '@/plugins/modal.js';
  77. import processList from '@/components/ygoa/processList.vue'
  78. import messageList from '@/components/ygoa/messageList.vue'
  79. import { useUserStore } from '@/store/user.js'
  80. import { getLoginInfo } from '@/utils/auth';
  81. import config from '@/config';
  82. const userStore = useUserStore()
  83. const processListRef = ref(null)
  84. onMounted(() => {
  85. uni.$on('showTabBarBadge', showTabBarBadge)
  86. uni.$on('ReloadProcessData', () => {
  87. new Promise((resolve, reject) => {
  88. processListRef.value.onClickItem()
  89. })
  90. })
  91. })
  92. onLoad((options) => {
  93. // 是否跳转打卡页
  94. if (options.to == 'clockIn'){
  95. toClockIn()
  96. }else if(options.noticeId){
  97. $tab.navigateTo('/pages/message/detail/index?noticeId=' + options.noticeId)
  98. }
  99. })
  100. onShow(() => {
  101. showTabBarBadge();
  102. })
  103. onBeforeMount(() => {
  104. uni.removeTabBarBadge({
  105. index: 0
  106. })
  107. })
  108. // 跳转打卡页
  109. function toClockIn() {
  110. // 确认是否跳转打卡页
  111. $modal.confirm('当前未打卡,是否前往打卡').then(() => {
  112. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  113. }).catch(() => { })
  114. }
  115. //子组件
  116. const msgListRef = ref(null)
  117. // 获取待办消息列表数据
  118. function getProcessData({ pSize, pageNo }, callback) {
  119. const params = {
  120. staffId: userStore.user.useId,
  121. page: pageNo,
  122. pageNum: pSize,
  123. modelId: "",
  124. control: 1
  125. }
  126. getUserProcess(params).then(({ returnParams }) => {
  127. callback(returnParams.list, returnParams.total, pageNo)
  128. });
  129. }
  130. // 分页获取待办消息列表数据
  131. function getProcessPage({ pSize, pageNo }, callback) {
  132. const params = {
  133. staffId: userStore.user.useId,
  134. page: pageNo,
  135. pageNum: pSize,
  136. modelId: "",
  137. control: 1
  138. }
  139. getUserProcess(params).then(({ returnParams }) => {
  140. callback(returnParams.list, returnParams.total, pageNo)
  141. });
  142. }
  143. // 点击待办消息列表项
  144. function handleToProcessDetail({ insId, tinsId, insName, control }) {
  145. $tab.navigateTo('/pages/process/detail/index?insId=' + insId + '&tinsId=' + tinsId + '&insName=' + insName + '&control=' + control)
  146. }
  147. // 获取公告列表数据
  148. function getNoticeData({ pSize, pageNo }, callback) {
  149. const params = {
  150. notice_title: "",
  151. p: pageNo,
  152. pSize,
  153. userId: userStore.user.useId,
  154. unitId: userStore.user.unitId,
  155. }
  156. getNoticeList(params).then(({ returnParams }) => {
  157. // 通知子组件加载完成
  158. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  159. })
  160. }
  161. // 分页获取公告数据
  162. function getNoticePage({ pSize, pageNo }, callback) {
  163. const params = {
  164. notice_title: "",
  165. p: pageNo,
  166. pSize,
  167. userId: userStore.user.useId,
  168. unitId: userStore.user.unitId,
  169. }
  170. getNoticeList(params).then(({ returnParams }) => {
  171. // 通知子组件加载完成
  172. callback(returnParams.noticelist.list, returnParams.total, pageNo)
  173. })
  174. }
  175. // 点击公告列表项
  176. function handleToNoticeDetail(notice) {
  177. $tab.navigateTo('/pages/message/detail/index?noticeId=' + notice.id)
  178. }
  179. // 消息列表
  180. // const messages = ref([])
  181. // 获取消息列表数据
  182. const msgPoint = ref(0)
  183. function getMessageData({ pSize, pageNo, type, segmentValue }, callback) {
  184. const flag = msgPoint.value = new Date().getTime()
  185. const params = {
  186. currentUser: userStore.user.useId,
  187. isRead: segmentValue,
  188. pSize: pSize,
  189. type: type,
  190. p: pageNo,
  191. }
  192. getMessageList(params).then(({ returnParams }) => {
  193. returnParams.list.forEach(item => {
  194. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  195. item.title = '(流程提醒)' + item.title.slice(12)
  196. }
  197. })
  198. // 通知子组件加载完成
  199. if (flag == msgPoint.value) {
  200. callback(returnParams.list, returnParams.total, pageNo)
  201. }
  202. })
  203. }
  204. // 分页获取消息数据
  205. function getMessagePage({ pSize, pageNo, type, segmentValue }, callback) {
  206. const params = {
  207. currentUser: userStore.user.useId,
  208. isRead: segmentValue,
  209. pSize: pSize,
  210. type: type,
  211. p: pageNo,
  212. }
  213. getMessageList(params).then(({ returnParams }) => {
  214. returnParams.list.forEach(item => {
  215. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  216. item.title = '(流程提醒)' + item.title.slice(12)
  217. }
  218. // return item
  219. })
  220. // 通知子组件加载完成
  221. callback(returnParams.list, returnParams.total, pageNo)
  222. })
  223. }
  224. // 点击消息列表项
  225. function handleToMessageDetail({ messageid, universalid }) {
  226. setMsgIsRead(universalid + ',').then((res) => {
  227. if (Number.isInteger(res)) {
  228. msgListRef.value.reload();// 调用子组件刷新数据
  229. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  230. } else {
  231. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  232. const loginInfo = getLoginInfo();
  233. userStore.LogOut().then(res => {
  234. uni.setStorageSync('loginInfo', loginInfo)
  235. $tab.reLaunch('/pages/login?type=autoLogin')
  236. })
  237. }).catch(() => { })
  238. }
  239. })
  240. }
  241. // AI咨询按钮
  242. function clickFabButton() {
  243. // console.log('clickFabButton');
  244. $tab.navigateTo('/pages/message/chat/index')
  245. }
  246. //跳转打卡页
  247. function toClockInBtn() {
  248. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  249. }
  250. //待办流程数
  251. const unProcessNum = ref(0)
  252. //未读消息数
  253. const unReadMsgNum = ref(0)
  254. //待阅消息数+待办流程数(用于tarbar导航栏)
  255. const unReadNum = ref(0)
  256. function showTabBarBadge() {
  257. getUnProcessNum(userStore.user.useId, "").then(res => {
  258. if ("failed" == res.returnMsg) {
  259. $modal.showToast('待办流程数获取失败')
  260. return
  261. } else {
  262. unProcessNum.value = parseInt(res.returnParams.total, 10);
  263. }
  264. getUnReadMessageNum(userStore.user.useId).then(res => {
  265. unReadMsgNum.value = parseInt(res.returnParams, 10);
  266. unReadNum.value = unReadMsgNum.value + unProcessNum.value;
  267. if (unReadNum.value == 0) {
  268. uni.removeTabBarBadge({
  269. index: 0
  270. })
  271. } else {
  272. uni.setTabBarBadge({
  273. index: 0,
  274. text: unReadNum.value > 99 ? '99+' : String(unReadNum.value)
  275. })
  276. }
  277. })
  278. })
  279. }
  280. // 设置所有消息已读
  281. function setAllMsgRead() {
  282. $modal.confirm('是否全部已读').then(res => {
  283. if (res) {
  284. const params = {
  285. currentUser: userStore.user.useId,
  286. isRead: "0",
  287. pSize: unReadMsgNum.value,
  288. type: "",
  289. p: 1,
  290. }
  291. getMessageList(params).then(({ returnParams }) => {
  292. const unReadMsgIds = returnParams.ids === "" ? "" : returnParams.ids + ",";
  293. setMsgIsRead(unReadMsgIds).then((res) => {
  294. if (Number.isInteger(res)) {
  295. switch (res) {
  296. case -1:
  297. $modal.msgError('操作失败')
  298. break
  299. case -2:
  300. case 0:
  301. $modal.msg('不存在未读消息')
  302. msgListRef.value.reload();// 调用子组件刷新数据
  303. showTabBarBadge()
  304. break
  305. default:
  306. $modal.msgSuccess('操作成功')
  307. //刷新页面
  308. msgListRef.value.reload();// 调用子组件刷新数据
  309. showTabBarBadge()
  310. }
  311. } else {
  312. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  313. userStore.LogOut().then(res => {
  314. uni.reLaunch({ url: '/pages/login?type=autoLogin' })
  315. })
  316. }).catch(() => { })
  317. }
  318. })
  319. })
  320. }
  321. }).catch(() => { })
  322. }
  323. </script>
  324. <style lang="scss" scoped>
  325. // @import "@/static/font/ygoa/iconfont.css";
  326. ::v-deep .uni-badge {
  327. height: calc(1.5rem + 0px) !important;
  328. min-width: calc(1.5rem + 0px) !important;
  329. line-height: calc(1.375rem + 0px) !important;
  330. font-size: calc(1.125rem + 0px) !important;
  331. }
  332. ::v-deep .process_container {
  333. .process_list {
  334. .process_contant {
  335. font-size: calc(14px + .5*(1rem - 16px));
  336. }
  337. .flow_step_section {
  338. .uni-section .uni-section-header {
  339. padding: 5px 10px;
  340. }
  341. }
  342. .flow_step_container {
  343. min-height: 60px;
  344. margin: 10px 15px;
  345. .u-steps {
  346. .u-steps-item {
  347. padding-bottom: 11px;
  348. .u-text__value--content {
  349. font-size: calc(13px + .5*(1rem - 16px)) !important;
  350. }
  351. .u-text__value--main {
  352. font-size: calc(13px + .5*(1rem - 16px)) !important;
  353. font-weight: 500 !important;
  354. }
  355. .u-text__value--tips {
  356. font-size: calc(12px + .5*(1rem - 16px)) !important;
  357. }
  358. .redcontent {
  359. .u-text__value--content {
  360. color: #ff4500;
  361. }
  362. }
  363. .active_step_circle {
  364. width: 20px;
  365. height: 20px;
  366. box-sizing: border-box;
  367. flex-shrink: 0;
  368. border-radius: 100px;
  369. border-width: 1px;
  370. border-color: #A78BFA;
  371. background-color: #A78BFA;
  372. border-style: solid;
  373. display: flex;
  374. flex-direction: row;
  375. align-items: center;
  376. justify-content: center;
  377. transition: background-color .3s;
  378. .active_step_text {
  379. color: #fff;
  380. font-size: 11px;
  381. display: flex;
  382. flex-direction: row;
  383. align-items: center;
  384. justify-content: center;
  385. text-align: center;
  386. line-height: 11px;
  387. }
  388. }
  389. }
  390. .u-steps-item view:last-of-type {
  391. margin-top: 0 !important;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. ::v-deep .notice_list {
  398. .msg_list_container {
  399. .zp-l-text-rpx {
  400. font-size: calc(30rpx + .5*(1rem - 16px));
  401. }
  402. }
  403. }
  404. .read_button {
  405. position: absolute;
  406. top: calc(12px + .5 * (1rem - 16px));
  407. right: 3.125rem;
  408. height: calc(1.75rem + 0px);
  409. line-height: 1.75rem;
  410. font-size: calc(0.875rem + 0px);
  411. background-color: #007aff;
  412. color: #fff;
  413. }
  414. .read_button[disabled] {
  415. background-color: #f5f5f5;
  416. color: #666;
  417. opacity: 0.5;
  418. }
  419. ::v-deep .message_list {
  420. .msg_list_container {
  421. .segmented_control_container {
  422. .segmented-control__text {
  423. font-size: calc(14px + .5*(1rem - 16px));
  424. }
  425. }
  426. .zp-paging-container-content {
  427. .zp-l-text-rpx {
  428. font-size: calc(30rpx + .5*(1rem - 16px));
  429. }
  430. }
  431. }
  432. }
  433. ::v-deep .fab_button {
  434. .toClockInBtn {
  435. .uni-fab__circle--rightBottom {
  436. bottom: 100px;
  437. }
  438. }
  439. .uni-fab__circle {
  440. width: calc(55px + .5*(1rem - 16px)) !important;
  441. height: calc(55px + .5*(1rem - 16px)) !important;
  442. .uni-icons {
  443. font-size: calc(32px + .5*(1rem - 16px)) !important;
  444. }
  445. }
  446. }
  447. </style>