calendar.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view class="calender-page">
  3. <view class="calender-remind" @click="toMessagePage">
  4. <image
  5. :src="
  6. messageType
  7. ? '/static/mission/消息中心未读.png'
  8. : '/static/mission/消息中心已读.png'
  9. "
  10. mode=""
  11. ></image>
  12. </view>
  13. <view class="cheanged-time" @click="clickTile"
  14. >{{ changedYear }}年{{ changedMonth }}月
  15. <!-- <text class="weekDay">{{changedDay}}</text> -->
  16. </view>
  17. <view>
  18. <text v-for="item in dayArray1" class="calendarTitle">{{ item }}</text>
  19. </view>
  20. <view>
  21. <view v-for="item in data1">
  22. <!-- {{item}} -->
  23. <view
  24. v-for="(items, index) in item"
  25. class="calendarCon"
  26. @click="dateClick(items, index)"
  27. >
  28. <view class="date">
  29. {{
  30. items.time
  31. ? items.time.slice(9, 10) == "0"
  32. ? items.time.slice(10, 11)
  33. : items.time.slice(9, 11)
  34. : ""
  35. }}
  36. </view>
  37. <view class="yinDate">
  38. {{ items.yinTime ? items.yinTime : "" }}
  39. </view>
  40. <view :class="items.work ? 'work' : ''">
  41. <view class="sum">{{ items.work ? items.work : "" }}</view>
  42. <view class="danwei">{{ items.work ? "单位" : "" }}</view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- <view v-for=""></view> -->
  48. <change-calendar
  49. v-if="showCC"
  50. :changedYear="changedYear"
  51. :changedMonth="changedMonth"
  52. @cancelCC="cancelCC"
  53. @sureCC="sureCC"
  54. ></change-calendar>
  55. <tm-tabbar />
  56. </view>
  57. </template>
  58. <script>
  59. import websocket from "../../utils/ws.js"; //引入websocket
  60. import moment from "moment";
  61. import changeCalendar from "./components/changeCalendar.vue";
  62. export default {
  63. data() {
  64. return {
  65. refTimer: null,
  66. isInitWs: null,
  67. messageType: null,
  68. dayArray: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
  69. dayArray1: ["日", "一", "二", "三", "四", "五", "六"],
  70. days_per_month: [],
  71. changedYear: moment().format("YYYY"),
  72. changedMonth: moment().format("MM"),
  73. changedDay: "",
  74. showCC: false,
  75. firstday: "",
  76. dayOfWeek: "",
  77. str_nums: "",
  78. data1: [],
  79. };
  80. },
  81. components: {
  82. changeCalendar,
  83. },
  84. created() {
  85. // this.getMissionList();
  86. // var data = '2021-02-19';
  87. this.changedDay = this.dayArray[new Date().getDay()];
  88. this.init(true);
  89. this.refTimer = setInterval(() => {
  90. this.isInitWs = websocket.ws ? false : true;
  91. this.init(this.isInitWs);
  92. }, 3 * 60 * 1000);
  93. },
  94. beforeDestroy() {
  95. // 关闭ws连接
  96. websocket.close();
  97. clearInterval(this.refTimer);
  98. },
  99. mounted() {
  100. this.days_per_month = new Array(
  101. 31,
  102. 28 + this.isLeap(this.changedYear),
  103. 31,
  104. 30,
  105. 31,
  106. 30,
  107. 31,
  108. 31,
  109. 30,
  110. 31,
  111. 30,
  112. 31
  113. ); //创建月份数组
  114. this.getCanList2();
  115. },
  116. methods: {
  117. getCanList() {
  118. this.$store
  119. .dispatch({
  120. type: "calendar/commActions",
  121. payload: {
  122. key: "getDefault",
  123. data: {
  124. pageNum: 1,
  125. pageSize: 10,
  126. },
  127. },
  128. })
  129. .then((data) => {
  130. if (data) {
  131. let hiId = uni.getStorageSync("hiId");
  132. let user = uni.getStorageSync("id");
  133. let permission = uni.getStorageSync("nowPermission");
  134. this.isInitWs && this.initWebsocket(hiId, user, permission);
  135. }
  136. });
  137. },
  138. init(isInitWs) {
  139. this.isInitWs = isInitWs;
  140. this.getCanList();
  141. },
  142. initWebsocket(hiId, user, permission) {
  143. websocket.url = `ws://192.168.1.45:8088/imed/pfm/websocket/${hiId}/${user}/${permission}`;
  144. websocket.createWebSocket(this.resolverWsData.bind(this));
  145. },
  146. // 解析websocket返回数据
  147. resolverWsData(type) {
  148. let types = JSON.parse(type);
  149. console.log(types, "iiiiiii");
  150. switch (types.type) {
  151. case "TO_READ":
  152. alert("99999");
  153. this.messageType = true;
  154. break;
  155. default:
  156. this.messageType = false;
  157. break;
  158. }
  159. },
  160. toMessagePage() {
  161. uni.navigateTo({
  162. url: `/pages/messages/messages`,
  163. });
  164. },
  165. clickTile() {
  166. this.showCC = true;
  167. },
  168. cancelCC(data) {
  169. this.showCC = data;
  170. },
  171. sureCC(data, year, month) {
  172. this.showCC = data;
  173. this.changedYear = year;
  174. this.changedMonth = month;
  175. let day = year + "-" + month + "-01";
  176. this.changedDay = this.dayArray[new Date(day).getDay()];
  177. this.getCanList2();
  178. },
  179. isLeap(year) {
  180. return year % 4 == 0
  181. ? year % 100 != 0
  182. ? 1
  183. : year % 400 == 0
  184. ? 1
  185. : 0
  186. : 0;
  187. },
  188. getMonth(m) {
  189. console.log(m);
  190. if (m.substr(0, 1) == "0") {
  191. console.log(true);
  192. return m.substr(1, 2);
  193. } else {
  194. return m;
  195. }
  196. },
  197. //获取上个月的天数
  198. getPreMonthCount(year, month) {
  199. if (month === 0) {
  200. return getMonthCount(year - 1, 11);
  201. } else {
  202. return getMonthCount(year, month - 1);
  203. }
  204. },
  205. getCanList2() {
  206. this.$store
  207. .dispatch({
  208. type: "calendar/commActions",
  209. payload: {
  210. key: "getDefault",
  211. data: {
  212. pageNum: 1,
  213. pageSize: 10,
  214. },
  215. },
  216. })
  217. .then((data) => {
  218. let data1 = [
  219. {
  220. time: "2021-02-03",
  221. yinTime: "二十",
  222. work: null,
  223. },
  224. {
  225. time: "2021-02-03",
  226. yinTime: "二十",
  227. work: null,
  228. },
  229. {
  230. time: "2021-02-03",
  231. yinTime: "二十",
  232. work: null,
  233. },
  234. {
  235. time: "2021-02-03",
  236. yinTime: "二十",
  237. work: null,
  238. },
  239. {
  240. time: "2021-02-03",
  241. yinTime: "二十",
  242. work: null,
  243. },
  244. {
  245. time: "2021-02-03",
  246. yinTime: "二十",
  247. work: null,
  248. },
  249. {
  250. time: "2021-02-03",
  251. yinTime: "二十",
  252. work: null,
  253. },
  254. {
  255. time: "2021-02-03",
  256. yinTime: "二十",
  257. work: null,
  258. },
  259. {
  260. time: "2021-02-03",
  261. yinTime: "二十",
  262. work: null,
  263. },
  264. {
  265. time: "2021-02-03",
  266. yinTime: "二十",
  267. work: null,
  268. },
  269. {
  270. time: "2021-02-03",
  271. yinTime: "二十",
  272. work: null,
  273. },
  274. {
  275. time: "2021-02-03",
  276. yinTime: "二十",
  277. work: null,
  278. },
  279. {
  280. time: "2021-02-03",
  281. yinTime: "二十",
  282. work: null,
  283. },
  284. {
  285. time: "2021-02-03",
  286. yinTime: "二十",
  287. work: null,
  288. },
  289. {
  290. time: "2021-02-03",
  291. yinTime: "二十",
  292. work: null,
  293. },
  294. {
  295. time: "2021-02-03",
  296. yinTime: "二十",
  297. work: null,
  298. },
  299. {
  300. time: "2021-02-03",
  301. yinTime: "二十",
  302. work: null,
  303. },
  304. {
  305. time: "2021-02-03",
  306. yinTime: "二十",
  307. work: null,
  308. },
  309. {
  310. time: "2021-02-03",
  311. yinTime: "二十",
  312. work: null,
  313. },
  314. {
  315. time: "2021-02-03",
  316. yinTime: "二十",
  317. work: null,
  318. },
  319. {
  320. time: "2021-02-03",
  321. yinTime: "二十",
  322. work: null,
  323. },
  324. {
  325. time: "2021-02-03",
  326. yinTime: "二十",
  327. work: null,
  328. },
  329. {
  330. time: "2021-02-03",
  331. yinTime: "二十",
  332. work: 5,
  333. },
  334. {
  335. time: "2021-02-03",
  336. yinTime: "二十",
  337. work: null,
  338. },
  339. {
  340. time: "2021-02-03",
  341. yinTime: "二十",
  342. work: null,
  343. },
  344. {
  345. time: "2021-02-03",
  346. yinTime: "二十",
  347. work: null,
  348. },
  349. {
  350. time: "2021-02-03",
  351. yinTime: "二十",
  352. work: null,
  353. },
  354. {
  355. time: "2021-02-03",
  356. yinTime: "二十",
  357. work: null,
  358. },
  359. ];
  360. this.firstday = new Date(
  361. this.changedYear,
  362. this.changedMonth.slice(0, 1) == "0"
  363. ? this.changedMonth.slice(1, 2) - 1
  364. : this.changedMonth - 1,
  365. 1
  366. ); //获取每月第一天
  367. this.dayOfWeek = this.firstday.getDay(); //判断第一天是星期几(返回[0-6]中的一个,0代表星期天,1代表星期一,以此类推)
  368. this.str_nums = Math.ceil((this.dayOfWeek + data1.length) / 7); //确定日期表格所需的行数
  369. let data2 = [];
  370. for (let i = 0; i < this.str_nums; i++) {
  371. data2[i] = [];
  372. if (i == 0 && this.dayOfWeek != 0) {
  373. for (let j = 0; j < this.dayOfWeek; j++) {
  374. data2[i].push({});
  375. }
  376. let data3 = data1.splice(0, 7 - this.dayOfWeek);
  377. for (let k = 0; k < data3.length; k++) {
  378. data2[i].push(data3[k]);
  379. }
  380. } else if (i == 0 && this.dayOfWeek == 0) {
  381. data2[i] = data1.splice(0, 7);
  382. } else {
  383. if (i == this.str_nums - 1 && data1.length < 7) {
  384. data2[i] = data1.splice(0, 7);
  385. for (let k = 1; k < 7 - data1.length; k++) {
  386. data2[i].push({});
  387. }
  388. } else if (i == this.str_nums - 1 && data1.length == 7) {
  389. data2[i] = data1.splice(0, 7);
  390. } else {
  391. data2[i] = data1.splice(0, 7);
  392. }
  393. }
  394. }
  395. console.log(data2);
  396. this.data1 = data2;
  397. });
  398. },
  399. dateClick(data, i) {
  400. console.log(data, i);
  401. if (data && data.work) {
  402. // uni.navigateTo({
  403. // url: `/pages/mission-details/mission-details?taskId=${data.businessId}`,
  404. // });
  405. }
  406. },
  407. },
  408. };
  409. </script>
  410. <style lang="less">
  411. .calender-page {
  412. height: 100%;
  413. position: relative;
  414. .calender-remind {
  415. width: 62.5rpx;
  416. height: 62.5rpx;
  417. position: fixed;
  418. top: 12.5rpx;
  419. right: 25rpx;
  420. background: rgba(255, 255, 255, 0.95);
  421. border-radius: 50%;
  422. z-index: 2;
  423. image {
  424. margin-left: 17.5rpx;
  425. margin-top: 16.87rpx;
  426. width: 27.5rpx;
  427. height: 28.75rpx;
  428. }
  429. }
  430. .cheanged-time {
  431. padding: 25rpx 0rpx 15rpx 25rpx;
  432. font-size: 35rpx;
  433. .weekDay {
  434. padding-left: 15rpx;
  435. font-size: 20rpx;
  436. color: #666f80;
  437. }
  438. }
  439. .calendarTitle {
  440. background-color: #fff;
  441. display: inline-block;
  442. width: 14.286%;
  443. text-align: center;
  444. font-size: 20rpx;
  445. color: #666e80;
  446. line-height: 55rpx;
  447. }
  448. .calendarCon {
  449. margin-right: 1.25rpx;
  450. margin-top: 1.25rpx;
  451. height: 168.75rpx;
  452. background-color: #fff;
  453. float: left;
  454. width: 14.1%;
  455. text-align: center;
  456. font-size: 35rpx;
  457. color: #292c33;
  458. .date {
  459. padding-top: 25rpx;
  460. padding-bottom: 15rpx;
  461. }
  462. .yinDate {
  463. color: #666e80;
  464. font-size: 17.5rpx;
  465. line-height: 17.5rpx;
  466. }
  467. .work {
  468. width: 87.5rpx;
  469. height: 50rpx;
  470. background-color: #ff894d;
  471. border-radius: 5rpx;
  472. margin: 16.25rpx auto;
  473. .sum {
  474. font-size: 20rpx;
  475. color: #fff;
  476. font-weight: bold;
  477. line-height: 30rpx;
  478. }
  479. .danwei {
  480. font-weight: 400;
  481. font-size: 15rpx;
  482. color: #fff;
  483. line-height: 15rpx;
  484. }
  485. }
  486. }
  487. }
  488. </style>