|
@@ -3,15 +3,18 @@
|
|
|
<el-form ref="form" label-width="156px" class="performance-belongs-container">
|
|
|
<el-form-item class="performance-belongs-line" label="销售人员" :required="required.salePerson">
|
|
|
<SelectTree
|
|
|
- v-model="form.salePerson"
|
|
|
class="sales-person-select"
|
|
|
+ :value="pageForm.salePerson"
|
|
|
+ @input="setPageFormData('salePerson', $event)"
|
|
|
@change="onSalePersonSelectChange"
|
|
|
:options="salesDepList"
|
|
|
placeholder="请选择销售人员">
|
|
|
</SelectTree>
|
|
|
- <div class="sale-person-list-container" v-if="form.salePerson.length > 1">
|
|
|
+ <div class="sale-person-list-container" v-if="pageForm.salePerson.length > 1">
|
|
|
<el-table
|
|
|
- :data="form.salePersonTableList"
|
|
|
+ :data="pageForm.salePersonTableList"
|
|
|
+ :summary-method="getSummaries"
|
|
|
+ show-summary
|
|
|
stripe
|
|
|
border>
|
|
|
<el-table-column
|
|
@@ -24,13 +27,15 @@
|
|
|
prop="money"
|
|
|
header-align="center"
|
|
|
align="center"
|
|
|
- label="预计回款金额(元)">
|
|
|
+ label="销售业绩(元)">
|
|
|
<template slot-scope="scope">
|
|
|
<number-input
|
|
|
- v-model.number="form.salePersonTableList[scope.$index].money"
|
|
|
+ :value="pageForm.salePersonTableList[scope.$index].money"
|
|
|
+ @input="onSalePersonSplitMoneyChange(scope, $event)"
|
|
|
+ :disabled="scope.$index === getLastEditLineIndex()"
|
|
|
type="number"
|
|
|
+ :decimal="2"
|
|
|
placeholder="请输入"
|
|
|
- @input="onSalePersonSplitMoneyChange(scope)"
|
|
|
size="medium"
|
|
|
></number-input>
|
|
|
</template>
|
|
@@ -41,16 +46,14 @@
|
|
|
align="center"
|
|
|
label="销售渠道">
|
|
|
<template slot-scope="scope" >
|
|
|
- <template v-if="scope.$index === form.salePersonTableList.length - 1">-</template>
|
|
|
- <template v-else>
|
|
|
- <el-cascader
|
|
|
- :options="saleChannelOptions"
|
|
|
- :props="conf.cascaderProps"
|
|
|
- v-model="form.salePersonTableList[scope.$index].saleWay"
|
|
|
- size="medium"
|
|
|
- placeholder="请选择销售渠道"
|
|
|
- clearable></el-cascader>
|
|
|
- </template>
|
|
|
+ <el-cascader
|
|
|
+ :options="saleChannelOptions"
|
|
|
+ :props="conf.cascaderProps"
|
|
|
+ :value="pageForm.salePersonTableList[scope.$index].saleWay"
|
|
|
+ @input="onChangeTableLineData('saleWay', scope.$index, $event)"
|
|
|
+ size="medium"
|
|
|
+ placeholder="请选择销售渠道"
|
|
|
+ clearable></el-cascader>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
@@ -58,7 +61,8 @@
|
|
|
</el-form-item>
|
|
|
<el-form-item class="performance-belongs-line" label="销售渠道" v-if="onlyOneSale" :required="required.saleWay && onlyOneSale">
|
|
|
<el-cascader
|
|
|
- v-model="form.saleWay"
|
|
|
+ :value="pageForm.saleWay"
|
|
|
+ @input="setPageFormData('saleWay', $event)"
|
|
|
:options="saleChannelOptions"
|
|
|
:props="conf.cascaderProps"
|
|
|
size="medium"
|
|
@@ -69,24 +73,15 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { debounce } from 'lodash'
|
|
|
-import { selectorVModelMixin } from '@/utils/mixins/selector-v-model'
|
|
|
import NumberInput from '@/views/create-order/ui/NumberInput.vue'
|
|
|
import SelectTree from '@/views/create-order/components/product-info-submodule/select-tree'
|
|
|
import { mapState, mapGetters } from 'vuex'
|
|
|
-
|
|
|
-class SalePersonTableRow {
|
|
|
- constructor(name = '', id = '', money = '', saleWay = '') {
|
|
|
- this.name = name
|
|
|
- this.id = id
|
|
|
- this.money = money
|
|
|
- this.saleWay = saleWay
|
|
|
- }
|
|
|
-}
|
|
|
+import { pageFormState } from '@/views/create-order/mixins'
|
|
|
+import { SalePersonTableRow } from '@/views/create-order/data/interface'
|
|
|
|
|
|
export default {
|
|
|
name: 'PerformanceBelongsModule',
|
|
|
- mixins: [selectorVModelMixin],
|
|
|
+ mixins: [pageFormState],
|
|
|
components: {
|
|
|
NumberInput,
|
|
|
SelectTree,
|
|
@@ -116,31 +111,39 @@ export default {
|
|
|
saleWay: false,
|
|
|
},
|
|
|
form: {
|
|
|
- salePerson: [],
|
|
|
- saleWay: [],
|
|
|
- salePersonTableList: [],
|
|
|
+ // salePerson: [],
|
|
|
+ // saleWay: [],
|
|
|
+ // salePersonTableList: [],
|
|
|
},
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters([
|
|
|
- 'getAdminUser',
|
|
|
- ]),
|
|
|
+ ...mapState({
|
|
|
+ currentUserId: state => state.order.conf.currentUserEntId,
|
|
|
+ defaultSaleChannel: state => state.order.conf.defaultSaleChannel,
|
|
|
+ }),
|
|
|
...mapGetters('order', [
|
|
|
'depTreeList',
|
|
|
'saleChannelOptions',
|
|
|
+ 'pageTotalMoney',
|
|
|
+ 'salesMoneyTotal',
|
|
|
]),
|
|
|
salesDepList() {
|
|
|
return this.depTreeList
|
|
|
},
|
|
|
onlyOneSale() {
|
|
|
- return this.form.salePerson.length === 1
|
|
|
+ return this.pageForm.salePerson.length === 1
|
|
|
},
|
|
|
salePersonDetailInfo() {
|
|
|
- return this.form.salePerson.map(fs => {
|
|
|
+ return this.pageForm.salePerson.map(fs => {
|
|
|
return this.deepestNodesArr.find(r => r.value === fs)
|
|
|
})
|
|
|
},
|
|
|
+ salesMoneyTotalNum() {
|
|
|
+ // 销售业绩=合同金额-渠道佣金
|
|
|
+ // return this.pageTotalMoney.contract - this.pageForm.channelCommission
|
|
|
+ return this.salesMoneyTotal
|
|
|
+ },
|
|
|
deepestNodesArr() {
|
|
|
return this.findDeepestNodes(this.salesDepList)
|
|
|
},
|
|
@@ -162,14 +165,23 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
watch: {
|
|
|
- 'form.salePerson': function() {
|
|
|
+ 'pageForm.salePerson': function() {
|
|
|
this.initSaleWayDefaultValue()
|
|
|
+ },
|
|
|
+ currentUserId: {
|
|
|
+ immediate: true,
|
|
|
+ handler() {
|
|
|
+ this.setDefaultUserFn()
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
+ created() {
|
|
|
+ window.t = this
|
|
|
+ },
|
|
|
methods: {
|
|
|
validate() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- const { salePerson, saleWay } = this.form
|
|
|
+ const { salePerson, saleWay } = this.pageForm
|
|
|
const pass = salePerson.length > 0 && saleWay.length > 0
|
|
|
if (pass) {
|
|
|
resolve()
|
|
@@ -178,12 +190,12 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- getState() {
|
|
|
- return Object.assign({}, this.form)
|
|
|
- },
|
|
|
- setState(t) {
|
|
|
- if (!t) return
|
|
|
- Object.assign(this.form, t)
|
|
|
+ setDefaultUserFn() {
|
|
|
+ if (this.setDefaultUser) {
|
|
|
+ if (this.currentUserId) {
|
|
|
+ this.setPageFormData('salePerson', [this.currentUserId])
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
findDeepestNodes(treeData = []) {
|
|
|
let deepestNodes = []
|
|
@@ -203,21 +215,9 @@ export default {
|
|
|
|
|
|
return deepestNodes
|
|
|
},
|
|
|
- getSaleWayOption() {
|
|
|
- if (this.conf.saleWayOptions.length > 0) return
|
|
|
- this.loading.saleWay = true
|
|
|
- const r = this.$store.dispatch('order/getSelectOptions')
|
|
|
- this.$request('/order/getSalesChannelItem').data({ name: '销售渠道' }).success((res) => {
|
|
|
- this.conf.saleWayOptions = res.data?.data || []
|
|
|
- }).complete(() => {
|
|
|
-
|
|
|
- }).post()
|
|
|
-
|
|
|
- this.loading.saleWay = false
|
|
|
- },
|
|
|
getSelectSalePersonDetailList() {
|
|
|
// 按照选择的顺序取
|
|
|
- const { salePerson } = this.form
|
|
|
+ const { salePerson } = this.pageForm
|
|
|
const arr = []
|
|
|
salePerson.forEach(id => {
|
|
|
const target = this.deepestNodesArr.find(opt => opt.value === id)
|
|
@@ -233,16 +233,16 @@ export default {
|
|
|
initSalePersonList() {
|
|
|
const selectDetailList = this.getSelectSalePersonDetailList()
|
|
|
const arr = selectDetailList.map(item => {
|
|
|
- return new SalePersonTableRow(item.label, item.value)
|
|
|
+ const saleWayKey = this.getDefaultSaleWayKey(item)
|
|
|
+ return new SalePersonTableRow(item.label, item.value, '', saleWayKey)
|
|
|
})
|
|
|
- arr.push(new SalePersonTableRow('合计'))
|
|
|
- this.form.salePersonTableList = arr
|
|
|
+ this.setPageFormData('salePersonTableList', arr)
|
|
|
},
|
|
|
calcSalePersonLastColumnMoney() {
|
|
|
// 1. 计算最后一个格子的金额
|
|
|
let eNum = 0
|
|
|
- this.form.salePersonTableList.forEach((p, index) => {
|
|
|
- if (index <= this.form.salePersonTableList.length - 2) {
|
|
|
+ this.pageForm.salePersonTableList.forEach((p, index) => {
|
|
|
+ if (index <= this.getLastEditLineIndex()) {
|
|
|
eNum += Number(p.money)
|
|
|
}
|
|
|
})
|
|
@@ -251,52 +251,124 @@ export default {
|
|
|
compareDepName(a = '', b = '') {
|
|
|
return a.includes(b) || b.includes(a)
|
|
|
},
|
|
|
+ getSummaries(param) {
|
|
|
+ const { columns } = param
|
|
|
+ const sums = [];
|
|
|
+ columns.forEach((column, index) => {
|
|
|
+ if (index === 0) {
|
|
|
+ sums[index] = '合计';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (index === 1) {
|
|
|
+ sums[index] = this.salesMoneyTotalNum || '-';
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (index === 2) {
|
|
|
+ sums[index] = '-';
|
|
|
+ return
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return sums;
|
|
|
+ },
|
|
|
initSaleWayDefaultValue() {
|
|
|
- const { salePerson } = this.form
|
|
|
+ const { salePerson } = this.pageForm
|
|
|
if (salePerson.length === 1) {
|
|
|
const depInfo = this.salePersonDetailInfo[0]
|
|
|
- const saleWayKey = this.getDefaultSaleWayKey(depInfo.parentLabel)
|
|
|
- this.form.saleWay = saleWayKey
|
|
|
+ const saleWayKey = this.getDefaultSaleWayKey(depInfo)
|
|
|
+ // this.form.saleWay = saleWayKey
|
|
|
+ if (saleWayKey) {
|
|
|
+ this.setPageFormData('saleWay', saleWayKey)
|
|
|
+ }
|
|
|
} else {
|
|
|
this.salePersonDetailInfo.forEach((depInfo, index) => {
|
|
|
- const saleWayKey = this.getDefaultSaleWayKey(depInfo.parentLabel)
|
|
|
- this.form.salePersonTableList[index].saleWay = saleWayKey
|
|
|
+ const saleWayKey = this.getDefaultSaleWayKey(depInfo)
|
|
|
+ // this.form.salePersonTableList[index].saleWay = saleWayKey
|
|
|
+ if (saleWayKey) {
|
|
|
+ this.onChangeTableLineData('saleWay', index, saleWayKey)
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- getDefaultSaleWayKey(name) {
|
|
|
- let parentLevel = null
|
|
|
- let childLevel = null
|
|
|
- const arr = []
|
|
|
- parentLevel = this.saleChannelOptions.find(first => {
|
|
|
- if (Array.isArray(first.children)) {
|
|
|
- const target = first.children.find(s => {
|
|
|
- const res = this.compareDepName(s.item_name, name)
|
|
|
- if (res) {
|
|
|
- childLevel = s
|
|
|
- return s
|
|
|
- }
|
|
|
- })
|
|
|
- if (target) {
|
|
|
- return first
|
|
|
- }
|
|
|
+ getSaleWayIdWith2(id) {
|
|
|
+ const prop = this.conf.cascaderProps.value
|
|
|
+ const target = this.saleChannelOptions.find(channel => {
|
|
|
+ if (Array.isArray(channel.children)) {
|
|
|
+ return channel.children.find(c => c[prop] === id)
|
|
|
}
|
|
|
+ console.log(channel.children)
|
|
|
})
|
|
|
- if (parentLevel && childLevel) {
|
|
|
- arr.push(parentLevel.item_code)
|
|
|
- arr.push(childLevel.item_code)
|
|
|
+ if (target) {
|
|
|
+ return target[prop]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getDefaultSaleWayKey(depInfo) {
|
|
|
+ const deptId = depInfo.deptId
|
|
|
+ if (this.defaultSaleChannel) {
|
|
|
+ const defaultSaleWayId = this.defaultSaleChannel[deptId]
|
|
|
+ if (defaultSaleWayId) {
|
|
|
+ const saleWayKey2 = this.getSaleWayIdWith2(defaultSaleWayId)
|
|
|
+ if (saleWayKey2) {
|
|
|
+ const saleWayKey = [saleWayKey2, defaultSaleWayId]
|
|
|
+ return saleWayKey
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- return arr || []
|
|
|
},
|
|
|
- onSalePersonSplitMoneyChange: debounce(function(scope) {
|
|
|
- if (scope.$index === this.form.salePersonTableList.length - 1) {
|
|
|
- // 最后一行,不做处理
|
|
|
- return
|
|
|
+ calcLastColumnMoney() {
|
|
|
+ // 1. 计算最后一个格子的金额
|
|
|
+ // 1.1 先计算除了最后一个的总和
|
|
|
+ let eNum = 0
|
|
|
+ this.pageForm.salePersonTableList.forEach((p, index) => {
|
|
|
+ if (index <= this.pageForm.salePersonTableList.length - 2) {
|
|
|
+ eNum += Number(p.money)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ const lastMoney = this.salesMoneyTotalNum - eNum
|
|
|
+
|
|
|
+ return lastMoney
|
|
|
+ },
|
|
|
+ getLastEditLineIndex() {
|
|
|
+ return this.pageForm.salePersonTableList.length - 1
|
|
|
+ },
|
|
|
+ onSalePersonSplitMoneyChange(scope, e) {
|
|
|
+ const index = scope.$index
|
|
|
+ this.onChangeTableLineData('money', index, e)
|
|
|
+ if (!this.pageTotalMoney.hasContract) {
|
|
|
+ this.onChangeTableLineData('money', index, '')
|
|
|
+ return this.$message({
|
|
|
+ message: '请先输入合同金额',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
}
|
|
|
- // 不是最后一行,计算最后一行的合计
|
|
|
- const total = this.calcSalePersonLastColumnMoney()
|
|
|
- this.form.salePersonTableList[this.form.salePersonTableList.length - 1].money = total
|
|
|
- }, 200),
|
|
|
+ if (scope.row.money === 0 || scope.row.money === '0') {
|
|
|
+ this.onChangeTableLineData('money', index, '')
|
|
|
+ return this.$message({
|
|
|
+ message: '不可为0',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ let lastMoney = this.calcLastColumnMoney()
|
|
|
+ // 1.2 限制当前格子的金额
|
|
|
+ if (lastMoney < 0) {
|
|
|
+ this.$message({
|
|
|
+ message: '合计值需小于应收金额',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
+ this.onChangeTableLineData('money', index, '')
|
|
|
+ lastMoney = this.calcLastColumnMoney()
|
|
|
+ }
|
|
|
+ this.onChangeTableLineData('money', this.getLastEditLineIndex(), lastMoney)
|
|
|
+ },
|
|
|
+ onChangeTableLineData(key, index, e) {
|
|
|
+ this.updatePageFormArrayObjectValue({
|
|
|
+ arrayName: 'salePersonTableList',
|
|
|
+ index,
|
|
|
+ key,
|
|
|
+ newValue: e
|
|
|
+ })
|
|
|
+ },
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -308,7 +380,7 @@ export default {
|
|
|
.el-input-group__append {
|
|
|
background: transparent;
|
|
|
border: none;
|
|
|
- color: #1d1d1d;
|
|
|
+ color: $gray_10;
|
|
|
}
|
|
|
.el-input-group--append {
|
|
|
width: auto;
|