forked from Simnation/Main
1 line
9.1 KiB
JavaScript
1 line
9.1 KiB
JavaScript
import{_ as E,R as D,P as N,o as m,X as f,a7 as a,a as t,w as n,a6 as b,ab as u,c as y,V as q,a5 as p,W as C,U as h,a9 as r,Y as S,Z as w}from"./app-014d9ed9.js";import{Q as V}from"./QForm.8d79ab03.js";import{Q as U}from"./QSelect.d7ce3d4c.js";import{Q}from"./QTooltip.9d840032.js";import{Q as I}from"./QMarkupTable.ba6854cc.js";import{d as O}from"./utils.9ce591f3.js";import{B as $}from"./BasicDialog.9dd9de92.js";import"./externalHosting.js";import"./QItemLabel.b6dd3adb.js";import"./position-engine.65ebcb34.js";import"./selection.2a17b691.js";import"./rtl.b51694b1.js";const B={name:"Vehicle",data(){return{RESOURCE:D,ACTION:N,defaults:["name","brand","model","price","category","categorylabel","hash","shop"],vehicle:{},customVars:[],pendingSave:!1,pendingDelete:!1}},methods:{can:O,isNumeric(e){return typeof e!="string"?!1:!isNaN(e)&&!isNaN(parseFloat(e))},isBoolean(e){return e==="true"||(e==="false"?!1:e)},addCustomVar(){this.customVars.push({name:"",value:""})},removeVar(e,l){e>-1&&this.$q.dialog({component:$,componentProps:{title:this.$i18n.t("components.devVehicle.deleteHeader"),message:this.$i18n.t("components.devVehicle.deleteCustomVarMsg",{name:l.name})},cancel:!0,persistent:!0}).onOk(()=>{delete this.vehicle[l.oldName],this.customVars.splice(e,1)})},trySave(){this.$refs.customVarForm.validate().then(e=>{if(!e){this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t("components.devVehicle.msg.error.uniqueVars")});return}this.customVars.forEach(l=>{!l.name||(l.oldName=l.name,this.vehicle[l.name]=this.isNumeric(l.value)?Number(l.value):this.isBoolean(l.value))}),this.pendingSave=!0,this.$axios.patch(`/api/dev-vehicles/save/${this.$route.params.vehicleId}`,this.vehicle).then(l=>{if(this.pendingSave=!1,!l.data.resCode){const v=l.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.devVehicle.msg.error.${v}`,{name:this.job.name})});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.saved")})}).catch(l=>{console.error(l)})})},tryDelete(){this.pendingDelete=!0,this.$q.dialog({component:$,componentProps:{title:this.$i18n.t("components.devVehicle.deleteHeader"),message:this.$i18n.t("components.devVehicle.deleteMsg",{model:this.vehicle.model})},cancel:!0,persistent:!0}).onOk(()=>{this.$axios.delete(`/api/dev-vehicles/delete/${this.$route.params.vehicleId}`).then(e=>{if(this.pendingDelete=!1,!e.data.resCode){const c=e.data.resMsg;this.$q.notify({message:this.$i18n.t("general.error"),position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:this.$i18n.t(`components.devVehicle.msg.error.${c}`)});return}this.$q.notify({message:this.$i18n.t("general.success"),position:"top",color:"green",icon:"fas fa-check",caption:this.$i18n.t("general.deleted")}),this.$router.push({name:"dev-vehicle-list"})}).catch(e=>{})}).onCancel(()=>{this.pendingDelete=!1})}},mounted(){this.$axios.get(`/api/dev-vehicles/${this.$route.params.vehicleId}`).then(e=>{const l=e.data.vehicle;if(!l){this.$q.notify({message:e.data.msg,position:"top",color:"red",icon:"fas fa-exclamation-triangle",caption:"Error"});return}this.vehicle=l,this.vehicle.shop=Array.isArray(l.shop)?l.shop:[l.shop];for(const[c,v]of Object.entries(l))this.defaults.includes(c.toLowerCase())||this.customVars.push({name:c,value:v,oldName:c})}).catch(e=>{console.error(e)})}},L={class:"row"},M={class:"col-12"},_={class:"q-ma-sm row"},R={class:"text-h6"},T={class:"text-primary"},F={class:"col-12"},A={class:"q-ma-sm row"},x={class:"row"},H={class:"text-h6"},j={class:"text-caption text-sub"},P={class:"q-ml-auto"},z={style:{width:"30px"},class:"text-right vertical-middle"},Y={class:"col-12"},W={class:"q-ma-sm row justify-end"};function X(e,l,c,v,o,d){return m(),f("div",L,[a("div",M,[a("div",_,[t(b,{class:"bg-secondary full-width row"},{default:n(()=>[t(p,{class:"col-12"},{default:n(()=>[a("div",R,[C(h(e.$t("components.devVehicle.edit"))+": ",1),a("span",T,h(o.vehicle.model),1)])]),_:1}),t(p,{class:"col-12 col-md-6"},{default:n(()=>[t(V,{ref:"vehDefaults"},{default:n(()=>[t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",disable:"",modelValue:o.vehicle.model,"onUpdate:modelValue":l[0]||(l[0]=s=>o.vehicle.model=s),label:e.$t("components.devVehicle.model")},null,8,["input-style","modelValue","label"]),t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",disable:"",class:"q-mt-md",modelValue:o.vehicle.model,"onUpdate:modelValue":l[1]||(l[1]=s=>o.vehicle.model=s),label:e.$t("components.devVehicle.hash")},null,8,["input-style","modelValue","label"]),t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:o.vehicle.name,"onUpdate:modelValue":l[2]||(l[2]=s=>o.vehicle.name=s),label:e.$t("components.devVehicle.name")},null,8,["input-style","modelValue","label"]),t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:o.vehicle.brand,"onUpdate:modelValue":l[3]||(l[3]=s=>o.vehicle.brand=s),label:e.$t("components.devVehicle.brand")},null,8,["input-style","modelValue","label"])]),_:1},512)]),_:1}),t(p,{class:"col-12 col-md-6"},{default:n(()=>[t(V,{ref:"vehShop"},{default:n(()=>[t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:o.vehicle.category,"onUpdate:modelValue":l[4]||(l[4]=s=>o.vehicle.category=s),label:e.$t("components.devVehicle.category")},null,8,["input-style","modelValue","label"]),t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:o.vehicle.categoryLabel,"onUpdate:modelValue":l[5]||(l[5]=s=>o.vehicle.categoryLabel=s),label:e.$t("components.devVehicle.categoryLabel")},null,8,["input-style","modelValue","label"]),t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-mt-md",modelValue:o.vehicle.price,"onUpdate:modelValue":l[6]||(l[6]=s=>o.vehicle.price=s),modelModifiers:{number:!0},type:"number",label:e.$t("components.devVehicle.price")},null,8,["input-style","modelValue","label"]),t(U,{ref:"accept",label:e.$t("components.devVehicle.shop"),color:"primary","label-color":"primary",filled:"",multiple:"",modelValue:o.vehicle.shop,"onUpdate:modelValue":l[7]||(l[7]=s=>o.vehicle.shop=s),"popup-content-class":"bg-secondary text-main","use-input":"","use-chips":"","hide-dropdown-icon":"","input-debounce":"0","new-value-mode":"add-unique","input-class":"text-main",class:"q-mt-md"},null,8,["label","modelValue"])]),_:1},512)]),_:1})]),_:1})])]),a("div",F,[a("div",A,[t(b,{class:"bg-secondary full-width row"},{default:n(()=>[t(p,{class:"col-12"},{default:n(()=>[a("div",x,[a("div",null,[a("div",H,h(e.$t("components.devVehicle.customVariables")),1),a("div",j,h(e.$t("components.devVehicle.customVarSub")),1)]),a("div",P,[t(u,{"text-color":"main",color:"primary",label:e.$t("components.devVehicle.addCustomVar"),onClick:d.addCustomVar},null,8,["label","onClick"])])])]),_:1}),t(p,{class:"col-12"},{default:n(()=>[t(V,{ref:"customVarForm"},{default:n(()=>[t(I,{class:"bg-secondary text-main",flat:"",square:"",separator:"none"},{default:n(()=>[a("tbody",null,[(m(!0),f(S,null,w(o.customVars,(s,g)=>(m(),f("tr",{key:`${g}-customVar`},[a("td",null,[t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",modelValue:s.name,"onUpdate:modelValue":i=>s.name=i,label:e.$t("components.devVehicle.customVarName"),"lazy-rules":"",rules:[i=>i&&i.length>0||e.$t("rules.required"),i=>i&&!/\s/.test(i)||e.$t("rules.noSpace"),i=>i&&o.customVars.filter(k=>k.name===i).length<=1||e.$t("rules.unique"),i=>i&&!o.defaults.includes(i.toLowerCase())||e.$t("rules.defaults")]},null,8,["input-style","modelValue","onUpdate:modelValue","label","rules"])]),a("td",null,[t(r,{"label-color":"primary","input-style":{color:"var(--q-main)"},filled:"",class:"q-field--with-bottom",modelValue:s.value,"onUpdate:modelValue":i=>s.value=i,label:e.$t("components.devVehicle.customVarValue")},null,8,["input-style","modelValue","onUpdate:modelValue","label"])]),a("td",z,[t(u,{"text-color":"main",class:"text-red-6",dense:"",flat:"",icon:"fas fa-trash",size:"xs",onClick:i=>d.removeVar(g,s)},{default:n(()=>[t(Q,null,{default:n(()=>[C(h(e.$t("general.delete")),1)]),_:1})]),_:2},1032,["onClick"])])]))),128))])]),_:1})]),_:1},512)]),_:1})]),_:1})])]),a("div",Y,[a("div",W,[t(u,{"text-color":"main",disable:o.pendingDelete||o.pendingSave,color:"primary",onClick:l[8]||(l[8]=s=>e.$router.push({name:"dev-vehicle-list"})),label:e.$t("general.back"),class:"q-mr-auto"},null,8,["disable","label"]),d.can(o.ACTION.DEV.VEHICLE.MODIFY,o.RESOURCE.DEV)?(m(),y(u,{key:0,"text-color":"main",loading:o.pendingSave,disable:o.pendingDelete,color:"primary",onClick:d.trySave,label:e.$t("general.save"),class:"q-mr-sm"},null,8,["loading","disable","onClick","label"])):q("",!0),d.can(o.ACTION.DEV.VEHICLE.DELETE,o.RESOURCE.DEV)?(m(),y(u,{key:1,"text-color":"main",loading:o.pendingDelete,disable:o.pendingSave,color:"negative",onClick:d.tryDelete,label:e.$t("general.delete")},null,8,["loading","disable","onClick","label"])):q("",!0)])])])}const re=E(B,[["render",X]]);export{re as default};
|