TableDoc.vue 4.4 KB
<template>
	<div>
		<el-form-item
			label=" "
			:prop="'expTree.'+index+'.value'"
			:rules="[
				{ required: true, message: '必输项'},
				{ validator: validTable, trigger: 'change' },
			]"
		>
			<el-table :data="tableList" 
				style="width: 100%"
				class="eContainer-table"
				max-height="350px"
				highlight-current-row 
				:row-class-name="rowClassName" 
				@row-click="handleRowClick"
			>
				<el-table-column
					prop="docnam"
					label="Document"
					min-width="200px"
					sortable
				>
					<template slot-scope="scope">
						<c-select
							v-model="scope.row.docnam"
							clearable
							v-limitLength="57"
							allow-create
							@change="handleChange"
						>
							<el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in docgrdList"></el-option>						
						</c-select>
					</template>
				</el-table-column>
				<el-table-column
					prop="cmail1"
					label="1st"
					min-width="69px"
					sortable
				>
					<template slot-scope="scope">
						<c-input v-model="scope.row.cmail1" maxlength="12" @blur="handleChange"></c-input>
					</template>
				</el-table-column>
				<el-table-column
					prop="cmail2"
					label="2nd"
					min-width="69px"
					sortable
				>
					<template slot-scope="scope">
						<c-input v-model="scope.row.cmail2" maxlength="12" @blur="handleChange"></c-input>
					</template>
				</el-table-column>
				<el-table-column label="" prop="det" min-width="95px" fixed="right">
					<template slot-scope="scope" slot="header">
						<c-button circle  class="el-icon-plus" size="mini" @click="addLeftRow(scope)">
						</c-button>
						<c-button  circle class="el-icon-minus" size="mini" @click="removeLeftRow(scope)">
						</c-button>
					</template>
				</el-table-column>
			</el-table>
		</el-form-item>
	</div>
</template>
<script>
import commonDepend from '~/mixin/commonDepend.js'
import { callbackify } from 'util';
export default {
	inject: ["root"],
	mixins: [commonDepend],
	props:['node','index'],
	data(){
		return{
			docgrdList:[
				{label:"增值税发票",value:"增值税发票"},
				{label:"发票",value:"发票"},
				{label:"装箱单",value:"装箱单"},
				{label: "空运单", value: "空运单"},
				{label: "海运提单", value: "海运提单"},
				{label: "铁路运单", value: "铁路运单"},
				{label: "货物收据", value: "货物收据"},
				{label: "邮政收据", value: "邮政收据"},
				{label:"出库单",value:"出库单"},
				{label:"保险单",value:"保险单"},
				{label:"质检证",value:"质检证"},
				{label:"受益人证明",value:"受益人证明"},
			],
			curIndex: 0,
			tableList: []
		}
	},
	mounted(){
	},
	//自定义下拉框输入长度
	directives: {
		limitLength: {
			bind:function (el,binding,vnode){
				const input = el.getElementsByTagName('input')[0]
				if(input){
					input.setAttribute('maxlength',binding.value)
				}
			}
		}
	},
	methods:{
		addLeftRow(row) {
      let newRow = {
				docnam:'',
				cmail1:'',
				cmail2:'',
      };
      let start = 0;
      if (this.tableList) {
        start = this.tableList.length;
      }
      this.tableList.splice(start, 0, newRow);
    },
    removeLeftRow() {
      if (this.curIndex === -1) {
        this.$notify.error({
          title: "错误",
          message: "请选择一条数据删除!"
        });
        return;
      }
      this.tableList.splice(this.curIndex, 1);
      this.curIndex = -1;
		},
		handleRowClick(row){
			this.curIndex = row.index
		},
		rowClassName({ row, rowIndex }) {
      row.index = rowIndex;
		},
		handleChange() {
			let str = ''
			let lineList = []
			this.node.value = ''
			if (this.tableList.length > 0) {
				this.tableList.forEach((item) => {
					let itemConList = []
					itemConList.push(item.docnam || '')
					itemConList.push(item.cmail1 || '')
					itemConList.push(item.cmail2 || '')
					let itemConStr = itemConList.join(' ')
					lineList.push(itemConStr)
				})
				str = lineList.join('\n')
				console.log('tableDoc:', str)
				this.node.value = str
			}
		},
		validTable(rule, value, callback) {
			let flag = this.tableList.some((item) => {
				return item.docnam && item.cmail1
			})
			if (!flag) {
				callback(new Error('必输项'))
			} else {
				callback()
			}
		}
	}
}
</script>

<style scoped>
.el-table .warning-row {
  background: oldlace;
}
.el-table .success-row {
  background: #f0f9eb;
}
.selectColumnClass .el-checkbox__label {
  width: 67px;
  font-size: 13px;
}
</style>