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