work-scene.wpy 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <style lang="less" scoped>
  2. .work-scene {
  3. border-top: 1px solid #c4c4c466;
  4. // height: 184rpx;
  5. // padding: 28rpx 40rpx 40rpx 40rpx;
  6. height:92px;
  7. display: flex;
  8. padding:0 40rpx;
  9. justify-content: space-around;
  10. align-items: center;
  11. }
  12. .off {
  13. display: flex;
  14. padding: 26rpx 24rpx;
  15. text-align: center;
  16. box-sizing: border-box;
  17. align-items: center;
  18. width: 156rpx;
  19. height: 116rpx;
  20. background: rgba(159, 183, 205, 0.15);
  21. border-radius: 32rpx;
  22. margin-left: 18rpx;
  23. .text-font {
  24. padding-left: 16rpx;
  25. width: 52rpx;
  26. height: 64rpx;
  27. height: 64rpx;
  28. font-family: 'Montserrat';
  29. font-style: normal;
  30. font-weight: 500;
  31. font-size: 26rpx;
  32. color: #4d5262;
  33. }
  34. }
  35. .imgSt {
  36. width: 40rpx;
  37. height: 40rpx;
  38. }
  39. .book {
  40. display: flex;
  41. justify-content: space-between;
  42. align-items: center;
  43. width: 100%;
  44. height: 116rpx;
  45. background: rgba(159, 183, 205, 0.15);
  46. &.hasWorkTime {
  47. background: rgba(61, 203, 204, 0.3);
  48. }
  49. border-radius: 16px;
  50. padding-left: 24rpx;
  51. .work-box {
  52. // margin-left: 16rpx;
  53. display: flex;
  54. align-items: center;
  55. // width: 220rpx;
  56. .fontSi {
  57. padding-top: 8rpx;
  58. font-family: 'Montserrat';
  59. font-style: normal;
  60. font-weight: 500;
  61. font-size: 30rpx;
  62. line-height: 36rpx;
  63. color: #1f2429;
  64. }
  65. .text-font {
  66. font-family: 'Montserrat';
  67. font-style: normal;
  68. font-weight: 500;
  69. font-size: 24rpx;
  70. line-height: 30rpx;
  71. color: #4d5262;
  72. }
  73. }
  74. .book-box {
  75. margin-right: 8rpx;
  76. width: 96rpx;
  77. height: 100rpx;
  78. display: flex;
  79. justify-content: center;
  80. align-items: center;
  81. padding: 9px;
  82. box-sizing: border-box;
  83. background: #ffffff;
  84. box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.1),
  85. 0px 4px 10px rgba(0, 0, 0, 0.07);
  86. border-radius: 32rpx;
  87. &.bigWidth {
  88. width: 196rpx;
  89. }
  90. .book-font {
  91. // width: 52rpx;
  92. // height: 64rpx;
  93. font-family: 'PingFang SC';
  94. font-style: normal;
  95. font-weight: 400;
  96. font-size: 26rpx;
  97. line-height: 32rpx;
  98. text-align: center;
  99. color: #000000;
  100. }
  101. }
  102. }
  103. </style>
  104. <template>
  105. <div class="work-scene">
  106. <div
  107. class="book"
  108. :class="{'hasWorkTime': timeText === '工作时间' && hasWorkTime}"
  109. @click="changeWorkStatus"
  110. >
  111. <div
  112. class="work-box"
  113. v-if="hasWorkTime"
  114. >
  115. <div class="imgSt">
  116. <img
  117. style="width:100%;height:100%"
  118. src="{{h5StaticPath+'icon-work.svg'}}"
  119. alt=""
  120. lazyload
  121. >
  122. </div>
  123. <div style="margin-left:20rpx">
  124. <div class="text-font">{{timeText}}</div>
  125. <div class="fontSi">{{timeRange}}</div>
  126. </div>
  127. </div>
  128. <div
  129. class="work-box"
  130. v-else
  131. >
  132. <div class="imgSt">
  133. <img
  134. style="width:100%;height:100%"
  135. src="{{h5StaticPath+'icon-work.svg'}}"
  136. alt=""
  137. lazyload
  138. >
  139. </div>
  140. <div style="margin-left:20rpx">
  141. <div class="text-font">请选择工作时间段</div>
  142. <div
  143. class="text-font"
  144. style="padding-top: 8rpx;"
  145. >将自动开启办公服务</div>
  146. </div>
  147. </div>
  148. <div
  149. class="book-box"
  150. :class="{'bigWidth':!(isWorkOff && !inCusRangeTime)}"
  151. >
  152. <div class="book-font">预约时间</div>
  153. </div>
  154. </div>
  155. <div
  156. class="off"
  157. v-if="isWorkOff && !inCusRangeTime"
  158. @click="handleWorkOff"
  159. >
  160. <div class="imgSt">
  161. <img
  162. style="width:100%;height:100%"
  163. src="{{h5StaticPath+'icon-work-over.svg'}}"
  164. alt=""
  165. lazyload
  166. >
  167. </div>
  168. <div class="text-font">我要离开</div>
  169. </div>
  170. </div>
  171. </template>
  172. <script>
  173. import wepy from '@wepy/core';
  174. import moment from 'moment';
  175. import store from '@/store';
  176. import config from '@/config';
  177. import { mapState, mapActions } from '@wepy/x';
  178. import { saveBatchCustomScene } from '@/packagesEnv/api/officehome.js'
  179. import { checkSpaceControl } from '@/packagesEnv/pages/common.js'
  180. function HHmm(time, num) {
  181. const HH = time.slice(num, num + 2);
  182. const mm = time.slice(num + 2, num + 4);
  183. return `${HH}:${mm}`
  184. }
  185. let timer = null;
  186. let isClickTimer = null;
  187. wepy.component({
  188. props: {
  189. workDayTime: Object,
  190. isControl: Boolean // 是否可控
  191. },
  192. store,
  193. data: {
  194. h5StaticPath: config.h5StaticPath + '/page-officehome/',
  195. isWorkOff: false, // 到下班时间
  196. hasWorkTime: true, // 有工作时间
  197. workTimeList: [], // 工作时间列表
  198. currentTimeRange: [], // 当前工作区间
  199. timeRange: '', // 工作时间区间
  200. timeText: '--', // 工作时间文案
  201. inCusRangeTime: false // 在服务时间内
  202. },
  203. computed: {
  204. },
  205. watch: {
  206. workDayTime(newVal) {
  207. if (newVal.data) {
  208. clearInterval(timer);
  209. timer = null;
  210. this.getData()
  211. timer = setInterval(() => {
  212. this.getData();
  213. }, 1000 * 10);
  214. }
  215. }
  216. },
  217. detached() {
  218. clearInterval(timer);
  219. timer = null;
  220. },
  221. methods: {
  222. ...mapActions([
  223. 'setCusTime',
  224. 'setIsNowTime'
  225. ]),
  226. isHasWorkTime() { // 有工作时间
  227. let flag = false;
  228. this.workTimeList.forEach((item, idx) => {
  229. if (item.length !== 0) {
  230. flag = true
  231. }
  232. })
  233. if (this.timeRange) { // 有时间段
  234. flag = true
  235. }
  236. return flag
  237. },
  238. concatText(today, val) {
  239. let text = '';
  240. if (today === val) {
  241. text = '今日'
  242. }
  243. if (Number(val) === (Number(today) + 1)) {
  244. text = '次日'
  245. }
  246. if (Number(val) > (Number(today) + 1)) {
  247. const weekDay = moment(val).weekday();
  248. const weekArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六' ];
  249. text = weekArr[weekDay];
  250. }
  251. return text
  252. },
  253. bookDayText(val, cusFlag) { // 预约显示日期
  254. if (cusFlag || (this.isWorkOff && !this.inCusRangeTime)) {
  255. return '工作时间'
  256. }
  257. if (!val.length) return ''
  258. const startDate = val[0].slice(0, 8);
  259. const endDate = val[1].slice(0, 8);
  260. const today = moment().format('YYYYMMDD');
  261. let startText = this.concatText(today, startDate);
  262. let endText = this.concatText(today, endDate);
  263. if (startText === endText) {
  264. return `已预约-${endText}`
  265. } else {
  266. return `已预约(${startText}-${endText})`
  267. }
  268. },
  269. showTimeText(val, cusFlag) { // 显示时间文案
  270. if (!this.hasWorkTime) {
  271. this.hasWorkTime = false; // console.log(this.workTimeList.length, '没有时间表,结束');
  272. return;
  273. }
  274. const nowTime = moment().format('YYYYMMDDHHmmss');
  275. let nowtimeFlag = false;
  276. val.forEach((item, idx) => {
  277. const start = item[0];
  278. const end = item[1];
  279. if (nowTime >= end) {
  280. this.workTimeList.splice(idx, 1, []); // 已经过去的从列表删除
  281. }
  282. if (start <= nowTime && nowTime <= end) { // 当前在这个区间内
  283. this.timeText = '工作时间'
  284. this.setIsNowTime(true)
  285. this.isWorkOff = true; // 过服务定制时间
  286. this.currentTimeRange = item;
  287. nowtimeFlag = true;
  288. }
  289. })
  290. if (!this.hasWorkTime) return;
  291. if (!nowtimeFlag) {
  292. this.currentTimeRange = this.workTimeList.find(item => item.length !== 0);
  293. this.timeText = this.bookDayText(this.currentTimeRange[0])
  294. }
  295. const startTime = HHmm(this.currentTimeRange[0], 8);
  296. const endTime = HHmm(this.currentTimeRange[1], 8);
  297. this.timeRange = `${startTime} ~ ${endTime}`
  298. this.setCusTime({ cusStartTime: startTime, cusEndTime: endTime })
  299. this.timeText = this.bookDayText(this.currentTimeRange, cusFlag); // 预约显示日期
  300. },
  301. arrTrans(num, arr) { // 一维数组转换为二维数组
  302. const iconsArr = []; // 声明数组
  303. arr.forEach((item, index) => {
  304. const page = Math.floor(index / num); // 计算该元素为第几个素组内
  305. if (!iconsArr[page]) { // 判断是否存在
  306. iconsArr[page] = [];
  307. }
  308. iconsArr[page].push(item);
  309. });
  310. const nowDayTime = moment().format('YYYYMMDDHHmmss');
  311. let resultArr = [];
  312. iconsArr.find((item, idx) => {
  313. let itemEnd = item[1];
  314. if (nowDayTime > itemEnd) {
  315. } else {
  316. resultArr.push(item)
  317. }
  318. })
  319. return resultArr;
  320. },
  321. getData() {
  322. this.setIsNowTime(false)
  323. this.isWorkOff = false;
  324. let resData = this.workDayTime.data || []
  325. let timeArr = []; // 时间组
  326. let cusFlag = false; // 服务定制内
  327. let cusEle = {};
  328. this.setCusTime({
  329. cusStartTime: '',
  330. cusEndTime: ''
  331. })
  332. resData.forEach((ele, eleIdx) => {
  333. const nowDay = moment().format('YYYYMMDD');
  334. const nowTime = moment().format('HHmmss');
  335. this.inCusRangeTime = false;
  336. if (ele.date === nowDay && ele.cusStartTime && nowTime >= ele.cusStartTime && nowTime < ele.cusEndTime) { // 是当天且有服务定制
  337. cusFlag = true;
  338. cusEle = ele;
  339. timeArr.push(`${ele.date}${ele.cusStartTime}`);
  340. timeArr.push(`${ele.date}${ele.cusEndTime}`);
  341. }
  342. if (ele.customSceneList) {
  343. let bookItemArr = ele.customSceneList;
  344. bookItemArr.forEach((item, idx) => {
  345. timeArr.push(`${item.startDate}${item.startTime}`);
  346. timeArr.push(`${item.startDate}${item.endTime}`);
  347. })
  348. }
  349. })
  350. if (cusFlag) { // 服务定制时间
  351. this.isWorkOff = false;
  352. this.inCusRangeTime = true;
  353. this.hasWorkTime = true;
  354. this.setIsNowTime(true)
  355. // return;
  356. }
  357. if (timeArr.length === 0) { // 没有预约时间
  358. this.workTimeList = [];
  359. this.hasWorkTime = false;
  360. return
  361. }
  362. timeArr.sort(); // 排序
  363. let timeArrCopy = JSON.parse(JSON.stringify(timeArr));
  364. timeArrCopy.forEach((item, idx) => {
  365. let date = Number(item.slice(0, 8));
  366. let time = item.slice(8, 16);
  367. let nextItem = timeArrCopy[idx + 1] || '';
  368. let nextDate = Number(nextItem.slice(0, 8));
  369. let nextTime = nextItem.slice(8, 16);
  370. if (time === nextTime && nextDate === date) { // 去重
  371. timeArr.splice(timeArr.findIndex(jtem => jtem === item), 1);
  372. timeArr.splice(timeArr.findIndex(jtem => jtem === nextItem), 1);
  373. }
  374. if (time === '240000' && nextTime === '000000' && (nextDate - 1 === date)) { // 时间段跨天相邻
  375. timeArr.splice(timeArr.findIndex(jtem => jtem === item), 1);
  376. timeArr.splice(timeArr.findIndex(jtem => jtem === nextItem), 1);
  377. }
  378. })
  379. // console.log(timeArr, 'timeArrtimeArrtimeArrtimeArrtimeArr');
  380. let timeArrResult = this.arrTrans(2, timeArr) // 一维数组转换为二维数组
  381. if (timeArrResult.length === 0) {
  382. this.hasWorkTime = false;
  383. return
  384. }
  385. this.workTimeList = JSON.parse(JSON.stringify(timeArrResult));
  386. this.hasWorkTime = this.isHasWorkTime();
  387. // console.log(this.workTimeList, ' this.workTimeList');
  388. this.showTimeText(timeArrResult, cusFlag);// 显示时间文案
  389. },
  390. handleWorkOff() { // 我要离开
  391. if (!checkSpaceControl(this.isControl)) return;
  392. if (wx.canIUse('vibrateShort')) {
  393. wx.vibrateShort();
  394. } else {
  395. wx.vibrateLong();
  396. }
  397. this.$emit('component-open-sceneShowpop', 'showWorkOff')
  398. const currentStart = this.currentTimeRange[0];
  399. const currenEnd = this.currentTimeRange[1];
  400. let paramsArr = [];
  401. this.workDayTime.data.forEach((ele, eleIdx) => {
  402. let bookItemArr = ele.customSceneList || [];
  403. if (bookItemArr.length > 0) {
  404. bookItemArr.find(item => {
  405. const itemStart = `${item.startDate}${item.startTime}`
  406. const itemEnd = `${item.startDate}${item.endTime}`
  407. if (currentStart <= itemStart && itemEnd <= currenEnd) {
  408. item.type = 1
  409. paramsArr.push(item);
  410. }
  411. })
  412. }
  413. })
  414. saveBatchCustomScene({ 'historyBookList': paramsArr, 'type': 'workOff' }).then(res => {
  415. this.$emit('component-get-workTimeData');
  416. clearTimeout(isClickTimer);
  417. })
  418. },
  419. changeWorkStatus() {
  420. if (!checkSpaceControl(this.isControl)) return;
  421. this.$emit('component-open-workTimePop', true)
  422. }
  423. }
  424. })
  425. </script>