meraproject/lib/js/bws/react/form/ShopItemPropValues.min.js
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

3 lines
8.1 KiB
JavaScript

var ShopItemPropValues,ShopItemPropValuesPrice,ePropertyType,eShopItemPriceType;ePropertyType=function(){class e{}return e.TEXT=1,e.NUMBER=2,e.VALUES_ONE=3,e.VALUES_MANY=4,e}.call(this),eShopItemPriceType=function(){class e{}return e.PRICE=1,e.COMPONENT=2,e.COMPONENT_LIST=3,e.GROWTH=4,e}.call(this);export default window.ShopItemPropValues=ShopItemPropValues=class extends React.Component{constructor(e){var t,a,i,l,s;super(e),s=null,(t=null!=(a=e.data)?a:[]).length>0&&(s=t[0]),null==e.value&&(e.value={}),this.state={data:t,value:null!=(i=e.value.vals)?i:{},price_type:null!=(l=e.value.price_type)?l:1,selected:s},this.onSelect=this.onSelect.bind(this),this.enterTextValue=this.enterTextValue.bind(this),this.onChangeMany=this.onChangeMany.bind(this),this.onChangeManyDefault=this.onChangeManyDefault.bind(this),this.onChangeOne=this.onChangeOne.bind(this),this.input=null,this.properties={},this.defaults={},this.prices={}}getValue(){var e,t,a,i;for(t in({value:i}=this.state),i)for(e in i[t])a=i[t][e],i[t][e].is_default=i[t][e].is_default?1:0,void 0!==this.prices[t]&&void 0!==this.prices[t][a.value]&&null!=this.prices[t][a.value]&&(i[t][e].price=this.prices[t][a.value].getValue());return i}onSelect(e){return this.setState({selected:e})}onChangeManyDefault(e,t,a){var i,l,s;for(i in({value:s}=this.state),s[e])l=s[e][i],s[e][i].is_default=!1,l.value===t.id&&(s[e][i].is_default=a);for(i in this.defaults[e])null!=this.defaults[e][i]&&void 0!==this.defaults[e][i]&&(this.defaults[e][i].setValueSilence(!1),i===t.id&&this.defaults[e][i].setValueSilence(a));return this.setState({value:s})}onChangeMany(e,t,a){var i,l;if(({value:l}=this.state),void 0===l[e]&&(l[e]=[]),a)l[e].push({value:t.id,title:t.title});else for(i in l[e])if(l[e][i].value===t.id){l[e].splice(i,1);break}return this.setState({value:l})}onChangeOne(e,t,a){var i,l;if(({value:l}=this.state),void 0===l[e]&&(l[e]=[]),a)for(i in l[e]=[{value:t.id,title:t.title}],this.properties[e])this.properties[e][i].setValueSilence(i===t.id);else for(i in l[e]=[],this.properties[e])this.properties[e][i].setValueSilence(!1);return this.setState({value:l})}enterTextValue(){var e,t,a;return({selected:e,value:a}=this.state),t=this.input.value,a[parseInt(e.id)]=""===t?[]:[{title:t,value:t}],this.setState({value:a})}render(){var e,t,a,i,l,s,c,n,r,p,u,o,d,h,m,v,f,y,E,R,_,N,S,g,T,P,b,V,C,I,O,M,w,k,x=this;for(({data:t,value:M,selected:V}=this.state),C=this,w=[],c=0,u=t.length;c<u;c++)if(M[(R=t[c]).id]){for(O=[],n=0,o=(_=M[R.id]).length;n<o;n++)I=_[n],O.push(React.createElement("div",{className:"sub_color"},I.title));O.length>0&&w.push(React.createElement("div",null,React.createElement("div",{className:"h2 "+(w.length>0?"mt-20":"")},R.title),O))}if(k=[],null!==V)switch(parseInt(V.type)){case ePropertyType.TEXT:case ePropertyType.NUMBER:a="",void 0!==M[V.id]&&(a=null!=(N=null!=(S=M[V.id][0])?S.title:void 0)?N:""),k.push(React.createElement("div",{class:"input_wrap",key:"prop"+V.id},React.createElement("div",{class:"label"},"Значение"),React.createElement("input",{placeholder:"Введите значение",defaultValue:a,className:"i",onKeyUp:this.enterTextValue,ref:function(e){return x.input=e}})));break;case ePropertyType.TEXT:case ePropertyType.VALUES_MANY:if(e={},void 0!==M[V.id])for(p=0,d=(g=M[V.id]).length;p<d;p++)i=g[p],e[i.value]=!0;for(this.properties[V.id]={},this.defaults[V.id]={},k.push(React.createElement("div",{class:"label",key:"prop"+V.id},"Можно выбрать несколько значений")),f=0,h=(T=V.values).length;f<h;f++)i=T[f],l=!0===e[i.id],s=V.is_price&&l,r="prop"+V.id+"value"+i.id,void 0===C.prices[V.id]&&(C.prices[V.id]={}),k.push(React.createElement("div",{key:r,className:k.length>0?"mt-20":""},React.createElement("div",{class:s?"row2":""},React.createElement("div",{class:s?"c c-50":""},React.createElement(SwitchIOS,{label:i.title,checked:l,onChange:this.onChangeMany.bind(null,V.id,i)})),s?React.createElement("div",{className:"c c-50"},function(e,t){var a,i;if(a=!1,void 0!==C.state.value[e.id])for(i in C.state.value[e.id])if((I=C.state.value[e.id][i]).value===t.id){a=I.is_default,console.log("is_def",I);break}return React.createElement(SwitchIOS,{label:"По умолчанию",ref:function(a){return C.defaults[e.id][t.id]=a},checked:a,onChange:C.onChangeManyDefault.bind(null,e.id,t)})}(V,i)):null),V.is_price?function(e,t,a,i){var l,s;if(l={},void 0!==C.state.value[a.id])for(s in C.state.value[a.id])if((I=C.state.value[a.id][s]).value===i.id){l=I.price;break}return React.createElement(ShopItemPropValuesPrice,{visible:e,type:t,price:l,ref:function(e){return C.prices[a.id][i.id]=e}})}(l,this.state.price_type,V,i):null));break;case ePropertyType.TEXT:case ePropertyType.VALUES_ONE:if(e={},void 0!==M[V.id])for(y=0,m=(P=M[V.id]).length;y<m;y++)i=P[y],e[i.value]=!0;for(this.properties[V.id]={},k.push(React.createElement("div",{class:"label",key:"prop"+V.id},"Можно выбрать только одно значение")),E=0,v=(b=V.values).length;E<v;E++)!function(t,a){k.push(React.createElement("div",{key:"prop"+a.id+"value"+t.id,className:k.length>0?"mt-20":""},React.createElement(SwitchIOS,{label:t.title,checked:!0===e[t.id],ref:function(e){return C.properties[a.id][t.id]=e},onChange:C.onChangeOne.bind(null,a.id,t)})))}(i=b[E],V)}return React.createElement("div",{className:"mt-20"},React.createElement("div",{className:"row2"},React.createElement("div",{className:"c c-50"},React.createElement("div",{className:"h1"},"Выберите параметр"),React.createElement(Select,{data:t,onSelect:this.onSelect,search:!0}),React.createElement("div",{className:"mt-20"},k)),React.createElement("div",{className:"c c-50"},React.createElement("div",{className:"h1"},"Выбранные значения"),w)))}};ShopItemPropValuesPrice=class extends React.Component{constructor(e){var t;super(e),t=void 0===e.price?{}:e.price,this.state={type:parseInt(e.type),visible:e.visible,price:null!=t?t:{}},this.types=[{id:1,title:"Значение"},{id:2,title:"Процент"}]}componentWillReceiveProps(e){return this.setState({visible:e.visible})}getValue(){var e,t;return{item_price:null!=this.item_price&&void 0!==this.item_price?this.item_price.value:0,item_type:null!=this.item_type&&void 0!==this.item_type?"function"==typeof(e=this.item_type).getValue?e.getValue():void 0:0,component_price:null!=this.component_price&&void 0!==this.component_price?this.component_price.value:0,component_type:null!=this.component_type&&void 0!==this.component_type?"function"==typeof(t=this.component_type).getValue?t.getValue():void 0:0}}render(){var e,t,a,i,l,s,c,n,r,p,u,o,d,h=this;return({type:o,visible:d,price:c}=this.state),d?(l=null!=(n=c.item_price)?n:0,s=null!=(r=c.item_type)?r:1,e=null!=(p=c.component_price)?p:0,t=null!=(u=c.component_type)?u:1,i=o===eShopItemPriceType.PRICE||o===eShopItemPriceType.COMPONENT||o===eShopItemPriceType.COMPONENT_LIST,a=o===eShopItemPriceType.COMPONENT,React.createElement("div",null,i?React.createElement("div",{className:"row2 mt-10"},React.createElement("div",{className:"c c-60"},React.createElement("div",{className:"input_wrap"},React.createElement("div",{className:"label"},"Цена на товар"),React.createElement("input",{type:"text",placeholder:"100",className:"i c-100",autoComplete:"off",defaultValue:l,ref:function(e){return h.item_price=e}}))),React.createElement("div",{className:"c c-40"},React.createElement("div",{className:"input_wrap"},React.createElement("div",{className:"label"},"Тип"),React.createElement(Select,{data:this.types,id:s,ref:function(e){return h.item_type=e}})))):null,a?React.createElement("div",{className:"row2 mt-10"},React.createElement("div",{className:"c c-60"},React.createElement("div",{className:"input_wrap"},React.createElement("div",{className:"label"},"Цена на компонент"),React.createElement("input",{type:"text",placeholder:"100",className:"i c-100",autoComplete:"off",defaultValue:e,ref:function(e){return h.component_price=e}}))),React.createElement("div",{className:"c c-40"},React.createElement("div",{className:"input_wrap"},React.createElement("div",{className:"label"},"Тип"),React.createElement(Select,{data:this.types,id:t,ref:function(e){return h.component_type=e}})))):null)):null}};
//# sourceMappingURL=ShopItemPropValues.min.js.map