<template>
<div class="app-container">
<div class="box-card" ref="top" style="border-bottom: 1px solid #eee">
<el-form :inline="true" size="mini" ref="form" :model="pageFilter">
<el-form-item label="日期">
<el-date-picker
v-model="dateValue"
type="date"
size="small"
placeholder="选择日期"
format="yyyy 年 MM 月 dd 日"
value-format="yyyy-MM-dd">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button round size="mini" icon="el-icon-search" @click="onSearch"
>搜索</el-button
>
</el-form-item>
<el-form-item>
<el-button
round
size="mini"
icon="el-icon-refresh-left"
@click="onReset"
>重置</el-button
>
</el-form-item>
<el-form-item>
<el-button round size="mini" icon="el-icon-setting" @click="setIndex()">设置指标</el-button>
</el-form-item>
</el-form>
</div>
<el-card class="box-card" style="margin-bottom: 15px" shadow="always">
<el-table style="width: 100%;margin-top: 8px;margin-bottom: 15px" v-loading="listLoading" :height="tableHeight" :data="tableData" row-key="index" element-loading-text="拼命加载中" border fit highlight-current-row >
<template v-for="item in tablelist" :key>
<el-table-column
align="center"
show-overflow-tooltip
:width="120"
:label="item.label"
>
<template slot-scope="scope"><span :class="item.class ? item.class : scope.row.class">{{ scope.row[item.value] }}</span></template>
</el-table-column>
</template>
</el-table>
</el-card>
<el-dialog title="设置指标" :visible.sync="dialogTableVisible" :close-on-click-modal="false" @open="open">
<el-table ref="myTable" :data="gridData" :cell-style="{ textAlign: 'center' }" :span-method="objectSpanMethod" :header-cell-style="{textAlign: 'center'}" stripe border highlight-current-row @cell-mouse-leave="loseFcous">
<el-table-column property="chargePerson" label="" width="150"></el-table-column>
<el-table-column property="region" label="大区" width="150"></el-table-column>
<el-table-column property="campus" label="校区" width="200"></el-table-column>
<el-table-column property="dailyOperationIndex" label="日经营A指标">
<template slot-scope="scope">
<div @click.stop="changeNum(scope.$index,'editDailyOperationIndex')">
<el-input v-if="editable[scope.$index]" v-model="scope.row.dailyOperationIndex" size="mini" class="editDailyOperationIndex" @change="changeInput(scope.row)"/>
<span v-else>{{ scope.row.dailyOperationIndex?scope.row.dailyOperationIndex:0 }}</span>
</div>
</template>
</el-table-column>
<el-table-column property="monthlyMemberIndex" label="月会员指标">
<template slot-scope="scope">
<div @click.stop="changeNumMonthly(scope.$index,'editMonthlyMemberIndex')">
<el-input v-if="editableMonthly[scope.$index]" v-model="scope.row.monthlyMemberIndex" size="mini" class="editMonthlyMemberIndex" @change="changeInput(scope.row)"/>
<span v-else>{{ scope.row.monthlyMemberIndex?scope.row.monthlyMemberIndex:0 }}</span>
</div>
</template>
</el-table-column>
</el-table>
</el-dialog>
</div>
</template>
<script>
import { listSignTarget2,getSchoolsRelation, todaySign } from "@/api/report";
import { getRosterId } from "@/utils/auth";
export default {
data() {
return {
dateValue: null,
tableHeight: 300,
listLoading: false,
tableData: [],
pageFilter: {
loginId: getRosterId()
},
tablelist: [
{
value: "deptName",
label: "网招部",
class: "none",
},
{
value: "rosterName",
label: "总负责人",
class: "none",
},
{
value: "rosterName",
label: "区域",
class: "none",
},
{
value: "rosterName",
label: "校区",
class: "none",
},
{
value: "rosterName",
label: "来校",
class: "none",
},
{
value: "rosterName",
label: "当日报名",
class: "none",
},
{
value: "rosterName",
label: "网汇",
class: "none",
},
{
value: "rosterName",
label: "汇款人数",
class: "none",
},
{
value: "rosterName",
label: "明天到校",
class: "none",
},
],
top: "",
dialogTableVisible:false,
gridData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}],
saveItem: {}, // 点击单元格可编辑
editable: [], // 点击单元格可编辑
editableMonthly: [], // 点击单元格可编辑
};
},
mounted() {
this.$nextTick((h) => {
this.top = this.$refs.top.clientHeight + "px";
this.tableHeight=window.innerHeight-200;
window.onresize = () =>{
this.tableHeight=window.innerHeight-200;
}
});
this.loadData();
},
methods: {
loseFcous() {
this.editable = new Array(this.$refs.myTable.data.length);
this.editable.forEach(value => value = false);
this.editableMonthly = new Array(this.$refs.myTable.data.length);
this.editableMonthly.forEach(value => value = false);
},
changeInput(val) {
console.log(val)
// this.$ajax.post('bom/upDateMemo ', this.saveItem
// ).then((res) => {
// this.$message({ message: res.getMessage(), type: 'success' });
// });
},
changeNum(index, className) {
// 设置是否可以编辑
this.editable = new Array(this.$refs.myTable.data.length);
this.editable[index] = true;
this.$set(this.editable, index, true);
// 让input自动获取焦点
this.$nextTick(function() {
let editInputList = document.getElementsByClassName(className);
editInputList[0].children[0].focus();
});
},
changeNumMonthly(index, className) {
// 设置是否可以编辑
this.editableMonthly = new Array(this.$refs.myTable.data.length);
this.editableMonthly[index] = true;
this.$set(this.editableMonthly, index, true);
// 让input自动获取焦点
this.$nextTick(function() {
let editInputList = document.getElementsByClassName(className);
editInputList[0].children[0].focus();
});
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
return {
rowspan: row.rowspan,
colspan: 1
}
}
if (columnIndex === 1) {
return {
rowspan: row.rowspan1,
colspan: 1
}
}
},
open(){
getSchoolsRelation().then((response) => {
this.gridData = response.data;
// 先给所有的数据都加一个v.rowspan = 1
this.gridData.forEach(v => {
v.rowspan = 1;
v.rowspan1 = 1;
})
// 双层循环
for (let i = 0; i < this.gridData.length; i++) {
// 内层循环,上面已经给所有的行都加了v.rowspan = 1
// 这里进行判断
// 如果当前行的id和下一行的id相等
// 就把当前v.rowspan + 1
// 下一行的v.rowspan - 1
for (let j = i + 1; j < this.gridData.length; j++) {
if (this.gridData[i].chargePerson === this.gridData[j].chargePerson) {
this.gridData[i].rowspan++
this.gridData[j].rowspan--
}
}
// 这里跳过已经重复的数据
i = i + this.gridData[i].rowspan - 1;
}
for (let i = 0; i < this.gridData.length; i++) {
// 内层循环,上面已经给所有的行都加了v.rowspan = 1
// 这里进行判断
// 如果当前行的id和下一行的id相等
// 就把当前v.rowspan + 1
// 下一行的v.rowspan - 1
for (let j = i + 1; j < this.gridData.length; j++) {
if (this.gridData[i].region === this.gridData[j].region) {
this.gridData[i].rowspan1++
this.gridData[j].rowspan1--
}
}
// 这里跳过已经重复的数据
i = i + this.gridData[i].rowspan1 - 1;
}
});
},
setIndex(){
this.dialogTableVisible=true
},
/**
* 查找
*/
onSearch() {
this.loadData();
},
/**
* 重置
*/
onReset() {
this.dateValue = '';
this.onSearch();
},
loadData() {
this.listLoading = true;
listSignTarget2(this.pageFilter).then((response) => {
this.tableData = response.data.a;
this.tableDatas = response.data.b;
this.tableData.map((item) => {
if (
item.arriveTargetNum &&
item.arriveCount &&
item.arriveTargetNum < item.arriveCount
) {
item.class = "reds";
} else {
item.class = "grue";
}
});
this.tableDatas.map((item) => {
if (
item.arriveTargetNum &&
item.arriveCount &&
item.arriveTargetNum < item.arriveCount
) {
item.class = "reds";
} else {
item.class = "grue";
}
});
this.listLoading = false;
});
},
},
};
</script>
<!--样式参考:https://www.cnblogs.com/goloving/p/9119460.html-->
<style lang="scss">
.el-table__header tr,
.el-table__header th {
padding: 4px 0;
height: 20px;
}
.el-table__body tr,
.el-table__body td {
padding: 4px 0;
height: 10px;
}
</style>
03-26
768