feat(owner-vue): 상태변경 로직 추가

This commit is contained in:
bum12ark
2022-03-10 16:45:21 +09:00
parent f12f7bab9d
commit 34f2c42887
3 changed files with 85 additions and 43 deletions

View File

@@ -9,7 +9,7 @@ export default {
page: page page: page
} }
} }
return axios.get( process.env.VUE_APP_ORDER_URL + "/order/prev-order", options); return axios.get( process.env.VUE_APP_API_URL + "/order/prev-order", options);
}, },
requestOrder(orderDate, lastOrderId) { requestOrder(orderDate, lastOrderId) {
const options = { const options = {
@@ -18,6 +18,12 @@ export default {
lastOrderId: lastOrderId lastOrderId: lastOrderId
} }
} }
return axios.get(process.env.VUE_APP_ORDER_URL + "/order/order-main", options); return axios.get(process.env.VUE_APP_API_URL + "/order/order-main", options);
},
patchOrder(orderId, orderStatus) {
const body = {
orderStatus: orderStatus
}
return axios.patch(process.env.VUE_APP_OWNER_SERVICE_BASEURL + "/order-service/order/" + orderId, body);
} }
} }

View File

@@ -9,19 +9,44 @@
<v-card-subtitle></v-card-subtitle> <v-card-subtitle></v-card-subtitle>
<v-card-text>{{ orderTime }}</v-card-text> <v-card-text>{{ orderTime }}</v-card-text>
<v-card-actions> <v-card-actions>
<v-btn v-if="orderStatus === 'PENDING'" <v-row v-if="orderStatus === 'ORDER'">
block depressed color="primary"> <v-col sm="6">
주문 대기 <v-btn
</v-btn> block depressed color="success"
<v-btn v-else-if="orderStatus === 'PLACED'" @click="placed"
block depressed color="primary"> >
주문 수령 주문 수령
</v-btn> </v-btn>
</v-col>
<v-col sm="6">
<v-btn block depressed color="error"
@click="reject"
>
주문 거절
</v-btn>
</v-col>
</v-row>
<v-row v-else-if="orderStatus === 'PLACED'">
<v-col>
<v-btn block depressed color="primary">
수락됨
</v-btn>
</v-col>
</v-row>
<v-row v-else-if="orderStatus === 'REJECT'">
<v-col>
<v-btn block depressed color="blue-grey" class="white--text">
거절됨
</v-btn>
</v-col>
</v-row>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</template> </template>
<script> <script>
import orderApi from "../api/order";
export default { export default {
name: "OrderCard", name: "OrderCard",
data: function() { data: function() {
@@ -30,11 +55,32 @@ export default {
}; };
}, },
props: { props: {
orderId: Number, id: Number,
userName: Number, userName: Number,
itemNames: [], itemNames: [],
orderTime: String, orderTime: String,
orderStatus: String orderStatus: String
},
methods: {
placed: async function() {
try {
await orderApi.patchOrder(this.id, 'PLACED');
this.$emit("placed");
alert("해당 주문이 수락 되었습니다.");
} catch(error) {
console.log(error);
}
},
reject: async function() {
try {
await orderApi.patchOrder(this.id, 'REJECT');
this.$emit("reject");
alert("해당 주문이 거절 되었습니다.");
} catch(error) {
console.log(error);
}
}
} }
} }
</script> </script>

View File

@@ -15,18 +15,20 @@
<v-row> <v-row>
<v-col v-for="card in cards" cols="4" :key="card.orderId"> <v-col v-for="card in cards" cols="4" :key="card.orderId">
<order-card <order-card
:order-id="card.orderId" :id="card.orderId"
:userName="card.userName" :userName="card.userName"
:itemNames="card.itemNames" :itemNames="card.itemNames"
:orderTime="card.orderTime" :orderTime="card.orderTime"
:orderStatus="card.orderStatus" :orderStatus="card.orderStatus"
@placed="card.orderStatus = 'PLACED'"
@reject="card.orderStatus = 'REJECT'"
> >
</order-card> </order-card>
</v-col> </v-col>
</v-row> </v-row>
<br><br><br> <br><br><br>
<v-row justify="center" v-if="showButton"> <v-row justify="center" v-if="hasNext">
<v-btn rounded outlined color="primary" <v-btn rounded outlined color="primary"
@click="more">더보기</v-btn> @click="more">더보기</v-btn>
</v-row> </v-row>
@@ -53,45 +55,38 @@ export default {
date: '', date: '',
cards: [], cards: [],
lastOrderId: null, lastOrderId: null,
showButton: false hasNext: false
} }
}, },
methods: { methods: {
search: function() { search: async function() {
this.cards = []; this.cards = [];
this.lastOrderId = null; this.lastOrderId = null;
OrderApi.requestOrder(this.date, this.lastOrderId)
.then( (response) => { const response = await OrderApi.requestOrder(this.date, this.lastOrderId);
this.renderCard(response.data);
}) this.renderCard(response.data)
.catch( (error) => {
console.log(error);
})
}, },
renderCard: function (json) { renderCard: function (json) {
const orders = json.data; console.log(json);
const orders = json.data.orders;
const size = orders.length; const size = orders.length;
if (size === 0) { this.hasNext = json.data.hasNext;
alert("검색 데이터가 없습니다.");
this.showButton = false;
} else {
this.showButton = true;
}
orders.forEach( (order, index) => { orders.forEach( (order, index) => {
if (index === (size - 1)) { if (index === (size - 1)) {
this.lastOrderId = order.orderId; this.lastOrderId = order.id;
} }
let orderItemNames = [] let orderItemNames = [];
order.orderItemResponses.forEach( (orderItem) => { order.orderItems.forEach( (orderItem) => {
orderItemNames.push(orderItem.itemId); orderItemNames.push(orderItem.itemName);
}) })
this.cards.push({ this.cards.push({
orderId: order.orderId, orderId: order.id,
userName: order.orderId, userName: order.userName,
itemNames: orderItemNames, itemNames: orderItemNames,
orderTime: order.orderTime, orderTime: order.orderTime,
orderStatus: order.orderStatus orderStatus: order.orderStatus
@@ -101,14 +96,9 @@ export default {
inputDate: function(value) { inputDate: function(value) {
this.date = value; this.date = value;
}, },
more: function() { more: async function() {
OrderApi.requestOrder(this.date, this.lastOrderId) const response = await OrderApi.requestOrder(this.date, this.lastOrderId);
.then( (response) => { this.renderCard(response.data);
this.renderCard(response.data);
})
.catch( (error) => {
console.log(error);
})
} }
} }
} }