fix(owner-vue): owner vue item 등록 수정 픽스
- owner vue item 등록 수정 픽스
This commit is contained in:
@@ -64,7 +64,7 @@ export default {
|
|||||||
addItemOption : function () {
|
addItemOption : function () {
|
||||||
if(!this.data) return;
|
if(!this.data) return;
|
||||||
|
|
||||||
this.dialog = false
|
this.dialog = !this.dialog
|
||||||
this.$emit('addItemOption',this.data,this.optionType)
|
this.$emit('addItemOption',this.data,this.optionType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
md="12"
|
md="12"
|
||||||
>
|
>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
|
type="number"
|
||||||
v-model="modalData.itemPrice"
|
v-model="modalData.itemPrice"
|
||||||
:rules="[() => !!modalData.itemPrice || 'This field is required']"
|
:rules="[() => !!modalData.itemPrice || 'This field is required']"
|
||||||
label="가격*"
|
label="가격*"
|
||||||
@@ -65,7 +66,7 @@
|
|||||||
>
|
>
|
||||||
<v-select
|
<v-select
|
||||||
v-model="modalData.requiredOption"
|
v-model="modalData.requiredOption"
|
||||||
:items="modalData.requiredOption"
|
:items="modalData.requiredOptionItems"
|
||||||
item-text="name"
|
item-text="name"
|
||||||
item-value="id"
|
item-value="id"
|
||||||
label="필수 옵션*"
|
label="필수 옵션*"
|
||||||
@@ -87,7 +88,7 @@
|
|||||||
>
|
>
|
||||||
<v-select
|
<v-select
|
||||||
v-model="modalData.otherOption"
|
v-model="modalData.otherOption"
|
||||||
:items="modalData.otherOption"
|
:items="modalData.otherOptionItems"
|
||||||
item-text="name"
|
item-text="name"
|
||||||
item-value="id"
|
item-value="id"
|
||||||
label="기타 옵션"
|
label="기타 옵션"
|
||||||
|
|||||||
@@ -162,7 +162,9 @@ export default {
|
|||||||
categoryId: 0,
|
categoryId: 0,
|
||||||
categoryList : [],
|
categoryList : [],
|
||||||
requiredOption : [],
|
requiredOption : [],
|
||||||
otherOption : []
|
requiredOptionItems : [],
|
||||||
|
otherOption : [],
|
||||||
|
otherOptionItems : []
|
||||||
}
|
}
|
||||||
|
|
||||||
store.getCategoryList()
|
store.getCategoryList()
|
||||||
@@ -184,10 +186,14 @@ export default {
|
|||||||
vm.modalData.itemPrice = item.price;
|
vm.modalData.itemPrice = item.price;
|
||||||
vm.modalData.categoryId = item.categoryId;
|
vm.modalData.categoryId = item.categoryId;
|
||||||
item.itemOptions.forEach(function(ele){
|
item.itemOptions.forEach(function(ele){
|
||||||
if(ele.optionType === "REQUIRED")
|
if(ele.optionType === "REQUIRED"){
|
||||||
vm.modalData.requiredOption.push(ele)
|
vm.modalData.requiredOption.push(ele)
|
||||||
else
|
vm.modalData.requiredOptionItems.push(ele)
|
||||||
|
}
|
||||||
|
else{
|
||||||
vm.modalData.otherOption.push(ele)
|
vm.modalData.otherOption.push(ele)
|
||||||
|
vm.modalData.otherOptionItems.push(ele)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -198,17 +204,46 @@ export default {
|
|||||||
method='put'
|
method='put'
|
||||||
else
|
else
|
||||||
method='post'
|
method='post'
|
||||||
store.saveItem(method,itemData);
|
|
||||||
|
|
||||||
|
var requiredOption = []
|
||||||
|
for (const ele of this.modalData.requiredOption) {
|
||||||
|
if(isNaN(ele)) {
|
||||||
|
requiredOption.push(ele)
|
||||||
|
}else{
|
||||||
|
const option = this.modalData.requiredOptionItems.find(value => value.id == ele)
|
||||||
|
requiredOption.push(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var otherOption = []
|
||||||
|
for (const ele of this.modalData.otherOption) {
|
||||||
|
if(isNaN(ele)) {
|
||||||
|
otherOption.push(ele)
|
||||||
|
}else{
|
||||||
|
const option = this.modalData.otherOptionItems.find(value => value.id == ele)
|
||||||
|
otherOption.push(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.modalData.requiredOption = requiredOption
|
||||||
|
this.modalData.otherOption = otherOption
|
||||||
|
store.saveItem(method,itemData)
|
||||||
},
|
},
|
||||||
addItemOption:function (itemOptionValue,type){
|
addItemOption:function (itemOptionValue,type){
|
||||||
var item = {
|
var item = {
|
||||||
name:itemOptionValue,
|
name:itemOptionValue,
|
||||||
optionType:type
|
optionType:type
|
||||||
}
|
}
|
||||||
if(type ==='REQUIRED')
|
if(type ==='REQUIRED'){
|
||||||
this.modalData.requiredOption.push(item)
|
this.modalData.requiredOption.push(item)
|
||||||
else
|
this.modalData.requiredOptionItems.push(item)
|
||||||
|
}
|
||||||
|
else{
|
||||||
this.modalData.otherOption.push(item)
|
this.modalData.otherOption.push(item)
|
||||||
|
this.modalData.otherOptionItems.push(item)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ItemRepositoryCustom {
|
|||||||
|
|
||||||
public Optional<Item> fetchItem(Long itemId){
|
public Optional<Item> fetchItem(Long itemId){
|
||||||
Item fetchItem = queryFactory.selectFrom(item)
|
Item fetchItem = queryFactory.selectFrom(item)
|
||||||
.join(item.itemOptions, itemOption).fetchJoin()
|
.leftJoin(item.itemOptions, itemOption).fetchJoin()
|
||||||
.join(item.category,category).fetchJoin()
|
.join(item.category,category).fetchJoin()
|
||||||
.where(item.id.eq(itemId))
|
.where(item.id.eq(itemId))
|
||||||
.fetchOne();
|
.fetchOne();
|
||||||
|
|||||||
@@ -89,10 +89,23 @@ public class ItemServiceImpl implements ItemService {
|
|||||||
|
|
||||||
item.setItemNameAndPriceAndCategory(itemName,itemPrice,category);
|
item.setItemNameAndPriceAndCategory(itemName,itemPrice,category);
|
||||||
|
|
||||||
|
|
||||||
|
//item에 해당하는 itemoption 전부조회
|
||||||
|
List<ItemOption> byItem = itemOptionRepository.findByItem(item);
|
||||||
|
|
||||||
|
//itemOptionDtos 없는 itemOption 전부 삭제
|
||||||
|
byItem.forEach(itemOption -> {
|
||||||
|
boolean isDeleted = true;
|
||||||
|
for ( ItemOptionDto itemOptionDto: itemOptionDtos) {
|
||||||
|
if(itemOption.getId().equals(itemOptionDto.getId())) isDeleted = false;
|
||||||
|
}
|
||||||
|
if(isDeleted) itemOptionRepository.delete(itemOption);
|
||||||
|
});
|
||||||
|
|
||||||
|
//id가 없으면 저장
|
||||||
itemOptionDtos
|
itemOptionDtos
|
||||||
.forEach(itemOptionDto -> {
|
.forEach(itemOptionDto -> {
|
||||||
if(itemOptionDto.getId()!=null) return;
|
if(itemOptionDto.getId()==null)
|
||||||
if (itemOptionRepository.existsById(itemOptionDto.getId()))
|
|
||||||
itemOptionRepository.save(ItemOptionDto.createItemOption(itemOptionDto, item));
|
itemOptionRepository.save(ItemOptionDto.createItemOption(itemOptionDto, item));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user