index.vue 12 KB

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