xinyb
2024-07-18 80430d52f7716e3eb3e517dc96f94c4a6f9657bf
提交 | 用户 | age
a6a76f 1 package com.yc.sdk.shopping.service;
F 2
3 import java.text.SimpleDateFormat;
4 import java.util.Calendar;
5 import java.util.Date;
6 import java.util.List;
7
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.context.annotation.Scope;
10 import org.springframework.stereotype.Service;
11
12 import com.yc.sdk.shopping.entity.MatCodeEntity;
13 import com.yc.sdk.shopping.entity.MatOptionEntity;
14 import com.yc.sdk.shopping.util.SettingKey;
15 import com.yc.service.BaseService;
16
17 @Service("MatComponentImpl")
18 @Scope("prototype")
19 public class MatComponentImpl  extends BaseService implements MatComponentIfc {
20     @Autowired
21     MatOptionIfc matOptionIfc;
22     
23     @Override
24     public String getMatComponent(MatCodeEntity matCodeEntity,String matCode,String currency,boolean isMoblieBrowser,boolean isShowBuyButton) {
25         String ret = "" ;
26         List<MatOptionEntity> list = matOptionIfc.getMatOption(matCode);
27         ret +="        <div id=\"product\"><hr>";
28         ret +="                <h3>选项及配件</h3>";
29         
30         Integer lastOptionId = null;
31         for(int i = 0;list != null && i <list.size();i++) {
32             if(lastOptionId == null  || ! lastOptionId.equals(list.get(i).getOptionId())) {
33                 if (list.get(i).getType().equalsIgnoreCase("radio")) { 
34                     ret += getRadio(list,list.get(i).getOptionId(),currency,list.get(i).getOptionName()) ;
35                 }
36                 
37                 if (list.get(i).getType().equalsIgnoreCase("text")) { 
38                     ret += getText(list,list.get(i).getOptionId()) ;
39                 }
40                 
41                 if (list.get(i).getType().equalsIgnoreCase("textarea")) { 
42                     ret += getTextArea(list,list.get(i).getOptionId()) ;
43                 }
44
45                 if (list.get(i).getType().equalsIgnoreCase("checkbox")) { 
46                     ret += getCheckbox(list,list.get(i).getOptionId(),currency,list.get(i).getOptionName()) ;
47                 }                
48                 
49                 if (list.get(i).getType().equalsIgnoreCase("select")) { 
50                     ret += getSelect(list,list.get(i).getOptionId(),currency,list.get(i).getOptionName()) ;
51                 }
52                 
53                 if (list.get(i).getType().equalsIgnoreCase("date")) { 
54                     ret += getDate(list,list.get(i).getOptionId()) ;
55                 }
56                 
57                 
58                 if (list.get(i).getType().equalsIgnoreCase("time")) { 
59                     ret += getTime(list,list.get(i).getOptionId()) ;
60                 }    
61                 
62                 if (list.get(i).getType().equalsIgnoreCase("datetime")) { 
63                     ret += getDateTime(list,list.get(i).getOptionId()) ;
64                 }    
65                 
66                 if (list.get(i).getType().equalsIgnoreCase("file")) { 
67                     ret += getFile(list,list.get(i).getOptionId()) ;
68                 }                
69                 if (list.get(i).getType().equalsIgnoreCase("image")) { 
70                     ret += getImage(list,list.get(i).getOptionId()) ;
71                 }                
72
73
74             }
75         
76             lastOptionId = list.get(i).getOptionId();
77         }
78                 
79         ret +="                <div class=\"form-group required\">\n";
80         ret +="                  <label class=\"control-label\" for=\"input-quantity\">数量</label>\n";
81         if ( isMoblieBrowser) {
82             ret +="                  <div class=\"car-item-count\">";
83             ret +="                  <a onclick=\"javascript:void(0)\" class=\"a-red\">";
84             ret +="                      <span></span>";
85             ret +="                  </a>";
86             ret +="                  <input id=\"input-quantity\" type=\"text\" name=\"quantity\" value=\""+ (matCodeEntity.getMininum().intValue() == 0 ? 1 : matCodeEntity.getMininum().intValue() ) +"\" size=\"1\" class=\"form-control car-item-count-inp\">";
87             ret +="                  <a onclick=\"javascript:void(0)\" class=\"a-add\">";
88             ret +="                      <span></span>";
89             ret +="                  </a>";
90             ret +="                  </div>";
91         }else {
92             
93             ret +="                  <input type=\"text\" name=\"quantity\" value=\""+ (matCodeEntity.getMininum().intValue() == 0 ? 1 : matCodeEntity.getMininum().intValue() ) +"\" size=\"2\" id=\"input-quantity\" class=\"form-control\" />\n";
94         }
95         ret +="                  <input type=\"hidden\" name=\""+SettingKey.MATCODE+ "\" value=\""+matCode+"\" />\n";
96         ret +="                  <br />\n";
97         if (isShowBuyButton) {   //移动版(微信)启用新版时,把它隐藏起来
98             ret +="                  <button type=\"button\" id=\"button-cart\" data-loading-text=\"正在加载...\" class=\"btn btn-primary btn-lg btn-block\">加入购物车</button>\n";
99         }
100         ret +="                </div>\n";
101         if (matCodeEntity.getMininum().intValue() > 1) {
102             ret +="                <div class=\"alert alert-info\"><i class=\"fa fa-info-circle\"></i> 本商品的最小起订量为"+  matCodeEntity.getMininum().intValue()  +"</div>\n";
103         }
104         ret +="                </div>\n";
105         
106         return ret ;
107     }
108     
109     private String getRadio(List<MatOptionEntity> list,Integer optionId,String currency,String name) {
110         String ret = "" ;
111         ret +="                <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
112         ret +="                  <label class=\"control-label\">"+name+"</label>\n";
113         ret +="                  <div id=\"input-option"+ optionId+"\">\n";
114         for (int k = 0 ;list != null && k < list.size() ;k++) {
115             if (list.get(k).getOptionId().equals(optionId)) {
116             ret +="                    <div class=\"radio\">\n";
117             ret +="                      <label>\n";
118             ret +="                        <input type=\"radio\" name=\"option["+optionId+"]\" value=\""+list.get(k).getValue() +"\" />\n";
119             ret +="                        "+list.get(k).getValue()+"("+ (list.get(k).getPricePrefix()!=null&&"1".equals(list.get(k).getPricePrefix())?"+":"-") +(currency==null?"":currency)+list.get(k).getPrice()+")";
120             ret +="                      </label>\n";
121             ret +="                    </div>\n";
122             }
123         }
124         ret +="           </div>\n";
125         ret +="        </div>\n";
126         return ret;
127         
128     }
129     
130     private String getText(List<MatOptionEntity> list,Integer optionId) {
131         String ret = "" ;
132         for (int k = 0 ;list != null && k < list.size() ;k++) {
133             if (list.get(k).getOptionId().equals(optionId)) {
134             ret +="        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
135             ret +="           <label class=\"control-label\" for=\"input-option"+optionId+"\">"+list.get(k).getOptionName()+"</label>\n";
136             ret +="           <input type=\"text\" name=\"option["+optionId+"]\" value=\"\" placeholder=\"Text\" id=\"input-option"+optionId+"\" class=\"form-control\" />\n";
137             ret +="        </div>\n";
138             }
139         }
140         return ret;
141         
142     }
143     
144     private String getTextArea(List<MatOptionEntity> list,Integer optionId) {
145         String ret = "" ;
146         for (int k = 0 ;list != null && k < list.size() ;k++) {
147             if (list.get(k).getOptionId().equals(optionId)) {
148             ret +="    <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
149             
150             ret +="       <label class=\"control-label\" for=\"input-option"+optionId+"\">"+list.get(k).getOptionName()+"</label>\n";
151             ret +="       <textarea name=\"option["+optionId+"]\" rows=\"5\" placeholder=\"Textarea\" id=\"input-option"+optionId+"\" class=\"form-control\"></textarea>\n";
152             ret +="    </div>\n";
153             }
154         }
155         return ret;
156     }
157     private String getCheckbox(List<MatOptionEntity> list,Integer optionId,String currency,String name) {
158         String ret = "" ;
159         ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
160         ret += "        <label class=\"control-label\">"+name+"</label>\n";
161         ret += "        <div id=\"input-option"+optionId+"\">\n";
162         for (int k = 0 ;list != null && k < list.size() ;k++) {
163             if (list.get(k).getOptionId().equals(optionId)) {
164             ret += "          <div class=\"checkbox\">\n";
165             ret += "            <label>\n";
166             ret += "              <input type=\"checkbox\" name=\"option["+optionId+"]\" value=\""+list.get(k).getValue()+"\" />\n";
167             ret += "              "+list.get(k).getValue()+"("+ (list.get(k).getPricePrefix()!=null&&"1".equals(list.get(k).getPricePrefix())?"+":"-") +(currency==null?"":currency)+list.get(k).getPrice()+")";
168             ret += "            </label>\n";
169             ret += "          </div>\n";
170             }
171         }
172         ret += "         </div>\n";
173         ret += "         </div>\n";
174         return ret;
175         
176     }
177     private String getSelect(List<MatOptionEntity> list,Integer optionId,String currency,String name) {        
178         String ret = "" ;
179         ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
180         ret += "        <label class=\"control-label\" for=\"input-option"+optionId+"\">"+name+"</label>\n";
181         ret += "        <select name=\"option["+optionId+"]\" id=\"input-option"+optionId+"\" class=\"form-control\">\n";
182         ret += "          <option value=\"\"> --- 请选择 --- </option>\n";
183         for (int k = 0 ;list != null && k < list.size() ;k++) {
184             if (list.get(k).getOptionId().equals(optionId)) {
185             ret += "          <option value="+list.get(k).getValue()+">"+list.get(k).getValue()+"("+ (list.get(k).getPricePrefix()!=null&&"1".equals(list.get(k).getPricePrefix())?"+":"-") +(currency==null?"":currency)+list.get(k).getPrice()+")</option>\n";
186             }
187         }
188         ret += "        </select>\n";
189         ret += "        </div>\n";
190       return ret;
191         
192     }
193     
194     private String getDate(List<MatOptionEntity> list,Integer optionId) {
195         Calendar c1 = Calendar.getInstance();
196         c1.setTime(new Date());
197         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
198         
199         String ret = "" ;
200         for (int k = 0 ;list != null && k < list.size() ;k++) {
201             if (list.get(k).getOptionId().equals(optionId)) {
202             ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
203             ret += "        <label class=\"control-label\" for=\"input-option"+optionId+"\">"+list.get(k).getOptionName()+"</label>";
204             ret += "        <div class=\"input-group date\">\n";
205             ret += "          <input type=\"text\" name=\"option["+optionId+"]\" value=\""+ format.format(c1.getTime())+"\" data-date-format=\"YYYY-MM-DD\" id=\"input-option"+optionId+"\" class=\"form-control\" />\n";
206             ret += "          <span class=\"input-group-btn\">\n";
207             ret += "          <button class=\"btn btn-default\" type=\"button\"><i class=\"fa fa-calendar\"></i></button>\n";
208             ret += "          </span></div>\n";
209             ret += "        </div>\n";    
210             }
211         }
212         return ret;
213         
214     }
215     
216     private String getTime(List<MatOptionEntity> list,Integer optionId) {
217         Calendar c1 = Calendar.getInstance();
218         c1.setTime(new Date());        
219         SimpleDateFormat format = new SimpleDateFormat("HH:mm");
220         String ret = "" ;
221         for (int k = 0 ;list != null && k < list.size() ;k++) {
222             if (list.get(k).getOptionId().equals(optionId)) {            
223                 ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
224                 ret += "        <label class=\"control-label\" for=\"input-option"+optionId+"\">"+list.get(k).getOptionName()+"</label>\n";
225                 ret += "        <div class=\"input-group time\">\n";
226                 ret += "          <input type=\"text\" name=\"option["+optionId+"]\" value=\""+ format.format(c1.getTime())+"\" data-date-format=\"HH:mm\" id=\"input-option"+optionId+"\" class=\"form-control\" />\n";
227                 ret += "          <span class=\"input-group-btn\">\n";
228                 ret += "          <button type=\"button\" class=\"btn btn-default\"><i class=\"fa fa-calendar\"></i></button>\n";
229                 ret += "          </span></div>\n";
230                 ret += "       </div>\n";
231             }
232         }
233         return ret;
234         
235     }
236     private String getDateTime(List<MatOptionEntity> list,Integer optionId) {
237         Calendar c1 = Calendar.getInstance();
238         c1.setTime(new Date());        
239         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
240         String ret = "" ;
241         for (int k = 0 ;list != null && k < list.size() ;k++) {
242             if (list.get(k).getOptionId().equals(optionId)) {            
243                 ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
244                 ret += "        <label class=\"control-label\" for=\"input-option"+optionId+"\">Date &amp; Time</label>\n";
245                 ret += "        <div class=\"input-group datetime\">\n";
246                 ret += "          <input type=\"text\" name=\"option["+optionId+"]\" value=\""+ format.format(c1.getTime())+"\" data-date-format=\"YYYY-MM-DD HH:mm\" id=\"input-option"+optionId+"\" class=\"form-control\" />\n";
247                 ret += "          <span class=\"input-group-btn\">\n";
248                 ret += "          <button type=\"button\" class=\"btn btn-default\"><i class=\"fa fa-calendar\"></i></button>\n";
249                 ret += "          </span></div>\n";
250                 ret += "        </div>\n";
251             }
252         }
253         return ret;
254         
255     }
256     private String getFile(List<MatOptionEntity> list,Integer optionId) {
257         String ret = "" ;
258         for (int k = 0 ;list != null && k < list.size() ;k++) {
259             if (list.get(k).getOptionId().equals(optionId)) {
260             ret += "        <div class=\"form-group " + (matOptionIfc.isRequired( list,optionId)  ? " required":"" ) + "\">\n";
261             ret += "        <label class=\"control-label\">"+list.get(k).getOptionName()+"</label>\n";
262             ret += "        <button type=\"button\" id=\"button-upload"+optionId+"\" data-loading-text=\"正在加载...\" class=\"btn btn-default btn-block\"><i class=\"fa fa-upload\"></i> 上传文件</button>\n";
263             ret += "        <input type=\"hidden\" name=\"option["+optionId+"]\" value=\"\" id=\"input-option"+optionId+"\" />\n";
264             ret += "        </div>\n";
265             }
266         }
267         return ret;
268         
269     }
270     private String getImage(List<MatOptionEntity> list,Integer OptionId) {
271         //TODO
272         return "";
273         
274     }
275
276
277 }