add and delete room
This commit is contained in:
parent
c3bfa19d92
commit
2ef4bd7b14
|
@ -34,6 +34,9 @@ class Room(models.Model):
|
|||
def __str__(self):
|
||||
return f'{self.name}'
|
||||
|
||||
def get_seat_count(self):
|
||||
return self.seat_set.all().count()
|
||||
|
||||
|
||||
class Seat(models.Model):
|
||||
id = models.CharField('ID', max_length=36, default=uuid.uuid1, primary_key=True)
|
||||
|
|
|
@ -28,6 +28,8 @@ class SettingSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class RoomSerializer(serializers.ModelSerializer):
|
||||
seat_count = serializers.IntegerField(source='get_seat_count', required=False)
|
||||
|
||||
class Meta:
|
||||
model = models.Room
|
||||
fields = '__all__'
|
||||
|
|
|
@ -23,19 +23,29 @@ class SettingDetail(generics.RetrieveUpdateAPIView):
|
|||
permission_classes = (permissions.IsAdminUser,)
|
||||
|
||||
|
||||
class Room(generics.ListAPIView):
|
||||
class Room(generics.ListCreateAPIView):
|
||||
"""
|
||||
获得room列表
|
||||
新建room
|
||||
"""
|
||||
queryset = models.Room.objects.all().order_by('name')
|
||||
serializer_class = serializers.RoomSerializer
|
||||
permission_classes = (permissions.IsAuthenticated,)
|
||||
|
||||
def perform_create(self, serializer):
|
||||
data = serializer.validated_data
|
||||
seat_count = data['get_seat_count']
|
||||
del data['get_seat_count']
|
||||
room = models.Room.objects.create(**data)
|
||||
for i in range(100, 100 + seat_count):
|
||||
seat = models.Seat.objects.create(room=room, name=str(i))
|
||||
|
||||
class RoomDetail(generics.RetrieveUpdateAPIView):
|
||||
|
||||
class RoomDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||
"""
|
||||
获得指定room
|
||||
更新指定room
|
||||
删除指定room
|
||||
"""
|
||||
queryset = models.Room.objects.all()
|
||||
serializer_class = serializers.RoomSerializer
|
||||
|
@ -54,8 +64,8 @@ class Seat(generics.ListCreateAPIView):
|
|||
filterset_fields = ['room__id']
|
||||
|
||||
def perform_create(self, serializer):
|
||||
name = serializer.validated_data.get('name')
|
||||
r = serializer.validated_data.get('room')
|
||||
name = serializer.validated_data['name']
|
||||
r = serializer.validated_data['room']
|
||||
room = models.Room.objects.get(id=r.id)
|
||||
models.Seat.objects.create(room=room, name=name)
|
||||
|
||||
|
|
|
@ -4,12 +4,18 @@ export default {
|
|||
getRoomList (params) {
|
||||
return fetchAPI('booking/room/', 'get', null, params)
|
||||
},
|
||||
createRoom (room) {
|
||||
return fetchAPI('/booking/room/', 'post', room)
|
||||
},
|
||||
getRoom (id) {
|
||||
return fetchAPI(`booking/room/${id}/`, 'get')
|
||||
},
|
||||
updateRoom (id, room) {
|
||||
return fetchAPI(`booking/room/${id}/`, 'put', room)
|
||||
},
|
||||
deleteRoom (id) {
|
||||
return fetchAPI(`booking/room/${id}/`, 'delete')
|
||||
},
|
||||
getSeatList (params) {
|
||||
return fetchAPI('booking/seat/', 'get', null, params)
|
||||
},
|
||||
|
|
|
@ -57,6 +57,13 @@ export const routerMap = [
|
|||
component: () => import(/* webpackChunkName: "room" */ '../views/room/Seat'),
|
||||
meta: { title: '座位管理' }
|
||||
},
|
||||
{
|
||||
path: '/room/:id/create',
|
||||
name: 'roomCreate',
|
||||
hidden: true,
|
||||
component: () => import(/* webpackChunkName: "room" */ '../views/room/RoomDetail'),
|
||||
meta: { title: '新建房间' }
|
||||
},
|
||||
{
|
||||
path: '/room/:id/edit',
|
||||
name: 'roomEdit',
|
||||
|
|
|
@ -1,83 +1,79 @@
|
|||
<template>
|
||||
<page-layout title="用户">
|
||||
<a-card>
|
||||
<a-row>
|
||||
<a-input-group class="tool">
|
||||
<a-row :gutter="6">
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-select
|
||||
v-model="params.role"
|
||||
style="width: 100%;"
|
||||
@change="getData()">
|
||||
<a-select-option value="">角色筛选</a-select-option>
|
||||
<a-select-option :value="item.id" v-for="item in roleList">{{item.name}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-select
|
||||
v-model="params.ordering"
|
||||
style="width: 100%;"
|
||||
@change="getData()">
|
||||
<a-select-option value="">排序</a-select-option>
|
||||
<a-select-option value="id">ID正排序</a-select-option>
|
||||
<a-select-option value="-id">ID倒排序</a-select-option>
|
||||
<a-select-option value="username">用户名正排序</a-select-option>
|
||||
<a-select-option value="-username">用户名倒排序</a-select-option>
|
||||
<a-select-option value="date_joined">加入时间正排序</a-select-option>
|
||||
<a-select-option value="-date_joined">加入时间倒排序</a-select-option>
|
||||
<a-select-option value="last_login">上次登录正排序</a-select-option>
|
||||
<a-select-option value="-last_login">上次登录倒排序</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-input
|
||||
v-model="params.search"
|
||||
style="width: 100%;"
|
||||
placeholder="ID,用户名,邮箱"
|
||||
@keypress.enter="getData">
|
||||
</a-input>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
:xs="{ span: 12 }"
|
||||
:sm="{ span: 8 }"
|
||||
:xl="{ span: 4 }">
|
||||
<a-button
|
||||
style="width: 100%;"
|
||||
icon="search"
|
||||
@click="getData">
|
||||
搜索
|
||||
</a-button>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-button
|
||||
style="width: 100%;"
|
||||
icon="delete"
|
||||
@click="handleClearParams">
|
||||
重置
|
||||
</a-button>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-button
|
||||
type="primary"
|
||||
icon="plus"
|
||||
style="width: 100%;"
|
||||
@click="$router.push({name: 'accountCreate'})">
|
||||
新建
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-input-group>
|
||||
<a-row :gutter="6">
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-select
|
||||
v-model="params.role"
|
||||
style="width: 100%;"
|
||||
@change="getData()">
|
||||
<a-select-option value="">角色筛选</a-select-option>
|
||||
<a-select-option :value="item.id" v-for="item in roleList">{{item.name}}</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-select
|
||||
v-model="params.ordering"
|
||||
style="width: 100%;"
|
||||
@change="getData()">
|
||||
<a-select-option value="">排序</a-select-option>
|
||||
<a-select-option value="id">ID正排序</a-select-option>
|
||||
<a-select-option value="-id">ID倒排序</a-select-option>
|
||||
<a-select-option value="username">用户名正排序</a-select-option>
|
||||
<a-select-option value="-username">用户名倒排序</a-select-option>
|
||||
<a-select-option value="date_joined">加入时间正排序</a-select-option>
|
||||
<a-select-option value="-date_joined">加入时间倒排序</a-select-option>
|
||||
<a-select-option value="last_login">上次登录正排序</a-select-option>
|
||||
<a-select-option value="-last_login">上次登录倒排序</a-select-option>
|
||||
</a-select>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-input
|
||||
v-model="params.search"
|
||||
style="width: 100%;"
|
||||
placeholder="ID,用户名,邮箱"
|
||||
@keypress.enter="getData">
|
||||
</a-input>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
:xs="{ span: 12 }"
|
||||
:sm="{ span: 8 }"
|
||||
:xl="{ span: 4 }">
|
||||
<a-button
|
||||
style="width: 100%;"
|
||||
icon="search"
|
||||
@click="getData">
|
||||
搜索
|
||||
</a-button>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-button
|
||||
style="width: 100%;"
|
||||
icon="delete"
|
||||
@click="handleClearParams">
|
||||
重置
|
||||
</a-button>
|
||||
</a-col>
|
||||
<a-col
|
||||
class="item"
|
||||
v-bind="layout2">
|
||||
<a-button
|
||||
type="primary"
|
||||
icon="plus"
|
||||
style="width: 100%;"
|
||||
@click="$router.push({name: 'accountCreate'})">
|
||||
新建
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row>
|
||||
<a-col class="item">
|
||||
|
|
|
@ -225,12 +225,9 @@
|
|||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-popconfirm title="是否要取消?" @confirm="$router.go(-1)">
|
||||
<a-button style="float: right; margin: 0 4px;">
|
||||
取消
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
|
||||
<a-button style="float: right; margin: 0 4px;" @click="$router.go(-1)">
|
||||
返回
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-col>
|
||||
|
|
|
@ -102,7 +102,7 @@
|
|||
提交申请
|
||||
</a-button>
|
||||
<a-button @click="$router.go(-1)" style="float: right; margin-right: 8px">
|
||||
取消
|
||||
返回
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
|
|
|
@ -56,6 +56,9 @@
|
|||
@click="handleCreate">
|
||||
新建预约
|
||||
</a-button>
|
||||
<a-button style="float: right; margin: 0 4px;" @click="$router.go(-1)">
|
||||
返回
|
||||
</a-button>
|
||||
</a-row>
|
||||
<a-row>
|
||||
<span>总计: {{room.booked_count_total}} / {{room.count_total}}</span>
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
<template>
|
||||
<page-layout title="房间">
|
||||
<a-card>
|
||||
<a-row>
|
||||
<a-col
|
||||
class="item"
|
||||
:xs="{ span: 24 }"
|
||||
:sm="{ span: 8, offset: 16 }"
|
||||
:xl="{ span: 6, offset: 18 }">
|
||||
<a-button
|
||||
style="width: 100%"
|
||||
type="primary"
|
||||
icon="plus"
|
||||
@click="$router.push({name : 'roomCreate'})">
|
||||
新建
|
||||
</a-button>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row>
|
||||
<a-col class="item">
|
||||
<a-table
|
||||
|
@ -14,8 +29,13 @@
|
|||
<a-button type="primary" @click="$router.push({name: 'roomEdit', params: {id: record.id.toString()}})">
|
||||
编辑
|
||||
</a-button>
|
||||
<a-popconfirm title="确定删除吗?" @confirm="handleDelete(record)">
|
||||
<a-button type="danger">
|
||||
删除
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button @click="$router.push({name: 'seat', params: {id: record.id.toString()}})">座位管理</a-button>
|
||||
<a-button @click="handleDownload">下载二维码</a-button>
|
||||
<a-button @click="handleDownload">二维码</a-button>
|
||||
</a-button-group>
|
||||
</template>
|
||||
</a-table>
|
||||
|
@ -35,12 +55,17 @@
|
|||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
width: '15%'
|
||||
width: '10%'
|
||||
},
|
||||
{
|
||||
title: '座位数量',
|
||||
dataIndex: 'seat_count',
|
||||
width: '10%'
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'description',
|
||||
width: '25%'
|
||||
width: '20%'
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
|
@ -60,16 +85,6 @@
|
|||
data () {
|
||||
return {
|
||||
columns,
|
||||
layout1: {
|
||||
xs: { span: 24 },
|
||||
sm: { span: 8 },
|
||||
xl: { span: 8 },
|
||||
},
|
||||
layout2: {
|
||||
xs: { span: 12 },
|
||||
sm: { span: 8 },
|
||||
xl: { span: 4 },
|
||||
},
|
||||
state: {
|
||||
loading: false,
|
||||
},
|
||||
|
@ -91,6 +106,13 @@
|
|||
this.state.loading = false
|
||||
})
|
||||
},
|
||||
handleDelete (room) {
|
||||
api.deleteRoom(room.id)
|
||||
.then(data => {
|
||||
this.$notification.success({ message: '成功', description: '成功删除房间', key: 'SUCCESS' })
|
||||
this.getData()
|
||||
})
|
||||
},
|
||||
handleDownload () {
|
||||
|
||||
}
|
||||
|
@ -99,5 +121,7 @@
|
|||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
.item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<page-layout :title="`${room.name} 编辑`">
|
||||
<page-layout :title="isEdit ? `${room.name} 房间编辑` : '新建房间'">
|
||||
<a-card>
|
||||
<a-col
|
||||
:xs="{span: 24}"
|
||||
|
@ -11,6 +11,7 @@
|
|||
:form="form"
|
||||
@submit="handleSubmit">
|
||||
<a-form-item
|
||||
v-if="isEdit"
|
||||
label="ID"
|
||||
v-bind="layout">
|
||||
{{room.id}}
|
||||
|
@ -22,7 +23,29 @@
|
|||
type="text"
|
||||
v-decorator="[
|
||||
'name',
|
||||
{initialValue: room.name}
|
||||
{
|
||||
rules: [{required: true, message: '请输入名称'}],
|
||||
validateTrigger: 'blur',
|
||||
initialValue: isEdit ? room.name : null
|
||||
}
|
||||
]">
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
v-if="!isEdit"
|
||||
label="座位数量"
|
||||
v-bind="layout">
|
||||
<a-input
|
||||
type="number"
|
||||
v-decorator="[
|
||||
'seat_count',
|
||||
{
|
||||
rules: [
|
||||
{required: true, message: '请输入座位数量'},
|
||||
{min: 0, message: '请输入大于等于1的数量'}
|
||||
],
|
||||
validateTrigger: 'blur'
|
||||
}
|
||||
]">
|
||||
</a-input>
|
||||
</a-form-item>
|
||||
|
@ -34,7 +57,7 @@
|
|||
:rows="4"
|
||||
v-decorator="[
|
||||
'description',
|
||||
{initialValue: room.description}
|
||||
{initialValue: isEdit ? room.description: ''}
|
||||
]">
|
||||
</a-textarea>
|
||||
</a-form-item>
|
||||
|
@ -42,11 +65,9 @@
|
|||
<a-button type="primary" @click="handleSubmit" style="float: right">
|
||||
保存
|
||||
</a-button>
|
||||
<a-popconfirm title="是否要取消?" @confirm="$router.go(-1)">
|
||||
<a-button style="float: right; margin: 0 4px;">
|
||||
取消
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button style="float: right; margin: 0 4px;" @click="$router.go(-1)">
|
||||
返回
|
||||
</a-button>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-col>
|
||||
|
@ -77,7 +98,9 @@
|
|||
}
|
||||
},
|
||||
mounted () {
|
||||
this.getData()
|
||||
if (this.isEdit) {
|
||||
this.getData()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getData () {
|
||||
|
@ -90,15 +113,28 @@
|
|||
e.preventDefault()
|
||||
this.form.validateFields((error, data) => {
|
||||
if (!error) {
|
||||
api.updateRoom(this.id, data)
|
||||
.then(data => {
|
||||
this.$notification.success({ message: '成功', description: '成功修改房间', key: 'SUCCESS' })
|
||||
this.$router.push({ name: 'room' })
|
||||
})
|
||||
if (this.isEdit) {
|
||||
api.updateRoom(this.id, data)
|
||||
.then(data => {
|
||||
this.$notification.success({ message: '成功', description: '成功修改房间', key: 'SUCCESS' })
|
||||
this.$router.push({ name: 'room' })
|
||||
})
|
||||
} else {
|
||||
api.createRoom(data)
|
||||
.then(data => {
|
||||
this.$notification.success({ message: '成功', description: '成功新建房间', key: 'SUCCESS' })
|
||||
this.$router.push({ name: 'room' })
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
isEdit () {
|
||||
return this.$route.path.split('/').pop() === 'edit'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
:pagination="false">
|
||||
<template slot="operation" slot-scope="text, record, index">
|
||||
<a-button-group>
|
||||
<a-button @click="handleDownload">下载二维码</a-button>
|
||||
<a-button @click="handleDownload">二维码</a-button>
|
||||
</a-button-group>
|
||||
</template>
|
||||
</a-table>
|
||||
|
|
Loading…
Reference in New Issue