index.vue
14.4 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<template>
<div class="table-wrap">
<table>
<tr class="th-wrap">
<th rowspan="2">规格</th>
<th rowspan="2">价格区间(万元)</th>
<th rowspan="2">是否计算</th>
<th rowspan="2">价格系数</th>
<th colspan="2" v-for="(item, index) in tableData.salePeriodData" :key="index">{{ item.servicePeriod }}年版</th>
<th rowspan="2" style="white-space: nowrap">操作</th>
</tr>
<tr>
<template v-for="(item, index) in tableData.salePeriodData">
<th :key="index">
上架成本
<!-- <el-tooltip class="item" effect="dark" content="提示待运营提供" placement="top">
<img class="tip" :src="require('@/assets/tip.png')" />
</el-tooltip> -->
</th>
<th :key="index">
嘀加成本
<!-- <el-tooltip class="item" effect="dark" content="提示待运营提供" placement="top">
<img class="tip" :src="require('@/assets/tip.png')" />
</el-tooltip> -->
</th>
</template>
</tr>
<tr>
<td :rowspan="tableData.gradeConfigList.length + 2">{{ tableData.serviceGrade }}</td>
<td>标准</td>
<td>-</td>
<td>-</td>
<template v-for="(item, index) in tableData.salePeriodData">
<td :key="index"><el-input :placeholder="placeholder" @input="changePrice($event, item, 'standardShelfCost')" :disabled="disabled" v-model="item.standardShelfCost"></el-input></td>
<td :key="index"><el-input :placeholder="placeholder" @input="changePrice($event, item, 'standardSalesCost')" :disabled="disabled" v-model="item.standardSalesCost"></el-input></td>
</template>
<td></td>
</tr>
<tr v-for="(item, index) in tableData.gradeConfigList" :key="index">
<td class="price">
<el-input :placeholder="placeholder" @input="changePrice($event, item, 'minPrice')" :disabled="disabled || (routeInfo.id && !item.addFlag)" v-model="item.minPrice"></el-input>
<span class="sign">-</span>
<el-input :placeholder="placeholder" @input="changePrice($event, item, 'maxPrice')" :disabled="disabled || (routeInfo.id && !item.addFlag)" v-model="item.maxPrice"></el-input>
</td>
<td><el-switch v-model="item.computeFlag" :active-value="0" @change="changeComputeFlag($event, item, index)" :inactive-value="1" :disabled="disabled"></el-switch></td>
<td>
<span v-if="item.computeFlag == 1">-</span>
<el-input v-else :placeholder="placeholder" @input="changePrice($event, item, 'priceCoefficient', index)" :disabled="disabled" v-model="item.priceCoefficient" @blur="formatPrice($event, item, 'priceCoefficient', 100)"></el-input>
</td>
<template v-for="(ele, eIdx) in tableData.salePeriodData">
<template v-if="item.computeFlag == 0">
<td :key="eIdx">{{ calcPrice(ele.standardShelfCost, item.priceCoefficient) }}</td>
<td :key="eIdx">{{ calcPrice(ele.standardSalesCost, item.priceCoefficient) }}</td>
</template>
<template v-if="item.computeFlag == 1">
<td :key="eIdx"><el-input v-model="item.childSalePeriodData[eIdx].shelfCost" :placeholder="placeholder" @input="changePrice($event, item.childSalePeriodData[eIdx], 'shelfCost')" :disabled="disabled"></el-input></td>
<td :key="eIdx"><el-input v-model="item.childSalePeriodData[eIdx].salesCost" :placeholder="placeholder" @input="changePrice($event, item.childSalePeriodData[eIdx], 'salesCost')" :disabled="disabled"></el-input></td>
</template>
</template>
<td class="del-btn"><span v-if="!disabled" class="btn" @click="delSection(index)">删除</span></td>
</tr>
<tr>
<td class="add-btn" :colspan="tableData.salePeriodData.length * 2 + 4"><span v-if="!disabled" class="btn" @click="addSection">新增价格区间</span></td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 5">
<div class="desc">
<label for="">服务条款概述:</label>
<Editor :disabled="disabled" :editorOption="overviewOption" v-model="tableData.serviceOverview"></Editor>
</div>
</td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 5">
<div class="desc">
<label for="">规格详细描述:</label>
<Editor :disabled="disabled" :editorOption="DetailOption" v-model="tableData.serviceDetail"></Editor>
</div>
</td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 5">
<div class="desc condition-desc">
<label class="required-label">购买条件:</label>
<div class="buy-condition">
<el-checkbox-group :disabled="disabled" v-model="tableData.buyConditions">
<el-checkbox v-for="(item, index) in conditionList" :disabled="!item.id" :label="item.id" :key="item.id || index">
<span class="sign">条件{{ index + 1 }}</span>
<div class="condition-text">
<span v-if="!item.newItem" class="condition">{{ item.contractContent }}</span>
<el-input class="condition-input" v-focus v-else type="textarea" v-model="curEditCondition.value" @blur.stop="$emit('create-config', 0, item)"></el-input>
<i v-if="!item.newItem && !disabled" class="el-icon-edit-outline edit" @click.prevent="$emit('edit-condition', item, 'conditionList')"></i>
</div>
</el-checkbox>
</el-checkbox-group>
<div v-if="!disabled" class="add-btn" @click="$emit('add-condition', 'conditionList')">
<i class="el-icon-circle-plus-outline"></i>
新增条件
</div>
</div>
</div>
</td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 5">
<div class="desc">
<label class="required-label">前提条件:</label>
<Editor :disabled="disabled" v-model="tableData.prerequisite"></Editor>
</div>
</td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 5">
<div class="desc condition-desc">
<label class="required-label">除外责任:</label>
<div class="buy-condition">
<el-checkbox-group :disabled="disabled" v-model="tableData.exclusionsResponsibility">
<el-checkbox v-for="(item, index) in responsibilityList" :disabled="!item.id" :label="item.id" :key="item.id || index">
<span class="sign">责任{{ index + 1 }}</span>
<div class="condition-text">
<span v-if="!item.newItem" class="condition">{{ item.contractContent }}</span>
<el-input class="condition-input" v-focus v-else type="textarea" v-model="curEditCondition.value" @blur.stop="$emit('create-config', 1, item)"></el-input>
<i v-if="!item.newItem && !disabled" class="el-icon-edit-outline edit" @click.prevent="$emit('edit-condition', item, 'responsibilityList')"></i>
</div>
</el-checkbox>
</el-checkbox-group>
<div v-if="!disabled" class="add-btn" @click="$emit('add-condition', 'responsibilityList')">
<i class="el-icon-circle-plus-outline"></i>
新增责任
</div>
</div>
</div>
</td>
</tr>
</table>
</div>
</template>
<script>
import Editor from '@/components/Editor'
export default {
name: 'ServicesTable',
components: {
Editor
},
props: {
name: {
type: String,
default: ''
},
tableData: {
type: Object,
default: () => {
return {}
}
},
disabled: {
type: Boolean,
default: false
},
conditionList: {
type: Array,
default: () => []
},
responsibilityList: {
type: Array,
default: () => []
},
curEditCondition: {
type: Object,
default: () => ({})
},
url: {
type: String,
default: ''
},
key: {
type: String,
default: ''
},
routeInfo: {
type: Object,
default: () => {
return {}
}
}
},
data() {
return {
placeholder: '请输入',
overviewOption: {
placeholder: '请输入服务条款概述',
modules: {
toolbar: false,
clipboard: {
// 粘贴版,处理粘贴时候的自带样式
matchers: [[Node.ELEMENT_NODE, this.HandleCustomMatcher]]
}
}
},
DetailOption: {
placeholder: '请输入规格详细描述',
modules: {
toolbar: false,
clipboard: {
// 粘贴版,处理粘贴时候的自带样式
matchers: [[Node.ELEMENT_NODE, this.HandleCustomMatcher]]
}
}
}
}
},
directives: {
focus: {
inserted(el) {
el.querySelector('textarea').focus()
}
}
},
methods: {
changePrice(value, item, key) {
const decimal = ['standardShelfCost', 'standardSalesCost', 'minPrice', 'maxPrice'].includes(key) ? 2 : 16
const maxNum = ['minPrice', 'maxPrice'].includes(key) ? 200 : null
item[key] = value
? value
.replace(/^0\d/g, '0')
.replace(/[^\d.]/g, '')
.replace(/^\./g, '')
.replace(/^\d{6}\d+(\.\d+)?/g, value.substr(0, 6))
.replace(/\.{2,}/g, '')
.replace('.', '$#$')
.replace(/\./g, '')
.replace('$#$', '.')
.replace(new RegExp(`^(\\-)*(\\d+)\\.(\\d{${decimal}}).*`, 'g'), '$1$2.$3')
.replace(new RegExp(`^(-?\\d+(?:\\.\\d{0,${decimal}})?).*`), match => {
if (maxNum !== null) {
const num = parseFloat(match)
if (num > maxNum) {
return maxNum.toString()
}
}
return match
})
: ''
},
changeComputeFlag(e, item) {
if (e == 1) {
item?.childSalePeriodData?.forEach(ele => {
ele.shelfCost = ''
ele.salesCost = ''
})
}
},
formatPrice(e, item, key, maxNum) {
let num = e.target.value
if (num > maxNum) {
item[key] = maxNum
}
},
calcPrice(price1, price2) {
price1 = price1 || 0
price2 = price2 || 0
return Number((price1 * price2)?.toFixed(2))
},
HandleCustomMatcher(node, Delta) {
// 文字、图片等,从别处复制而来,清除自带样式,转为纯文本
let ops = []
Delta.ops.forEach(op => {
if (op.insert && typeof op.insert === 'string') {
ops.push({
insert: op.insert
})
}
})
Delta.ops = ops
return Delta
},
addSection() {
if (this.tableData.gradeConfigList?.length >= 20) return this.$message.error('最多添加20个价格区间')
// 获取最后一个的最大价格赋值到新增的最小价格
const minPrice = this.tableData.gradeConfigList[this.tableData.gradeConfigList.length - 1]?.maxPrice || ''
const arr = this.tableData.salePeriodData.map(item => {
return { servicePeriod: item.servicePeriod, standardShelfCost: '', standardSalesCost: '', shelfCost: '', salesCost: '' }
})
let sectionItem = {
servicePeriod: '',
maxPrice: '',
minPrice,
computeFlag: 0,
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: '',
childSalePeriodData: arr,
addFlag: true
}
this.tableData.gradeConfigList.push(sectionItem)
},
delSection(idx) {
// const minPrice = this.tableData.gradeConfigList[idx - 1]?.maxPrice
this.tableData.gradeConfigList.splice(idx, 1)
// if (this.tableData.gradeConfigList.length > idx) {
// this.$set(this.tableData.gradeConfigList[idx], 'minPrice', minPrice)
// }
}
}
}
</script>
<style lang="scss" scoped>
.table-wrap {
.th-wrap {
white-space: nowrap;
}
.del-btn {
color: #5f5efb;
}
.btn {
cursor: pointer;
}
.add-btn {
color: #5f5efb;
text-align: left;
}
.tip {
width: 14px;
vertical-align: middle;
margin-bottom: 2px;
cursor: pointer;
}
/deep/ .el-input__inner {
padding: 0 2px;
text-align: center;
}
th,
td {
border: 1px solid #e5e5e5;
padding: 0 16px;
vertical-align: middle;
text-align: center;
}
th {
background: #f4f6fc;
font-weight: 600;
font-size: 14px;
color: #333333;
}
td {
font-weight: 400;
height: 56px;
font-size: 14px;
color: #666666;
}
.price {
width: 136px;
.sign {
margin: 0 6px;
}
.el-input {
width: 50px;
}
}
.desc-wrap {
height: 88px;
.desc-td {
height: auto;
padding: 12px 16px;
}
.desc {
display: flex;
height: 100%;
label {
white-space: nowrap;
}
/deep/ .editor {
width: 100%;
text-align: left;
border-radius: 4px;
.w-e-text-container {
border-radius: 4px;
}
}
}
.condition-desc {
align-items: flex-start;
text-align: left;
.buy-condition {
flex: 1;
.el-checkbox {
display: block;
width: fit-content;
margin-bottom: 10px;
}
.condition-text {
display: inline-flex;
align-items: center;
}
.condition-input {
width: 592px;
}
.sign {
margin-right: 8px;
}
.condition {
display: inline-block;
box-sizing: border-box;
vertical-align: text-top;
white-space: pre-wrap;
width: 592px;
line-height: 32px;
background: #f5f7fa;
border-radius: 4px;
padding: 0 12px;
font-size: 14px;
color: #333333;
}
.edit {
color: #c6c6c6;
margin-left: 8px;
}
}
}
.required-label::before {
content: '*';
margin-right: 4px;
color: #f56c6c;
}
}
}
</style>