Browse Source

user路由

陈远志 6 năm trước cách đây
mục cha
commit
51c4505ec5

+ 14 - 4
front_end/src/api/hotel.js

@@ -1,13 +1,23 @@
 import { axios } from '@/utils/request'
+const api = {
+    hotelPre: '/api/hotel'
+}
 export function getHotelsAPI() {
     return axios({
-        url: '/api/hotel/all',
-        method: 'get'
+        url: `${api.hotelPre}/all`,
+        method: 'get',
     })
 }
 export function getHotelByIdAPI(param) {
     return axios({
-        url: `/api/hotel/${param.hotelId}/detail`,
-        method: 'GET'
+        url: `${api.hotelPre}/${param.hotelId}/detail`,
+        method: 'GET',
+    })
+}
+export function reserveHotel(data) {
+    return axios({
+        url: `${api.hotelPre}/reserve`,
+        method: 'POST',
+        data,
     })
 }

+ 24 - 0
front_end/src/api/hotelManager.js

@@ -0,0 +1,24 @@
+import { axios } from '@/utils/request'
+const api = {
+    hotelPre: '/api/hotel'
+}
+export function addRoomAPI(data) {
+    return axios({
+        url: `${api.hotelPre}/roomInfo`,
+        method: 'POST',
+        data,
+    })
+}
+export function addHotelAPI(data) {
+    return axios({
+        url: `${api.hotelPre}`,
+        method: 'POST',
+        data,
+    })
+}
+export function getAllOrdersAPI() {
+    return axios({
+        url: '/api/order/all',
+        method: 'GET'
+    })
+}

+ 6 - 6
front_end/src/api/user.js

@@ -1,31 +1,31 @@
 import { axios } from '@/utils/request'
 
 const api = {
-    userPre: 'api/user'
+    userPre: '/api/user'
 }
 export function loginAPI(data){
     return axios({
-        url:`/api/login`,
+        url:`${api.userPre}/login`,
         method: 'POST',
         data
     })
 }
 export function registerAPI(data){
     return axios({
-        url: `/api/register`,
+        url: `${api.userPre}/register`,
         method: 'POST',
         data
     })
 }
 export function getUserInfoAPI(){
     return axios({
-        url: `${api.userPre}/getUserInfo`,
+        url: `${api.userPre}/userInfo`,
         method: 'GET'
     })
 }
-export function updateUserInfoByIdAPI(data) {
+export function updateUserInfoAPI(data) {
     return axios({
-        url: `${api.userPre}/updateUserInfoById`,
+        url: `${api.userPre}/userInfo/update`,
         method: 'POST',
         data
     })

+ 5 - 1
front_end/src/store/getters.js

@@ -12,7 +12,11 @@ const getters = {
   //admin
   userList: state => state.admin.userList,
   addUserModalVisible: state => state.admin.addUserModalVisible,
-  addUserParams: state => state.admin.addUserParams
+  addUserParams: state => state.admin.addUserParams,
+  //hotelManager
+  orderList: state => state.hotelManager.orderList,
+  addHotelModalVisible: state => state.hotelManager.addHotelModalVisible,
+  addRoomModalVisible: state => state.hotelManager.addRoomModalVisible,
   }
   
   export default getters

+ 53 - 3
front_end/src/store/modules/hotelManager.js

@@ -1,12 +1,62 @@
+import {
+    getAllOrdersAPI,
+    addRoomAPI,
+    addHotelAPI,
+} from '@/api/hotelManager'
 const hotelManager = {
-    stata: {
+    state: {
+        orderList: [],
+        addHotelParams: {
 
+        },
+        addHotelModalVisible: false,
+        addRoomParams: {
+
+        },
+        addRoomModalVisible: false
     },
     mutations: {
-
+        set_orderList: function(state, data) {
+            state.orderList = data
+        },
+        set_addHotelModalVisible: function(state, data) {
+            state.addHotelModalVisible = data
+        },
+        set_addHotelParams: function(state, data) {
+            state.addHotelParams = {
+                ...state.addHotelParams,
+                ...data,
+            }
+        },
+        set_addRoomModalVisible: function(state, data) {
+            state.addRoomModalVisible = data
+        },
+        set_addRoomParams: function(state, data) {
+            state.addRoomParams = {
+                ...state.addRoomParams,
+                ...data,
+            }
+        }
     },
     actions: {
-
+        getAllOrders: async({ state, commit }) => {
+            const res = await getAllOrdersAPI()
+            if(res){
+                commit('set_orderList', res.data)
+            }
+        },
+        addHotel: async({ state, dispatch }) => {
+            const res = await addHotelAPI(state.addHotelParams)
+            if(res){
+                dispatch('getAllOrders')
+            }
+        },
+        addRoom: async({ state, dispatch }) => {
+            const res = await addRoomAPI(state.addRoomParams)
+            if(res){
+                dispatch('getAllOrders')
+            }
+        }
     }
 }
 export default hotelManager

+ 23 - 16
front_end/src/store/modules/user.js

@@ -6,6 +6,8 @@ import { message } from 'ant-design-vue'
 import {
     loginAPI,
     registerAPI,
+    getUserInfoAPI,
+    updateUserInfoAPI
 } from '@/api/user'
 
 const getDefaultState = () => {
@@ -49,7 +51,6 @@ const user = {
             const res = await loginAPI(userData)
             if(res){
                 setToken(res)
-                // Vue.ls.set('ACCESS_TOKEN', res, 7 * 24 * 60 * 60 * 1000)
                 commit('set_token', res)
             }
         },
@@ -59,21 +60,27 @@ const user = {
                 message.success('注册成功')
             }
         },
-        // getUserInfo({ commit }) {
-        //     return new Promise((resolve, reject) => {
-        //       getUserInfoAPI().then(response => {
-        //         const data = response
-        //         if (!data) {
-        //           reject('登录已过期,请重新登录')
-        //         }
-        //         commit('set_userInfo', data)
-        //         commit('set_userId', data.userId)
-        //         resolve(data)
-        //       }).catch(error => {
-        //         reject(error)
-        //       })
-        //     })
-        // },
+        getUserInfo({ commit }) {
+            return new Promise((resolve, reject) => {
+              getUserInfoAPI().then(response => {
+                const data = response
+                if (!data) {
+                  reject('登录已过期,请重新登录')
+                }
+                commit('set_userInfo', data)
+                commit('set_userId', data.userId)
+                resolve(data)
+              }).catch(error => {
+                reject(error)
+              })
+            })
+        },
+        updateUserInfo: async({ state, commit }) => {
+            const res = await updateUserInfoAPI()
+            if(res){
+
+            }
+        },
         logout: async({ commit }) => {
             removeToken()
             resetRouter()

+ 0 - 4
front_end/src/views/hotel/hotelDetail.vue

@@ -23,10 +23,6 @@
                             <span class="label">地址</span>
                             <span class="value">{{ currentHotelInfo.address }}</span>
                         </div>
-                        <div class="items" v-if="currentHotelInfo.casts">
-                            <span class="label">主演:</span>
-                            <span class="value" v-for="item in currentHotelInfo.casts" :key="item.index">{{ item }}</span>
-                        </div>
                         <div class="items" v-if="currentHotelInfo.rate">
                             <span class="label">评分:</span> 
                             <span class="value">{{ currentHotelInfo.rate }}</span>

+ 104 - 0
front_end/src/views/hotelManager/components/addHotalModal.vue

@@ -0,0 +1,104 @@
+<template>
+    <a-modal
+        :visible="addHotelModalVisible"
+        title="添加酒店"
+        cancelText="取消"
+        okText="确定"
+        @cancel="cancel"
+        @ok="handleSubmit"
+    >
+        <a-form :form="form" style="margin-top: 30px" v-bind="formItemLayout">
+            <a-form-item label="酒店名">
+                <a-input
+                    placeholder="请填写酒店名称"
+                    v-decorator="['hotelName', { rules: [{ required: true, message: '请填写酒店名称' }] }]"
+                />
+            </a-form-item>
+            <a-form-item label="酒店地址" v-bind="formItemLayout">
+                <a-input
+                    placeholder="请填写酒店地址"
+                    v-decorator="['address', { rules: [{ required: true, message: '请填写酒店地址' }] }]"
+                />
+            </a-form-item>
+            <a-form-item label="酒店星级" v-bind="formItemLayout">
+                <a-select
+                    v-decorator="[
+                    'hotelStar', 
+                    { rules: [{ required: true, message: '请选择酒店星级' }] }]"
+                    @change="changeStar"
+                >
+                  <a-select-option value="Three">三星级</a-select-option>
+                  <a-select-option value="Four">四星级</a-select-option>
+                  <a-select-option value="Five">五星级</a-select-option>
+                </a-select>
+            </a-form-item>
+            <a-form-item label="手机号" v-bind="formItemLayout">
+                <a-input
+                    placeholder="请填写手机号"
+                    v-decorator="['phoneNumber', { rules: [{ required: true, message: '请输入手机号' }] }]"
+                />
+            </a-form-item>
+            <a-form-item label="酒店简介" v-bind="formItemLayout">
+                <a-input
+                    type="textarea"
+                    :rows="4"
+                    placeholder="请填写酒店简介"
+                    v-decorator="['email', { rules: [{ required: true, message: '请填写酒店简介' }] }]"
+                />
+            </a-form-item>
+        </a-form>
+    </a-modal>
+</template>
+<script>
+import { mapGetters, mapMutations, mapActions } from 'vuex'
+export default {
+    name: 'addUserModal',
+    data() {
+        return {
+            formItemLayout: {
+                labelCol: {
+                    xs: { span: 12 },
+                    sm: { span: 6 },
+                },
+                wrapperCol: {
+                    xs: { span: 24 },
+                    sm: { span: 16 },
+                },
+            },
+        }
+    },
+    computed: {
+        ...mapGetters([
+            'addHotelModalVisible'
+        ])
+    },
+    beforeCreate() {
+        this.form = this.$form.createForm(this, { name: 'addHotelModal' });
+    },
+    mounted() {
+
+    },
+    methods: {
+        ...mapMutations([
+            'set_addHotelModalVisible'
+        ]),
+        ...mapActions([
+
+        ]),
+        cancel() {
+            this.set_addHotelModalVisible(false)
+        },
+        changeStar(v){
+
+        },
+        handleSubmit(e) {
+            e.preventDefault();
+            this.form.validateFieldsAndScroll((err, values) => {
+                if (!err) {
+                    console.log('Received values of form: ', values);
+                }
+            });
+        },
+    }
+}
+</script>

+ 54 - 41
front_end/src/views/hotelManager/manageHotel.vue

@@ -1,14 +1,23 @@
 <template>
     <div class="manageHotel-wrapper">
         <a-tabs>
-            <a-tab-pane tab="录入客房" key="1">
-                <a-form :form="form" style="margin-top: 30px">
-                    
-                </a-form>
+            <a-tab-pane tab="酒店管理" key="1">
+                <div style="width: 100%; text-align: right; margin:20px 0">
+                    <a-button type="primary" @click="addHotel"><a-icon type="plus" />添加酒店</a-button>
+                </div>
+                 <a-table
+                    :columns="columns1"
+                    :dataSource="data"
+                    bordered
+                >
+                    <span slot="action" slot-scope="text, record">
+                        <a-button type="primary" @click="order(record)">录入房间</a-button>
+                    </span>
+                </a-table>
             </a-tab-pane>
             <a-tab-pane tab="订单管理" key="2">
                 <a-table
-                    :columns="columns"
+                    :columns="columns2"
                     :dataSource="data"
                     bordered
                 >
@@ -23,11 +32,36 @@
                 </a-table>
             </a-tab-pane>
         </a-tabs>
+        <AddHotelModal></AddHotelModal>
     </div>
 </template>
 <script>
 import { mapGetters, mapMutations, mapActions } from 'vuex'
-const columns = [
+import AddHotelModal from './components/addHotalModal'
+const columns1 = [
+    {  
+        title: '酒店名',
+        dataIndex: 'name',
+    },
+    {
+        title: '地址',
+        dataIndex: 'address',
+    },
+    {
+        title: '评分',
+        dataIndex: 'hotelRate',
+    },
+    {
+        title: '简介',
+        dataIndex: 'description',
+    },
+    {
+      title: '操作',
+      key: 'action',
+      scopedSlots: { customRender: 'action' },
+    },
+  ];
+const columns2 = [
     {  
         title: '酒店名',
         dataIndex: 'hotelName',
@@ -64,58 +98,37 @@ export default {
         return {
             formLayout: 'horizontal',
             pagination: {},
-            columns,
+            columns1,
+            columns2,
             data: [],
             form: this.$form.createForm(this, { name: 'manageHotel' }),
         }
     },
     components: {
+        AddHotelModal
     },
     computed: {
         ...mapGetters([
-            
+            'orderList',
+            'addHotelModalVisible',
+            'addRoomModalVisible'
         ])
     },
     mounted() {
 
     },
     methods: {
+        ...mapMutations([
+            'set_addHotelModalVisible',
+            'set_addRoomModalVisible'
+        ]),
         ...mapActions([
             'updateUserInfoById',
         ]),
-        saveModify() {
-            this.form.validateFields((err, values) => {
-                if (!err) {
-                    const data = {
-                        username: this.form.getFieldValue('username'),
-                        nickname: this.form.getFieldValue('nickname'),
-                        email: this.form.getFieldValue('email'),
-                        phoneNumber: this.form.getFieldValue('phoneNumber'),
-                        gender: this.form.getFieldValue('gender'),
-                        address: this.form.getFieldValue('address')
-                    }
-                    this.updateUserInfoById(data).then(()=>{
-                        this.modify = false
-                    })
-                }
-            });
-        },
-        modifyInfo() {
-            setTimeout(() => {
-                this.form.setFieldsValue({
-                    'username': this.userInfo.username,
-                    'nickname': this.userInfo.nickname,
-                    'email': this.userInfo.email,
-                    'phoneNumber': this.userInfo.phoneNumber,
-                    'gender': this.userInfo.gender,
-                    'address': this.userInfo.address
-                })
-            }, 0)
-            this.modify = true
+        addHotel() {
+            this.set_addHotelModalVisible(true)
         },
-        cancelModify() {
-            this.modify = false
-        }
+        
         
     }
 }
@@ -132,7 +145,7 @@ export default {
     }
 </style>
 <style lang="less">
-    .info-wrapper {
+    .manageHotel-wrapper {
         .ant-tabs-bar {
             padding-left: 30px
         }