Sfoglia il codice sorgente

订单、管理员、酒店工作人员功能基本实现

陈远志 6 anni fa
parent
commit
9cee13faff

+ 8 - 5
front_end/src/api/admin.js

@@ -1,13 +1,16 @@
 import { axios } from '@/utils/request'
-export function getUserListAPI(){
+const api = {
+    adminPre: '/api/admin'
+}
+export function getManagerListAPI(){
     return axios({
-        url: '',
-        method: 'GET'
+        url: `${api.adminPre}/getAllManagers`,
+        method: 'POST'
     })
 }
-export function addUserAPI(data) {
+export function addManagerAPI(data) {
     return axios({
-        url: '',
+        url: `${api.adminPre}/addManager`,
         method: 'POST',
         data
     })

+ 2 - 2
front_end/src/api/hotelManager.js

@@ -11,14 +11,14 @@ export function addRoomAPI(data) {
 }
 export function addHotelAPI(data) {
     return axios({
-        url: `${api.hotelPre}`,
+        url: `${api.hotelPre}/addHotel`,
         method: 'POST',
         data,
     })
 }
 export function getAllOrdersAPI() {
     return axios({
-        url: '/api/order/all',
+        url: '/api/order/getAllOrders',
         method: 'GET'
     })
 }

+ 7 - 1
front_end/src/api/user.js

@@ -25,8 +25,14 @@ export function getUserInfoAPI(id){
 }
 export function updateUserInfoAPI(data) {
     return axios({
-        url: `${api.userPre}/userInfo/update`,
+        url: `${api.userPre}/${data.id}/userInfo/update`,
         method: 'POST',
         data
     })
+}
+export function getUserOrdersAPI(data) {
+    return axios({
+        url: `/api/order/${data.userId}/getUserOrders`,
+        method: 'GET'
+    })
 }

+ 6 - 3
front_end/src/store/getters.js

@@ -3,6 +3,7 @@ const getters = {
   token: state => state.user.token,
   userId: state => state.user.userId,
   userInfo: state => state.user.userInfo,
+  userOrderList: state => state.user.userOrderList,
   hotelListLoading: state => state.hotel.hotelListLoading,
   hotelList: state => state.hotel.hotelList,
   currentHotelInfo: state => state.hotel.currentHotelInfo,
@@ -10,13 +11,15 @@ const getters = {
   orderModalVisible: state => state.hotel.orderModalVisible,
   currentOrderRoom: state => state.hotel.currentOrderRoom,
   //admin
-  userList: state => state.admin.userList,
-  addUserModalVisible: state => state.admin.addUserModalVisible,
-  addUserParams: state => state.admin.addUserParams,
+  managerList: state => state.admin.managerList,
+  addManagerModalVisible: state => state.admin.addManagerModalVisible,
+  addManagerParams: state => state.admin.addManagerParams,
   //hotelManager
   orderList: state => state.hotelManager.orderList,
   addHotelModalVisible: state => state.hotelManager.addHotelModalVisible,
   addRoomModalVisible: state => state.hotelManager.addRoomModalVisible,
+  activeHotelId: state => state.hotelManager.activeHotelId,
+
   }
   
   export default getters

+ 27 - 18
front_end/src/store/modules/admin.js

@@ -1,44 +1,53 @@
 import {
-    getUserListAPI,
-    addUserAPI,
+    getManagerListAPI,
+    addManagerAPI,
 } from '@/api/admin'
+import { message } from 'ant-design-vue'
 
 const admin = {
     state: {
-        userList: [
+        managerList: [
 
         ],
-        addUserModalVisible: false,
-        addUserParams: {
+        addManagerModalVisible: false,
+        addManagerParams: {
             email:'',
             password:''
         }
     },
     mutations: {
-        set_userList: function(state, data) {
-            state.userList = data
+        set_managerList: function(state, data) {
+            state.managerList = data
         },
-        set_addUserModalVisible: function(state, data) {
-            state.addUserModalVisible = data
+        set_addManagerModalVisible: function(state, data) {
+            state.addManagerModalVisible = data
         },
-        set_addUserParams: function(state, data) {
-            state.addUserParams = {
-                ...state.addUserParams,
+        set_addManagerParams: function(state, data) {
+            state.addManagerParams = {
+                ...state.addManagerParams,
                 ...data,
             }
         }
     },
     actions: {
-        getUserList: async({ commit }) => {
-            const res = await getUserListAPI()
+        getManagerList: async({ commit }) => {
+            const res = await getManagerListAPI()
             if(res){
-                commit('set_userList', res.data)
+                commit('set_managerList', res)
             }
         },
-        addUser: async({ state, commit, dispatch }) => {
-            const res = await addUserAPI(state.addUserParams)
+        addManager: async({ state, commit, dispatch }) => {
+            const res = await addManagerAPI(state.addManagerParams)
             if(res) {
-                dispatch('getUserList')
+                commit('set_addManagerParams',{
+                    email:'',
+                    password:''
+                })
+                commit('set_addManagerModalVisible', false)
+                message.success('添加成功')
+                dispatch('getManagerList')
+            }else{
+                message.error('添加失败')
             }
         }
     }

+ 3 - 3
front_end/src/store/modules/hotel.js

@@ -7,9 +7,9 @@ import {
 
 const hotel = {
     state: {
-        hotelList: {
-
-        },
+        hotelList: [
+            
+        ],
         hotelListParams: {
             pageNo: 0,
             pageSize: 12

+ 47 - 7
front_end/src/store/modules/hotelManager.js

@@ -3,17 +3,30 @@ import {
     addRoomAPI,
     addHotelAPI,
 } from '@/api/hotelManager'
+import { message } from 'ant-design-vue'
 const hotelManager = {
     state: {
         orderList: [],
         addHotelParams: {
-
+            name: '',
+            address: '',
+            bizRegion:'XiDan',
+            hotelStar:'',
+            rate: 0,
+            description:'',
+            phoneNum:'',
+            managerId:'',
         },
         addHotelModalVisible: false,
         addRoomParams: {
-
+            roomType: '',
+            hotelId: '',
+            price: '',
+            total: 0,
+            curNum: 0,
         },
-        addRoomModalVisible: false
+        addRoomModalVisible: false,
+        activeHotelId: 0,
     },
     mutations: {
         set_orderList: function(state, data) {
@@ -36,6 +49,9 @@ const hotelManager = {
                 ...state.addRoomParams,
                 ...data,
             }
+        },
+        set_activeHotelId: function(state, data) {
+            state.activeHotelId = data
         }
     },
     actions: {
@@ -45,16 +61,40 @@ const hotelManager = {
                 commit('set_orderList', res.data)
             }
         },
-        addHotel: async({ state, dispatch }) => {
+        addHotel: async({ state, dispatch, commit }) => {
             const res = await addHotelAPI(state.addHotelParams)
             if(res){
-                dispatch('getAllOrders')
+                dispatch('getHotelList')
+                commit('set_addHotelParams', {
+                    name: '',
+                    address: '',
+                    bizRegion:'XiDan',
+                    hotelStar:'',
+                    rate: 0,
+                    description:'',
+                    phoneNum:'',
+                    managerId:'',
+                })
+                commit('set_addHotelModalVisible', false)
+                message.success('添加成功')
+            }else{
+                message.error('添加失败')
             }
         },
-        addRoom: async({ state, dispatch }) => {
+        addRoom: async({ state, dispatch, commit }) => {
             const res = await addRoomAPI(state.addRoomParams)
             if(res){
-                dispatch('getAllOrders')
+                commit('set_addRoomModalVisible', false)
+                commit('set_addRoomParams', {
+                    roomType: '',
+                    hotelId: '',
+                    price: '',
+                    total: 0,
+                    curNum: 0,
+                })
+                message.success('添加成功')
+            }else{
+                message.error('添加失败')
             }
         }
     }

+ 29 - 7
front_end/src/store/modules/user.js

@@ -7,16 +7,19 @@ import {
     loginAPI,
     registerAPI,
     getUserInfoAPI,
-    updateUserInfoAPI
+    updateUserInfoAPI,
+    getUserOrdersAPI,
 } from '@/api/user'
 
 const getDefaultState = () => {
     return {
-        token: getToken(),
         userId: '',
         userInfo: {
 
         },
+        userOrderList: [
+
+        ]
     }
 }
 
@@ -29,7 +32,8 @@ const user = {
             state.userId = '',
             state.userInfo = {
                 
-            }
+            },
+            state.userOrderList = []
         },
         set_token: function(state, token){
             state.token = token
@@ -46,6 +50,9 @@ const user = {
                 ...data
             }
         },
+        set_userOrderList: (state, data) => {
+            state.userOrderList = data
+        }
     },
 
     actions: {
@@ -54,6 +61,7 @@ const user = {
             if(res){
                 setToken(res.id)
                 commit('set_userId', res.id)
+                dispatch('getUserInfo')
                 router.push('/hotel/hotelList')
             }
         },
@@ -71,17 +79,31 @@ const user = {
                   reject('登录已过期,请重新登录')
                 }
                 commit('set_userInfo', data)
-                commit('set_userId', data.userId)
+                commit('set_userId', data.id)
                 resolve(data)
               }).catch(error => {
                 reject(error)
               })
             })
         },
-        updateUserInfo: async({ state, commit }) => {
-            const res = await updateUserInfoAPI()
+        updateUserInfo: async({ state, dispatch }, data) => {
+            const params = {
+                id: state.userId,
+                ...data,
+            }
+            const res = await updateUserInfoAPI(params)
             if(res){
-
+                message.success('修改成功')
+                dispatch('getUserInfo')
+            }
+        },
+        getUserOrders: async({ state, commit }) => {
+            const data = {
+                userId: state.userId
+            }
+            const res = await getUserOrdersAPI(data)
+            if(res){
+                commit('set_userOrderList', res)
             }
         },
         logout: async({ commit }) => {

+ 16 - 8
front_end/src/views/admin/components/addUserModal.vue → front_end/src/views/admin/components/addManagerModal.vue

@@ -1,6 +1,6 @@
 <template>
     <a-modal
-        :visible="addUserModalVisible"
+        :visible="addManagerModalVisible"
         title="添加用户"
         cancelText="取消"
         okText="确定"
@@ -30,7 +30,7 @@
 <script>
 import { mapGetters, mapMutations, mapActions } from 'vuex'
 export default {
-    name: 'addUserModal',
+    name: 'addManagerModal',
     data() {
         return {
             formItemLayout: {
@@ -47,30 +47,38 @@ export default {
     },
     computed: {
         ...mapGetters([
-            'addUserModalVisible'
+            'addManagerModalVisible',
+            'managerList',
         ])
     },
     beforeCreate() {
-        this.form = this.$form.createForm(this, { name: 'addUserModal' });
+        this.form = this.$form.createForm(this, { name: 'addManagerModal' });
     },
     mounted() {
 
     },
     methods: {
         ...mapMutations([
-            'set_addUserModalVisible'
+            'set_addManagerModalVisible',
+            'set_addManagerParams',
         ]),
         ...mapActions([
-
+            'getManagerList',
+            'addManager',
         ]),
         cancel() {
-            this.set_addUserModalVisible(false)
+            this.set_addManagerModalVisible(false)
         },
         handleSubmit(e) {
             e.preventDefault();
             this.form.validateFieldsAndScroll((err, values) => {
                 if (!err) {
-                    console.log('Received values of form: ', values);
+                    const data = {
+                        email: this.form.getFieldValue('email'),
+                        password: this.form.getFieldValue('password')
+                    }
+                    this.set_addManagerParams(data)
+                    this.addManager()
                 }
             });
         },

+ 19 - 16
front_end/src/views/admin/manageUser.vue

@@ -3,11 +3,11 @@
         <a-tabs>
             <a-tab-pane tab="账户管理" key="1">
                 <div style="width: 100%; text-align: right; margin:20px 0">
-                    <a-button type="primary" @click="addUser"><a-icon type="plus" />添加用户</a-button>
+                    <a-button type="primary" @click="addManager"><a-icon type="plus" />添加用户</a-button>
                 </div>
                 <a-table
                     :columns="columns"
-                    :dataSource="data"
+                    :dataSource="managerList"
                     bordered
                 >
                     <span slot="price" slot-scope="text">
@@ -19,16 +19,20 @@
                 </a-table>
             </a-tab-pane>
         </a-tabs>
-        <AddUserModal></AddUserModal>
+        <AddManagerModal></AddManagerModal>
     </div>
 </template>
 <script>
 import { mapGetters, mapMutations, mapActions } from 'vuex'
-import AddUserModal from './components/addUserModal'
+import AddManagerModal from './components/addManagerModal'
 const columns = [
+    {  
+        title: '用户邮箱',
+        dataIndex: 'email',
+    },
     {  
         title: '用户名',
-        dataIndex: 'username',
+        dataIndex: 'userName',
     },
     {
         title: '用户密码',
@@ -39,8 +43,8 @@ const columns = [
         dataIndex: 'phoneNumber',
     },
     {
-        title: '会员等级',
-        dataIndex: 'leve',
+        title: '信用值',
+        dataIndex: 'credit',
     },
     {
       title: '操作',
@@ -60,27 +64,26 @@ export default {
         }
     },
     components: {
-        AddUserModal
+        AddManagerModal
     },
     computed: {
         ...mapGetters([
-            'addUserModalVisible',
-            'userList'
+            'addManagerModalVisible',
+            'managerList'
         ])
     },
     mounted() {
-      
+      this.getManagerList()
     },
     methods: {
         ...mapActions([
-            
+            'getManagerList'
         ]),
         ...mapMutations([
-            'set_addUserModalVisible'
+            'set_addManagerModalVisible'
         ]),
-        addUser(){
-            this.set_addUserModalVisible(true)
-            console.log(this.addUserModalVisible)
+        addManager(){
+            this.set_addManagerModalVisible(true)
         }
     }
 }

+ 16 - 4
front_end/src/views/hotelManager/components/addHotelModal.vue

@@ -43,7 +43,7 @@
                     type="textarea"
                     :rows="4"
                     placeholder="请填写酒店简介"
-                    v-decorator="['email', { rules: [{ required: true, message: '请填写酒店简介' }] }]"
+                    v-decorator="['description', { rules: [{ required: true, message: '请填写酒店简介' }] }]"
                 />
             </a-form-item>
         </a-form>
@@ -52,7 +52,7 @@
 <script>
 import { mapGetters, mapMutations, mapActions } from 'vuex'
 export default {
-    name: 'addUserModal',
+    name: 'addHotelModal',
     data() {
         return {
             formItemLayout: {
@@ -69,6 +69,8 @@ export default {
     },
     computed: {
         ...mapGetters([
+            'userId',
+            'addHotelParams',
             'addHotelModalVisible'
         ])
     },
@@ -80,10 +82,11 @@ export default {
     },
     methods: {
         ...mapMutations([
+            'set_addHotelParams',
             'set_addHotelModalVisible'
         ]),
         ...mapActions([
-
+            'addHotel'
         ]),
         cancel() {
             this.set_addHotelModalVisible(false)
@@ -95,7 +98,16 @@ export default {
             e.preventDefault();
             this.form.validateFieldsAndScroll((err, values) => {
                 if (!err) {
-                    console.log('Received values of form: ', values);
+                    const data = {
+                        name: this.form.getFieldValue('hotelName'),
+                        description: this.form.getFieldValue('description'),
+                        address: this.form.getFieldValue('address'),
+                        phoneNum: this.form.getFieldValue('phoneNumber'),
+                        hotelStar: this.form.getFieldValue('hotelStar'),
+                        managerId: Number(this.userId)
+                    }
+                    this.set_addHotelParams(data)
+                    this.addHotel()
                 }
             });
         },

+ 18 - 8
front_end/src/views/hotelManager/components/addRoomModal.vue

@@ -14,15 +14,15 @@
                     'roomType', 
                     { rules: [{ required: true, message: '请选择房型' }] }]"
                 >
-                  <a-select-option value="大床房">大床房</a-select-option>
-                  <a-select-option value="双床房">双床房</a-select-option>
-                  <a-select-option value="家庭房">家庭房</a-select-option>
+                  <a-select-option value="BigBed">大床房</a-select-option>
+                  <a-select-option value="DoubleBed">双床房</a-select-option>
+                  <a-select-option value="Family">家庭房</a-select-option>
                 </a-select>
             </a-form-item>
             <a-form-item label="房间数量" v-bind="formItemLayout">
                 <a-input
                     placeholder="请填写房间数量"
-                    v-decorator="['address', { rules: [{ required: true, message: '请输入房间数量' }] }]"
+                    v-decorator="['roomNum', { rules: [{ required: true, message: '请输入房间数量' }] }]"
                 />
             </a-form-item>
             <a-form-item label="原始价格" v-bind="formItemLayout">
@@ -54,7 +54,8 @@ export default {
     },
     computed: {
         ...mapGetters([
-            'addRoomModalVisible'
+            'addRoomModalVisible',
+            'activeHotelId'
         ])
     },
     beforeCreate() {
@@ -65,10 +66,11 @@ export default {
     },
     methods: {
         ...mapMutations([
-            'set_addRoomModalVisible'
+            'set_addRoomModalVisible',
+            'set_addRoomParams'
         ]),
         ...mapActions([
-
+            'addRoom'
         ]),
         cancel() {
             this.set_addRoomModalVisible(false)
@@ -77,7 +79,15 @@ export default {
             e.preventDefault();
             this.form.validateFieldsAndScroll((err, values) => {
                 if (!err) {
-                    console.log('Received values of form: ', values);
+                    const data = {
+                        roomType: this.form.getFieldValue('roomType'),
+                        price: Number(this.form.getFieldValue('price')),
+                        total: Number(this.form.getFieldValue('roomNum')),
+                        curNum: Number(this.form.getFieldValue('roomNum')),
+                        hotelId: this.activeHotelId,
+                    }
+                    this.set_addRoomParams(data)
+                    this.addRoom()
                 }
             });
         },

+ 15 - 21
front_end/src/views/hotelManager/manageHotel.vue

@@ -7,7 +7,7 @@
                 </div>
                  <a-table
                     :columns="columns1"
-                    :dataSource="data1"
+                    :dataSource="hotelList"
                     bordered
                 >
                     <span slot="action" slot-scope="record">
@@ -27,7 +27,7 @@
             <a-tab-pane tab="订单管理" key="2">
                 <a-table
                     :columns="columns2"
-                    :dataSource="data2"
+                    :dataSource="orderList"
                     bordered
                 >
                     <span slot="status" slot-scope="status">
@@ -71,7 +71,7 @@ const columns1 = [
     },
     {
         title: '商圈',
-        dataIndex: 'BizRegion',
+        dataIndex: 'bizRegion',
     },
     {
         title: '地址',
@@ -83,7 +83,7 @@ const columns1 = [
     },
     {
         title: '评分',
-        dataIndex: 'hotelRate',
+        dataIndex: 'rate',
     },
     {
         title: '简介',
@@ -135,17 +135,6 @@ const columns2 = [
       scopedSlots: { customRender: 'action' },
     },
   ];
-  const data1 = [
-      {
-          key: '1',
-          name: '如家酒店(珠江路地铁站店)',
-          BizRegion:'鼓楼',
-          address: '鼓楼区珠江路888号',
-          hotelRate: '4.8',
-          hotelStar: 'Four',
-          description: '酒店描述信息',
-      }
-  ];
   const data2 = [
     {
       key: '1',
@@ -178,7 +167,6 @@ export default {
             pagination: {},
             columns1,
             columns2,
-            data1,
             data2,
             form: this.$form.createForm(this, { name: 'manageHotel' }),
         }
@@ -190,25 +178,31 @@ export default {
     computed: {
         ...mapGetters([
             'orderList',
+            'hotelList',
             'addHotelModalVisible',
-            'addRoomModalVisible'
+            'addRoomModalVisible',
+            'activeHotelId',
         ])
     },
-    mounted() {
-
+    async mounted() {
+        await this.getHotelList()
+        await this.getAllOrders()
     },
     methods: {
         ...mapMutations([
             'set_addHotelModalVisible',
-            'set_addRoomModalVisible'
+            'set_addRoomModalVisible',
+            'set_activeHotelId',
         ]),
         ...mapActions([
-            'updateUserInfoById',
+            'getHotelList',
+            'getAllOrders'
         ]),
         addHotel() {
             this.set_addHotelModalVisible(true)
         },
         addRoom(record) {
+            this.set_activeHotelId(record.id)
             this.set_addRoomModalVisible(true)
         },
         deleteHotel(){

+ 9 - 5
front_end/src/views/user/info.vue

@@ -51,7 +51,7 @@
             <a-tab-pane tab="我的订单" key="2">
                 <a-table
                     :columns="columns"
-                    :dataSource="data"
+                    :dataSource="userOrderList"
                     bordered
                 >
                     <span slot="price" slot-scope="text">
@@ -116,16 +116,20 @@ export default {
     },
     computed: {
         ...mapGetters([
+            'userId',
             'userInfo',
+            'userOrderList'
         ])
     },
-    mounted() {
-        this.getUserInfo()
+    async mounted() {
+        await this.getUserInfo()
+        await this.getUserOrders()
     },
     methods: {
         ...mapActions([
             'getUserInfo',
-            'updateUserInfoById',
+            'getUserOrders',
+            'updateUserInfo',
         ]),
         saveModify() {
             this.form.validateFields((err, values) => {
@@ -135,7 +139,7 @@ export default {
                         phoneNumber: this.form.getFieldValue('phoneNumber'),
                         password: this.form.getFieldValue('password')
                     }
-                    this.updateUserInfoById(data).then(()=>{
+                    this.updateUserInfo(data).then(()=>{
                         this.modify = false
                     })
                 }