<template>
<div class="app-container">
<div style="text-align:right;">
<el-button type="primary" @click="addrow(list)">新建行</el-button>
<el-button type="primary" @click="AddBatch()">保存全部</el-button>
</div>
<el-table
v-loading="listLoading"
:data="list.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
element-loading-text="Loading"
border
fit
highlight-current-row
header-cell-style="background-color:#5768cc;color:white;"
>
<el-table-column prop="username" label="用戶(hù)名" align="center" width="100px">
<template scope="scope">
<el-input size="mini" v-model="scope.row.username"></el-input>
</template>
</el-table-column>
<el-table-column prop="addtime" label="添加日期" align="center" width="300px">
<template scope="scope">
<el-date-picker
v-model="scope.row.addtime"
type="datetime"
value-format="yyyy-MM-dd HH:mm:ss"
placeholder="選擇日期時(shí)間"
></el-date-picker>
</template>
</el-table-column>
<el-table-column prop="num1" label="數量" width="110px" align="center">
<template scope="scope">
<el-input
type="text"
oninput="value=value.replace(/[^\d]/g,'')"
maxlength="9"
v-model="scope.row.num1"
placeholder="請輸入數量"
clearable
></el-input>
</template>
</el-table-column>
<el-table-column label="操作" align="center" min-width="100px">
<template slot-scope="scope">
<el-button type="primary" icon="el-icon-edit" @click="addrow(list)" circle></el-button>
<el-button type="danger" icon="el-icon-delete" @click="delRow(scope.$index,list)" circle></el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
layout="prev, pager, next, sizes, total, jumper"
:page-sizes="[5, 10,100]"
:page-size="pageSize"
:total="list.length"
:current-page.sync="currentPage"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
style="text-align: center;margin-top: 1%;"
></el-pagination>
</div>
</template>
<script>
import { getList, AddBatch } from "@/api/test";
export default {
filters: {},
data() {
return {
list: [],
listLoading: true,
usernamef: "",
pageSize: 5,
currentPage: 1,
};
},
created() {
this.fetchData();
},
methods: {
fetchData() {
this.listLoading = true;
let param = { username: this.usernamef };
getList(param).then((response) => {
this.list = response.Data;
this.listLoading = false;
this.currentPage = 1;
});
},
handleCurrentChange: function (cpage) {
this.$data.currentPage = cpage;
},
handleSizeChange: function (psize) {
this.$data.pageSize = psize;
},
addrow(tableData, event) {
tableData.push({
username: "s",
addtime: new Date().toUTCString(),
num1: 1,
});
},
delRow(index, rows) {
rows.splice(index, 1);
},
AddBatch() {
//代表通過(guò)驗證 ,將參數傳回后臺
let params = this.list;
AddBatch(params).then((res) => {
this.$message({
type: "info",
message: res.Message,
});
if (res.Code == 702) {
return;
}
});
},
},
};
</script>
聯(lián)系客服