condition.vue
7.71 KB
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
223
224
225
226
227
228
229
230
<!--
* @Author: yangming yangming@didihu.com.cn
* @Date: 2023-12-25 13:34:43
* @LastEditors: yangming yangming@didihu.com.cn
* @LastEditTime: 2024-01-16 10:47:30
* @FilePath: \scrm-micro-peregrination\src\views\journeyModel\components\condition.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
<div>
<div class="condition-select flex">
<el-select v-model="step" placeholder="请选择" :size="size" @change="selectStep">
<el-option v-for="item in stepList" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
<div class="flex">
<el-select v-model="conditionList.flag" placeholder="请选择" :size="size" class="m-r-10" v-if="conditionList.conditions && conditionList.conditions.length > 1">
<el-option v-for="item in conditionList.conditions" :key="item.id" :label="item.name" :value="item.id"></el-option>
</el-select>
<template v-if="condition && condition.operators && condition.operators.length">
<el-select v-model="operators" @change="condition.operators[operators].value = ''" placeholder="请选择" :size="size" class="m-r-10">
<el-option v-for="(item, index) in condition.operators" :key="index" :label="item.name" :value="index"></el-option>
</el-select>
<div class="condition-input" v-if="condition.operators[operators]">
<el-input v-model="condition.operators[operators].value" maxLength="3" oninput="value=value.replace(/^0+|[^1-9\d]/g, '')"></el-input>
</div>
<span>天 切换到此旅程阶段</span>
</template>
</div>
</div>
<div class="condition-more" v-if="condition && condition.subConditions">
<div>
<template>
<div class="flex-column-center m-t-10" v-for="(item, k) in condition.subConditions" :key="item.id">
<label>并且满足</label>
<el-select v-model="item.name" placeholder="请选择" :size="size" class="condition-1" v-if="item.operators">
<el-option v-for="itm in [item.name]" :key="itm" :label="itm" :value="itm"></el-option>
</el-select>
<el-select v-model="item.value" @change="setInputValue(item.operators)" placeholder="请选择" :size="size" class="condition-1" v-if="item.operators">
<el-option v-for="(itm, i) in item.operators" :key="i" :label="itm.name" :value="i"></el-option>
</el-select>
<div class="condition-input" v-if="item.operators[item.value].style == 'input'">
<el-input v-model="item.operators[item.value].value"></el-input>
</div>
<el-select v-model="item.operators[item.value].value" placeholder="请选择" :size="size" class="condition-2" v-if="item.operators[item.value].style == 'select'">
<el-option v-for="i in journeyList" :key="i" :label="i" :value="i"></el-option>
</el-select>
<span>{{ item.operators[item.value].unit }}</span>
<i class="el-icon-delete" @click="delCondition(condition.subConditions, k)"></i>
</div>
<div class="condition-add" @click="addCondition(condition.subConditions)">
<i class="el-icon-circle-plus-outline"></i>
添加条件
</div>
</template>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
step: null,
addFinal: {},
addInfo: {},
condition_i: null,
conditionIndex: 0,
operators: 0,
conditionList: [],
condition: '',
journeyList: [],
stepList: []
}
},
inject: ['stepList', 'app'],
mounted() {
const stepList = this.app.stepList || []
stepList.forEach(item => {
item.flag = ''
item.conditions.forEach(i => {
if (i.subConditions)
i.subConditions.forEach(j => {
j.value = 0
})
})
})
this.stepList = stepList
this.journeyList = this.app.journeyList.filter(i => i)
},
watch: {
'conditionList.flag'(val) {
if (!this.conditionList.conditions.length) return
if (!val) {
val = this.conditionList.conditions[0]
this.conditionList.flag = val.id
}
this.condition = this.conditionList.conditions.find(i => i.id == val)
}
},
methods: {
setInputValue(arr) {
for (let i in arr) {
arr[i].value = ''
}
},
// mergeArr(arr1, arr2, val) {
// // 遍历数组 arr1
// arr1.forEach(a1 => {
// // 在数组 arr2 中查找相同 id 的对象
// const obj = arr2.find(a2 => a1.id === a2.id)
// // 如果找到匹配的对象,则进行覆盖
// if (obj[val] && typeof obj[val] != 'object' && obj[val] != a1[val]) {
// Object.assign(a1, obj)
// }
// })
// },
// contrastObj(obj1, obj2) {
// for (let i in obj1) {
// if (Array.isArray(obj1[i])) {
// this.mergeArr(obj1[i], obj2[i])
// }
// }
// },
setCondition(val, index) {
this.step = val.id
this.conditionListAll = this.$common.utils.deepClone(val)
this.conditionList = this.$common.utils.deepClone(val)
if (this.conditionList.conditions) this.conditionList.conditions = this.conditionList.conditions.filter(i => !i.isHide)
this.condition_i = index
this.condition = this.conditionList.conditions && this.conditionList.conditions[0]
const _conditions = this.stepList.find(i => i.id == val.id).conditions
_conditions.forEach(i => {
if (i.id == this.condition.id && this.condition.subConditions.length == 0 && i.subConditions.length > 0) {
this.condition.subConditions = this.$common.utils.deepClone(i.subConditions)
}
})
console.log(this.condition, _conditions, 'this.conditionList')
},
// 保存最后一项用于新增
delCondition(val, k) {
if (val.length == 1) {
this.addInfo = this.$common.utils.deepClone(val[0])
}
val.splice(k, 1)
},
// 新增条件
addCondition(val) {
let l = val.length,
prop = this.$common.utils.deepClone(val[l - 1])
if (!prop) prop = this.addInfo
console.log(prop, 'prop')
prop.id++
val.push(prop)
},
selectStep(e) {
const conditions = this.stepList.find(item => {
return item.id == e
})
this.conditionListAll = this.$common.utils.deepClone(conditions)
this.conditionList = this.$common.utils.deepClone(conditions)
if (this.conditionList.conditions) this.conditionList.conditions = this.conditionList.conditions.filter(i => !i.isHide)
this.condition = this.conditionList.conditions[0]
}
}
}
</script>
<style lang="scss" scoped>
.dialog-body {
padding: 0px 50px;
}
.require {
color: red;
}
.condition-item {
line-height: 30px;
font-size: 14px;
color: #666666;
.condition-more {
background: #f9f9f9;
padding: 20px;
margin-top: 10px;
.condition-1 {
width: 136px;
margin: 0 10px;
}
.condition-2 {
width: 136px;
}
i {
color: #999999;
margin-left: 10px;
cursor: pointer;
}
.condition-add {
display: flex;
align-items: center;
margin-top: 10px;
cursor: pointer;
i {
font-size: 20px;
margin-right: 6px;
color: #5850ff;
}
font-size: 12px;
color: #5850ff;
}
}
.condition-input {
a {
color: #5850ff;
}
/deep/ {
.el-input {
width: 136px;
margin: 0px 4px;
}
.el-input__inner {
height: 32px;
line-height: 32px;
}
}
}
span {
color: #333333;
}
}
</style>