移动系统liao
昨天 9f3ead22a8198d33891a0f8f23faec15dcfc731a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!--
 * @FilePath: editDialog.vue
 * @Author: 小飞侠
 * @Date: 2025-06-25 11:22:03
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-07-22 17:28:33
 * Copyright: 2025  MinTinge CO.,LTD. All Rights Reserved.
 * @Descripttion: 写入你的描述
-->
<script lang="ts" name="fBS_EnterpriseType" setup>
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import type { FormRules } from "element-plus";
import { formatDate } from '/@/utils/formatTime';
import { useFBS_EnterpriseTypeApi } from '/@/api/Customer/fBS_EnterpriseType';
 
//父级传递来的函数,用于回调
const emit = defineEmits(["reloadTable"]);
const fBS_EnterpriseTypeApi = useFBS_EnterpriseTypeApi();
const ruleFormRef = ref();
 
const state = reactive({
    title: '',
    loading: false,
    showDialog: false,
    ruleForm: {} as any,
    stores: {},
    dropdownData: {} as any,
    tableData: [] as any[],
});
 
// 自行添加其他规则
const rules = ref<FormRules>({
    name: [{ required: true, message: '请输入名称!', trigger: 'blur', },],
    code: [{ required: true, message: '请输入代码!', trigger: 'blur', },]
    // parentId: [{ required: true, message: '请选择父!', trigger: 'blur', },],
});
 
// 页面加载时
onMounted(async () => {
});
 
// 打开弹窗
const openDialog = async (row: any, data:any,title: string) => {
    
    state.title = title;
    row = row ?? {};
    state.ruleForm = row.id ? await fBS_EnterpriseTypeApi.detail(row.id).then(res => res.data.result) : JSON.parse(JSON.stringify(row));
    state.showDialog = true;
    state.tableData = data;
    
};
 
// 关闭弹窗
const closeDialog = () => {
    emit("reloadTable");
    console.log("listdata",state.tableData);
    
    state.showDialog = false;
};
 
// 提交
const submit = async () => {
    ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
        if (isValid) {
            let values = state.ruleForm;
            if(values.parentId==null)
            values.parentId=0;
            await fBS_EnterpriseTypeApi[state.ruleForm.id ? 'update' : 'add'](values);
            closeDialog();
        } else {
            ElMessage({
                message: `表单有${Object.keys(fields).length}处验证失败,请修改后再提交`,
                type: "error",
            });
        }
    });
};
const treeProps = reactive({
 
    children: 'child',
  label: 'name',
  value: 'id',
  disabled:(node:any)=>{
    return state.ruleForm?.id== node.id;
  }
 
})
 
//将属性或者函数暴露给父组件
defineExpose({ openDialog });
</script>
<template>
    <div class="fBS_EnterpriseType-container">
        <el-dialog v-model="state.showDialog" :width="800" draggable :close-on-click-modal="false">
            <template #header>
                <div style="color: #fff">
                    <span>{{ state.title }}</span>
                </div>
            </template>
            <el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" :rules="rules">
                <el-row :gutter="35">
                    <el-form-item v-show="false">
                        <el-input v-model="state.ruleForm.id" />
                    </el-form-item>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="名称" prop="name">
                            <el-input v-model="state.ruleForm.name" placeholder="请输入名称" maxlength="256" show-word-limit
                                clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="代码" prop="code">
                            <el-input v-model="state.ruleForm.code" placeholder="请输入代码" maxlength="36" show-word-limit
                                clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="代码" prop="description">
                            <el-input v-model="state.ruleForm.description" placeholder="请输入说明" maxlength="36" show-word-limit
                                clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="上级" prop="parentId">                            
                            <el-tree-select :props="treeProps"  clearable   v-model="state.ruleForm.parentId" :data="state.tableData" check-strictly :render-after-expand="false"
                                style="width: 240px" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="() => state.showDialog = false">取 消</el-button>
                    <el-button @click="submit" type="primary" v-reclick="1000">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>
<style lang="scss" scoped>
:deep(.el-select),
:deep(.el-input-number) {
    width: 100%;
}
</style>