Commit 9f6f035e by zhangquan

价格区间

1 parent 9efd79f4
import NP from 'number-precision'
const gradeObj = {
gradeConfigList: [
{
servicePeriod: '',
priceGrade: '0',
maxPrice: '15',
minPrice: '0',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
},
{
servicePeriod: '',
priceGrade: '1',
maxPrice: '30',
minPrice: '15',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
},
{
servicePeriod: '',
priceGrade: '2',
maxPrice: '200',
minPrice: '30',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
},
],
salePeriodData: [],
serviceGrade: 'A',
serviceOverview: '',
serviceDetail: ''
gradeConfigList: [
{
servicePeriod: '',
maxPrice: '15',
minPrice: '0',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
},
{
servicePeriod: '',
maxPrice: '30',
minPrice: '15',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
},
{
servicePeriod: '',
maxPrice: '200',
minPrice: '30',
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
}
],
salePeriodData: [],
serviceGrade: 'A',
serviceOverview: '',
serviceDetail: ''
}
const deepClone = (obj)=> {
// Handle the 3 simple types, and null or undefined or function
if (obj == null || typeof obj !== 'object') return obj
// Handle Date
if (obj instanceof Date) {
const copy = new Date()
copy.setTime(obj.getTime())
return copy
}
// Handle Array or Object
if ((obj instanceof Array) | (obj instanceof Object)) {
const copy = obj instanceof Array ? [] : {}
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) {
copy[attr] = deepClone(obj[attr])
}
const deepClone = obj => {
// Handle the 3 simple types, and null or undefined or function
if (obj == null || typeof obj !== 'object') return obj
// Handle Date
if (obj instanceof Date) {
const copy = new Date()
copy.setTime(obj.getTime())
return copy
}
// Handle Array or Object
if ((obj instanceof Array) | (obj instanceof Object)) {
const copy = obj instanceof Array ? [] : {}
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) {
copy[attr] = deepClone(obj[attr])
}
return copy
}
throw new Error("Unable to clone obj! Its type isn't supported.")
return copy
}
throw new Error("Unable to clone obj! Its type isn't supported.")
}
export const addGradeItem = (grade='A' , salePeriodList=[])=>{
export const addGradeItem = (grade = 'A', salePeriodList = []) => {
let _gradeObj = deepClone(gradeObj)
_gradeObj.serviceGrade = grade
salePeriodList = salePeriodList.sort(function(a,b){return a-b});
_gradeObj.salePeriodData = salePeriodList.map(item=>{
return { servicePeriod: item, standardShelfCost: '', standardSalesCost: ''}
salePeriodList = salePeriodList.sort(function(a, b) {
return a - b
})
_gradeObj.salePeriodData = salePeriodList.map(item => {
return { servicePeriod: item, standardShelfCost: '', standardSalesCost: '' }
})
console.log(_gradeObj)
return _gradeObj
}
export const handleGradeData = (dataFromApi, salePeriodList=[])=>{
export const handleGradeData = (dataFromApi, salePeriodList = []) => {
console.log(dataFromApi)
const data = deepClone(dataFromApi)
const data = deepClone(dataFromApi)
let arr = []
data.forEach(element => {
const { serviceOverview, serviceDetail, serviceGrade, gradeConfigList, id } = element
......@@ -81,20 +80,20 @@ export const handleGradeData = (dataFromApi, salePeriodList=[])=>{
serviceGrade,
gradeConfigList: []
}
const gradeList = ['0','1','2'] //三个区间等级,后端定义的
gradeList.forEach(item => {
const _target = gradeConfigList.find(o => o.priceGrade == item)
let { id, servicePeriod, maxPrice, minPrice, priceCoefficient } = _target || {}
gradeConfigList.forEach(item => {
let { id, servicePeriod, maxPrice, minPrice, priceCoefficient } = item || {}
maxPrice = NP.divide(maxPrice || 0, 1000000)
minPrice = NP.divide(minPrice || 0, 1000000)
_gradeObj.gradeConfigList.push({ servicePeriod, priceGrade: item, maxPrice, minPrice, priceCoefficient, id })
_gradeObj.gradeConfigList.push({ servicePeriod, maxPrice, minPrice, priceCoefficient, id })
})
salePeriodList = salePeriodList.sort(function(a,b){return a-b})
_gradeObj.salePeriodData = salePeriodList.map(item=>{
const _target = element.gradeConfigList.find( o => o.servicePeriod == item)
return { servicePeriod: item, standardShelfCost: NP.divide(_target?.standardShelfCost || 0, 100), standardSalesCost: NP.divide(_target?.standardSalesCost || 0, 100)}
salePeriodList = salePeriodList.sort(function(a, b) {
return a - b
})
_gradeObj.salePeriodData = salePeriodList.map(item => {
const _target = element.gradeConfigList.find(o => o.servicePeriod == item)
return { servicePeriod: item, standardShelfCost: NP.divide(_target?.standardShelfCost || 0, 100), standardSalesCost: NP.divide(_target?.standardSalesCost || 0, 100) }
})
arr.push(_gradeObj)
});
})
return arr
}
\ No newline at end of file
}
......@@ -349,8 +349,8 @@ export default {
this.gradeList.forEach(item => {
const { id, serviceGrade, serviceOverview, serviceDetail, salePeriodData, gradeConfigList } = item
let _gradeConfigList = []
gradeConfigList.forEach(ele => {
let { priceGrade, priceCoefficient, minPrice, maxPrice } = ele
gradeConfigList.forEach((ele, eleIdx) => {
let { priceCoefficient, minPrice, maxPrice } = ele
if (this.isEmpty(minPrice) || this.isEmpty(maxPrice) || this.isEmpty(priceCoefficient)) {
throw new Error(`请输入${serviceGrade}规格的${this.isEmpty(priceCoefficient) ? '价格系数' : '价格区间'}`)
}
......@@ -363,7 +363,7 @@ export default {
let max_price = NP.times(maxPrice || 0, 1000000)
standardSalesCost = NP.times(standardSalesCost || 0, 100)
standardShelfCost = NP.times(standardShelfCost || 0, 100)
let gradeConfigObj = { id, priceGrade, priceCoefficient, minPrice: min_price, maxPrice: max_price, servicePeriod, standardSalesCost, standardShelfCost }
let gradeConfigObj = { id, priceGrade: eleIdx, priceCoefficient, minPrice: min_price, maxPrice: max_price, servicePeriod, standardSalesCost, standardShelfCost }
_gradeConfigList.push(gradeConfigObj)
})
})
......
......@@ -6,6 +6,7 @@
<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">操作</th>
</tr>
<tr>
<template v-for="(item, index) in tableData.salePeriodData">
......@@ -24,28 +25,33 @@
</template>
</tr>
<tr>
<td rowspan="4">{{ tableData.serviceGrade }}</td>
<td :rowspan="tableData.gradeConfigList.length + 2">{{ tableData.serviceGrade }}</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')" @blur="formatPrice($event, item, 'minPrice', 200)" :disabled="disabled" v-model="item.minPrice"></el-input>
<el-input :placeholder="placeholder" @input="changePrice($event, item, 'minPrice')" :disabled="disabled" v-model="item.minPrice"></el-input>
<span class="sign">-</span>
<el-input :placeholder="placeholder" @input="changePrice($event, item, 'maxPrice')" @blur="formatPrice($event, item, 'maxPrice', 200)" :disabled="disabled" v-model="item.maxPrice"></el-input>
<el-input :placeholder="placeholder" @input="changePrice($event, item, 'maxPrice')" :disabled="disabled" v-model="item.maxPrice"></el-input>
</td>
<td><el-input :placeholder="placeholder" @input="changePrice($event, item, 'priceCoefficient')" :disabled="disabled" @blur="formatPrice($event, item, 'priceCoefficient', 100)" v-model="item.priceCoefficient"></el-input></td>
<template v-for="(ele, eIdx) in tableData.salePeriodData">
<td :key="eIdx">{{ calcPrice(ele.standardShelfCost, item.priceCoefficient) }}</td>
<td :key="eIdx">{{ calcPrice(ele.standardSalesCost, item.priceCoefficient) }}</td>
</template>
<td class="del-btn"><span v-if="index > 2" class="btn" @click="delSection(index)">删除</span></td>
</tr>
<tr>
<td class="add-btn" :colspan="tableData.salePeriodData.length * 2 + 3"><span class="btn" @click="addSection">新增价格区间</span></td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 3">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 4">
<div class="desc">
<label for="">服务条款概述:</label>
<Editor :disabled="disabled" :hasTool="false" :editorOption="overviewOption" v-model="tableData.serviceOverview"></Editor>
......@@ -53,7 +59,7 @@
</td>
</tr>
<tr class="desc-wrap">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 3">
<td class="desc-td" :colspan="tableData.salePeriodData.length * 2 + 4">
<div class="desc">
<label for="">规格详细描述:</label>
<Editor :disabled="disabled" :hasTool="false" :editorOption="DetailOption" v-model="tableData.serviceDetail"></Editor>
......@@ -158,12 +164,42 @@ export default {
})
Delta.ops = ops
return Delta
},
addSection() {
// 获取最后一个的最大价格赋值到新增的最小价格
const minPrice = this.tableData.gradeConfigList[this.tableData.gradeConfigList.length - 1].maxPrice
let sectionItem = {
servicePeriod: '',
maxPrice: '',
minPrice,
priceCoefficient: '',
standardShelfCost: '',
standardSalesCost: ''
}
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 {
.del-btn {
color: #5f5efb;
}
.btn {
cursor: pointer;
}
.add-btn {
color: #5f5efb;
text-align: left;
}
.tip {
width: 14px;
vertical-align: middle;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!