index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. <template>
  2. <div class="app-container app-calendar-container">
  3. <div style="display: flex;justify-content: space-between;">
  4. <div>
  5. <el-button type="primary" v-hasPermi="['ticketMr:schedulingConfiguration:add']" @click="handleAdd('ADD')">配置排期</el-button>
  6. <el-button type="primary" v-hasPermi="['ticketMr:schedulingConfiguration:delect']" @click="checkIsClear()">批量清空</el-button>
  7. <el-button type="primary" @click="quickQueryFun()">快速查询</el-button>
  8. </div>
  9. <div>
  10. <el-button type="primary" v-hasPermi="['ticketMr:schedulingConfiguration:release']" @click="clearCalendarPrice(1)">批量启用</el-button>
  11. <el-button type="primary" v-hasPermi="['ticketMr:schedulingConfiguration:release']" @click="clearCalendarPrice(2)">批量禁用</el-button>
  12. </div>
  13. </div>
  14. <div v-loading="loading" class="calendar-dialog">
  15. <el-calendar v-model="timeValue">
  16. <template
  17. slot="dateCell"
  18. slot-scope="{date, data}">
  19. <div
  20. :class="['calendar_box', selectTime(data)]"
  21. @mouseover="mouseoverFun(data)"
  22. @click.stop="clickTimeFun(data)"
  23. >
  24. <div class="calendar_box-date" @click.stop="return ''">
  25. <span>
  26. {{ data.day.split('-').slice(1).join('-') }}
  27. {{ data.day == moment().format("YYYY-MM-DD") ? '(今天)':'' }}
  28. </span>
  29. <span style="color: #BEBEBE;" @click.stop="handlePerFormList('ADD',data)" v-if="getPerFormList(data).length>0">详情</span>
  30. </div>
  31. <div
  32. class="calendar_box-select"
  33. :style="{width: '100%', display: 'flex',flexWrap: 'wrap',height: height + 'px'}"
  34. >
  35. <div
  36. :key="index"
  37. :style="{marginLeft: index%2 == 0?'':'20px',color: item.status == 1 ?'#6F86FA':'#909399'}"
  38. v-for="(item,index) in getPerFormList(data)"
  39. >
  40. {{ item.performTimeStart }}-{{ item.performTimeEnd }}
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. </el-calendar>
  46. </div>
  47. <!-- 排期配置 -->
  48. <addAndEdit ref="addAndEdit" @getList="getList" />
  49. <!-- 排期列表 -->
  50. <perFormListBox ref="perFormListBox" @getList="getList" />
  51. <!-- 快速查询 -->
  52. <quickQuery ref="quickQuery" />
  53. </div>
  54. </template>
  55. <script>
  56. import {
  57. calendarList,
  58. deleteByDateApi,
  59. updateStatusByDateApi
  60. } from '@/api/ticketMr/schedulingConfiguration'
  61. import moment from "moment"
  62. import calendarBox from './dialog/calendarBox.vue';
  63. import perFormListBox from './dialog/perFormListBox.vue';
  64. import addAndEdit from "./dialog/addAndEdit";
  65. import quickQuery from './dialog/quickQuery.vue';
  66. export default {
  67. name: "SchedulingConfiguration",
  68. dicts: [],
  69. components: { calendarBox,perFormListBox,addAndEdit,quickQuery },
  70. data() {
  71. return {
  72. // 遮罩层
  73. loading: true,
  74. // 弹出层标题
  75. title: "",
  76. // 查询参数
  77. queryParams: {
  78. startDate: null,
  79. endDate: null,
  80. },
  81. timeValue: new Date(),
  82. timeValueObj: {
  83. prev: null,
  84. next: null,
  85. hover: null
  86. },
  87. perFormList: [],
  88. showCalendar: false,
  89. today: moment().format("YYYY-MM-DD"),
  90. height: 86,
  91. };
  92. },
  93. created() {
  94. this.showCalendar = false
  95. this.queryParams = {
  96. startDate: moment(this.timeValue).startOf('month').format("YYYY-MM-DD"),
  97. endDate: moment(this.timeValue).endOf('month').format("YYYY-MM-DD"),
  98. }
  99. this.getList();
  100. },
  101. methods: {
  102. moment,
  103. /** 查询列表 */
  104. getList() {
  105. this.loading = true;
  106. let params = JSON.parse(JSON.stringify(this.queryParams))
  107. calendarList(this.addDateRange({...params}, this.dateRange))
  108. .then(response => {
  109. // console.log(response)
  110. let list = response.data.rows || []
  111. let l = 1
  112. list.forEach((item,index)=>{
  113. if(item.list && item.list.length>l) {
  114. l = item.list.length
  115. }
  116. })
  117. this.height = (Math.floor(l/2) * 30 < 90) ? 90 : (Math.floor(l/2) * 30)
  118. this.perFormList = list
  119. this.showCalendar = true
  120. this.loading = false;
  121. }
  122. ).catch(() => {
  123. this.loading = false;
  124. });
  125. },
  126. getPerFormList(data) {
  127. let list = []
  128. this.perFormList.forEach((item,index)=>{
  129. if(item.performDate == data.day) {
  130. list = item.list
  131. }
  132. })
  133. return list
  134. },
  135. /** 选中得时间 */
  136. selectTime(data) {
  137. let srt = ''
  138. let newTime = moment(data.day).startOf('day').valueOf()
  139. let newTime1 = moment().startOf('day').valueOf()
  140. if(newTime < newTime1 ) {
  141. return "disable_time"
  142. }
  143. if( this.timeValueObj ) {
  144. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  145. let minTime = moment(this.timeValueObj.prev).valueOf()
  146. let maxTime = moment(this.timeValueObj.next).valueOf()
  147. if(newTime == minTime || newTime == maxTime) {
  148. return 'is-select_time_self'
  149. }
  150. if(minTime > maxTime){
  151. if(minTime >= newTime && maxTime <= newTime){
  152. srt = 'is-select_time'
  153. }
  154. }else {
  155. if(minTime <= newTime && maxTime >= newTime){
  156. srt = 'is-select_time'
  157. }
  158. }
  159. }else if( this.timeValueObj.prev && !this.timeValueObj.next && this.timeValueObj.hover ){
  160. let minTime = moment(this.timeValueObj.prev).valueOf()
  161. let maxTime = moment(this.timeValueObj.hover).valueOf()
  162. if(newTime == minTime || newTime == maxTime) {
  163. return 'is-select_time_self'
  164. }
  165. if(minTime > maxTime){
  166. if(minTime >= newTime && maxTime <= newTime){
  167. srt = 'is-select_time_hover'
  168. }
  169. }else {
  170. if(minTime <= newTime && maxTime >= newTime){
  171. srt = 'is-select_time_hover'
  172. }
  173. }
  174. }else if(this.timeValueObj.prev) {
  175. let minTime = moment(this.timeValueObj.prev).valueOf()
  176. if(newTime == minTime) {
  177. return 'is-select_time_self'
  178. }
  179. }
  180. }
  181. return srt
  182. },
  183. clickTimeFun(data) {
  184. let newTime1 = moment(data.day).startOf('day').valueOf()
  185. let newTime = moment().startOf('day').valueOf()
  186. if(newTime1 < newTime ) {
  187. return
  188. }
  189. if(moment(data.day).format("YYYY-MM") != moment(this.timeValue).format("YYYY-MM") ) {
  190. return
  191. }
  192. if( !this.timeValueObj || !this.timeValueObj.prev ) {
  193. this.timeValueObj.prev = moment(data.day).format("YYYY-MM-DD")
  194. }else if( this.timeValueObj.prev && !this.timeValueObj.next ){
  195. this.timeValueObj.next = moment(data.day).format("YYYY-MM-DD")
  196. }else if( this.timeValueObj.prev && this.timeValueObj.next ) {
  197. this.timeValueObj.prev = moment(data.day).format("YYYY-MM-DD")
  198. this.timeValueObj.next = null
  199. }
  200. },
  201. mouseoverFun(data) {
  202. if(moment(data.day).format("YYYY-MM") != moment(this.timeValue).format("YYYY-MM") ) {
  203. return
  204. }
  205. if( this.timeValueObj.prev && !this.timeValueObj.next ){
  206. this.timeValueObj.hover = moment(data.day).format("YYYY-MM-DD")
  207. this.timeValue = new Date(this.timeValueObj.hover)
  208. }
  209. },
  210. /** 新增按钮操作 */
  211. handleAdd(type) {
  212. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  213. this.openPrice = true
  214. this.formPrice = {}
  215. let obj = {}
  216. let minTime = moment(this.timeValueObj.prev).valueOf()
  217. let maxTime = moment(this.timeValueObj.hover).valueOf()
  218. if(minTime > maxTime){
  219. obj['next'] = this.timeValueObj.prev
  220. obj['prev'] = this.timeValueObj.next
  221. }else {
  222. obj['prev'] = this.timeValueObj.prev
  223. obj['next'] = this.timeValueObj.next
  224. }
  225. this.$nextTick(()=>{
  226. this.$refs["addAndEdit"].openDialog("配置排期", obj, type);
  227. })
  228. }else {
  229. this.$message.error("请选择时间区间!!!");
  230. }
  231. },
  232. quickQueryFun(type){
  233. this.$refs["quickQuery"].openDialog("快速查询", null, type);
  234. },
  235. /** 排期列表 */
  236. handlePerFormList(type,data) {
  237. this.$refs["perFormListBox"].openDialog("排期详情", {performDate: data.day},type);
  238. },
  239. // 获取日历显示时间范围
  240. getRange(date){
  241. // 日历第一天
  242. let firstDay = '';
  243. // 日历最后一天
  244. let lastDay = '';
  245. // 今天
  246. const today = date ? date : new Date()
  247. // 上月
  248. const m = today.getMonth()
  249. // 本月
  250. const cm = m + 1
  251. // 下月
  252. const lm = m + 2 > 12 ? 1 : m + 2
  253. // 要显示的本月
  254. const currentMonth = cm < 10 ? '0' + cm : cm
  255. // 要显示的本本年
  256. const currentYear = today.getFullYear()
  257. // 要显示的上个月的年份,m = 0 则当前1月,上月则是去年12月
  258. const prevYear = m == 0 ? currentYear - 1 : currentYear
  259. const prevMonth = m == 0 ? 12 : m < 10 ? '0' + m : m
  260. // 上个月天数
  261. const pmd = new Date(prevYear, m, 0).getDate()
  262. // 下个月的年份,当前12月,则需要加一年
  263. const lastYear = cm + 1 > 12 ? currentYear + 1 : currentYear
  264. const lastMonth = lm < 10 ? '0' + lm : lm
  265. // 1号是周几
  266. const firstWeek = new Date(today.setDate(1)).getDay()
  267. // 如果是周日,则不需要显示上个月
  268. if (firstWeek == 0) {
  269. firstDay = `${currentYear}-${currentMonth}-01`
  270. }
  271. // 其他周几,对应用上个月的天数往前推算
  272. else {
  273. firstDay = `${prevYear}-${prevMonth}-${pmd - (firstWeek - 1)}`
  274. }
  275. // 这个月天数
  276. const currentMonthDate = new Date(currentYear, cm, 0).getDate()
  277. // 最后一天是周几
  278. const lastWeek = new Date(today.setDate(currentMonthDate)).getDay()
  279. // 周六显示当月最后一天
  280. if (lastWeek == 6) {
  281. lastDay = `${currentYear}-${currentMonth}-${currentMonthDate}`
  282. }
  283. // 其他周几,对应往后推算
  284. else {
  285. const day = ['06', '05', '04', '03', '02', '01']
  286. lastDay = `${lastYear}-${lastMonth}-${day[lastWeek]}`
  287. }
  288. // console.log('第一天', firstDay)
  289. // console.log('最后一天', lastDay)
  290. this.queryParams = {
  291. startDate: firstDay,
  292. endDate: lastDay,
  293. }
  294. this.getList();
  295. },
  296. /** 时间调整顺序 */
  297. setTimeValueObj(){
  298. if (this.timeValueObj.prev && this.timeValueObj.next) {
  299. let minTime = moment(this.timeValueObj.prev).valueOf()
  300. let maxTime = moment(this.timeValueObj.next).valueOf()
  301. let startDate = null
  302. let endDate = null
  303. if (minTime > maxTime) {
  304. startDate = this.timeValueObj.next
  305. endDate = this.timeValueObj.prev
  306. } else {
  307. startDate = this.timeValueObj.prev
  308. endDate = this.timeValueObj.next
  309. }
  310. return {
  311. startDate,
  312. endDate
  313. }
  314. } else {
  315. this.$message.error("请选择时间区间!!!");
  316. return false
  317. }
  318. },
  319. checkIsClear(){
  320. if (this.timeValueObj.prev && this.timeValueObj.next) {
  321. let minTime = moment(this.timeValueObj.prev).valueOf()
  322. let maxTime = moment(this.timeValueObj.next).valueOf()
  323. let startDate = null
  324. let endDate = null
  325. if (minTime > maxTime) {
  326. startDate = this.timeValueObj.next
  327. endDate = this.timeValueObj.prev
  328. } else {
  329. startDate = this.timeValueObj.prev
  330. endDate = this.timeValueObj.next
  331. }
  332. this.$modal.confirm('确定要清空勾选"' + startDate + '——' + endDate + '"的日期范围内的数据吗?').then(()=> {
  333. this.deleteCalendarPrice()
  334. }).catch(() => {});
  335. } else {
  336. this.$message.error("请选择时间区间!!!");
  337. }
  338. },
  339. /** 一键清除 */
  340. async deleteCalendarPrice() {
  341. try {
  342. if( this.timeValueObj.prev && this.timeValueObj.next ) {
  343. let minTime = moment(this.timeValueObj.prev).valueOf()
  344. let maxTime = moment(this.timeValueObj.next).valueOf()
  345. let startDate = null
  346. let endDate = null
  347. if(minTime > maxTime){
  348. startDate = this.timeValueObj.next
  349. endDate = this.timeValueObj.prev
  350. }else {
  351. startDate = this.timeValueObj.prev
  352. endDate = this.timeValueObj.next
  353. }
  354. let res = await deleteByDateApi({
  355. startDate: startDate,
  356. endDate: endDate
  357. })
  358. if(res.code == 200) {
  359. this.openPrice = false
  360. this.$modal.msgSuccess(res.msg);
  361. this.getList()
  362. }
  363. }else {
  364. this.$message.error("请选择时间区间!!!");
  365. }
  366. } catch (error) {
  367. }
  368. },
  369. /** 批量禁用/启用 */
  370. async clearCalendarPrice(type) {
  371. try {
  372. let timeS = this.setTimeValueObj()
  373. if(!timeS) return
  374. this.$modal.confirm(`确定要批量${ type == 1 ? '启用' : '禁用' }" ${timeS.startDate} —— ${timeS.endDate} "的日期范围内的场次吗?`).then(async ()=> {
  375. let res = await updateStatusByDateApi({
  376. startDate: timeS.startDate,
  377. endDate: timeS.endDate,
  378. status: type
  379. })
  380. if (res.code == 200) {
  381. this.$modal.msgSuccess(res.msg);
  382. this.timeValueObj = {
  383. prev: null,
  384. next: null,
  385. hover: null
  386. }
  387. this.getList()
  388. }
  389. }).catch(() => {});
  390. } catch (error) {
  391. }
  392. },
  393. },
  394. watch:{
  395. timeValue(newValue,oldValue){
  396. let time = moment(newValue).format("YYYY-DD-MM")
  397. if (newValue.getFullYear() !== oldValue.getFullYear() || newValue.getMonth() !== oldValue.getMonth()) {
  398. this.getRange(newValue)
  399. }
  400. }
  401. }
  402. };
  403. </script>
  404. <style scoped lang="scss">
  405. .is-selected {
  406. color: #1989FA;
  407. }
  408. .app-calendar-container ::v-deep .el-calendar-day {
  409. padding-bottom: 0px !important;
  410. padding-left: 0px !important;
  411. padding-right: 0px !important;
  412. padding-top: 0px !important;
  413. height: auto;
  414. //min-height: 86px;
  415. }
  416. .app-calendar-container ::v-deep .is-today {
  417. background-color: rgba(255, 240, 24, 0);
  418. .calendar_box {
  419. border: 1px solid #0F40F5;
  420. }
  421. }
  422. .app-calendar-container ::v-deep .prev {
  423. background-color: rgba(223, 230, 236,0.5) !important;
  424. }
  425. .app-calendar-container ::v-deep .next {
  426. background-color: rgba(223, 230, 236,0.5) !important;
  427. }
  428. .today_yes {
  429. }
  430. .today_no {
  431. }
  432. /** 今天 */
  433. .el-calendar-table td.is-today {
  434. .calendar_box {
  435. color: #0F40F5;
  436. }
  437. }
  438. .calendar_box{
  439. width: 100%;
  440. min-height: 86px;
  441. padding: 8px;
  442. .calendar_box-date {
  443. display: flex;
  444. width: 100% ;
  445. justify-content: space-between;
  446. }
  447. }
  448. .disable_time {
  449. .calendar_box-select {
  450. padding-top: 10px;
  451. user-select: none;
  452. cursor: not-allowed;
  453. }
  454. }
  455. .is-select_time_self {
  456. background-color: #C2D4FF;
  457. }
  458. .is-select_time {
  459. background-color: #E4ECFF;
  460. }
  461. .is-select_time_hover {
  462. background-color: #E4ECFF;
  463. }
  464. </style>
  465. <style lang="scss">
  466. .calendar-dialog ::v-deep .el-calendar-table .el-calendar-day {
  467. padding: none !important;
  468. height: auto;
  469. }
  470. </style>