vue+element ui项目总结点(二)table合计栏目,按照起始年份--截止年份 插入数据并向后追加数据以最后一条年份+1
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>
vue+element ui项目总结点(二)table合计栏目,按照起始年份--截止年份 插入数据并向后追加数据以最后一条年份+1的更多相关文章
- vue+element ui项目总结点(一)select、Cascader级联选择器、encodeURI、decodeURI转码解码、mockjs用法、路由懒加载三种方式
不多说上代码: <template> <div class="hello"> <h1>{{ msg }}</h1> <p> ...
- vue+element ui项目总结点(六)table编辑当前行、删除当前行、新增、合计操作
具体属性方法参考官方网站:http://element-cn.eleme.io/#/zh-CN/component/installation <template> <div clas ...
- vue+element ui项目总结点(三)富文本编辑器 vue-wangeditor
1.参考 https://www.npmjs.com/package/vue-wangeditor 使用该富文本编辑器 <template> <div class="egi ...
- vue+element ui项目总结点(四)零散细节概念巩固如vue父组件调用子组件的方法、拷贝数据、数组置空问题 等
vue config下面的index.js配置host: '0.0.0.0',共享ip (假设你的电脑启动了这个服务我电脑一样可以启动)-------------------------------- ...
- vue+element ui项目总结点(五)Carousel 走马灯组件、Collapse 折叠面板、Tree 树形控件
<template> <div class="ele_test_box"> <!-- 常用效果 Popover 弹出框组件 具体属性查看官方文档--& ...
- Vue + Element UI项目初始化
1.安装相关组件 1.1安装Node 检查本地是否安装node node -v 如果没有安装,从Node官网下载 1.2安装npm npm -v 如果没有安装:使用该指令安装: npm install ...
- Vue+element ui table 导出到excel
需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...
- Vue+Element UI 实现视频上传
一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
随机推荐
- MVC 登录后重定向回最初请求的 URL FormsAuthentication.RedirectFromLoginPage
在传统的Asp.net webForm 中如果使用 Form身份验证.登录后重定向到最初请求的页面只需使用 FormsAuthentication.RedirectFromLoginPage 但在MV ...
- 关于group_concat函数拼接字符超长的问题
昨天测试的人火急火燎的找我,跟我说数据不对!说明情况后我去查看,原来是数据上有个子查询出来的字段没有完全展示 问题很明显,就是数据被截断了.下面贴上我写的查询 wyids_是正确的显示,通过它子查询出 ...
- 使用escape、encodeURI 和 encodeURIComponent 解决url中文乱码问题
escape(), encodeURI()和encodeURIComponent()是在Javascript中用于编码字符串的三个常用的方法,而他们之间的异同却困扰了很多的Javascript初学者, ...
- Linux 执行定时任务 shell脚本
Linux上面执行定时任务,我们可以利用crontab -e直接编辑定时任务 另外我们还可以写好shell脚本,定时去执行shell脚本,这两个方法都可以起到定时执行的作用 下面我详细说一下入如何执行 ...
- Qt Creator Theme FlatDark 配色
1.预处理指令,宏定义 颜色 #FF6AAD 2.普通代码 颜色 #D6CF9A 3.头文件 #D69545 4.系统限定符(namespace, class, public, typedef等) ...
- 生产环境下Flask项目目录构建
接触Flask已经有大半年了,本篇博客主要来探讨如何规范化生产环境下Flask的项目目录结构.虽然目录结构见仁见智,个人有个人的看法和习惯,但总的来说,经过很多人的实践和总结,还是有很多共同的意见和想 ...
- 【Hadoop】MapReduce笔记(三):MapReduce的Shuffle和Sort阶段详解
一.MapReduce 总体架构 整体的Shuffle过程包含以下几个部分:Map端Shuffle.Sort阶段.Reduce端Shuffle.即是说:Shuffle 过程横跨 map 和 reduc ...
- Flutter实战视频-移动电商-45.详细页_说明区域UI编写
45.详细页_说明区域UI编写 pages/details_page/details_expain.dart 详情页面引用组件 效果展示: 最终代码: import 'package:flutter/ ...
- JAVA基础--JAVA API集合框架(其他集合类,集合原理)15
一.ArrayList介绍 1.ArrayList介绍 ArrayList它是List接口的真正的实现类.也是我们开发中真正需要使用集合容器对象. ArrayList类,它是List接口的实现.肯定拥 ...
- Git之通过ssh clone代码
1.git平台:码云 2.服务器系统:Linux 1.在Linux中创建ssh公钥,将创建的公钥添加到码云的ssh公钥管理 2.一般来说我们配置完站点之后,都会生成一个站点对应的文件夹,进入文件夹,然 ...