Commit 39b3c095 authored by 王's avatar

不上课日期

parent fbb3c5c9
...@@ -12,13 +12,12 @@ ...@@ -12,13 +12,12 @@
<el-col :span="8"> <el-col :span="8">
<el-form-item> <el-form-item>
<el-date-picker <el-date-picker
type="dates" v-model="noLessonDate"
v-model="list" type="date"
format="yyyy-MM-dd" format="yyyy-MM-dd"
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
placeholder="选择一个或多个日期"> placeholder="选择日期">
</el-date-picker> </el-date-picker>
<!--<el-input v-model="form.desc" type="textarea"></el-input>-->
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
...@@ -50,11 +49,11 @@ ...@@ -50,11 +49,11 @@
form:{ form:{
key:'noLesson', key:'noLesson',
value:'noLesson', value:'noLesson',
desc:'' desc:[]
}, },
list: [], noLessonDate: '',
rules:{ rules:{
desc:[ noLessonDate:[
{ required: true, message: '请选择日期', trigger: 'change' } { required: true, message: '请选择日期', trigger: 'change' }
] ]
} }
...@@ -65,26 +64,43 @@ ...@@ -65,26 +64,43 @@
}, },
methods:{ methods:{
save(){ save(){
if(this.list.length === 0){ if(!this.noLessonDate){
this.$message({ this.$message({
type: 'error', type: 'error',
message: '请选择不上课时间!' message: '请选择不上课时间!'
}); });
return; return;
} }
this.form.desc = this.list.join(','); let json = {
if(this.dialogObj.id){ key: this.form.key,
updateConfigApi(this.id,this.form).then(res=>{ value: this.form.value
}
let _desc = this.form.desc || [];
let index = _desc.findIndex((val)=>{
return val === this.noLessonDate
})
if (index === -1){
_desc.push(this.noLessonDate);
} else {
this.$message({
type: 'error',
message: '日期不能重复添加!'
});
return;
}
json.desc = JSON.stringify(_desc);
if (this.id) {
updateConfigApi(this.id,json).then(res=>{
this.$message({ this.$message({
type: 'success', type: 'success',
message: '修改成功!' message: '新增成功!'
}); });
this.$emit("reflash"); this.$emit("reflash");
this.show = false; this.show = false;
}) })
}else{ } else {
this.form.desc = this.list.join(','); saveConfigApi(json).then(res=>{
saveConfigApi(this.form).then(res=>{
this.$message({ this.$message({
type: 'success', type: 'success',
message: '新增成功!' message: '新增成功!'
...@@ -93,6 +109,7 @@ ...@@ -93,6 +109,7 @@
this.show = false; this.show = false;
}) })
} }
}, },
initDialog(){ initDialog(){
this.show = this.dialogObj.show; this.show = this.dialogObj.show;
......
...@@ -5,54 +5,21 @@ ...@@ -5,54 +5,21 @@
<el-button type="success" plain @click="add">添加不上课日期</el-button> <el-button type="success" plain @click="add">添加不上课日期</el-button>
</el-col> </el-col>
</el-row> </el-row>
<el-table <div class="card">
:data="list" <el-card :body-style="{ padding: '0px' }" v-for="(currentDate, index) in list">
style="width: 100%"> <span class="time">{{ currentDate }}</span>
<el-table-column type="expand"> <div class="bottom clearfix">
<template slot-scope="props"> <el-button type="text" class="button" @click="del(currentDate)">删除</el-button>
<el-form label-position="left" class="demo-table-expand"> </div>
<el-form-item label="不上课日期"> </el-card>
<span>{{ props.row.desc }}</span> </div>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column
label="ID"
prop="id">
</el-table-column>
<el-table-column
label="Key"
prop="key">
</el-table-column>
<el-table-column
label="关键词"
prop="value">
</el-table-column>
<el-table-column
prop="created_at"
label="创建时间">
</el-table-column>
<el-table-column
width="250"
label="操作">
<template slot-scope="scope">
<el-button size="mini" plain type="warning" @click="edit(scope.row)">
编辑
</el-button>
<el-button size="mini" plain type="danger" @click="del(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<dialog-com :dialogObj="dialogObj" @changeShow="changeShow" @reflash="getList"/> <dialog-com :dialogObj="dialogObj" @changeShow="changeShow" @reflash="getList"/>
</div> </div>
</template> </template>
<script> <script>
import dialogCom from './dialog' import dialogCom from './dialog'
import {getConfigListApi,deleteConfigApi,getConfigDetailApi} from "../../service/api"; import {getConfigListApi,deleteConfigApi,getConfigDetailApi,updateConfigApi} from "../../service/api";
export default { export default {
name: "index", name: "index",
data() { data() {
...@@ -63,7 +30,8 @@ ...@@ -63,7 +30,8 @@
show:false, show:false,
id:'' id:''
}, },
list: [] list: [],
id: ''
} }
}, },
components:{ components:{
...@@ -81,13 +49,23 @@ ...@@ -81,13 +49,23 @@
key:'noLesson' key:'noLesson'
}; };
getConfigListApi(json).then(res => { getConfigListApi(json).then(res => {
this.list = res.list if(res.list.length > 0){
let _desc = res.list[0].desc;
console.log('desc', _desc)
this.id = res.list[0].id;
this.list = _desc ? JSON.parse(_desc) : [];
}
}) })
}, },
add(){ add(){
this.dialogObj.title = '添加不上课日期'; this.dialogObj.title = '添加不上课日期';
this.dialogObj.desc = ''; this.dialogObj.desc = this.list || [];
this.dialogObj.show = true this.dialogObj.show = true
if (this.list.length > 0){
this.dialogObj.id = this.id;
} else {
this.dialogObj.id = '';
}
}, },
edit(data){ edit(data){
getConfigDetailApi(data.id).then((res) => { getConfigDetailApi(data.id).then((res) => {
...@@ -97,18 +75,32 @@ ...@@ -97,18 +75,32 @@
}); });
}, },
del(data){ del(data){
console.log('data', data);
this.$confirm('此操作将删除该记录?', '提示', { this.$confirm('此操作将删除该记录?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
deleteConfigApi(data.id).then(res=>{ let json = {
this.getList() key: 'noLesson',
value: 'noLesson'
}
let _desc = [];
this.list.forEach((val)=>{
if(val !== data) {
console.log('_desc val', val)
_desc.push(val);
}
})
json.desc = JSON.stringify(_desc);
console.log('_desc json', json)
updateConfigApi(this.id,json).then(res=>{
this.$message({ this.$message({
type: 'success', type: 'success',
message: '删除成功!' message: '删除成功!'
}); });
}); this.getList();
})
}); });
} }
} }
...@@ -120,5 +112,46 @@ ...@@ -120,5 +112,46 @@
.add-btn { .add-btn {
margin: 10px 0; margin: 10px 0;
} }
.card {
display: flex;
flex-flow: row wrap;
justify-content: flex-start;
align-items: center;
& >div {
width: 236px;
margin-top: 10px;
margin-left: 10px;
padding: 10px;
}
}
.time {
font-size: 13px;
color: #999;
}
.bottom {
margin-top: 13px;
line-height: 12px;
}
.button {
padding: 0;
float: right;
}
.image {
width: 100%;
display: block;
}
.clearfix:before,
.clearfix:after {
display: table;
content: "";
}
.clearfix:after {
clear: both
}
</style> </style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment