index.vue 12 KB

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