|
|
@@ -4,15 +4,16 @@
|
|
|
<el-button type="primary" @click="add" size="small">添加</el-button>
|
|
|
<el-button type="primary" @click="_delete" size="small">删除</el-button>
|
|
|
</div>
|
|
|
- <div class="table-wrap">
|
|
|
+ <el-form class="table-wrap" :model="form" ref="tableForm" :rules="rules">
|
|
|
<el-table
|
|
|
ref="multipleTable"
|
|
|
@selection-change="selectionChange"
|
|
|
- :data="tableData"
|
|
|
+ :data="form.tableData"
|
|
|
style="width: 100%"
|
|
|
>
|
|
|
- <el-table-column type="selection" width="55"> </el-table-column>
|
|
|
- <el-table-column prop="date" label="排序" width="100">
|
|
|
+ <el-table-column type="selection" width="55" align="center">
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="date" label="排序" width="80" align="center">
|
|
|
<template slot-scope="{ row }">
|
|
|
<div class="sort-wrap">
|
|
|
<i class="el-icon-caret-top" @click="sortTop(row)"></i>
|
|
|
@@ -21,7 +22,31 @@
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
<el-table-column prop="type.descp" label="类型" width="130">
|
|
|
- <template slot-scope="{ row }">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-form-item
|
|
|
+ :prop="'tableData.' + scope.$index + '.type.code'"
|
|
|
+ :rules="{
|
|
|
+ required: true,
|
|
|
+ message: '',
|
|
|
+ trigger: 'change'
|
|
|
+ }"
|
|
|
+ >
|
|
|
+ <el-select
|
|
|
+ @change="settype(scope.row, $event)"
|
|
|
+ v-model="scope.row.type.code"
|
|
|
+ placeholder="请选择"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in options.type"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ >
|
|
|
+ </el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ </template>
|
|
|
+ <!-- <template slot-scope="{ row }">
|
|
|
<el-select
|
|
|
@change="settype(row, $event)"
|
|
|
v-model="row.type.code"
|
|
|
@@ -35,7 +60,7 @@
|
|
|
>
|
|
|
</el-option>
|
|
|
</el-select>
|
|
|
- </template>
|
|
|
+ </template> -->
|
|
|
</el-table-column>
|
|
|
<el-table-column prop="content" label="内容" width="180">
|
|
|
<template slot-scope="{ row }">
|
|
|
@@ -88,149 +113,165 @@
|
|
|
></el-input>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column prop="address" label="说明"></el-table-column>
|
|
|
+ <el-table-column prop="address" label="说明">
|
|
|
+ <template slot-scope="{ row }">
|
|
|
+ <el-input v-model="row.remark" placeholder="请输入"></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
</el-table>
|
|
|
- </div>
|
|
|
+ </el-form>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
-export default {
|
|
|
- data() {
|
|
|
- return {
|
|
|
- tableData: [],
|
|
|
- selectData: [],
|
|
|
- options: {
|
|
|
- type: [
|
|
|
- {
|
|
|
- value: 1,
|
|
|
- label: '日期'
|
|
|
- },
|
|
|
- {
|
|
|
- value: 2,
|
|
|
- label: '流水号'
|
|
|
- },
|
|
|
- {
|
|
|
- value: 3,
|
|
|
- label: '固定值'
|
|
|
- }
|
|
|
- ],
|
|
|
- date: [
|
|
|
- {
|
|
|
- value: '年月日',
|
|
|
- label: '年月日'
|
|
|
- },
|
|
|
- {
|
|
|
- value: '年月日时分秒',
|
|
|
- label: '年月日时分秒'
|
|
|
- },
|
|
|
- {
|
|
|
- value: '年月日时',
|
|
|
- label: '年月日时'
|
|
|
- },
|
|
|
- {
|
|
|
- value: '年月',
|
|
|
- label: '年月'
|
|
|
- },
|
|
|
- {
|
|
|
- value: '年',
|
|
|
- label: '年'
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- };
|
|
|
- },
|
|
|
- methods: {
|
|
|
- selectionChange(selection) {
|
|
|
- if (selection.length > 1) {
|
|
|
- this.$refs.multipleTable.clearSelection();
|
|
|
- this.$refs.multipleTable.toggleRowSelection(selection.pop());
|
|
|
- }
|
|
|
+ export default {
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ selectData: [],
|
|
|
+ form: {
|
|
|
+ tableData: []
|
|
|
+ },
|
|
|
+ rules: {},
|
|
|
+ options: {
|
|
|
+ type: [
|
|
|
+ {
|
|
|
+ value: 1,
|
|
|
+ label: '日期'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 2,
|
|
|
+ label: '流水号'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 3,
|
|
|
+ label: '固定值'
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ date: [
|
|
|
+ {
|
|
|
+ value: '年月日',
|
|
|
+ label: '年月日'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: '年月日时分秒',
|
|
|
+ label: '年月日时分秒'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: '年月日时',
|
|
|
+ label: '年月日时'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: '年月',
|
|
|
+ label: '年月'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: '年',
|
|
|
+ label: '年'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ };
|
|
|
},
|
|
|
+ methods: {
|
|
|
+ selectionChange (selection) {
|
|
|
+ if (selection.length > 1) {
|
|
|
+ this.$refs.multipleTable.clearSelection();
|
|
|
+ this.$refs.multipleTable.toggleRowSelection(selection.pop());
|
|
|
+ }
|
|
|
+ },
|
|
|
|
|
|
- settype(row, val) {
|
|
|
- row.type.descp = this.options.type.find((n) => n.value == val).label;
|
|
|
- // 重选初始化数据
|
|
|
- row.content = ''
|
|
|
- row.length = ''
|
|
|
- row.currentId = ''
|
|
|
- row.step = ''
|
|
|
- row.remark = ''
|
|
|
- },
|
|
|
+ settype (row, val) {
|
|
|
+ row.type.descp = this.options.type.find((n) => n.value == val).label;
|
|
|
+ // 重选初始化数据
|
|
|
+ row.content = '';
|
|
|
+ row.length = '';
|
|
|
+ row.currentId = '';
|
|
|
+ row.step = '';
|
|
|
+ row.remark = '';
|
|
|
+ },
|
|
|
|
|
|
- // 获取选中值
|
|
|
- getSelection() {
|
|
|
- return this.$refs.multipleTable.selection;
|
|
|
- },
|
|
|
- _delete() {
|
|
|
- let selection = this.getSelection();
|
|
|
- if (selection.length > 0) {
|
|
|
- let itemIndex = this.tableData.findIndex((n) => {
|
|
|
- return n.sort == selection[0].sort;
|
|
|
+ // 获取选中值
|
|
|
+ getSelection () {
|
|
|
+ return this.$refs.multipleTable.selection;
|
|
|
+ },
|
|
|
+ _delete () {
|
|
|
+ let selection = this.getSelection();
|
|
|
+ if (selection.length > 0) {
|
|
|
+ let itemIndex = this.tableData.findIndex((n) => {
|
|
|
+ return n.sort == selection[0].sort;
|
|
|
+ });
|
|
|
+ if (itemIndex !== -1) {
|
|
|
+ this.tableData.splice(itemIndex, 1);
|
|
|
+ this.againSort();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ add () {
|
|
|
+ this.form.tableData.push({
|
|
|
+ type: {
|
|
|
+ code: '',
|
|
|
+ descp: ''
|
|
|
+ },
|
|
|
+ content: '',
|
|
|
+ length: '', // 长度
|
|
|
+ currentId: '', // 当前流水
|
|
|
+ step: '', // 步长
|
|
|
+ remark: '', // 说明
|
|
|
+ sort: this.form.tableData.length + 1
|
|
|
});
|
|
|
- if (itemIndex !== -1) {
|
|
|
- this.tableData.splice(itemIndex, 1);
|
|
|
- this.againSort();
|
|
|
+ },
|
|
|
+ sortTop (row) {
|
|
|
+ if (row.sort <= 1) {
|
|
|
+ return;
|
|
|
}
|
|
|
+ let rowN = this.form.tableData.find((n) => n.sort == row.sort - 1);
|
|
|
+ rowN.sort += 1;
|
|
|
+ row.sort -= 1;
|
|
|
+ this.form.tableData.sort((a, b) => {
|
|
|
+ return a.sort - b.sort;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ sortBottom (row) {
|
|
|
+ if (row.sort >= this.form.tableData.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let rowN = this.form.tableData.find((n) => n.sort == row.sort + 1);
|
|
|
+ rowN.sort -= 1;
|
|
|
+ row.sort += 1;
|
|
|
+ this.form.tableData.sort((a, b) => {
|
|
|
+ return a.sort - b.sort;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ againSort () {
|
|
|
+ this.form.tableData.forEach((n, index) => {
|
|
|
+ n.sort = index + 1;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ validateForm (callback) {
|
|
|
+ //开始表单校验
|
|
|
+ this.$refs.tableForm.validate((valid) => {
|
|
|
+ callback(valid);
|
|
|
+ });
|
|
|
}
|
|
|
- },
|
|
|
- add() {
|
|
|
- this.tableData.push({
|
|
|
- type: {
|
|
|
- code: '',
|
|
|
- descp: ''
|
|
|
- },
|
|
|
- content: '',
|
|
|
- length: '', // 长度
|
|
|
- currentId: '', // 当前流水
|
|
|
- step: '', // 步长
|
|
|
- remark: '', // 说明
|
|
|
- sort: this.tableData.length + 1
|
|
|
- });
|
|
|
- },
|
|
|
- sortTop(row) {
|
|
|
- if (row.sort <= 1) {
|
|
|
- return;
|
|
|
- }
|
|
|
- let rowN = this.tableData.find((n) => n.sort == row.sort - 1);
|
|
|
- rowN.sort += 1;
|
|
|
- row.sort -= 1;
|
|
|
- this.tableData.sort((a, b) => {
|
|
|
- return a.sort - b.sort;
|
|
|
- });
|
|
|
- },
|
|
|
- sortBottom(row) {
|
|
|
- if (row.sort >= this.tableData.length) {
|
|
|
- return;
|
|
|
- }
|
|
|
- let rowN = this.tableData.find((n) => n.sort == row.sort + 1);
|
|
|
- rowN.sort -= 1;
|
|
|
- row.sort += 1;
|
|
|
- this.tableData.sort((a, b) => {
|
|
|
- return a.sort - b.sort;
|
|
|
- });
|
|
|
- },
|
|
|
- againSort() {
|
|
|
- this.tableData.forEach((n, index) => {
|
|
|
- n.sort = index + 1;
|
|
|
- });
|
|
|
}
|
|
|
- }
|
|
|
-};
|
|
|
+ };
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
-.sort-wrap {
|
|
|
- i {
|
|
|
- font-size: 30px;
|
|
|
- cursor: pointer;
|
|
|
+ .sort-wrap {
|
|
|
+ i {
|
|
|
+ font-size: 30px;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ .el-icon-caret-top {
|
|
|
+ color: red;
|
|
|
+ }
|
|
|
+ .el-icon-caret-bottom {
|
|
|
+ color: #157a2c;
|
|
|
+ }
|
|
|
}
|
|
|
- .el-icon-caret-top {
|
|
|
- color: red;
|
|
|
+ .btn-wrap {
|
|
|
+ margin-bottom: 20px;
|
|
|
}
|
|
|
- .el-icon-caret-bottom {
|
|
|
- color: #157a2c;
|
|
|
+ :deep(.table-wrap .el-form-item__error) {
|
|
|
+ display: none;
|
|
|
}
|
|
|
-}
|
|
|
-.btn-wrap{
|
|
|
- margin-bottom: 20px;
|
|
|
-}
|
|
|
-</style>
|
|
|
+</style>
|