

<script>
/* eslint-disable */
// sd-skip-auto-import
import{message}from"ant-design-vue";import PageService from"@/common/services/page-service";import components from"./_import-components/sd-form-template-save-modal-import";var _render=function e(){var t=this,a=t._self._c;return a("a-modal",{attrs:{visible:t.visible,title:"存为模板","destroy-on-close":"","confirm-loading":t.confirmLoading},on:{ok:t.saveTemplate,cancel:()=>{t.$emit("hide")}}},[a("a-form-model",{ref:"templForm",attrs:{model:t.templateProps,"label-col":{span:6},"wrapper-col":{span:18}}},[a("a-form-model-item",{attrs:{label:"模板名称",prop:"templetName",rules:[{required:true}]}},[a("a-input",{model:{value:t.templateProps.templetName,callback:function(e){t.$set(t.templateProps,"templetName","string"===typeof e?e.trim():e)},expression:"templateProps.templetName"}})],1),a("a-form-model-item",{attrs:{label:"模板分类",prop:"templetCategory",rules:[{required:true}]}},[a("sd-form-template-cate-picker",{model:{value:t.templateProps.templetCategory,callback:function(e){t.$set(t.templateProps,"templetCategory",e)},expression:"templateProps.templetCategory"}}),a("a-button",{attrs:{type:"link"},on:{click:t.newCategory}},[t._v("新建分类")])],1)],1),a("a-modal",{attrs:{visible:t.newCategoryVisible,title:"新建分类","destroy-on-close":"","confirm-loading":t.newCategoryConfirmLoading},on:{ok:t.saveCategory,cancel:()=>{t.newCategoryVisible=false}}},[a("a-form-model",{ref:"newCateForm",attrs:{model:t.newCategoryProps,"label-col":{span:6},"wrapper-col":{span:18}}},[a("a-form-model-item",{attrs:{label:"分类名称",prop:"categoryName",rules:[{required:true}]}},[a("a-input",{model:{value:t.newCategoryProps.categoryName,callback:function(e){t.$set(t.newCategoryProps,"categoryName","string"===typeof e?e.trim():e)},expression:"newCategoryProps.categoryName"}})],1),a("a-form-model-item",{attrs:{label:"上级分类",prop:"parent",rules:[{required:true}]}},[a("sd-form-template-cate-picker",{attrs:{"select-root":""},model:{value:t.newCategoryProps.parent,callback:function(e){t.$set(t.newCategoryProps,"parent",e)},expression:"newCategoryProps.parent"}})],1)],1)],1)],1)};var staticRenderFns=[];_render._withStripped=true;export default{name:"SdFormTemplateSaveModal",components:components,props:{visible:{type:Boolean,default:false},formData:{type:Object,default:()=>({})}},data(){return{templateProps:{},confirmLoading:false,newCategoryVisible:false,newCategoryConfirmLoading:false,newCategoryProps:{},pageParams:{}}},watch:{visible(e){if(e)this.templateProps={templetName:this.formData.head.tableTxt+"模板"}}},methods:{saveTemplate(){this.$refs.templForm.validate().then((e=>{if(e){this.confirmLoading=true;this.getPageParamInfo("online/templet/onlFormTemplet").then((e=>{const t=[{name:"templetName",value:this.templateProps.templetName},{name:"templetCategory",value:this.templateProps.templetCategory[0]?.id},{name:"templetType",value:this.formData.head.formType},{name:"attrFd",value:JSON.stringify(this.formData.head.attrFD)},{name:"fieldsJson",value:JSON.stringify(this.adjustTemplateFields(this.formData.fields))}];const a={eventId:"save",inputs:t,pageFlowId:e.pageflowId,pagePath:e.pagePath};PageService.save(a).then((e=>{if(200===e.status){message.success("保存模板成功");this.$emit("hide")}else message.error(e.data?.message||"保存模板失败")})).catch((()=>message.error("保存模板失败"))).finally((()=>{this.confirmLoading=false}))})).catch((()=>{message.error("获取模板表单参数失败");this.confirmLoading=false}))}}))},adjustTemplateFields(e){const t=JSON.parse(JSON.stringify(e));const a=e=>{if(e.attr?.subTableName)delete e.attr.subTableName;e.attr?.dync?.filter((e=>"collection"===e.dataType)).forEach((e=>a(e)))};t.filter((e=>"collection"===e.dataType)).forEach((e=>a(e)));return t},newCategory(){this.newCategoryProps={categoryName:""};this.newCategoryVisible=true},saveCategory(){this.$refs.newCateForm.validate().then((e=>{if(e){this.newCategoryConfirmLoading=true;this.getPageParamInfo("online/templet/onlFormTempcategory").then((e=>{const t=[{name:"categoryName",value:this.newCategoryProps.categoryName},{name:"parentId",value:this.newCategoryProps.parent[0]?.id}];const a={eventId:"save",inputs:t,pageFlowId:e.pageflowId,pagePath:e.pagePath};PageService.save(a).then((e=>{if(200===e.status){message.success("保存模板分类成功");this.newCategoryVisible=false}else message.error(e.data?.message||"保存模板分类失败")})).catch((()=>message.error("保存模板分类失败"))).finally((()=>{this.newCategoryConfirmLoading=false}))})).catch((()=>{message.error("获取模板分类表单参数失败");this.newCategoryConfirmLoading=false}))}}))},getPageParamInfo(e){if(this.pageParams[e])return Promise.resolve(this.pageParams[e]);else return PageService.get({},e).then((t=>{if(200===t.status){this.pageParams[e]={pageflowId:t.data.attrs.pageflowId,pagePath:t.data.attrs.pagePath};return this.pageParams[e]}}))}},render:_render,staticRenderFns:staticRenderFns};</script>

<style module lang="scss"></style>
