1414 <v-stepper-items class =" elevation-0" >
1515 <v-stepper-content step =" 1" class =" pt-0" >
1616 <v-layout column wrap >
17- <v-flex v-for =" payload in payloads " :key =" payload .id" class =" my-2" >
17+ <v-flex v-for =" searchbar in searchbars " :key =" searchbar .id" class =" my-2" >
1818 <v-layout column wrap >
1919 <v-flex >
2020 <v-layout row >
2121 <v-flex xs4 class =" ml-2" >
22- <v-select v-model =" payload.classString " :items =" classes" label =" 분류" ></v-select >
22+ <v-select v-model =" searchbar.classification " :items =" classes" label =" 분류" ></v-select >
2323 </v-flex >
2424 <v-flex xs8 class =" ml-5" >
2525 <v-textarea
26- v-model =" payload.searchingProducts "
26+ v-model =" searchbar.keywords "
2727 append-icon =" search"
2828 placeholder =" 명칭 (붕산비료, 생물 비료, 도매업)"
2929 auto-grow
3838 color =" secondary"
3939 flat
4040 slot =" activator"
41- @click =" deleteForm(payload .id)"
41+ @click =" deleteForm(searchbar .id)"
4242 >
4343 <v-icon >delete</v-icon >
4444 </v-btn >
@@ -105,16 +105,15 @@ export default {
105105 },
106106 data () {
107107 return {
108- payloads : [
108+ searchbars : [
109109 {
110110 id: 1 ,
111- classString: " " ,
112- _class: - 1 ,
113- searchingProducts: " "
111+ classification: " " ,
112+ keywords: " "
114113 }
115114 ],
116115 curStep: 0 ,
117- formCount : 1 ,
116+ searchbarId : 1 ,
118117 searchLoading: false
119118 };
120119 },
@@ -124,27 +123,59 @@ export default {
124123 }
125124 },
126125 methods: {
126+ isNoticed (keyword , checklist ) {
127+ return (
128+ Object .keys (checklist).length > 0 &&
129+ checklist .hasOwnProperty (this .trim (keyword))
130+ );
131+ },
132+ trim (keyword ) {
133+ return keyword .replace (/ \s / g , " " );
134+ },
127135 classifyProducts () {
128136 this .searchLoading = true ;
129- for (let i = 0 ; i < this .payloads .length ; i++ ) {
130- this .payloads [i]._class = this .classes .indexOf (
131- this .payloads [i].classString
132- );
133- }
134137 const requests = [];
135- for (let i = 0 ; i < this .payloads .length ; i++ ) {
138+ for (const searchbar of this .searchbars ) {
139+ const classification = this .classes .indexOf (searchbar .classification );
136140 requests .push (
137- this .$searchManager .search (this .payloads [i]).then (response => {
138- return response;
141+ this .$searchManager .search (0 , searchbar .keywords ).then (response => {
142+ const checklist = response .reduce ((acc , val ) => {
143+ acc[this .trim (val[" 지정상품(국문)" ])] = val;
144+ return acc;
145+ }, {});
146+
147+ const keywords = this .$searchManager .trimKeywords (
148+ searchbar .keywords
149+ );
150+
151+ const noticed = keywords
152+ .filter (keyword => this .isNoticed (keyword, checklist))
153+ .map (keyword => checklist[this .trim (keyword)]);
154+
155+ const unnoticed = keywords
156+ .filter (keyword => ! this .isNoticed (keyword, checklist))
157+ .map (keyword => {
158+ return {
159+ id: Math .random (),
160+ NICE 분류: classification,
161+ " 지정상품(국문)" : keyword,
162+ " 지정상품(영문)" : " " ,
163+ 유사군코드: " " ,
164+ 고시명칭: false
165+ };
166+ });
167+
168+ return { noticed: [... new Set (noticed)], unnoticed: unnoticed };
139169 })
140170 );
141171 }
172+
142173 let productAdderPointer = this ;
143174 Promise .all (requests).then (responses => {
144175 let result = { noticed: [], unnoticed: [] };
145- for (let i = 0 ; i < responses . length ; i ++ ) {
146- result .noticed = result .noticed .concat (responses[i] .noticed );
147- result .unnoticed = result .unnoticed .concat (responses[i] .unnoticed );
176+ for (const response of responses) {
177+ result .noticed = result .noticed .concat (response .noticed );
178+ result .unnoticed = result .unnoticed .concat (response .unnoticed );
148179 }
149180 productAdderPointer .$productTransmissionBus .$emit (
150181 " transmitClassified" ,
@@ -155,24 +186,24 @@ export default {
155186 });
156187 },
157188 addProducts () {
158- this .$submissionAlarmBus .$emit (' submitProductsToBriefcase' );
189+ this .$submissionAlarmBus .$emit (" submitProductsToBriefcase" );
159190 },
160191 addForm () {
161- this .payloads .push ({
162- id: ++ this .formCount ,
163- _class : - 1 ,
164- searchingProducts : " "
192+ this .searchbars .push ({
193+ id: ++ this .searchbarId ,
194+ classificationEdited : - 1 ,
195+ keywords : " "
165196 });
166197 },
167- deleteForm (payloadId ) {
168- const deletedIndex = this .payloads .findIndex (
169- payload => payload [" id" ] == payloadId
198+ deleteForm (searchbarId ) {
199+ const deletedIndex = this .searchbars .findIndex (
200+ searchbar => searchbar [" id" ] == searchbarId
170201 );
171- this .payloads .splice (deletedIndex, 1 );
202+ this .searchbars .splice (deletedIndex, 1 );
172203 }
173204 },
174205 mounted () {
175- this .$submissionAlarmBus .$on (' submissionComplete' , () => {
206+ this .$submissionAlarmBus .$on (" submissionComplete" , () => {
176207 this .curStep = 3 ;
177208 });
178209 },
0 commit comments