lzhe
2024-06-06 a2441175073f8b09a7eff29effd7e3e617de2f7d
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<template>
    <div class="branch-wrap">
        <div class="branch-box-wrap">
            <div class="branch-box">
                <el-button class="add-branch" type="success" plain round @click="addTerm">添加条件</el-button>
                <div class="col-box" v-for="(item,index) in nodeConfig.conditionNodes" :key="index">
                    <div class="condition-node">
                        <div class="condition-node-box">
                            <div class="auto-judge" @click="show(index)">
                                <div class="sort-left" v-if="index!=0" @click.stop="arrTransfer(index,-1)">
                                    <el-icon><el-icon-arrow-left /></el-icon>
                                </div>
                                <div class="title">
                                    <span class="node-title">{{ item.nodeName }}</span>
                                    <span class="priority-title">优先级{{item.priorityLevel}}</span>
                                    <el-icon class="close" @click.stop="delTerm(index)"><el-icon-close /></el-icon>
                                </div>
                                <div class="content">
                                    <span v-if="toText(nodeConfig, index)">{{ toText(nodeConfig, index) }}</span>
                                    <span v-else class="placeholder">请设置条件</span>
                                </div>
                                <div class="sort-right" v-if="index!=nodeConfig.conditionNodes.length-1" @click.stop="arrTransfer(index)">
                                    <el-icon><el-icon-arrow-right /></el-icon>
                                </div>
                            </div>
                            <add-node v-model="item.childNode"></add-node>
                        </div>
                    </div>
                    <slot v-if="item.childNode" :node="item"></slot>
                    <div class="top-left-cover-line" v-if="index==0"></div>
                    <div class="bottom-left-cover-line" v-if="index==0"></div>
                    <div class="top-right-cover-line" v-if="index==nodeConfig.conditionNodes.length-1"></div>
                    <div class="bottom-right-cover-line" v-if="index==nodeConfig.conditionNodes.length-1"></div>
                </div>
            </div>
            <add-node v-model="nodeConfig.childNode"></add-node>
        </div>
        <el-drawer title="条件设置" v-model="drawer" destroy-on-close append-to-body :size="600">
            <template #header>
                <div class="node-wrap-drawer__title">
                    <label @click="editTitle" v-if="!isEditTitle">{{form.nodeName}}<el-icon class="node-wrap-drawer__title-edit"><el-icon-edit /></el-icon></label>
                    <el-input v-if="isEditTitle" ref="nodeTitle" v-model="form.nodeName" clearable @blur="saveTitle" @keyup.enter="saveTitle"></el-input>
                </div>
            </template>
            <el-container>
                <el-main style="padding:0 20px 20px 20px">
                    <el-form label-position="top">
                        <el-form-item label="条件关系">
                            <el-radio-group v-model="form.conditionMode">
                                <el-radio :label="1">且</el-radio>
                                <el-radio :label="2">或</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-divider></el-divider>
                        <el-form-item>
                            <el-table :data="form.conditionList">
                                <el-table-column prop="label" label="描述">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.label" placeholder="描述"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="field" label="条件字段" width="130">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.field" placeholder="条件字段"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="operator" label="运算符" width="130">
                                    <template #default="scope">
                                        <el-select v-model="scope.row.operator" placeholder="Select">
                                            <el-option label="等于" value="="></el-option>
                                            <el-option label="不等于" value="!="></el-option>
                                            <el-option label="大于" value=">"></el-option>
                                            <el-option label="大于等于" value=">="></el-option>
                                            <el-option label="小于" value="<"></el-option>
                                            <el-option label="小于等于" value="<="></el-option>
                                            <el-option label="包含" value="include"></el-option>
                                            <el-option label="不包含" value="notinclude"></el-option>
                                        </el-select>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="value" label="值" width="100">
                                    <template #default="scope">
                                        <el-input v-model="scope.row.value" placeholder="值"></el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column prop="value" label="移除" width="55">
                                    <template #default="scope">
                                        <el-link type="danger" :underline="false" @click="deleteConditionList(scope.$index)">移除</el-link>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </el-form-item>
                        <p><el-button type="primary" icon="el-icon-plus" round @click="addConditionList">增加条件</el-button></p>
                    </el-form>
                </el-main>
                <el-footer>
                    <el-button type="primary" @click="save">保存</el-button>
                    <el-button @click="drawer=false">取消</el-button>
                </el-footer>
            </el-container>
        </el-drawer>
    </div>
</template>
 
<script>
    import addNode from './addNode'
 
    export default {
        props: {
            modelValue: { type: Object, default: () => {} }
        },
        components: {
            addNode
        },
        data() {
            return {
                nodeConfig: {},
                drawer: false,
                isEditTitle: false,
                index: 0,
                form: {}
            }
        },
        watch:{
            modelValue(){
                this.nodeConfig = this.modelValue
            }
        },
        mounted() {
            this.nodeConfig = this.modelValue
        },
        methods: {
            show(index){
                this.index = index
                this.form = {}
                this.form = JSON.parse(JSON.stringify(this.nodeConfig.conditionNodes[index]))
                this.drawer = true
            },
            editTitle(){
                this.isEditTitle = true
                this.$nextTick(()=>{
                    this.$refs.nodeTitle.focus()
                })
            },
            saveTitle(){
                this.isEditTitle = false
            },
            save(){
                this.nodeConfig.conditionNodes[this.index] = this.form
                this.$emit("update:modelValue", this.nodeConfig)
                this.drawer = false
            },
            addTerm(){
                let len = this.nodeConfig.conditionNodes.length + 1
                this.nodeConfig.conditionNodes.push({
                    nodeName: "条件" + len,
                    type: 3,
                    priorityLevel: len,
                    conditionMode: 1,
                    conditionList: []
                })
            },
            delTerm(index){
                this.nodeConfig.conditionNodes.splice(index, 1)
                if (this.nodeConfig.conditionNodes.length == 1) {
                    if (this.nodeConfig.childNode) {
                        if (this.nodeConfig.conditionNodes[0].childNode) {
                            this.reData(this.nodeConfig.conditionNodes[0].childNode, this.nodeConfig.childNode)
                        }else{
                            this.nodeConfig.conditionNodes[0].childNode = this.nodeConfig.childNode
                        }
                    }
                    this.$emit("update:modelValue", this.nodeConfig.conditionNodes[0].childNode);
                }
            },
            reData(data, addData) {
                if (!data.childNode) {
                    data.childNode = addData
                } else {
                    this.reData(data.childNode, addData)
                }
            },
            arrTransfer(index, type = 1){
                this.nodeConfig.conditionNodes[index] = this.nodeConfig.conditionNodes.splice(index + type, 1, this.nodeConfig.conditionNodes[index])[0]
                this.nodeConfig.conditionNodes.map((item, index) => {
                    item.priorityLevel = index + 1
                })
                this.$emit("update:modelValue", this.nodeConfig)
            },
            addConditionList(){
                this.form.conditionList.push({
                    label: '',
                    field: '',
                    operator: '=',
                    value: ''
                })
            },
            deleteConditionList(index){
                this.form.conditionList.splice(index, 1)
            },
            toText(nodeConfig, index){
                var { conditionList } = nodeConfig.conditionNodes[index]
                if (conditionList && conditionList.length == 1) {
                    const text = conditionList.map(item => `${item.label}${item.operator}${item.value}`).join(" 和 ")
                    return text
                }else if(conditionList && conditionList.length > 1){
                    const conditionModeText = nodeConfig.conditionNodes[index].conditionMode==1?'且行':'或行'
                    return conditionList.length + "个条件," + conditionModeText
                }else{
                    if(index == nodeConfig.conditionNodes.length - 1){
                        return "其他条件进入此流程"
                    }else{
                        return false
                    }
                }
            }
        }
    }
</script>
 
<style>
</style>