situationsCenter.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. <template>
  2. <view class="situationsCenter-page">
  3. <view class="calender-remind" @click="toMessagePage">
  4. <image
  5. :src="`/static/message-${messageType ? 'unread' : 'read'}.png`"
  6. ></image>
  7. </view>
  8. <view class="situation-list">
  9. <view class="search-box">
  10. <view
  11. class="search-model"
  12. @click="openSearchBar"
  13. v-show="isSearchBoxShow"
  14. >
  15. <image class="search-pic" src="/static/search.png"></image>
  16. </view>
  17. <view class="search-bar" v-show="isSearchBarShow">
  18. <view class="search-item">
  19. <image class="search-pic" src="/static/search.png"></image>
  20. <image
  21. class="text-clear"
  22. @click="valueEmpty"
  23. src="/static/text-clear.png"
  24. ></image>
  25. <input
  26. class="searh-input"
  27. v-model="inputValue"
  28. @confirm="searchByKeywords($event)"
  29. placeholder="搜索项目"
  30. placeholder-style="font-weight: 400,color: #A1A7B3"
  31. />
  32. </view>
  33. <text class="cancel-text" @click="closeSearchBar">取消</text>
  34. </view>
  35. </view>
  36. <scroll-view
  37. class="scroll-box"
  38. scroll-y="true"
  39. @scrolltolower="toLower"
  40. lower-threshold="184"
  41. >
  42. <view class="content" :style="{height: situationList.length === 0 ? '100%' : 'auto'}">
  43. <view
  44. class="situation"
  45. v-for="(item, index) in situationList"
  46. :key="item.id"
  47. @click="gotoDetail(item.situationID)"
  48. >
  49. <image
  50. class="situation-topic"
  51. :src="`/static/${
  52. item.topic ? 'situation-case' : 'situation-system'
  53. }.png`"
  54. ></image>
  55. <view class="title">
  56. <text class="title-name">{{ item.name }}</text>
  57. </view>
  58. <view class="check-group">
  59. <text class="group-text">
  60. {{
  61. nowPermission == 2
  62. ? "剩余" + (item.toDistributeCount || 0) + "个待分配"
  63. : item.checkGroupName
  64. }}</text
  65. >
  66. </view>
  67. <view class="row">
  68. <image
  69. class="situation-check"
  70. src="/static/situation-check.png"
  71. ></image>
  72. <text class="text">{{ item.checkStatus }}</text>
  73. </view>
  74. <view class="row">
  75. <image
  76. class="situation-time"
  77. src="/static/situation-time.png"
  78. ></image>
  79. <text class="text">{{ item.nextCheckTime }}</text>
  80. </view>
  81. </view>
  82. <tm-no-data v-if="situationList.length === 0"
  83. :textArr="['还没有情境', '快点击右下方按钮新建一个吧']" />
  84. </view>
  85. </scroll-view>
  86. </view>
  87. <view v-if="nowPermission == 1" class="situaions-add" @click="gotoCreate">
  88. <image class="add-pic" src="/static/situation-add.png"></image>
  89. </view>
  90. <tm-tabbar :permission="nowPermission" />
  91. </view>
  92. </template>
  93. /**
  94. * 情境中心
  95. */
  96. <script>
  97. import websocket from "../../utils/ws.js"; //引入websocket
  98. import {wsURL} from "../../utils/requestUrl.js";
  99. export default {
  100. data() {
  101. return {
  102. page: 1, //页数
  103. inputValue: "",
  104. nowPermission: "",
  105. isSearchBarShow: false, //搜索栏是否可见
  106. isSearchBoxShow: true, //搜索图标是否可见
  107. situationList: [], //情境卡片列表
  108. totalCount: "", //返回数据的总条数
  109. refTimer: null,
  110. isInitWs: null,
  111. messageType: null,
  112. num: 1,
  113. timer: null,
  114. // ws接口参数
  115. initParams: {}
  116. };
  117. },
  118. created: function () {
  119. this.nowPermission = uni.getStorageSync("nowPermission");
  120. this.init(true);
  121. this.refTimer = setInterval(() => {
  122. this.isInitWs = websocket.ws ? false : true;
  123. const {hiId, user, permission} = this.initParams;
  124. this.isInitWs && this.initWebsocket(hiId, user, permission);
  125. }, 3 * 60 * 1000);
  126. // this.messStatus();
  127. },
  128. beforeDestroy() {
  129. // 关闭ws连接
  130. websocket.close();
  131. clearInterval(this.refTimer);
  132. clearTimeout(this.timer);
  133. },
  134. // watch:{
  135. // "$route":{
  136. // handler(route){
  137. // this.messStatus();
  138. // }
  139. // }
  140. // },
  141. methods: {
  142. openSearchBar() {
  143. this.isSearchBarShow = true;
  144. this.isSearchBoxShow = false;
  145. },
  146. closeSearchBar() {
  147. this.isSearchBarShow = false;
  148. this.isSearchBoxShow = true;
  149. },
  150. valueEmpty() {
  151. this.inputValue = "";
  152. },
  153. gotoCreate() {
  154. uni.navigateTo({
  155. url: "/pages/creatingSituations/creatingSituations",
  156. });
  157. },
  158. gotoDetail(id) {
  159. uni.navigateTo({
  160. url: `/pages/situationDetail/situationDetail?situationId=${id}`,
  161. });
  162. },
  163. getSituationList(data, callback) {
  164. this.$store
  165. .dispatch({
  166. type: "situationsCenter/commActions",
  167. payload: {
  168. data,
  169. key: "situationList",
  170. },
  171. })
  172. .then((data) => {
  173. if (data) callback(data);
  174. });
  175. },
  176. searchByKeywords(event) {
  177. let data = {
  178. pageNum: 1,
  179. pageSize: 10,
  180. keyword: event.target.value,
  181. };
  182. this.getSituationList(data, (data) => {
  183. this.situationList = [];
  184. this.createSituationList(data.list);
  185. });
  186. },
  187. createSituationList(list = []) {
  188. list.map((item, index) => {
  189. this.situationList.push({
  190. name: item.name,
  191. checkStatus: item.checkStatus,
  192. nextCheckTime: item.nextCheckTime,
  193. checkGroupName: item.checkGroupName,
  194. topic: item.topic == 0 ? true : false,
  195. situationID: item.id,
  196. toDistributeCount: item.toDistributeCount,
  197. });
  198. });
  199. },
  200. toLower() {
  201. uni.showToast({
  202. title: "加载中....",
  203. icon: "loading",
  204. duration: 2000,
  205. });
  206. let count = this.situationList.length;
  207. if (this.totalCount != count) {
  208. this.page++;
  209. let data = {
  210. pageNum: this.page,
  211. pageSize: 10,
  212. };
  213. this.getSituationList(data, (data) => {
  214. this.createSituationList(data.list);
  215. let hiId = uni.getStorageSync("hiId");
  216. let user = uni.getStorageSync("id");
  217. let permission = uni.getStorageSync("nowPermission");
  218. this.initParams = {
  219. hiId,
  220. user,
  221. permission
  222. };
  223. this.isInitWs && this.initWebsocket(hiId, user, permission);
  224. });
  225. } else {
  226. uni.showToast({
  227. title: "没有更多数据了",
  228. icon: "none",
  229. duration: 1000,
  230. });
  231. }
  232. },
  233. toMessagePage() {
  234. // this.messageType = false;
  235. uni.navigateTo({
  236. url: `/pages/messages/messages`,
  237. });
  238. },
  239. init(isInitWs) {
  240. this.isInitWs = isInitWs;
  241. this.initSituationList();
  242. },
  243. initWebsocket(hiId, user, permission) {
  244. websocket.url = wsURL(hiId, user, permission);
  245. websocket.createWebSocket(this.resolverWsData.bind(this));
  246. },
  247. // 解析websocket返回数据
  248. resolverWsData(type) {
  249. let types = JSON.parse(type);
  250. switch (types.type) {
  251. case "TO_READ":
  252. this.messageType = true;
  253. break;
  254. default:
  255. this.messageType = false;
  256. break;
  257. }
  258. },
  259. initSituationList() {
  260. let data = {
  261. pageNum: 1,
  262. pageSize: 10,
  263. };
  264. this.getSituationList(data, (data) => {
  265. this.totalCount = data.totalCount;
  266. this.createSituationList(data.list);
  267. let hiId = uni.getStorageSync("hiId");
  268. let user = uni.getStorageSync("id");
  269. let permission = uni.getStorageSync("nowPermission");
  270. this.initParams = {
  271. hiId,
  272. user,
  273. permission
  274. };
  275. this.isInitWs && this.initWebsocket(hiId, user, permission);
  276. });
  277. },
  278. // messStatus(){
  279. // let num = 1;
  280. // let timer = setInterval(()=>{
  281. // this.$store.dispatch({
  282. // type: "calendar/commActions",
  283. // payload: {
  284. // key: "messagesList",
  285. // data: {
  286. // pageNum: num,
  287. // pageSize: 100,
  288. // },
  289. // },
  290. // }).then((res)=>{
  291. // if(res && res.list.length == 0){
  292. // clearInterval(timer)
  293. // }else if(res && res.list.length != 0){
  294. // res.list.map((item)=>{
  295. // if(!item.readStatus){
  296. // this.messageType = true;
  297. // return;
  298. // }
  299. // })
  300. // }
  301. // })
  302. // num++;
  303. // },200)
  304. // }
  305. },
  306. };
  307. </script>
  308. <style lang="less">
  309. .situationsCenter-page {
  310. height: 100%;
  311. .calender-remind {
  312. width: 62.5rpx;
  313. height: 62.5rpx;
  314. position: fixed;
  315. right: 25rpx;
  316. background: rgba(255, 255, 255, 0.95);
  317. border-radius: 50%;
  318. z-index: 2;
  319. image {
  320. margin-left: 17.5rpx;
  321. margin-top: 16.87rpx;
  322. width: 27.5rpx;
  323. height: 28.75rpx;
  324. }
  325. }
  326. .situation-list {
  327. position: relative;
  328. height: 100%;
  329. .search-box {
  330. position: fixed;
  331. left: 25rpx;
  332. top: 0rpx;
  333. z-index: 2;
  334. .search-model {
  335. height: 62.5rpx;
  336. width: 62.5rpx;
  337. background-color: #ffffff;
  338. text-align: center;
  339. border-radius: 50%;
  340. box-shadow: 0px 10px 10px 0px rgba(217, 221, 228, 0.5);
  341. border: 1px solid #e6eaf2;
  342. opacity: 0.85;
  343. .search-pic {
  344. width: 27.5rpx;
  345. height: 27.5rpx;
  346. margin-top: 17.5rpx;
  347. }
  348. }
  349. .search-bar {
  350. background-color: #ffffff;
  351. width: 700rpx;
  352. height: 62.5rpx;
  353. top: 31.25rpx;
  354. position: absolute;
  355. z-index: 2;
  356. .search-item {
  357. background-color: #ffffff;
  358. width: 593.75rpx;
  359. height: 62.5rpx;
  360. float: left;
  361. border-radius: 6.25rpx;
  362. border: 1.25rpx solid #f0f2f7;
  363. .search-pic {
  364. width: 21.87rpx;
  365. height: 21.87rpx;
  366. margin-left: 12.5rpx;
  367. margin-top: 20.62rpx;
  368. float: left;
  369. }
  370. .searh-input {
  371. background-color: #ffffff;
  372. width: 525rpx;
  373. height: 55rpx;
  374. font-size: 22.5rpx;
  375. float: right;
  376. margin-top: 3.75rpx;
  377. margin-left: 3.12rpx;
  378. }
  379. .text-clear {
  380. width: 21.87rpx;
  381. height: 21.87rpx;
  382. float: right;
  383. margin-top: 20.62rpx;
  384. margin-right: 6.25rpx;
  385. }
  386. }
  387. .cancel-text {
  388. font-size: 22.5rpx;
  389. line-height: 62.5rpx;
  390. color: #a1a7b3;
  391. margin-right: 31.25rpx;
  392. float: right;
  393. }
  394. }
  395. }
  396. .scroll-box {
  397. width: 100%;
  398. height: calc(100% - 87.5rpx);
  399. .content {
  400. display: flex;
  401. flex-flow: row wrap;
  402. padding-bottom: 25rpx;
  403. .situation {
  404. height: 187.5rpx;
  405. width: 337.5rpx;
  406. background: #ffffff;
  407. box-shadow: 0px 6px 20px 0px rgba(0, 13, 51, 0.1);
  408. border-radius: 8px;
  409. margin-left: 25rpx;
  410. margin-top: 25rpx;
  411. .situation-topic {
  412. width: 62.5rpx;
  413. height: 25rpx;
  414. float: right;
  415. }
  416. .title {
  417. height: 22.5rpx;
  418. margin-left: 20rpx;
  419. margin-top: 25rpx;
  420. display: flex;
  421. align-items: center;
  422. .title-name {
  423. font-size: 22.5rpx;
  424. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  425. font-weight: bold;
  426. color: #292c33;
  427. }
  428. }
  429. .check-group {
  430. margin-left: 20rpx;
  431. margin-top: 15rpx;
  432. margin-bottom: 25rpx;
  433. height: 17.5rpx;
  434. display: flex;
  435. align-items: center;
  436. .group-text {
  437. font-size: 17.5rpx;
  438. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  439. font-weight: 400;
  440. color: #666e80;
  441. }
  442. }
  443. .row {
  444. margin-left: 20rpx;
  445. margin-bottom: 17.5rpx;
  446. display: flex;
  447. align-items: center;
  448. height: 20rpx;
  449. .situation-check {
  450. width: 20rpx;
  451. height: 20rpx;
  452. }
  453. .situation-time {
  454. width: 20rpx;
  455. height: 20rpx;
  456. }
  457. .text {
  458. font-size: 20rpx;
  459. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  460. font-weight: 400;
  461. color: #292c33;
  462. margin-left: 11.25rpx;
  463. }
  464. }
  465. }
  466. }
  467. }
  468. }
  469. .situaions-add {
  470. position: fixed;
  471. right: 25rpx;
  472. bottom: 130rpx;
  473. .add-pic {
  474. width: 75rpx;
  475. height: 75rpx;
  476. }
  477. }
  478. }
  479. </style>