scheduling.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <div class="scheduling">
  3. <div class="search">
  4. <el-date-picker
  5. v-model="monthValue"
  6. value-format="yyyy-MM-dd"
  7. type="month"
  8. placeholder="选择时间"
  9. :clearable="false"
  10. ></el-date-picker>
  11. <div class="search-icon">
  12. <el-tooltip
  13. effect="light"
  14. placement="bottom"
  15. content="批量排班"
  16. >
  17. <i
  18. class="zoniot_font zoniot-icon-piliangshenhe"
  19. @click="add()"
  20. ></i>
  21. </el-tooltip>
  22. <el-tooltip
  23. effect="light"
  24. placement="bottom"
  25. content="返回"
  26. >
  27. <i
  28. class="zoniot_font zoniot-icon-fanhui"
  29. @click="goback()"
  30. ></i>
  31. </el-tooltip>
  32. </div>
  33. </div>
  34. <el-calendar
  35. first-day-of-week="7"
  36. v-model="monthValue"
  37. >
  38. <template
  39. slot="dateCell"
  40. slot-scope="{ date, data }"
  41. v-if="data.type === 'current-month'"
  42. >
  43. <div class="showDateDay">{{ date | dateNewType }}</div>
  44. <div class="schedulingUser">
  45. <template v-for="(item, index) in calendarData">
  46. <div
  47. :key="index"
  48. v-if="data.day == item.partrolDate"
  49. >
  50. <template v-for="(itx, inxs) in item.rosterUserDtos">
  51. <div
  52. :key="inxs"
  53. class="listTime"
  54. v-if="thisDayOfStaDay(data)"
  55. >
  56. <span>{{ itx.partrolTime }}</span>
  57. <span>{{ itx.partolName }}</span>
  58. </div>
  59. </template>
  60. <template v-if="
  61. date.getTime() <= $moment(zeroTetracosa(thisObj.endDate)).valueOf() &&
  62. thisTimeFF(data, item.rosterUserDtos)
  63. ">
  64. <!-- 每周那几天 -->
  65. <span v-if="thisObj.periodType == 1">
  66. <template v-if="periodValueType(thisObj.periodValue).includes(date.getDay() + '') && thisDayOfStaDay(data)">
  67. <div
  68. class="pointSet"
  69. @click="addItem(date, data, item,1)"
  70. >点击设置</div>
  71. </template>
  72. </span>
  73. <!-- 每隔N天 -->
  74. <span v-else>
  75. <template v-if="timeAddDay(thisObj, thisObj.periodValue, data)">
  76. <div
  77. class="pointSet"
  78. @click="addItem(date, data, item,2)"
  79. >点击设置</div>
  80. </template>
  81. </span>
  82. </template>
  83. </div>
  84. </template>
  85. <!-- 时间范围内且没有排班 -->
  86. <template v-if="
  87. date.getTime() <= $moment(zeroTetracosa(thisObj.endDate)).valueOf() &&
  88. thisTimeNull(data, thisObj.timePeriod) &&
  89. !trueArr.includes(data.day)
  90. ">
  91. <!-- 每周那几天 -->
  92. <span v-if="thisObj.periodType == 1">
  93. <template v-if="periodValueType(thisObj.periodValue).includes(date.getDay() + '') && thisDayOfStaDay(data)">
  94. <div
  95. class="pointSet"
  96. @click="add(data)"
  97. >点击设置</div>
  98. </template>
  99. </span>
  100. <!-- 每隔N天 -->
  101. <span v-else>
  102. <template v-if="timeAddDay(thisObj, thisObj.periodValue, data)">
  103. <div
  104. class="pointSet"
  105. @click="add(data)"
  106. >点击设置</div>
  107. </template>
  108. </span>
  109. </template>
  110. </div>
  111. </template>
  112. </el-calendar>
  113. </div>
  114. </template>
  115. <script>
  116. export default {
  117. data () {
  118. return {
  119. monthValue: '',
  120. findUser: [],
  121. thisObj: {},
  122. calendarData: [],
  123. indexThis: 0,
  124. trueArr: [] //已有设置时间集合
  125. };
  126. },
  127. filters: {
  128. dateNewType (val) {
  129. return val.getDate();
  130. }
  131. },
  132. watch: {
  133. monthValue (e) {
  134. try {
  135. let timeArr = e.split('-');
  136. let time = new Date(timeArr[0], Number(timeArr[1]), 0);
  137. this.getShiftInformation({
  138. patrolRouteId: this.thisObj.id,
  139. startTime: `${timeArr[0]}-${timeArr[1]}-01 00:00:00`,
  140. endTime: `${timeArr[0]}-${timeArr[1]}-${time.getDate()} 23:59:59`
  141. });
  142. } catch { }
  143. }
  144. },
  145. methods: {
  146. zeroTetracosa (val) {
  147. if (!!val) {
  148. return this.$moment(val).format('YYYY-MM-DD') + ' 23:59:59';
  149. }
  150. return val;
  151. },
  152. add (dateDe) {
  153. let title = '排班',
  154. isSingle = true;
  155. if (dateDe == undefined) {
  156. title = '批量排班';
  157. isSingle = false;
  158. }
  159. new Promise((resolve) => {
  160. this.$store.dispatch('addPopup', {
  161. url: '/patrolManagement/popups/schedulingAdd.vue',
  162. width: '450px',
  163. height: '300px',
  164. props: {
  165. callback: resolve,
  166. findUser: this.findUser,
  167. dateDe,
  168. thisObj: this.thisObj,
  169. isSingle: isSingle
  170. },
  171. title: title
  172. });
  173. }).then(() => {
  174. let newTime = this.$moment(this.monthValue).format('YYYY-MM-DD');
  175. let timeArr = newTime.split('-');
  176. let time = new Date(timeArr[0], Number(timeArr[1]), 0);
  177. this.getShiftInformation({
  178. patrolRouteId: this.thisObj.id,
  179. startTime: `${timeArr[0]}-${timeArr[1]}-01 00:00:00`,
  180. endTime: `${timeArr[0]}-${timeArr[1]}-${time.getDate()} 23:59:59`
  181. });
  182. });
  183. },
  184. addItem (da, dateDe, onj, index) {
  185. console.log('测试', da, dateDe, onj, index)
  186. new Promise((resolve) => {
  187. this.$store.dispatch('addPopup', {
  188. url: '/patrolManagement/popups/schedulingAdd.vue',
  189. width: '450px',
  190. height: '300px',
  191. props: {
  192. callback: resolve,
  193. findUser: this.findUser,
  194. dateDe,
  195. onj,
  196. index,
  197. thisObj: this.thisObj,
  198. isSingle: true
  199. },
  200. title: '排班'
  201. });
  202. }).then(() => {
  203. let newTime = this.$moment(this.monthValue).format('YYYY-MM-DD');
  204. let timeArr = newTime.split('-');
  205. let time = new Date(timeArr[0], Number(timeArr[1]), 0);
  206. this.getShiftInformation({
  207. patrolRouteId: this.thisObj.id,
  208. startTime: `${timeArr[0]}-${timeArr[1]}-01 00:00:00`,
  209. endTime: `${timeArr[0]}-${timeArr[1]}-${time.getDate()} 23:59:59`
  210. });
  211. });
  212. },
  213. goback () {
  214. this.$emit('initPage');
  215. },
  216. initDate (type) {
  217. this.monthValue = this.$moment().format(type);
  218. },
  219. getShiftInformation (obj) {
  220. this.$http.post('/sc-community/patrolRoute/getShiftInformation', obj).then(({ data, status, msg }) => {
  221. if (!!data) {
  222. this.calendarData = [];
  223. let calendarData = [],
  224. trueArr = [];
  225. for (let inx in data) {
  226. let rosterUserDtos = [];
  227. data[inx].map((item) => {
  228. rosterUserDtos.push({
  229. partrolTime: item.patrolTime,
  230. partolName: item.partolName,
  231. patrolUserId: item.patrolUserId,
  232. currentUsers: item.currentUsers,
  233. });
  234. });
  235. trueArr.push(this.$moment(inx).format('YYYY-MM-DD'));
  236. calendarData.push({
  237. partrolDate: this.$moment(inx).format('YYYY-MM-DD'),
  238. rosterUserDtos: rosterUserDtos
  239. });
  240. }
  241. this.calendarData = calendarData;
  242. this.trueArr = trueArr;
  243. this.indexThis = 0;
  244. this.$forceUpdate();
  245. }
  246. });
  247. },
  248. periodValueType (value) {
  249. if (!!value) {
  250. let vra = value.split(',').sort();
  251. vra.map((item, index) => {
  252. if (item == 7) {
  253. vra[index] = '0';
  254. }
  255. });
  256. return vra;
  257. }
  258. return [];
  259. },
  260. timeAddDay (val, sunDay, d) {
  261. let sum = sunDay || 0;
  262. let bb = false;
  263. if (!!val && !!sunDay) {
  264. if (this.indexThis <= 30) {
  265. this.indexThis++;
  266. }
  267. let { startDate } = val;
  268. let thisD = this.$moment(d.day + ' 00:00:00').valueOf();
  269. if (this.thisTimeTypeShow(this.$moment(startDate).valueOf(), Number(sum)).includes(thisD)) {
  270. bb = true;
  271. }
  272. }
  273. return bb;
  274. },
  275. thisTimeTypeShow (kai, sum) {
  276. // 零点计算 sum天得+1
  277. let oneDay = 86400000,
  278. indU = [];
  279. for (let x = 0; x <= 16; x++) {
  280. indU.push(kai + x * (sum + 1) * oneDay);
  281. }
  282. return indU;
  283. },
  284. thisTimeNull (s, item) {
  285. let thisDate = this.$moment(new Date());
  286. let sur = false;
  287. if (!!item) {
  288. let timePot = item.split('-');
  289. timePot.map((its) => {
  290. if (this.$moment(`${s.day} ${its}:00`).valueOf() > thisDate.valueOf()) {
  291. sur = true;
  292. return sur;
  293. }
  294. });
  295. }
  296. return sur;
  297. },
  298. thisDayOfStaDay (data) {
  299. let startDate = this.$moment(this.thisObj.startDate).valueOf();
  300. let thisDate = this.$moment(data.day + ' 00:00:00').valueOf();
  301. return startDate <= thisDate;
  302. },
  303. thisTimeFF (s, arr) {
  304. let thisDate = this.$moment(new Date());
  305. let sur = false;
  306. arr.map((item, index) => {
  307. let timePot = item.partrolTime.split('-');
  308. timePot.map((its) => {
  309. if (this.$moment(`${s.day} ${its}:00`).valueOf() > thisDate.valueOf()) {
  310. sur = true;
  311. return sur;
  312. }
  313. });
  314. return sur;
  315. });
  316. return sur;
  317. }
  318. },
  319. created () {
  320. this.initDate('YYYY-MM-DD');
  321. },
  322. mounted () {
  323. this.findUser = this.$parent.findUser;
  324. this.thisObj = this.$parent.thisObj;
  325. this.thisObj.periodType == 1;
  326. this.$el.querySelector('div.el-calendar__header').remove();
  327. }
  328. };
  329. </script>
  330. <style scoped lang='scss'>
  331. .scheduling {
  332. font-size: 12px;
  333. .showDateDay {
  334. font-size: 30px;
  335. text-align: center;
  336. }
  337. .schedulingUser {
  338. cursor: pointer;
  339. padding: 0 20px;
  340. line-height: 25px;
  341. .listTime {
  342. width: 100%;
  343. display: flex;
  344. justify-content: space-between;
  345. }
  346. }
  347. .pointSet {
  348. cursor: pointer;
  349. line-height: 35px;
  350. text-align: center;
  351. color: #0eaeff;
  352. }
  353. /deep/ .el-calendar-table {
  354. &:not(.is-range) {
  355. td.next {
  356. pointer-events: none;
  357. }
  358. td.prev {
  359. pointer-events: none;
  360. }
  361. }
  362. .el-calendar-day {
  363. height: 110px;
  364. overflow: auto;
  365. &::-webkit-scrollbar {
  366. width: 5px;
  367. }
  368. &::-webkit-scrollbar-track {
  369. border-radius: 5px;
  370. background: #f4f7f9a8;
  371. }
  372. &::-webkit-scrollbar-thumb {
  373. border-radius: 5px;
  374. background: #c6c4c4a9;
  375. }
  376. }
  377. }
  378. }
  379. </style>