1.oninput 事件在用户输入时触发;

<template>
<div class="test_box">
<p>hell,你好</p>
<p>encodeURI编码后转码的路由参数内容----<span style="color: red">({{routerParmas}})</span></p>
<div class="table_box">
<el-table :data="sheetTableData" border style="width: 100%" :summary-method="getSummaries" show-summary>
<el-table-column prop="years" label="年度" align='center' sortable>
<template slot-scope="scope">
<el-input class="txt_ct" v-model="scope.row.years" placeholder="请输入" disabled></el-input>
</template>
</el-table-column>
<el-table-column prop="firstSeason" label="第一季度统计" align='center'>
<template slot-scope="scope">
<el-input class="txt_ct" v-model="scope.row.firstSeason" placeholder="请输入" oninput="value=value.replace(/[^\d\.]/g,'').replace(/^(\d*(\.\d{0,4})?).*/,'$1')" :disabled="isEgdit" v-on:input="changeValue"></el-input>
</template>
</el-table-column>
<el-table-column prop="secondSeason" label="第二季度统计" align='center'>
<template slot-scope="scope">
<el-input class="txt_ct" v-model="scope.row.secondSeason" placeholder="请输入" oninput="value=value.replace(/[^\d\.]/g,'').replace(/^(\d*(\.\d{0,4})?).*/,'$1')" :disabled="isEgdit" v-on:input="changeValue"></el-input>
</template>
</el-table-column>
<el-table-column prop="thirdSeason" label="第三季度统计" align='center'>
<template slot-scope="scope">
<el-input class="txt_ct" v-model="scope.row.thirdSeason" placeholder="请输入" oninput="value=value.replace(/[^\d\.]/g,'').replace(/^(\d*(\.\d{0,4})?).*/,'$1')" :disabled="isEgdit" v-on:input="changeValue"></el-input>
</template>
</el-table-column>
<el-table-column prop="fourthSeason" label="第四季度统计" align='center'>
<template slot-scope="scope">
<el-input class="txt_ct" v-model="scope.row.fourthSeason" placeholder="请输入" oninput="value=value.replace(/[^\d\.]/g,'').replace(/^(\d*(\.\d{0,4})?).*/,'$1')" :disabled="isEgdit" v-on:input="changeValue"></el-input>
</template>
</el-table-column>
<el-table-column fixed="right" label="操作" align='center'>
<template slot-scope="scope">
<el-button type="primary" size="small" @click='addData' icon="el-icon-plus" circle></el-button>
<el-button v-if="scope.$index == sheetTableData.length-1 || scope.$index == 0" @click.native.prevent="deleteData(scope.$index,sheetTableData)" type="danger" size="small" icon="el-icon-delete" circle></el-button>
</template>
</el-table-column>
<!-- 暂无数据 -->
<div slot="empty" v-if="!sheetTableData.length" style="padding:20px;">
<div style="margin-top: 10px">暂无数据
<span>,请 <el-button type="text" @click="dialogVisible = true">新增</el-button></span>
</div>
</div>
</el-table>
<!-- 弹窗 -->
<el-dialog title="请选择起始年份/截止年份" :visible.sync="dialogVisible">
<div style="display: flex;align-items: center;justify-content: center;">
<div class="block">
<el-date-picker v-model="startYear" type="year" placeholder="起始年份" value-format="yyyy">
</el-date-picker>
</div>
<div class="block">
<p style="padding:10px;">至</p>
</div>
<div class="block">
<el-date-picker v-model="endYear" type="year" placeholder="截止年份" value-format="yyyy">
</el-date-picker>
</div>
</div>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="sureAddData">确 定</el-button>
</span>
</el-dialog>
</div>
</div>
</template>
<script>
export default {
data() {
return {
isEgdit: false,//是否可编辑
sheetTableData: [],//数据
startYear: '',//起始年份
endYear: '',//截止年份
dialogVisible: false,//弹窗是否显示
routerParmas: decodeURI(decodeURI(this.$route.query.goodName)), //路由编码参数解码
};
},
methods: {
//新增数据
addData() {
let item = {
"id": null,
"years": Number(this.sheetTableData[this.sheetTableData.length - 1].years) + 1,
"firstSeason": null,
"secondSeason": null,
"thirdSeason": null,
"fourthSeason": null
}
this.sheetTableData.push(item)
},
//确认依据起始年份/截止年份 添加数据
sureAddData() {
let yearDiff = Number(this.endYear - this.startYear)
//console.log(yearDiff, 'yearDiff', this.endYear, 'timeEnd', this.startYear, 'timeStart')
if (yearDiff > 0) {
for (let i = 0; i <= yearDiff; i++) {
this.sheetTableData.push({
"id": null,
"years": Number(this.startYear) + Number(i),
"firstSeason": null,
"secondSeason": null,
"thirdSeason": null,
"fourthSeason": null,
})
}
} else {
this.$eleMessage('截止年份应大于起始年份', 'error', 500)
}
this.dialogVisible = false;
},
//删除
deleteData(index, list) {
list.splice(index, 1);
},
//合计---Element ui自带合计功能还是蛮好用的 (前提是dom中的prop属性必须要有)
getSummaries(param) {
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计';
return;
}
const values = data.map(item => Number(item[column.property]));
if (!values.every(value => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index] += '';
} else {
sums[index] = '';
}
});
return sums;
},
changeValue(){
//1、oninput事件在value改变时触发,实时的即每增加或删除一个字符就会触发,然而通过js改变value时,却不会触发。
//2、onchange 事件在内容改变(两次内容有可能还是相等的)且失去焦点时触发。
console.log('输入时候可以做些什么事情')
}
} } </script>
<style scoped> </style>

最新文章

  1. delphi中exit,abort,break,continue 的区别
  2. Xcode Build Settings Architectures
  3. linux chmod 755
  4. 区分各浏览器的CSS hack(包括360、搜狗、opera)
  5. 一道javascript面试题
  6. RecycleView可以策划的Item
  7. Uploadify使用
  8. httpcomponents 学习1--并发多线程GET
  9. AspxGridView ComboBoxComlum列数据联动
  10. jquery 创建 SVG DOM 的处理方法
  11. OOP组合和继续的优缺点
  12. Python 获得Facebook用户有一个共同的兴趣Friends
  13. android命令行网络时间同步
  14. Spring Boot初探之restful服务发布
  15. vim配置强悍来袭
  16. 最新版 INSPINIA IN+ - WebApp Admin Theme v2.7.1,包含asp.net MVC5示例代码,做管理系统最佳的选择。
  17. eclipse,import,导入项目显示红色叹号
  18. mysql数据库中实现内连接、左连接、右连接
  19. 20155328 实验四 Android程序设计 实验报告
  20. TCP Flow Control and Data Transfer

热门文章

  1. attachEvent与addEventListener的区别 真实例子
  2. sqlserver 拷贝同步多个表数据到另一张表
  3. 13.详解oauth2授权码流程
  4. sql server 2008 删除某数据库所有表
  5. E20190114-hm
  6. CSS Unicode字体
  7. Event事件的三个阶段
  8. tp5 验证码功能实现
  9. UGUI技术之LayoutGroup布局实现详解
  10. WINDOWS编程基础-最简单的windows程序