StepBar.vue
4.46 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
<template>
<div>
<div class="step-bar container m-b-20">
<div v-for="(step, index) in steps" :key="index" class="step ">
<div :class="['step-content', { 'active': index === currentStep },{ 'completed': index < currentStep }]">
<div class="step-circle">{{ currentStep > index ? '' : index + 1 }}</div>
<div class="step-label">{{ step }}</div>
</div>
<div class="step-line" v-if="index < steps.length - 1"></div>
</div>
</div>
<div class="center">
<slot name="center"></slot>
</div>
<div class="button-container">
<el-button v-if="currentStep > 0" @click="previousStep" class="previous-button">上一步</el-button>
<el-button v-if="currentStep == 0" @click="cancelOptions" class="previous-button">取消</el-button>
<el-button type="primary" v-if="currentStep < steps.length - 1" @click="nextStep" class="next-button">下一步
</el-button>
<el-button type="primary" v-if="currentStep == steps.length - 1" class="previous-button" @click="saveTemplate">
保存
</el-button>
</div>
</div>
</template>
<script>
export default {
data() {
return {
currentStep: 0, // 当前步骤
isNext: false,
steps: ['选择旅程模版', '配置旅程SOP', '分配门店'], // 步骤条的文本
tplId: '',
sopTplGrants: null,
nodes:[]
};
},
methods: {
previousStep() {
if (this.currentStep > 0) {
this.currentStep--;
this.$emit('changeStep', this.currentStep)
}
},
nextStep() {
// 每次进入先把isNext赋值为false 校验通过后再赋值为true
this.isNext = false
if (this.currentStep == 0) {
this.$bus.$emit('vertifyTemplate', {currentStep: this.currentStep})
}
if (this.currentStep < this.steps.length - 1 && (this.isNext || this.currentStep == 1)) {
this.currentStep++;
this.$emit('changeStep', this.currentStep)
}
},
cancelOptions() {
this.$router.back()
},
saveTemplate() {
// 校验门店
this.isNext = false
this.$bus.$emit('vertifyMerchant', {currentStep: this.currentStep})
let params = {
tplId: this.tplId,
sopTplGrants:this.sopTplGrants,
nodes:this.nodes
}
if (this.isNext){
this.$apis.journeyConfig.sopInstsApi(params).then(res=>{
if (res && res.code == 200 ){
console.log(res)
this.$message.success('创建模板实例成功')
this.$router.back()
}else{
this.$message.error(res.message)
}
}).catch(err => {
console.log(err + 'err')
})
}
}
},
mounted() {
this.$bus.$on('whetherToProceedNext', (data) => {
this.isNext = data.isNext
this.tplId = data.tplId
})
this.$bus.$on('saveEvent', (data) => {
this.isNext = data.isNext
this.sopTplGrants = data.sopTplGrants
})
this.$bus.$on('sopListSet',data =>{
this.nodes = data.sopList
})
}
};
</script>
<style lang="scss" scoped>
.step-bar {
display: flex;
align-items: center;
justify-content: center;
.step {
display: flex;
align-items: center;
//margin: 0 10px;
&::before {
content: '';
flex-grow: 1;
height: 2px;
background-color: #ccc;
margin-right: 5px;
}
&:first-child::before {
display: none;
}
& .active {
.step-circle {
border-color: #5850FF;
background: #5850FF;
color: #ffffff;
}
.step-label {
color: #5850FF;
}
}
& .completed {
.step-circle {
border-color: #5850FF;
&::after {
content: "√";
color: #5850FF;
font-size: 20px;
}
}
}
.step-line {
height: 1px;
width: 200px;
background: #ccc;
margin-left: 10px;
}
.step-content {
display: flex;
align-items: center;
}
.step-circle {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2px solid #ccc;
display: flex;
align-items: center;
justify-content: center;
}
.step-label {
margin-left: 10px;
text-align: center;
}
}
}
//.center{
// min-height: 700px;
//}
.button-container {
//bottom: 0;
display: flex;
justify-content: center;
margin-top: 20px;
.previous-button,
.next-button {
padding: 10px 20px;
margin: 0 10px;
}
}
</style>