<template>
<div id="segmentCompany">
<el-row :gutter="10" class="formWrap">
<el-col class="form-item" :span="10">
<div class="inputLabel">成本中心编码</div>
<el-input :maxlength="20" v-model.trim="costSearch.code"></el-input>
</el-col>
<el-col class="form-item" :span="10">
<div class="inputLabel">成本中心名称</div>
<el-input :maxlength="20" v-model.trim="costSearch.name"></el-input>
</el-col>
<el-col class="form-item" :span="4" style="line-height:50px">
<el-button type="primary" @click='searchAction()'>查询</el-button>
</el-col>
</el-row>
<el-row>
<el-table :data="tableData" @select='selectItem' @select-all='selection' height=335 border style="width:100%">
<el-table-column type="selection" header-align='center' min-width="45">
</el-table-column>
<el-table-column label="序号" width="65" align="center" type="index">
</el-table-column>
<el-table-column label="成本中心编码" prop="code" width=250>
</el-table-column>
<el-table-column label="成本中心名称" :show-overflow-tooltip='true' prop="name">
</el-table-column>
</el-table>
</el-row>
<el-row>
<div class="myPaginationBox">
<p>共{{ (mainData.total / costSearch.pageSize) === 0 ? 0 : Math.ceil(mainData.total / costSearch.pageSize) }}页/<b>{{mainData.total}}</b>条数据</p>
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[5, 10, 20,30]" :page-size='costSearch.pageSize'
:current-page="costSearch.pageNum" layout="sizes, prev, pager, next, jumper" :total='mainData.total'>
</el-pagination>
</div>
</el-row>
<el-row class="commonFoot">
<span>
<el-button @click='colseAction()'>取 消</el-button>
<el-button type="primary" @click='saveAction()'>确 定</el-button>
</span>
</el-row>
</div>
</template>
<style>
.dialog-footer {
text-align: center;
margin-top: 20px;
}
</style>
<script>
// import Global from '@/js/global.js';
export default {
props: ["ledgerCode"],
data() {
return {
URL: "", //生产环境路径
//URL: Global.test, //ci环境路径
//rootURL: "http://10.118.150.100:8080", //后台测试。连接本地
tableData: [],
mainData: [], //保存分页数据
selections: [],
costSearch: {
pageNum: 1,
pageSize: 10,
id: '',
name: '',
code: '',
ledgerCode: '',//账套ID
// companySegmentValCode: '', //所属公司段 请求中没有此字段
// companySegment:'' , //所属公司段 请求中没有此字段
// segmentType:'SEGMENT1',
}
}
},
//生产环境路径
created() {
// debugger
//this.URL = `${this.$root.loadUrl}/mdm-service`;
this.URL = `${this.$root.loadUrl}`;
this.mainData.total = 0;
},
mounted() {
//父组件带值
this.costSearch.ledgerCode = this.ledgerCode;
this.searchAction();
},
methods: {
//取消关闭
colseAction() {
//console.log('关闭')
// for (var prop in this.costSearch) {
// this.costSearch[prop] = '';
// }
this.$emit('closedCost')
},
//查询
searchAction() {
this.$http.post(this.URL + '/flexValues/queryCostCenter', this.costSearch).then((res) => {
var result = res.body;
// console.log(result)
if (result.code == '000000') {
this.tableData = result.data.list;
this.mainData = result.data;
}
})
},
//保存
saveAction() {
if (this.selections.length == 0) {
this.$message({ type: 'info', message: '请选择数据再保存' });
return;
} else if (this.selections.length > 1) {
this.$message({ type: 'info', message: '仅可选择一条数据进行保存' });
return;
} else {
this.costSearch.name = this.selections[0].name;
this.costSearch.code = this.selections[0].code;
this.costSearch.id = this.selections[0].id;
// debugger
this.$emit('saveCostData', this.costSearch)
}
},
//table框选择
selectItem(selections) {
this.selections = selections;
},
//多选
selection(selections) {
this.selections = selections;
},
//当前页数
handleCurrentChange(currentPage) {
// console.log(`当前 ${currentPage} 页`)
this.costSearch.pageNum = currentPage;
this.searchAction()
},
//当前每页条数
handleSizeChange(pageSize) {
//console.log(`每页 ${pageSize} 条`);
this.costSearch.pageSize = pageSize;
this.searchAction()
}
}
}
</script>