index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <div class="app-container app-calendar-container">
  3. <div>
  4. <el-button type="primary" @click="handlePerFormList('ADD')">排期配置</el-button>
  5. </div>
  6. <div v-loading="loading">
  7. <el-calendar v-model="timeValue" v-if="showCalendar">
  8. <template
  9. slot="dateCell"
  10. slot-scope="{date, data}">
  11. <div @click.stop="selectTime(data.day)" :class="[data.day == today?'today_yes':'today_no']">
  12. <span>{{ data.day.split('-').slice(1).join('-') }}</span>
  13. <div style="width: 100%; display: flex;flex-wrap: wrap;" >
  14. <div
  15. :key="index"
  16. :style="{marginLeft: index%2 == 0?'':'20px',color: item.status == 1 ?'#67c23a':'#909399'}"
  17. v-for="(item,index) in getPerFormList(data)"
  18. @click.stop="handlePerFormDeatils(item)"
  19. >
  20. {{ item.performTimeStart }}-{{ item.performTimeEnd }}
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. </el-calendar>
  26. <!-- <calendarBox /> -->
  27. </div>
  28. <!-- 排期详情 -->
  29. <perFormDeatils ref="perFormDeatils" @getList="getList" />
  30. <!-- 排期列表 -->
  31. <perFormListBox ref="perFormListBox" @getList="getList" />
  32. </div>
  33. </template>
  34. <script>
  35. import { calendarList } from '@/api/ticketMr/schedulingConfiguration'
  36. import moment from "moment"
  37. import calendarBox from './dialog/calendarBox.vue';
  38. import perFormDeatils from './dialog/perFormDeatils.vue';
  39. import perFormListBox from './dialog/perFormListBox.vue';
  40. export default {
  41. name: "SchedulingConfiguration",
  42. dicts: [],
  43. components: { calendarBox,perFormDeatils,perFormListBox },
  44. data() {
  45. return {
  46. // 遮罩层
  47. loading: true,
  48. // 弹出层标题
  49. title: "",
  50. // 查询参数
  51. queryParams: {
  52. startDate: null,
  53. endDate: null,
  54. },
  55. timeValue: new Date(),
  56. perFormList: [],
  57. showCalendar: false,
  58. today: moment().format("YYYY-MM-DD")
  59. };
  60. },
  61. created() {
  62. this.showCalendar = false
  63. this.queryParams = {
  64. startDate: moment(this.timeValue).startOf('month').format("YYYY-MM-DD"),
  65. endDate: moment(this.timeValue).endOf('month').format("YYYY-MM-DD"),
  66. }
  67. this.getList();
  68. },
  69. methods: {
  70. /** 查询列表 */
  71. getList() {
  72. this.loading = true;
  73. let params = JSON.parse(JSON.stringify(this.queryParams))
  74. calendarList(this.addDateRange({...params}, this.dateRange))
  75. .then(response => {
  76. console.log(response)
  77. this.perFormList = response.data.rows
  78. this.showCalendar = true
  79. this.loading = false;
  80. }
  81. ).catch(() => {
  82. this.loading = false;
  83. });
  84. },
  85. getPerFormList(data) {
  86. let list = []
  87. this.perFormList.forEach((item,index)=>{
  88. if(item.performDate == data.day) {
  89. console.log("dsfsdfdsfdsf")
  90. list = item.list
  91. }
  92. })
  93. return list
  94. },
  95. selectTime(value){
  96. console.log("value====",value)
  97. // this.queryParams = {
  98. // startDate: moment(value).startOf('month').format("YYYY-MM-DD"),
  99. // endDate: moment(value).endOf('month').format("YYYY-MM-DD"),
  100. // }
  101. // this.getList();
  102. },
  103. /** 修改按钮操作 */
  104. handleUpdate(row) {
  105. this.$refs["addAndEdit"].openDialog("修改数据", row);
  106. },
  107. /** 排期详情 */
  108. handlePerFormDeatils(row) {
  109. this.$refs["perFormDeatils"].openDialog("排期详情", row);
  110. },
  111. /** 排期列表 */
  112. handlePerFormList() {
  113. this.$refs["perFormListBox"].openDialog("排期详情", null);
  114. },
  115. // 获取日历显示时间范围
  116. getRange(date){
  117. // 日历第一天
  118. let firstDay = '';
  119. // 日历最后一天
  120. let lastDay = '';
  121. // 今天
  122. const today = date ? date : new Date()
  123. // 上月
  124. const m = today.getMonth()
  125. // 本月
  126. const cm = m + 1
  127. // 下月
  128. const lm = m + 2 > 12 ? 1 : m + 2
  129. // 要显示的本月
  130. const currentMonth = cm < 10 ? '0' + cm : cm
  131. // 要显示的本本年
  132. const currentYear = today.getFullYear()
  133. // 要显示的上个月的年份,m = 0 则当前1月,上月则是去年12月
  134. const prevYear = m == 0 ? currentYear - 1 : currentYear
  135. const prevMonth = m == 0 ? 12 : m < 10 ? '0' + m : m
  136. // 上个月天数
  137. const pmd = new Date(prevYear, m, 0).getDate()
  138. // 下个月的年份,当前12月,则需要加一年
  139. const lastYear = cm + 1 > 12 ? currentYear + 1 : currentYear
  140. const lastMonth = lm < 10 ? '0' + lm : lm
  141. // 1号是周几
  142. const firstWeek = new Date(today.setDate(1)).getDay()
  143. // 如果是周日,则不需要显示上个月
  144. if (firstWeek == 0) {
  145. firstDay = `${currentYear}-${currentMonth}-01`
  146. }
  147. // 其他周几,对应用上个月的天数往前推算
  148. else {
  149. firstDay = `${prevYear}-${prevMonth}-${pmd - (firstWeek - 1)}`
  150. }
  151. // 这个月天数
  152. const currentMonthDate = new Date(currentYear, cm, 0).getDate()
  153. // 最后一天是周几
  154. const lastWeek = new Date(today.setDate(currentMonthDate)).getDay()
  155. // 周六显示当月最后一天
  156. if (lastWeek == 6) {
  157. lastDay = `${currentYear}-${currentMonth}-${currentMonthDate}`
  158. }
  159. // 其他周几,对应往后推算
  160. else {
  161. const day = ['06', '05', '04', '03', '02', '01']
  162. lastDay = `${lastYear}-${lastMonth}-${day[lastWeek]}`
  163. }
  164. console.log('第一天', firstDay)
  165. console.log('最后一天', lastDay)
  166. this.queryParams = {
  167. startDate: firstDay,
  168. endDate: lastDay,
  169. }
  170. this.getList();
  171. }
  172. },
  173. watch:{
  174. timeValue(newValue,oldValue){
  175. let time = moment(newValue).format("YYYY-DD-MM")
  176. if (newValue.getFullYear() !== oldValue.getFullYear() || newValue.getMonth() !== oldValue.getMonth()) {
  177. this.getRange(newValue)
  178. }
  179. }
  180. }
  181. };
  182. </script>
  183. <style scoped lang="scss">
  184. .is-selected {
  185. color: #1989FA;
  186. }
  187. .app-calendar-container ::v-deep .el-calendar-table .el-calendar-day {
  188. height: auto;
  189. min-height: 86px;
  190. }
  191. .app-calendar-container ::v-deep .is-today {
  192. background-color: rgba(255, 240, 24, 0.5);
  193. }
  194. .app-calendar-container ::v-deep .prev {
  195. background-color: rgba(223, 230, 236,0.5) !important;
  196. }
  197. .app-calendar-container ::v-deep .next {
  198. background-color: rgba(223, 230, 236,0.5) !important;
  199. }
  200. .today_yes {
  201. }
  202. .today_no {
  203. }
  204. </style>