Files
Rasadyar_FrontEnd/build/assets/CarManagement-6m_o25jQ.js

2 lines
17 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{j as u,a3 as _,ag as S,ak as P,av as q,aw as G,ax as v,aU as U,aa as au,T as D,ah as lu,ai as X,aj as Y,B as N,al as ou,b5 as nu,d as su,aJ as iu,I as cu,b0 as du,an as hu,b4 as K,ap as H,aq as $,b as Cu}from"./mui-vendor-CkIVaoQP.js";import{L as w,j as I,h as j,A as M,u as Z,X as y,b0 as B,N as k,b1 as pu,c as uu,M as E,b2 as J,G as R,S as O,b3 as mu}from"./index-Cr86_nOs.js";import{r as m}from"./react-vendor-CmFgShSM.js";import{a as L,u as V,f as W}from"./redux-vendor-B7uoacJt.js";import{C as yu}from"./CarPelak-Ddy5J5I5.js";import{a as xu}from"./index.esm-Bu7XMDZU.js";import{d as Au}from"./Tune-m0V6JHJm.js";import{d as vu}from"./EditOutlined-C6DCII3T.js";import{d as _u}from"./DeleteOutline-o1xP-ZPX.js";import{R as Q}from"./ResponsiveTable-Dua7tTwQ.js";import"./iconBase-BEJYyZsk.js";import"./FilterAlt-RwhTl5ac.js";import"./styled-components.browser.esm-gS9mh05b.js";const ju=L("PROVINCE_REGISTER_CAR_SERVICE",async(r,{dispatch:l})=>{try{l(w());const{data:t,status:s}=await I.post("kill_house_driver/",r);return l(j()),{data:t,status:s}}catch(t){return l(j()),{error:t.response.data.result}}}),fu=L("PROVINCE_EDIT_CAR_SERVICE",async(r,{dispatch:l})=>{try{l(w());const{data:t,status:s}=await I.put("kill_house_driver/0/",r);return l(j()),{data:t,status:s}}catch(t){return l(j()),{error:t.response.data.result}}}),Fu=uu({driver_mobile:E().required("شماره موبایل راننده الزامی است"),last_name:E().required("نام خانوادگی الزامی است"),first_name:E().required("نام الزامی است"),city_name:E().required("نام شهر الزامی است"),type_car:E().required("نوع خودرو الزامی است"),pelak:E().required("پلاک الزامی است"),capocity:E().required("ظرفیت الزامی است"),health_code:E().required("کد سلامت الزامی است")}),eu=({first_name:r,last_name:l,driver_mobile:t,city_name:s,type_car:h,pelak:x,capocity:i,health_code:A,driverKey:o,type:a})=>{const c=V(),[p]=m.useContext(M),{provinceGetCities:b}=W(n=>n.provinceSlice),e=Z({initialValues:{driver_mobile:t,last_name:l,first_name:r,city_name:s,type_car:h,pelak:"",capocity:i,health_code:A,type:a||"exclusive"},validationSchema:Fu,onSubmit:n=>{d()}}),[f,C]=m.useState([]);m.useEffect(()=>{if(x){const n=x.split(" ");C(n)}},[x]),m.useEffect(()=>{e.setFieldValue("pelak",f.length?f.join(" ").trim():"")},[f]);const d=()=>{const{values:n,errors:T}=e;T!=null&&T.length||(o?c(fu({driver_mobile:n.driver_mobile,last_name:n.last_name,first_name:n.first_name,city_name:n.city_name,type_car:n.type_car,pelak:f.join(" "),capocity:n.capocity,health_code:n.health_code,role:y(),driver_key:o,type:n.type})).then(g=>{g.payload.error?p({vertical:"top",horizontal:"center",msg:g.payload.error,severity:"error"}):(c(B()),c(k({right:!1,bottom:!1,content:null})),p({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}):c(ju({driver_mobile:n.driver_mobile,last_name:n.last_name,first_name:n.first_name,city_name:n.city_name,type_car:n.type_car,pelak:f.join(" "),capocity:n.capocity,health_code:n.health_code,role:y(),type:n.type})).then(g=>{g.payload.error?p({vertical:"top",horizontal:"center",msg:g.payload.error,severity:"error"}):(c(B()),c(k({right:!1,bottom:!1,content:null})),p({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}))},F=(n,T,g,z)=>{C([n,T,g,z])};return m.useEffect(()=>{c(pu()).then(n=>e.setFieldValue("city_name",s))},[]),u.jsx("form",{onSubmit:e.handleSubmit,children:u.jsxs(_,{container:!0,spacing:2,children:[u.jsx(_,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(P,{id:"first_name",name:"first_name",label:"نام",value:e.values.first_name,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.first_name&&!!e.errors.first_name,helperText:e.touched.first_name&&e.errors.first_name})})}),u.jsx(_,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(P,{id:"last_name",name:"last_name",label:"نام خانوادگی",value:e.values.last_name,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.last_name&&!!e.errors.last_name,helperText:e.touched.last_name&&e.errors.last_name})})}),u.jsx(_,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(P,{id:"driver_mobile",name:"driver_mobile",label:"شماره موبایل راننده",value:e.values.driver_mobile,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.driver_mobile&&!!e.errors.driver_mobile,helperText:e.touched.driver_mobile&&e.errors.driver_mobile})})}),(b==null?void 0:b.length)&&u.jsx(_,{item:!0,xs:12,children:u.jsxs(S,{fullWidth:!0,children:[u.jsx(q,{id:"demo-simple-select-label",children:"شهر"}),u.jsxs(G,{id:"city_name",name:"city_name",onChange:e.handleChange,label:"شهر",onBlur:e.handleBlur,value:e.values.city_name,error:e.touched.city_name&&!!e.errors.city_name,renderValue:n=>n||"نام شهر",children:[u.jsx(v,{value:"",disabled:!0,children:"نام شهر"}),b.map(n=>u.jsx(v,{value:n.name,children:n.name},n.id))]}),e.touched.city_name&&e.errors.city_name&&u.jsx(U,{error:!0,children:e.errors.city_name})]})}),u.jsx(_,{item:!0,xs:12,children:u.jsxs(S,{fullWidth:!0,children:[u.jsx(q,{id:"demo-simple-select-label",children:"نوع خودرو"}),u.jsxs(G,{id:"type_car",name:"type_car",label:"نوع خودرو",value:e.values.type_car,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.type_car&&!!e.errors.type_car,renderValue:n=>n||"انتخاب نوع خودرو",children:[u.jsx(v,{value:"",disabled:!0,children:"انتخاب نوع خودرو"}),u.jsx(v,{value:"ایسوزو",children:"ایسوزو"}),u.jsx(v,{value:"نیسان",children:"نیسان"}),u.jsx(v,{value:"وانت",children:"وانت"}),u.jsx(v,{value:"اف ام",children:"اف ام"}),u.jsx(v,{value:"کامیون",children:"کامیون"}),u.jsx(v,{value:"هیوندا کروس",children:"هیوندا کروس"}),u.jsx(v,{value:"بادسان",children:"بادسان"}),u.jsx(v,{value:"هیوندا",children:"هیوندا"}),u.jsx(v,{value:"کامیونت ایسوزو",children:"کامیونت ایسوزو"}),u.jsx(v,{value:"خاور بنز",children:"خاور بنز"})]}),e.touched.type_car&&e.errors.type_car&&u.jsx(U,{error:!0,children:e.errors.type_car})]})}),u.jsx(_,{item:!0,xs:12,alignItems:"center",justifyContent:"center",children:u.jsx(yu,{width:"100%",pelakState:f,handleChange:F})}),u.jsx(_,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(P,{id:"capocity",name:"capocity",label:"ظرفیت",type:"number",InputProps:{endAdornment:u.jsx(au,{position:"start",children:"کیلوگرم"})},value:e.values.capocity,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.capocity&&!!e.errors.capocity,helperText:e.touched.capocity&&e.errors.capocity})})}),u.jsx(_,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(P,{id:"health_code",name:"health_code",label:"کد بهداشتی",value:e.values.health_code,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.health_code&&!!e.errors.health_code,helperText:e.touched.health_code&&e.errors.health_code})})}),u.jsxs(_,{item:!0,xs:12,children:[u.jsx(D,{children:"ماهیت خودرو"}),u.jsx(S,{component:"fieldset",disabled:y()==="ProvinceOperator"||y()==="SuperAdmin"||y()==="AdminX"?!1:a?a==="rental":!1,children:u.jsxs(lu,{name:"type",value:e.values.type,onChange:e.handleChange,children:[(y()==="ProvinceOperator"||y()==="SuperAdmin"||y()==="AdminX")&&u.jsx(X,{value:"rental",control:u.jsx(Y,{}),label:u.jsx(_,{container:!0,children:u.jsxs(D,{children:["اجاره ای"," ",u.jsx(D,{variant:"caption",children:"(نمایش برای تمام کشتارگاه ها)"})]})})}),u.jsx(X,{value:"exclusive",control:u.jsx(Y,{}),label:"اختصاصی"})]})})]}),u.jsx(_,{item:!0,xs:12,children:u.jsx(N,{fullWidth:!0,variant:"contained",color:"primary",type:"submit",children:"ارسال"})})]})})},gu=L("PROVINCE_REMOVE_CAR",async r=>{const{data:l,status:t}=await I.delete("kill_house_driver/0/?key="+r);return{data:l,status:t}}),bu=L("PROVINCE_ADD_CAR_TO_KILLHOUSE_SERVICE",async(r,{dispatch:l})=>{try{l(w());const{data:t,status:s}=await I.post("kill_house_add_car/",{...r,role:y()});return l(j()),{data:t,status:s}}catch(t){return l(j()),{error:t.response.data.result}}}),Eu=L("PROVINCE_REMOVE_CAR_FROM_KILLHOUSE_SERVICE",async(r,{dispatch:l})=>{try{l(w());const{data:t,status:s}=await I.delete("kill_house_add_car/0/",{params:r});return l(j()),{data:t,status:s}}catch(t){return l(j()),{error:t.response.data.result}}}),Su=uu().shape({autocompleteField:E().required("This field is required")}),ku=({killHouseList:r,driverKey:l})=>{const[t]=m.useContext(M),s=Z({initialValues:{autocompleteField:""},validationSchema:Su,onSubmit:o=>{if(!(o!=null&&o.autocompleteField)||!l){t({vertical:"top",horizontal:"center",msg:"لطفا تمام فیلدها را پر کنید",severity:"error"});return}h(bu({kill_house_key:o.autocompleteField,driver_key:l})).then(a=>{var c;(c=a==null?void 0:a.payload)!=null&&c.error?t({vertical:"top",horizontal:"center",msg:a.payload.error,severity:"error"}):(h(B()),h(k({right:!1,bottom:!1,content:null})),t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}}),h=V(),[x,i]=m.useState([]),{provinceGetOnlyKillHouses:A}=W(o=>o.provinceSlice);return m.useEffect(()=>{y()==="KillHouse"?h(J("self_kill_houses")):h(J("role=ProvinceOperator"))},[]),m.useEffect(()=>{if(!A||!Array.isArray(A)){i([]);return}const o=A.map(a=>{if(!a)return null;let c;return a.killer?c="کشتارکن":c="کشتارگاه",{title:`${c} ${(a==null?void 0:a.name)||""}`,value:(a==null?void 0:a.key)||""}}).filter(a=>a!==null&&a.value);i(o||[])},[A]),u.jsxs(R,{children:[u.jsx("form",{onSubmit:s.handleSubmit,children:u.jsxs(R,{container:!0,direction:"column",gap:O.TINY,mb:O.SMALL,children:[u.jsx(ou,{id:"autocompleteField",options:x||[],getOptionLabel:o=>(o==null?void 0:o.title)||"",renderInput:o=>u.jsx(P,{...o,label:"انتخاب کشتارگاه",variant:"outlined",fullWidth:!0,error:s.touched.autocompleteField&&!!s.errors.autocompleteField,helperText:s.touched.autocompleteField&&s.errors.autocompleteField}),onChange:(o,a)=>s.setFieldValue("autocompleteField",(a==null?void 0:a.value)||""),value:x==null?void 0:x.find(o=>o.value===s.values.autocompleteField)}),u.jsx(N,{fullWidth:!0,variant:"contained",type:"submit",children:"ثبت"})]})}),u.jsx(D,{variant:"body1",fontWeight:"bold",children:"کشتارگاه های خودرو"}),r&&Array.isArray(r)&&r.length>0?r.map((o,a)=>o?u.jsxs(R,{container:!0,gap:O.TINY,alignItems:"center",justifyContent:"space-between",style:{borderBottom:"1px solid #DDD"},children:[u.jsxs(D,{children:[a+1,". ",(o==null?void 0:o.killHouseName)||""]}),u.jsx(N,{color:"error",onClick:()=>{if(!(o!=null&&o.killHouseKey)||!l){t({vertical:"top",horizontal:"center",msg:"اطلاعات ناقص است",severity:"error"});return}h(Eu({kill_house_key:o.killHouseKey,driver_key:l})).then(c=>{var p;(p=c==null?void 0:c.payload)!=null&&p.error?t({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(h(B()),h(k({right:!1,bottom:!1,content:null})),t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:"حذف"})]},o.killHouseKey||a):null):null]})},Ru=L("UPDATE_CAR_STATE_SERVICE",async(r,{dispatch:l})=>{try{l(w());const{data:t,status:s}=await I.put("kill_house_driver/0/",r);return l(j()),{data:t,status:s}}catch(t){return l(j()),{error:t.response.data.result}}}),Iu=({item:r})=>{const[l]=m.useContext(M),t=V(),[s,h]=m.useState(y()==="KillHouse"?r.addCarActiveState:r.driverActiveState),x=A=>{let o;y()==="KillHouse"?o={add_car_key:r.addCarKey,add_car_change_activation:A.target.checked}:o={driver_key:r.key,change_activation:A.target.checked},t(Ru(o)).then(a=>{var c,p;(c=a==null?void 0:a.payload)!=null&&c.error?l({vertical:"top",horizontal:"center",msg:(p=a==null?void 0:a.payload)==null?void 0:p.error,severity:"error"}):(t(B()),l({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}),h(A.target.checked)};let i=!1;return r.driverType==="rental"&&(i=!0),u.jsxs(u.Fragment,{children:[u.jsx(nu,{checked:s,onChange:x,name:"mySwitch",color:"primary",disabled:i}),s?u.jsx("label",{htmlFor:"mySwitch",children:"فعال"}):u.jsx("label",{htmlFor:"mySwitch",children:"غیرفعال"})]})},Tu=L("CARS_DASHBOARD",async(r,{dispatch:l})=>{l(w());const{data:t,status:s}=await I.get("kill_house_driver_total_dashboard",{params:{role:y()}});return l(j()),{data:t,status:s}}),Bu=()=>{var a,c,p,b,e,f;const r=V(),[l,t]=m.useState([]),[s]=m.useContext(M),{provinceCars:h}=W(C=>C.provinceSlice),x=W(C=>C.userSlice.userProfile.key);m.useEffect(()=>{r(B())},[]);const[i,A]=m.useState([]);m.useEffect(()=>{r(Tu()).then(C=>{A(C.payload.data)})},[r,h]),m.useEffect(()=>{const C=h==null?void 0:h.map((d,F)=>{var g;let n="-";d.type==="rental"?n="اجاره ای":d.type==="exclusive"&&(n="اختصاصی");const T=d.type==="rental"?"همه کشتارگاه ها/کشتارکن ها":(g=d==null?void 0:d.killHouseList)==null?void 0:g.map((z,ru)=>{const tu=ru+1===d.killHouseList.length?"":" - ";return(z==null?void 0:z.killHouseName)+tu});return[F+1,d.typeCar,n,d.pelak,d.capocity,parseInt(d.healthCode),d.driverName,d.driverMobile,T,u.jsx(Iu,{item:d},d.key),u.jsx(wu,{item:d,openNotif:s},`car-action-${d.key}`)]});t(C)},[h,r,s]);const[o]=m.useState(["ردیف","مدل خودرو","ماهیت","پلاک","ظرفیت","کد بهداشتی","نام راننده","موبایل راننده","کشتارگاه ها/کشتارکن ها","وضعیت","عملیات"]);return u.jsx(u.Fragment,{children:u.jsxs(R,{container:!0,alignItems:"center",justifyContent:"space-between",gap:O.SMALL,xs:12,children:[u.jsx(N,{variant:"contained",onClick:()=>{r(k({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"افزودن خودرو",content:u.jsx(eu,{})}))},children:"افزودن خودرو"}),u.jsx(su,{title:"خروجی اکسل",children:u.jsx("a",{href:`${I.defaults.baseURL}car_province_excel/?key=${x}&role=${y()}`,rel:"noreferrer",children:u.jsx(N,{color:"success",children:u.jsx(xu,{size:32})})})}),u.jsxs(iu,{sx:{width:"100%"},children:[u.jsx(R,{container:!0,mt:2,mb:4,isDashboard:!0,children:u.jsx(Q,{noPagination:!0,isDashboard:!0,columns:["تعداد خودرو ها","اختصاصی","اجاره ای","فعال","غیر فعال","معلق"],data:[[(a=i==null?void 0:i.total)==null?void 0:a.toLocaleString(),(c=i==null?void 0:i.exclusive)==null?void 0:c.toLocaleString(),(p=i==null?void 0:i.rental)==null?void 0:p.toLocaleString(),(b=i==null?void 0:i.active)==null?void 0:b.toLocaleString(),(e=i==null?void 0:i.inactive)==null?void 0:e.toLocaleString(),(f=i==null?void 0:i.suspended)==null?void 0:f.toLocaleString()]],title:"خلاصه اطلاعات"})}),u.jsx(Q,{paginated:!0,title:"خودروها",columns:o,data:l})]})]})})},wu=({item:r,openNotif:l})=>{var d;const t=V(),[s,h]=m.useState(null),x=!(y()==="ProvinceOperator"||y()==="SuperAdmin"||y()==="AdminX"),i=(d=r.killHouseList)==null?void 0:d.some(F=>!F.allowState),A=!x||!i,o=r.type==="rental",a=!!s,c=a?`province-cars-popover-${r.key}`:void 0,p=()=>h(null),b=()=>{p(),t(k({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"تخصیص/حذف کشتارگاه",content:u.jsx(ku,{driverKey:r.key,killHouseList:r.killHouseList})}))},e=()=>{p(),t(k({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش خودرو",content:u.jsx(eu,{first_name:r.firstName,pelak:r.pelak,city_name:r.city,type_car:r.typeCar,last_name:r.lastName,capocity:r.capocity,health_code:r.healthCode,driver_mobile:r.driverMobile,driverKey:r==null?void 0:r.key,type:r==null?void 0:r.type})}))},f=()=>{p(),t(w()),t(gu(r.key)).then(F=>{F.error?F.error.message.includes("403")?l({vertical:"top",horizontal:"center",msg:"امکان حذف بدلیل تخصیص بار فعال به خودرو وجود ندارد!",severity:"error"}):l({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):(t(k({right:!1,bottom:!1,content:null})),t(B()),l({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})),t(j())})},C=!A||x&&o;return u.jsxs("div",{children:[u.jsx(cu,{"aria-describedby":c,color:"primary",size:"small",onClick:F=>h(F.currentTarget),disabled:!A,children:u.jsx(Au,{})}),u.jsx(du,{id:c,anchorEl:s,open:a,onClose:p,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},disableRestoreFocus:!0,PaperProps:{sx:{p:2}},children:u.jsxs(hu,{sx:{py:0},children:[u.jsxs(K,{onClick:b,disabled:C,children:[u.jsx(H,{children:u.jsx(mu,{fontSize:"small",color:C?"disabled":"primary"})}),u.jsx($,{primary:"تخصیص به کشتارگاه",primaryTypographyProps:{variant:"body2",color:C?"text.secondary":"primary"}})]}),u.jsxs(K,{onClick:e,disabled:C,children:[u.jsx(H,{children:u.jsx(vu,{fontSize:"small",color:C?"disabled":"primary"})}),u.jsx($,{primary:"ویرایش",primaryTypographyProps:{variant:"body2",color:C?"text.secondary":"primary"}})]}),u.jsxs(K,{onClick:f,disabled:C,children:[u.jsx(H,{children:u.jsx(_u,{fontSize:"small",color:C?"disabled":"error"})}),u.jsx($,{primary:"حذف",primaryTypographyProps:{variant:"body2",color:C?"text.secondary":"error"}})]})]})})]})},Gu=()=>u.jsx(Cu,{display:"flex",justifyContent:"center",children:u.jsx(R,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,my:O.MEDIUM,children:u.jsx(R,{container:!0,justifyContent:"space-between",gap:O.SMALL,children:u.jsx(R,{xs:12,children:u.jsx(Bu,{})})})})});export{Gu as default};