index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="index_container">
  3. <uni-nav-bar dark :border="false" :fixed="true" title="宇光同行">
  4. </uni-nav-bar>
  5. <!-- 待办消息列表 -->
  6. <uni-collapse :accordion="true">
  7. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  8. :open="unProcessNum > 0 || false">
  9. <template v-slot:title>
  10. <uni-section title="待办" type="line" titleFontSize="1.3rem">
  11. <template v-slot:right>
  12. <uni-badge :text="unProcessNum" class="unReadBadge" v-if="unProcessNum > 0"></uni-badge>
  13. </template>
  14. </uni-section>
  15. </template>
  16. <view class="process_container">
  17. <view class="process_list">
  18. <process-list ref="processListRef" @clickSegment="getProcessData"
  19. @clickItem="handleToProcessDetail" @scrollToBottom="getProcessPage" :current="0" :pSize="5"
  20. :pageNo="1" contentHeight="69.5vh"></process-list>
  21. </view>
  22. </view>
  23. </uni-collapse-item>
  24. <!-- 公告列表 -->
  25. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  26. :open="unReadMsgNum > 0 || false">
  27. <template v-slot:title>
  28. <uni-section title="公告" type="line" titleFontSize="1.3rem">
  29. <!-- <template v-slot:right>
  30. <uni-badge :text="unReadMsgNum"
  31. v-if="unReadMsgNum !== undefined && unReadMsgNum > 0"></uni-badge>
  32. <button @click.stop="clickReadButton" class="read_button" v-if="unReadMsgNum !== undefined"
  33. :disabled="unReadMsgNum === 0 ? true : false">一键阅读</button>
  34. </template> -->
  35. </uni-section>
  36. </template>
  37. <message-list @clickSegment="getNoticeData" @clickItem="handleToNoticeDetail"
  38. @scrollToBottom="getNoticePage" :pSize="5" :pageNo="1" :anime="true" :open="false"></message-list>
  39. </uni-collapse-item>
  40. <!-- 消息列表 -->
  41. <uni-collapse-item title-border="show" :border="true" :show-animation="true"
  42. :open="unReadMsgNum > 0 || false">
  43. <template v-slot:title>
  44. <uni-section title="消息" type="line" titleFontSize="1.3rem">
  45. <template v-slot:right>
  46. <uni-badge :text="unReadMsgNum"
  47. v-if="unReadMsgNum !== undefined && unReadMsgNum > 0"></uni-badge>
  48. <button @click.stop="setAllMsgRead" class="read_button" v-if="unReadMsgNum !== undefined"
  49. :disabled="unReadMsgNum === 0 ? true : false">一键阅读</button>
  50. </template>
  51. </uni-section>
  52. </template>
  53. <message-list ref="msgListRef" @readMsg="setAllMsgRead" @clickSegment="getMessageData"
  54. @clickItem="handleToMessageDetail" @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5"
  55. :pageNo="1" :segments="{ '全部': '', '未读': '0', '已读': '1' }">
  56. </message-list>
  57. </uni-collapse-item>
  58. </uni-collapse>
  59. <!-- 公告列表 -->
  60. <!-- <message-list @clickSegment="getNoticeData" @clickItem="handleToNoticeDetail" @scrollToBottom="getNoticePage" :pSize="5" :pageNo="1" :anime="true" :open="false" title="公告"></message-list> -->
  61. <!-- 消息列表 -->
  62. <!-- <message-list ref="msgListRef" @readMsg="setAllMsgRead" :unReadNum="unReadMsgNum" @clickSegment="getMessageData" @clickItem="handleToMessageDetail" @scrollToBottom="getMessagePage" :defaultCurrent="1" :pSize="5" :pageNo="1" :anime="true" :open="false" :segments="{ '全部': '', '未读': '0', '已读': '1' }" title="消息"></message-list> -->
  63. <!-- 跳转打卡页按钮 -->
  64. <view class="fab_button toClockInBtn">
  65. <uni-fab :pattern="{ icon: 'calendar-filled' }" :popMenu="false" horizontal="right"
  66. @fabClick="toClockInBtn"></uni-fab>
  67. </view>
  68. <!-- AI咨询按钮 -->
  69. <!-- <view class="fab_button">
  70. <uni-fab :pattern="{ icon: 'headphones' }" :popMenu="false" horizontal="right"
  71. @fabClick="clickFabButton"></uni-fab>
  72. </view> -->
  73. </view>
  74. </template>
  75. <script setup lang="ts">
  76. import { onBeforeMount, onMounted, onUpdated, ref } from 'vue';
  77. import { onLoad, onShow } from '@dcloudio/uni-app'
  78. import { getMessageList, getNoticeList, getUnReadMessageNum, setMsgIsRead } from '@/api/message.js';
  79. import { getUserProcess, getUnProcessNum } from '@/api/process';
  80. import $tab from '@/plugins/tab.js';
  81. import $modal from '@/plugins/modal.js';
  82. import processList from '@/components/ygoa/processList.vue'
  83. import messageList from '@/components/ygoa/messageList.vue'
  84. import { useUserStore } from '@/store/user.js'
  85. import { getLoginInfo } from '@/utils/auth';
  86. const userStore = useUserStore()
  87. const processListRef = ref(null)
  88. onMounted(() => {
  89. uni.$on('showTabBarBadge', showTabBarBadge)
  90. uni.$on('ReloadProcessData', () => {
  91. new Promise((resolve, reject) => {
  92. processListRef.value.onClickItem()
  93. })
  94. })
  95. })
  96. onLoad((options) => {
  97. // 是否跳转打卡页
  98. if (options.to == 'clockIn') toClockIn()
  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. function getMessageData({ pSize, pageNo, type, segmentValue }, callback) {
  183. const params = {
  184. currentUser: userStore.user.useId,
  185. isRead: segmentValue,
  186. pSize: pSize,
  187. type: type,
  188. p: pageNo,
  189. }
  190. getMessageList(params).then(({ returnParams }) => {
  191. returnParams.list.forEach(item => {
  192. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  193. item.title = '(流程提醒)' + item.title.slice(12)
  194. }
  195. // return item
  196. })
  197. // 通知子组件加载完成
  198. callback(returnParams.list, returnParams.total, pageNo)
  199. })
  200. }
  201. // 分页获取消息数据
  202. function getMessagePage({ pSize, pageNo, type, segmentValue }, callback) {
  203. const params = {
  204. currentUser: userStore.user.useId,
  205. isRead: segmentValue,
  206. pSize: pSize,
  207. type: type,
  208. p: pageNo,
  209. }
  210. getMessageList(params).then(({ returnParams }) => {
  211. returnParams.list.forEach(item => {
  212. if ('(流程提醒)您有一个流程' == item.title.substring(0, 12)) {
  213. item.title = '(流程提醒)' + item.title.slice(12)
  214. }
  215. // return item
  216. })
  217. // 通知子组件加载完成
  218. callback(returnParams.list, returnParams.total, pageNo)
  219. })
  220. }
  221. // 点击消息列表项
  222. function handleToMessageDetail({ messageid, universalid }) {
  223. console.log();
  224. setMsgIsRead(universalid + ',').then((res) => {
  225. if (Number.isInteger(res)) {
  226. msgListRef.value.reload();// 调用子组件刷新数据
  227. $tab.navigateTo('/pages/message/detail/index?messageId=' + messageid + '&universalId=' + universalid)
  228. } else {
  229. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  230. const loginInfo = getLoginInfo();
  231. userStore.LogOut().then(res => {
  232. uni.setStorageSync('loginInfo', loginInfo)
  233. $tab.reLaunch('/pages/login')
  234. })
  235. }).catch(() => { })
  236. }
  237. })
  238. }
  239. // AI咨询按钮
  240. function clickFabButton() {
  241. console.log('clickFabButton');
  242. $tab.navigateTo('/pages/message/chat/index')
  243. }
  244. //跳转打卡页
  245. function toClockInBtn() {
  246. $tab.navigateTo('/pages/mine/clockIn/clockIn')
  247. }
  248. //待办流程数
  249. const unProcessNum = ref(0)
  250. //未读消息数
  251. const unReadMsgNum = ref(0)
  252. //待阅消息数+待办流程数(用于tarbar导航栏)
  253. const unReadNum = ref(0)
  254. function showTabBarBadge() {
  255. getUnProcessNum(userStore.user.useId, "").then(res => {
  256. if ("failed" == res.returnMsg) {
  257. $modal.showToast('待办流程数获取失败')
  258. return
  259. } else {
  260. unProcessNum.value = parseInt(res.returnParams.total, 10);
  261. }
  262. getUnReadMessageNum(userStore.user.useId).then(res => {
  263. unReadMsgNum.value = parseInt(res.returnParams, 10);
  264. unReadNum.value = unReadMsgNum.value + unProcessNum.value;
  265. if (unReadNum.value == 0) {
  266. uni.removeTabBarBadge({
  267. index: 0
  268. })
  269. } else {
  270. uni.setTabBarBadge({
  271. index: 0,
  272. text: unReadNum.value > 99 ? '99+' : String(unReadNum.value)
  273. })
  274. }
  275. })
  276. })
  277. }
  278. // 设置所有消息已读
  279. function setAllMsgRead() {
  280. $modal.confirm('是否全部已读').then(res => {
  281. if (res) {
  282. const params = {
  283. currentUser: userStore.user.useId,
  284. isRead: "0",
  285. pSize: unReadMsgNum.value,
  286. type: "",
  287. p: 1,
  288. }
  289. getMessageList(params).then(({ returnParams }) => {
  290. const unReadMsgIds = returnParams.ids === "" ? "" : returnParams.ids + ",";
  291. setMsgIsRead(unReadMsgIds).then((res) => {
  292. if (Number.isInteger(res)) {
  293. switch (res) {
  294. case -1:
  295. $modal.msgError('操作失败')
  296. break
  297. case -2:
  298. case 0:
  299. $modal.msg('不存在未读消息')
  300. msgListRef.value.reload();// 调用子组件刷新数据
  301. showTabBarBadge()
  302. break
  303. default:
  304. $modal.msgSuccess('操作成功')
  305. //刷新页面
  306. msgListRef.value.reload();// 调用子组件刷新数据
  307. showTabBarBadge()
  308. }
  309. } else {
  310. $modal.confirm('登录状态失效,您可以继续留在该页面,或者重新登录?').then(res => {
  311. userStore.LogOut().then(res => {
  312. uni.reLaunch({ url: '/pages/login' })
  313. })
  314. }).catch(() => { })
  315. }
  316. })
  317. })
  318. }
  319. }).catch(() => { })
  320. }
  321. </script>
  322. <style lang="scss" scoped>
  323. @import "@/static/font/ygoa/iconfont.css";
  324. .text {
  325. text-align: center;
  326. font-size: 26rpx;
  327. margin-top: 10rpx;
  328. }
  329. .toClockInBtn {
  330. .uni-fab__circle--rightBottom {
  331. bottom: 100px;
  332. }
  333. }
  334. ::v-deep .uni-badge {
  335. height: 1.5rem !important;
  336. min-width: calc(1.5rem + 0.5 * (1rem - 16px)) !important;
  337. line-height: 1.375rem !important;
  338. font-size: 1.125rem !important;
  339. }
  340. .read_button {
  341. position: absolute;
  342. top: calc(12px + 0.5 * (1rem - 16px));
  343. right: calc(50px + 0.5 * (1rem - 16px));
  344. height: 28px;
  345. line-height: 28px;
  346. font-size: 14px;
  347. background-color: #007aff;
  348. color: #fff;
  349. }
  350. .read_button[disabled] {
  351. background-color: #f5f5f5;
  352. color: #666;
  353. opacity: 0.5;
  354. }
  355. ::v-deep .flow_step_section {
  356. .uni-section .uni-section-header {
  357. padding: 5px 10px;
  358. }
  359. }
  360. ::v-deep .flow_step_container {
  361. min-height: 60px;
  362. margin: 10px 15px;
  363. .u-steps {
  364. .u-steps-item {
  365. padding-bottom: 11px;
  366. .redcontent {
  367. .u-text__value--content {
  368. color: #ff4500;
  369. }
  370. }
  371. .active_step_circle {
  372. width: 20px;
  373. height: 20px;
  374. box-sizing: border-box;
  375. flex-shrink: 0;
  376. border-radius: 100px;
  377. border-width: 1px;
  378. border-color: #A78BFA;
  379. background-color: #A78BFA;
  380. border-style: solid;
  381. display: flex;
  382. flex-direction: row;
  383. align-items: center;
  384. justify-content: center;
  385. transition: background-color .3s;
  386. .active_step_text {
  387. color: #fff;
  388. font-size: 11px;
  389. display: flex;
  390. flex-direction: row;
  391. align-items: center;
  392. justify-content: center;
  393. text-align: center;
  394. line-height: 11px;
  395. }
  396. }
  397. }
  398. .u-steps-item view:last-of-type {
  399. margin-top: 0 !important;
  400. }
  401. }
  402. }
  403. </style>