<!doctype html>
|
<html>
|
<head>
|
<meta charset="utf-8">
|
<title>权重设置</title>
|
<script src="../../../js/vue/vue.js"></script>
|
<script src="../../../js/vue/element-ui/lib/index.js"></script>
|
<!-- <script src="../../../js/vue/elementDefault.js"></script> -->
|
<script src="../../../js/vue/page.js"></script>
|
<script src="../../../js/myelement.js"></script>
|
<!-- <script src="../../../data/data.js"></script> -->
|
<script src="../setting.js"></script>
|
|
<link href="../../../js/vue/element-ui/lib/theme-chalk/index.css" rel="stylesheet">
|
<link href="../../../css/myelement.css" rel="stylesheet">
|
<link href="../../../css/iconfont.css" rel="stylesheet">
|
<link href="../../../css/page.css" rel="stylesheet">
|
</head>
|
|
<body>
|
<div id="vbody">
|
<div id="page_root">
|
<div style="width: 100%; height: 100%; padding: 20px; box-sizing: border-box;">
|
<div :style="{width: '61%', height: tableHeight2 + 50+'px', float: 'left', border: '1px solid #ccc'}">
|
<div v-if="treeData.length > 0" style="height: 50px; border-bottom: 1px solid #aaa;">
|
<div class="topbar" style="float: left; line-height: 50px;">
|
<span>{{title}}</span>
|
<template v-if="page.isVersionActive">
|
<span class="versionNo">版本号: {{currentVersion.label}}</span>
|
<h-select :datalist="versionList" v-on:itemselect="onVersionSelect"></h-select>
|
</template>
|
</div>
|
<div style="float: right; margin: 10px;">
|
<el-button-group style="margin-left: 3px; ">
|
<el-button icon="el-icon-refresh" @click="onRefreshTree">刷新</el-button>
|
<el-button v-if="buttons.append" :disabled="buttons.append.disabled" icon="el-icon-plus" @click="onNewTreeRecord">添加</el-button>
|
<el-button v-if="buttons.edit" :disabled="buttons.edit.disabled" @click="isEditTreeData = !isEditTreeData">{{isEditTreeData ? '取消编辑' : '在线编辑'}}</el-button>
|
</el-button-group>
|
</div>
|
</div>
|
<div style=" padding: 20px;">
|
<el-input
|
placeholder="输入搜索字"
|
v-model="filterText">
|
</el-input>
|
</div>
|
<div v-if="treeData.length > 0 && istree" :style="{height: tableHeight2 - 68 +'px', padding: '0px 20px 20px 20px', 'box-sizing': 'border-box'}">
|
<div :style="{height: tableHeight2 - 80 +'px', 'overflow-y': 'auto', 'font-size': '14px'}">
|
<el-tree ref="tree" :data="treeData" :props="defaultProps" node-key="id"
|
:filter-node-method="filterNode" :default-expanded-keys="defaultExpandedKeys"
|
highlight-current
|
@node-click="editnode"
|
>
|
<span class="custom-tree-node" slot-scope="{ node, data }">
|
<span>{{ node.label }} {{ data.field11 }}</span>
|
<span v-if="isEditTreeData">
|
<!-- <el-button style="padding: 2px; font-size: 10px;"
|
@click="() => editnode(node, data)">编辑</el-button> -->
|
<el-button type="danger" size="mini" style="padding: 2px; font-size: 10px;"
|
@click="() => remove(node, data)">删除</el-button>
|
</span>
|
</span>
|
</el-tree>
|
</div>
|
</div>
|
</div>
|
|
<div v-if="istree" :style="{width: '38%', height: tableHeight2 + 50+'px', float: 'right', border: '1px solid #ccc'}">
|
<div style="height: 50px; border-bottom: 1px solid #aaa;">
|
<div class="topbar" style="float: left; line-height: 50px;">
|
<span>详情</span>
|
</div>
|
<div v-if="isEditTreeData" style="float: right; margin: 10px;">
|
<el-button @click="saveRowNoe">保 存</el-button>
|
</div>
|
</div>
|
<div style="margin: 20px;">
|
<div>
|
<span v-if="isallocated && formFields.length>0">总指标{{selectnode.field11}} 已分配占比{{selectnode.allocated}}% 剩余占比{{selectnode.unallocated}}%</span>
|
</div>
|
<h-form
|
ref="form2"
|
:form-attr="formNodeAttr"
|
:table-fields="formFields"
|
:disabled="!isEditTreeData"
|
:form-data="formData"
|
v-on:show-popup="showPopup"
|
v-on:weight-change="weightchange"
|
>
|
</h-form>
|
</div>
|
</div>
|
</div>
|
|
<el-dialog :title="formNodeAttr.title+'节点'" :visible.sync="rowNodeDialog" width="60%">
|
<h-form
|
ref="form2"
|
:form-attr="formNodeAttr"
|
:table-fields="treeFields"
|
:form-data="formnodeData"
|
v-on:show-popup="showPopup"
|
>
|
</h-form>
|
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="rowNodeDialog = false">取 消</el-button>
|
<el-button type="primary" @click="saveRowNoe">保 存</el-button>
|
</div>
|
</el-dialog>
|
|
<el-dialog title="选择" :visible.sync="popupByFieldsDialog">
|
{{selectFormField.field}}
|
{{selectFormField.dataurl}}
|
|
<div slot="footer" class="dialog-footer" >
|
<el-button @click="popupByFieldsDialog = false">取 消</el-button>
|
<el-button type="primary" @click="saveFormValByField('123')">确 定</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
|
<div id="page_loading" style="position: absolute; top:0px; width: 100vw; height: 100vh;">
|
<div class="spinner">
|
<div class="cube1"></div>
|
<div class="cube2"></div>
|
</div>
|
</div>
|
</div>
|
|
<script type="text/javascript">
|
var role = Root.role;
|
var setting = getSetting("weight_list", role.code);
|
let id = 1000;
|
new Vue({
|
el: "#vbody",
|
data: {
|
title: "权重设置",
|
page: setting.page,
|
buttons: setting.buttons,
|
|
currentVersion: {
|
value: "1.0",
|
label: "1.0"
|
},
|
versionList: [
|
{
|
value: "1.0",
|
label: "1.0"
|
},
|
{
|
value: "2.0",
|
label: "2.0"
|
},
|
{
|
value: "3.0",
|
label: "3.0"
|
}
|
],
|
|
tableHeight2: 120,
|
isEditData:false,
|
isEditTreeData: false,
|
|
popupByFieldsDialog: false,
|
selectFormField:{},
|
|
formNodeAttr: {
|
istitle: false,
|
title: "权重设置",
|
columnnumber: 1,
|
labelwidth: "100px",
|
labelposition: "right",
|
align: "left",
|
border: "10px solid #c6c6c600"
|
},
|
|
treeFields: [],
|
formFields: [],
|
formData: {},
|
istree: false,
|
treeDataObj: {},
|
treeData: [],
|
defaultExpandedKeys: [],
|
defaultProps: {
|
children: 'children',
|
label: 'label'
|
},
|
salesStructure: [],
|
salesStructure_old: [],
|
filterText: '',
|
operationnodetype: "",
|
selectnode: {},
|
isallocated: true,
|
formnodeData: {},
|
rowNodeDialog: false,
|
},
|
created() {
|
this.treeFields = dataRootFields.tableFields.weight_;
|
this.tableHeight2 = document.documentElement.clientHeight - 40 - 40 - 48;
|
|
this.salesStructure = dataRoot.database.salesStructure;
|
this.salesStructure_old = clone(dataRoot.database.salesStructure);
|
},
|
|
mounted() {
|
this.getTree();
|
this.$nextTick(() => { // 以服务的方式调用的 Loading 需要异步关闭
|
document.getElementById('page_root').style.display = "block";
|
document.getElementById('page_loading').style.display = "none";
|
});
|
},
|
watch: {
|
filterText(val) {
|
this.$refs.tree.filter(val);
|
}
|
},
|
methods:{
|
ArrayToTree(array_, name, parentId, parId, disabled_field, isencode) {
|
if(!parentId) {
|
parentId = "parent_id";
|
}
|
|
if(!name) {
|
name = "label";
|
}
|
|
if(!parId) {
|
parId = "";
|
}
|
|
let obj = {};
|
let result = [];
|
let list = JSON.parse(JSON.stringify(array_));
|
list.map(el => {
|
obj[el.id] = el;
|
})
|
let openId = "";
|
for (let i = 0, len = list.length; i < len; i++) {
|
let parentId_ = list[i][parentId];
|
//如果存在判断只读字段,并且该字段有值则设置该节点为只读
|
if (disabled_field) {
|
if(list[i][disabled_field]) {
|
list[i].disabled = true;
|
}
|
}
|
|
//设置显示字段
|
if (isencode) {
|
list[i].label = decodeURI(encodeURI( list[i][name]));//数据如果带“%”的需要编码再解码,否则会存在格式错误
|
list[i].name = decodeURI(encodeURI( list[i][name]));
|
}
|
else {
|
list[i].label = decodeURI(list[i][name]);
|
list[i].name = decodeURI(list[i][name]);
|
}
|
if (parentId_ == parId || !parentId_ || parentId_ == "null") {
|
if(!obj[list[i].id].children) {
|
obj[list[i].id].children = null;
|
}
|
result.push(list[i]);
|
continue;
|
} else if (obj[parentId_]) {
|
if (!obj[parentId_].children) {
|
obj[parentId_].children = [];
|
}
|
obj[parentId_].children.push(list[i]);
|
}
|
}
|
return result;
|
},
|
|
getTree() {
|
this.defaultExpandedKeys = [];
|
this.istree = false;
|
let treeDataList = this.salesStructure;
|
treeDataList.map(e=>{
|
this.treeDataObj[e.id] = e;
|
});
|
let treeData_ = this.ArrayToTree(treeDataList, "field2", "field5");
|
treeData_.map(e=>{
|
this.defaultExpandedKeys.push(e.id);
|
if (e.children) {
|
e.children.map(ec=>{
|
if (e.field13 == "平均分配") {
|
ec.field11 = Math.round(e.field11 / e.children.length);
|
}
|
else if (e.field13 == "按权重分配") {
|
ec.field11 = Math.round(ec.field11 / 100 * e.field11);
|
}
|
else if (e.field13 == "按历史指标占比分配") {
|
|
}
|
else if (e.field13 == "自定义分配") {
|
|
}
|
});
|
}
|
});
|
this.treeFields[6].options = treeData_;
|
this.treeData = treeData_;
|
this.istree = true;
|
},
|
|
//表单
|
showPopup(obj) {
|
this.selectFormField = obj.obj;
|
this.popupByFieldsDialog = true;
|
},
|
saveFormValByField(val) {
|
this.popupByFieldsDialog = false;
|
this.$refs.form1.setFormValByField(this.selectFormField, val)
|
},
|
|
onVersionSelect(obj) {
|
this.currentVersion = obj;
|
},
|
onRefreshTree() {
|
this.salesStructure = this.salesStructure_old;
|
this.getTree();
|
},
|
|
filterNode(value, data) {
|
if (!value) return true;
|
return data.label.indexOf(value) !== -1;
|
},
|
append(data) {
|
const newChild = { id: id++, label: 'testtest', children: [] };
|
if (!data.children) {
|
this.$set(data, 'children', []);
|
}
|
data.children.push(newChild);
|
},
|
onNewTreeRecord() {
|
this.treeFields;
|
this.selectrow = {};
|
this.formData = {};
|
this.openMsg1('add');
|
},
|
editnode(data, node, tree) {
|
let e = data;
|
let formFields_ = [];
|
if (e.children) {
|
e.children.map(ec=>{
|
if (e.field13 == "平均分配") {
|
ec.field11 = Math.round(e.field11 / e.children.length);
|
}
|
else if (e.field13 == "按权重分配") {
|
ec.field11 = Math.round(ec.field11 / 100 * e.field11);
|
}
|
else if (e.field13 == "按历史指标占比分配") {
|
|
}
|
else if (e.field13 == "自定义分配") {
|
|
}
|
let fields_ = {field: ec.id, name: ec.field2, isshow: "T", change: "weight-change"};
|
formFields_.push(fields_);
|
});
|
}
|
this.formFields = formFields_;
|
|
this.operationnodetype = "edit";
|
this.selectnode = data;
|
if (!this.selectnode.allocated) {
|
this.selectnode.allocated = 0;
|
this.selectnode.unallocated = 100;
|
}
|
},
|
|
weightchange(obj) {
|
let allocated_ = 0
|
for (let k in this.formData) {
|
allocated_ += this.formData[k] * 1;
|
}
|
this.selectnode.allocated = allocated_;
|
this.selectnode.unallocated = 100 - allocated_;
|
this.isallocated = false;
|
this.isallocated = true;
|
},
|
getparent(parentid, parents) {
|
if (this.treeDataObj[parentid].parentid){
|
parents.unshift(this.treeDataObj[parentid].field5);
|
this.getparent(this.treeDataObj[parentid].field5, parents);
|
}
|
else {
|
return parents;
|
}
|
},
|
saveRowNoe() {
|
if (this.operationnodetype == "edit") {//修改
|
this.salesStructure.map(e=>{
|
if (e.id == this.formnodeData.id) {
|
e.name = this.formnodeData.name;
|
e.parentid = this.formnodeData.parentname[this.formnodeData.parentname.length-1]
|
}
|
});
|
}
|
else {//新增
|
let formnodeData_ = {
|
id: id++,
|
name: this.formnodeData.name,
|
parentid: this.formnodeData[this.formnodeData.length-1]
|
}
|
this.salesStructure.push(formnodeData_);
|
}
|
|
this.getTree();
|
//this.rowNodeDialog = false;
|
},
|
remove(node, data) {
|
Root.confirm('确定删除-' + data.name + '-吗?', '删除提示', {
|
confirmButtonText: '删除',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).then(() => {
|
const parent = node.parent;
|
const children = parent.data.children || parent.data;
|
const index = children.findIndex(d => d.id === data.id);
|
children.splice(index, 1);
|
Root.message({
|
type: 'success',
|
message: '删除成功!'
|
});
|
}).catch(() => {
|
Root.message({
|
type: 'info',
|
message: '已取消删除'
|
});
|
});
|
},
|
openMsg1(code, row) {
|
let me = this;
|
Root.popupParames = {
|
width: "900px",
|
//height: "580px",
|
url: "../md/plan/weight_edit.html",
|
callback: function(obj, callback) {
|
me.saveRowTable_popup(obj);
|
if (callback) {
|
callback();
|
}
|
}
|
};
|
if (code == "edit") {
|
this.operationnodetype = "edit";
|
Root.popupParames.data = row;
|
}
|
else {
|
this.operationnodetype = "add";
|
}
|
//Root.showSubItem(parames);
|
Root.popupParames.tableFields = this.treeFields;
|
Root.showPopup(Root.popupParames);
|
},
|
|
saveRowTable_popup(obj) {
|
let formData_ = obj.row;
|
|
if (this.operationnodetype == "edit") {//修改
|
for (var k in formData_) {
|
this.selectrow[k] = formData_[k];
|
}
|
|
}
|
else {//新增
|
let formnodeData_ = {};
|
for(var k in formData_) {
|
formnodeData_[k] =formData_[k];
|
}
|
formnodeData_.id= id++;
|
formnodeData_.field5= formData_.field6[formData_.field6.length-1];
|
this.salesStructure.push(formnodeData_);
|
}
|
this.getTree();
|
},
|
}
|
});
|
</script>
|
<style>
|
.el-dialog__body{
|
border-top: 1px solid #ccc;
|
border-bottom: 1px solid #ccc;
|
padding: 20px;
|
}
|
.custom-tree-node {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
font-size: 14px;
|
padding-right: 8px;
|
}
|
</style>
|
</body>
|
</html>
|