|  | @@ -0,0 +1,81 @@
 | 
	
		
			
				|  |  | +<script lang="ts" setup>
 | 
	
		
			
				|  |  | +/**
 | 
	
		
			
				|  |  | + * @Name: createDialog.vue
 | 
	
		
			
				|  |  | + * @Description: 产品属性-创建对话框
 | 
	
		
			
				|  |  | + * @Author: xinyan
 | 
	
		
			
				|  |  | + */
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import { ElMessage, FormInstance, FormRules } from 'element-plus';
 | 
	
		
			
				|  |  | +import { DictionaryStore } from '/@/stores/dictionary';
 | 
	
		
			
				|  |  | +import { useResponse } from '/@/utils/useResponse';
 | 
	
		
			
				|  |  | +import * as api from '../api';
 | 
	
		
			
				|  |  | +import { Close, Finished } from '@element-plus/icons-vue';
 | 
	
		
			
				|  |  | +import { createAttr, createBrand } from '../api';
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const loading = ref(false);
 | 
	
		
			
				|  |  | +const createOpen = defineModel({ default: false });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const emit = defineEmits(['refresh']);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +interface RuleForm {
 | 
	
		
			
				|  |  | +	name: any;
 | 
	
		
			
				|  |  | +	key: any;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const ruleFormRef = ref<FormInstance>();
 | 
	
		
			
				|  |  | +const ruleForm = reactive<RuleForm>({
 | 
	
		
			
				|  |  | +	name: '',
 | 
	
		
			
				|  |  | +	key: '',
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const rules = reactive<FormRules<RuleForm>>({
 | 
	
		
			
				|  |  | +	name: [{ required: true, message: '请输入属性名称', trigger: 'blur' }],
 | 
	
		
			
				|  |  | +	key: [{ required: true, message: '请输入属性标识', trigger: 'blur' }],
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const submitForm = async (formEl: FormInstance | undefined) => {
 | 
	
		
			
				|  |  | +	if (!formEl) return;
 | 
	
		
			
				|  |  | +	await formEl.validate(async (valid, fields) => {
 | 
	
		
			
				|  |  | +		if (valid) {
 | 
	
		
			
				|  |  | +			const body = {
 | 
	
		
			
				|  |  | +				name: ruleForm.name,
 | 
	
		
			
				|  |  | +				key: ruleForm.key,
 | 
	
		
			
				|  |  | +			};
 | 
	
		
			
				|  |  | +			const res = await useResponse(api.createAttr, body, loading);
 | 
	
		
			
				|  |  | +			if (res.code === 2000) {
 | 
	
		
			
				|  |  | +				ElMessage.success('创建成功');
 | 
	
		
			
				|  |  | +				createOpen.value = false;
 | 
	
		
			
				|  |  | +				emit('refresh');
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		} else {
 | 
	
		
			
				|  |  | +			// createOpen.value = false;
 | 
	
		
			
				|  |  | +			ElMessage.error('创建失败,请检查表单');
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	});
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const resetForm = (formEl: FormInstance | undefined) => {
 | 
	
		
			
				|  |  | +	if (!formEl) return;
 | 
	
		
			
				|  |  | +	formEl.resetFields();
 | 
	
		
			
				|  |  | +};
 | 
	
		
			
				|  |  | +</script>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +<template>
 | 
	
		
			
				|  |  | +	<el-dialog v-model="createOpen" :close-on-click-modal="false" :close-on-press-escape="false" :title="`产品品牌 - 创建 `" style="width: 30%">
 | 
	
		
			
				|  |  | +		<el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" class="mx-2.5 mt-5" label-position="top" label-width="auto" status-icon>
 | 
	
		
			
				|  |  | +					<el-form-item class="font-medium" label="属性名称" prop="name">
 | 
	
		
			
				|  |  | +						<el-input v-model="ruleForm.name" placeholder="请输入品牌名称" style="width:328px"/>
 | 
	
		
			
				|  |  | +					</el-form-item>
 | 
	
		
			
				|  |  | +				<el-form-item class="font-medium" label="属性标识" prop="key">
 | 
	
		
			
				|  |  | +						<el-input v-model="ruleForm.key" placeholder="请输入属性标识" style="width:328px"/>
 | 
	
		
			
				|  |  | +					</el-form-item>
 | 
	
		
			
				|  |  | +		</el-form>
 | 
	
		
			
				|  |  | +		<template #footer>
 | 
	
		
			
				|  |  | +			<el-button :icon="Finished" @click="resetForm(ruleFormRef);createOpen = false">取 消</el-button>
 | 
	
		
			
				|  |  | +			<el-button :icon="Close" :loading="loading" type="primary" @click="submitForm(ruleFormRef)">确 定</el-button>
 | 
	
		
			
				|  |  | +		</template>
 | 
	
		
			
				|  |  | +	</el-dialog>
 | 
	
		
			
				|  |  | +</template>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +<style scoped>
 | 
	
		
			
				|  |  | +</style>
 |