|
@@ -1,13 +1,13 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { reactive, ref } from "vue";
|
|
|
+import {reactive, ref} from "vue";
|
|
|
import * as $api from "@/api/agent/index";
|
|
|
-import { message } from "@/utils/message";
|
|
|
-import type { FormInstance } from "element-plus";
|
|
|
-import { cloneDeep } from "@pureadmin/utils";
|
|
|
+import {message} from "@/utils/message";
|
|
|
+import type {FormInstance} from "element-plus";
|
|
|
+import {cloneDeep} from "@pureadmin/utils";
|
|
|
import {enableOptions} from "@/constants/constants";
|
|
|
|
|
|
const title = "";
|
|
|
-defineOptions({ name: "templateEdit" });
|
|
|
+defineOptions({name: "templateEdit"});
|
|
|
const isDetail = ref(false);
|
|
|
const formRef = ref<FormInstance>();
|
|
|
// 初始化数据
|
|
@@ -17,8 +17,6 @@ const initData = {
|
|
|
status: 1
|
|
|
};
|
|
|
|
|
|
-// 表单校验规则
|
|
|
-const formRules = {};
|
|
|
|
|
|
// 页面数据
|
|
|
const pageData: any = reactive({
|
|
@@ -29,7 +27,12 @@ const pageData: any = reactive({
|
|
|
isUpdate: false,
|
|
|
// 表单数据
|
|
|
formData: initData,
|
|
|
- formRules: formRules
|
|
|
+ formRules: {
|
|
|
+ userName: [{ required: true, message: "账号不能为空", trigger: "blur" }],
|
|
|
+ password: [{ required: true, message: "密码不能为空", trigger: "blur" }],
|
|
|
+ status: [{ required: true, message: "账号不能为空", trigger: "blur" }]
|
|
|
+
|
|
|
+ }
|
|
|
});
|
|
|
// 暴露给父级调用
|
|
|
const emits = defineEmits(["ok", "close"]);
|
|
@@ -59,14 +62,14 @@ const handleClose = () => {
|
|
|
const handleConfirm = () => {
|
|
|
formRef.value!.validate((isValid: boolean) => {
|
|
|
if (isValid) {
|
|
|
- const { id } = pageData.formData;
|
|
|
+ const {id} = pageData.formData;
|
|
|
if (id) {
|
|
|
_update();
|
|
|
} else {
|
|
|
_save();
|
|
|
}
|
|
|
} else {
|
|
|
- message("表单校验失败", { type: "warning" });
|
|
|
+ message("表单校验失败", {type: "warning"});
|
|
|
}
|
|
|
});
|
|
|
};
|
|
@@ -74,74 +77,75 @@ const _save = () => {
|
|
|
pageData.formLoading = true;
|
|
|
const _data = cloneDeep(pageData.formData);
|
|
|
$api
|
|
|
- .save(_data)
|
|
|
- .then((res: any) => {
|
|
|
- if (res.success) {
|
|
|
- _confirm();
|
|
|
- } else {
|
|
|
- message(res.message, { type: "warning" });
|
|
|
- }
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- pageData.formLoading = false;
|
|
|
- });
|
|
|
+ .save(_data)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.success) {
|
|
|
+ _confirm();
|
|
|
+ } else {
|
|
|
+ message(res.message, {type: "warning"});
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ pageData.formLoading = false;
|
|
|
+ });
|
|
|
};
|
|
|
const _update = () => {
|
|
|
pageData.formLoading = true;
|
|
|
const _data = cloneDeep(pageData.formData);
|
|
|
$api
|
|
|
- .update(pageData.formData.id, _data)
|
|
|
- .then((res: any) => {
|
|
|
- if (res.success) {
|
|
|
- _confirm();
|
|
|
- } else {
|
|
|
- message(res.message, { type: "warning" });
|
|
|
- }
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
- pageData.formLoading = false;
|
|
|
- });
|
|
|
+ .update(pageData.formData.id, _data)
|
|
|
+ .then((res: any) => {
|
|
|
+ if (res.success) {
|
|
|
+ _confirm();
|
|
|
+ } else {
|
|
|
+ message(res.message, {type: "warning"});
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ pageData.formLoading = false;
|
|
|
+ });
|
|
|
};
|
|
|
const _confirm = () => {
|
|
|
pageData.dialogVisible = false;
|
|
|
emits("ok");
|
|
|
};
|
|
|
-defineExpose({ open });
|
|
|
+defineExpose({open});
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<el-dialog v-model="pageData.dialogVisible" destroy-on-close :width="500">
|
|
|
<template #header>
|
|
|
<el-text class="mx-1" type="primary" size="large">{{
|
|
|
- pageData.title
|
|
|
- }}</el-text>
|
|
|
+ pageData.title
|
|
|
+ }}
|
|
|
+ </el-text>
|
|
|
</template>
|
|
|
<div class="el-dialog-content">
|
|
|
<el-form
|
|
|
- ref="formRef"
|
|
|
- :model="pageData.formData"
|
|
|
- style="width: 90%; margin: 20px auto 0"
|
|
|
- label-width="auto"
|
|
|
- :rules="pageData.formRules"
|
|
|
- :loading="pageData.formLoading"
|
|
|
+ ref="formRef"
|
|
|
+ :model="pageData.formData"
|
|
|
+ style="width: 90%; margin: 20px auto 0"
|
|
|
+ label-width="auto"
|
|
|
+ :rules="pageData.formRules"
|
|
|
+ :loading="pageData.formLoading"
|
|
|
>
|
|
|
- <el-form-item label="代理名称" prop="userName">
|
|
|
+ <el-form-item label="代理账号" prop="userName">
|
|
|
<el-input
|
|
|
- v-model="pageData.formData.userName"
|
|
|
- clearable
|
|
|
- placeholder="请输入名称"
|
|
|
- size="small"
|
|
|
- :readonly="isDetail"
|
|
|
+ v-model="pageData.formData.userName"
|
|
|
+ clearable
|
|
|
+ placeholder="请输入名称"
|
|
|
+ size="small"
|
|
|
+ :readonly="pageData.formData.id != null"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="密码" prop="password">
|
|
|
<el-input
|
|
|
- v-model="pageData.formData.password"
|
|
|
- type="password"
|
|
|
- clearable
|
|
|
- placeholder="请输入密码"
|
|
|
- size="small"
|
|
|
- :readonly="isDetail"
|
|
|
+ v-model="pageData.formData.password"
|
|
|
+ type="password"
|
|
|
+ clearable
|
|
|
+ placeholder="请输入密码"
|
|
|
+ size="small"
|
|
|
+ :readonly="isDetail"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
|
|
@@ -164,7 +168,8 @@ defineExpose({ open });
|
|
|
<template #footer>
|
|
|
<el-button v-if="!isDetail" @click="handleClose">取消</el-button>
|
|
|
<el-button v-if="!isDetail" type="primary" @click="handleConfirm"
|
|
|
- >确认</el-button
|
|
|
+ >确认
|
|
|
+ </el-button
|
|
|
>
|
|
|
</template>
|
|
|
</el-dialog>
|