<template>
|
<el-dialog :visible.sync="isShow" :title="title" width="900px" :modal-append-to-body="false"
|
:close-on-click-modal="false">
|
<div class="allocationSet-style">
|
<div class="row-style">
|
<el-radio v-model="distributeType" label="AUTOMATIC">
|
<span class="label-style">比例分配</span>
|
<span class="memo-style">(选择该选项后,收到总库存数据将按照以下分配比例进行各渠道分发)</span>
|
</el-radio>
|
<el-form :model="tableForm" ref="tableForm">
|
<div class="table1-style">
|
<list-condition-template ref="table1" :tableData="tableForm.ratioTableData"
|
:indexColumn="false" :isShowPage="false">
|
<!-- 表格区域 -->
|
<template slot="columns">
|
<el-table-column label="渠道id" prop="id" align="center" v-if="disColumns">
|
</el-table-column>
|
<el-table-column label="渠道名称" prop="channelName" align="center">
|
</el-table-column>
|
<el-table-column label="分发比例(%)" align="center">
|
<template scope="scope">
|
<el-form-item :prop="'ratioTableData.'+ scope.$index + '.ratio'"
|
:rules="formRules.ratio" style="width:100%;">
|
<el-input class="custom-input-style" v-model="scope.row.ratio"
|
placeholder="请输入渠道分发占比,0为不分发库存">
|
</el-input>
|
</el-form-item>
|
</template>
|
</el-table-column>
|
</template>
|
</list-condition-template>
|
</div>
|
</el-form>
|
</div>
|
<div class="row-style">
|
<el-radio v-model="distributeType" label="MANUAL">
|
<span class="label-style">手动分配</span>
|
<span class="memo-style">(选择该选项后,收到总库存数据需手动分配各渠道库存)</span>
|
</el-radio>
|
</div>
|
<el-collapse v-model="isExpand">
|
<el-collapse-item title="操作日志" name="1">
|
<div class="table2-style">
|
<list-condition-template ref="table2" :tableData="logTableData" :total="logTotal"
|
@page-info-change="handlePageInfoChange">
|
<!-- 表格区域 -->
|
<template slot="columns">
|
<el-table-column label="操作时间" prop="createTime" width="160px">
|
</el-table-column>
|
<el-table-column label="分配类型" prop="allotType" align="center" width="120px"
|
show-overflow-tooltip>
|
<template slot-scope="scope">
|
<span v-if="scope.row.distributeType">
|
<!-- AUTOMATIC比例分配, MANUAL手动分配 -->
|
{{scope.row.distributeType === 'AUTOMATIC' ? '比例分配' : '手动分配'}}
|
</span>
|
<span v-else>-</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作内容" align="center" min-width="220px"
|
show-overflow-tooltip>
|
<template slot-scope="scope">
|
<span v-if="scope.row.distributeType === 'AUTOMATIC'">
|
{{getOperContent(scope.row.distributeData,tableForm.ratioTableData)}}
|
</span>
|
<span v-else>-</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="操作人" prop="createName" width="120px" show-overflow-tooltip>
|
</el-table-column>
|
</template>
|
</list-condition-template>
|
</div>
|
</el-collapse-item>
|
</el-collapse>
|
</div>
|
<div slot="footer" class="dialog-footer">
|
<el-button size="mini" @click="save" type="primary" :loading="loading">保存
|
</el-button>
|
<el-button size="mini" @click="isShow = false">取消</el-button>
|
</div>
|
</el-dialog>
|
</template>
|
|
<script>
|
import dictApi from '@/api/dict'
|
import commodityStocksApi from '@/api/stockManagement/commodityStocks'
|
import { vailInputRuleFloat } from '@/utils/validator'
|
export default {
|
name: "allocationSetDialog",
|
props: {
|
dialogVisible: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: ''
|
},
|
},
|
data() {
|
return {
|
disColumns: false,
|
isShow: false,
|
loading: false,
|
distributeType: null,
|
channelData: [],
|
tableForm: {
|
ratioTableData: [],
|
},
|
formRules: {
|
'ratio': [{ validator: vailInputRuleFloat }]
|
},
|
isExpand: [],
|
logTotal: 0,
|
logTableData: []
|
}
|
},
|
watch: {
|
/**
|
* 监控外部显示变量变化
|
* 传递到dialog组件
|
*/
|
dialogVisible: function (newShow, oldShow) {
|
this.isShow = newShow
|
},
|
/**
|
* 监控内部显示属性变化
|
* 传递到外部调用变量
|
*/
|
isShow: function (newDialogShow, oldDialogShow) {
|
this.$emit('update:dialogVisible', newDialogShow)
|
if (!newDialogShow) {
|
this.$nextTick(() => {
|
this.initData() // 初始化表单
|
})
|
}
|
}
|
},
|
mounted() {
|
this.initChannelData();
|
},
|
methods: {
|
/**
|
* 初始化表单
|
*/
|
initData() {
|
let _data = this.tableForm.ratioTableData;
|
if (_data && _data.length > 0) {
|
_data.forEach((item) => {
|
item.ratio = null;
|
})
|
}
|
this.logTableData = [];
|
this.logTotal = 0;
|
this.isExpand = [];
|
},
|
getInfo(_data) {
|
let _this = this;
|
_this.distributeType = _data.allotType;
|
if (_data.data && _data.data.length > 0) {
|
_this.tableForm.ratioTableData.forEach((v1) => {
|
let _obj = _data.data.find((v2) => v1.id === v2.channel);
|
if (_obj) {
|
v1.ratio = _obj.ratio;
|
}
|
})
|
}
|
_this.$nextTick(() => {
|
_this.getOperLogData(_this.$refs.table2.getPageInfo());
|
})
|
},
|
/**
|
*保存
|
*/
|
save() {
|
let _this = this;
|
if (_this.distributeType === 'AUTOMATIC') {
|
let total = 0;
|
_this.$refs.tableForm.validate((valid) => {
|
if (valid) {
|
_this.tableForm.ratioTableData.forEach((item) => {
|
if (item.ratio) {
|
total += parseFloat(item.ratio)
|
}
|
})
|
if (total > 100) {
|
_this.$message({
|
message: '渠道比例不得大于100%',
|
type: 'warning'
|
});
|
return;
|
} else if (total < 100) {
|
_this.$message({
|
message: `渠道比列剩余${(100 - total).toFixed(2)}%未分配`,
|
type: 'warning'
|
});
|
return;
|
} else {
|
//比例分配 --- 分发比例
|
let arr = [];
|
_this.tableForm.ratioTableData.forEach((v) => {
|
if (v.ratio) {
|
arr.push({
|
channel: v.id,
|
ratio: v.ratio
|
})
|
}
|
})
|
_this.submitData(arr);
|
}
|
} else {
|
console.log('error submit!!');
|
return false;
|
}
|
});
|
} else {
|
_this.submitData();
|
}
|
},
|
async submitData(data) {
|
let params = {
|
distributeType: this.distributeType,
|
}
|
if (data) {
|
params.distributeData = data;
|
}
|
this.loading = true;
|
const res = await commodityStocksApi.saveStockDistributeConf(params);
|
if (res.code === '200') {
|
this.$message({
|
message: '操作成功',
|
type: 'success'
|
})
|
this.isShow = false;
|
this.loading = false;
|
this.$emit("close")
|
} else {
|
this.loading = false;
|
}
|
},
|
/**
|
* 初始化渠道数据字典
|
*/
|
async initChannelData() {
|
const res = await dictApi.getChanneldict()
|
let _data = res.data;
|
if (res.code === '0' && _data && _data.length > 0) {
|
let _arr = [];
|
_data.forEach((item) => {
|
_arr.push({
|
id: item.dictCode,
|
channelName: item.dictName,
|
ratio: null,
|
})
|
})
|
this.tableForm.ratioTableData = _arr;
|
}
|
},
|
/**
|
* 分页信息改变时查询列表
|
*/
|
handlePageInfoChange(pageInfo) {
|
this.getOperLogData(pageInfo)
|
},
|
/**
|
* 获取操作日志
|
*/
|
async getOperLogData(pageInfo = { pageNum: 1, pageSize: 10 }) {
|
let pageParams = {
|
current: pageInfo.pageNum,
|
size: pageInfo.pageSize,
|
}
|
const res = await commodityStocksApi.getOperLogList(pageParams);
|
if (res.code === '200') {
|
let _data = res.data;
|
this.logTableData = _data.records;
|
this.logTotal = _data.total;
|
}
|
},
|
/**
|
* 操作内容字符串拼接
|
*/
|
getOperContent(arr, channelData) {
|
let str = "";
|
arr.forEach((item) => {
|
let _obj = channelData.find((v) => v.id === item.channel);
|
if (_obj) {
|
str += `${_obj.channelName}${item.ratio}%;`
|
}
|
})
|
return str;
|
}
|
},
|
}
|
</script>
|
|
<style lang="scss">
|
.allocationSet-style {
|
.row-style {
|
margin-bottom: 20px;
|
.label-style {
|
font-size: 16px;
|
}
|
.memo-style {
|
font-size: 14px;
|
color: rgb(144, 147, 153);
|
}
|
}
|
.main-b-style {
|
padding: 0 !important;
|
}
|
.el-collapse-item__header {
|
font-size: 16px !important;
|
}
|
.el-form-item__error {
|
margin-left: 50px;
|
}
|
.table1-style {
|
.el-table td,
|
.el-table th {
|
padding: 12px 0 0 !important;
|
}
|
}
|
.custom-input-style {
|
.el-input__inner {
|
height: 28px !important;
|
line-height: 28px !important;
|
}
|
}
|
}
|
</style>
|