index.vue 13 KB

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