forked from liweijie/education
校历删除功能完善
This commit is contained in:
@@ -275,16 +275,20 @@ export default {
|
||||
beforeDestroy() {
|
||||
this.$root.$off('semester-current-changed', this.handleCurrentChanged)
|
||||
},
|
||||
watch: {
|
||||
'form.kxrq': 'calculateWeeks',
|
||||
'form.jsrq': 'calculateWeeks'
|
||||
},
|
||||
methods: {
|
||||
/** 顶栏切换当前学期后自动刷新 */
|
||||
handleCurrentChanged() {
|
||||
this.getList()
|
||||
},
|
||||
/** 初始化学年选项 */
|
||||
/** 初始化学年选项(新增时只能从当前年份往后选择) */
|
||||
initYearOptions() {
|
||||
const current = new Date().getFullYear()
|
||||
const list = []
|
||||
for (let i = current - 10; i <= current + 10; i++) {
|
||||
for (let i = current; i <= current + 10; i++) {
|
||||
list.push(i)
|
||||
}
|
||||
this.yearOptions = list
|
||||
@@ -331,6 +335,22 @@ export default {
|
||||
if (!value) return ''
|
||||
return String(value).slice(0, 10)
|
||||
},
|
||||
/** 根据开学日期和结束日期自动计算学期周数 */
|
||||
calculateWeeks() {
|
||||
const kxrq = this.form.kxrq
|
||||
const jsrq = this.form.jsrq
|
||||
if (!kxrq || !jsrq) return
|
||||
const start = new Date(String(kxrq).slice(0, 10).replace(/-/g, '/'))
|
||||
const end = new Date(String(jsrq).slice(0, 10).replace(/-/g, '/'))
|
||||
if (isNaN(start.getTime()) || isNaN(end.getTime())) return
|
||||
if (end < start) return
|
||||
// 以开学当周周一为起点,向上取整到周
|
||||
const day = start.getDay()
|
||||
const monday = new Date(start)
|
||||
monday.setDate(start.getDate() - (day === 0 ? 6 : day - 1))
|
||||
const days = Math.round((end - monday) / (24 * 3600 * 1000)) + 1
|
||||
this.$set(this.form, 'sdzs', Math.max(1, Math.ceil(days / 7)))
|
||||
},
|
||||
/** 查询学期列表 */
|
||||
getList() {
|
||||
this.loading = true
|
||||
|
||||
Reference in New Issue
Block a user