<template>
	<el-dialog title="修改控制器名称" :visible.sync="xgkzqDia" width="40%" :modal-append-to-body="false">
		<el-select placeholder="请选择项目" size="small" v-model="valueseldata" @change="getIdsname">
			<el-option v-for="(obj, index) in firData" :label="obj.changeName" :value="obj.changeName" :key="index"></el-option>
		</el-select>

		<el-table :data="zlData" size="small" style="width: 100%; margin-top: 20px">
			<el-table-column prop="changeValve" label="支路名称" align="center">
				<template slot-scope="scope">
					<el-input v-model="scope.row.changeValve" />
				</template>
			</el-table-column>
			<el-table-column prop="ieName" label="支路" />
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button size="mini" type="primary" @click="editCtrl(scope.row)">确认</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--分页组件-->
		<el-pagination :total="total" :current-page="page" style="margin-top: 8px" layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />
	</el-dialog>
</template>
<script>
import { reqApi } from '@/api/sfyt.js'
import { mapGetters } from 'vuex'

export default {
	props: ['firData'],
	data() {
		return {
			page: 1,
			size: 10,
			total: 0,
			xgkzqDia: false,
			valueseldata: '旁路施肥机01E5',
			zlData: [],
		}
	},
	mounted() {
		this.changeKzq()
	},
	computed: {
		...mapGetters(['user']),
	},
	methods: {
		parentHandleclick() {
			this.xgkzqDia = true
		},
		//select ID
		getIdsname(rows) {
			this.page = 1
			this.valueseldata = rows
			this.changeKzq()
		},
		//修改
		changeKzq() {
			let param = {}
			param.size = this.size
			param.page = this.page
			param.changename = this.valueseldata

			reqApi.sfytDiv(param).then(res => {
				this.zlData = res.Records
				this.total = res.Total
				console.log(this.zlData)
			})
		},
		editCtrl(item) {
			console.log(item)
			let param = {}
			param.iefield = item.changeField
			param.iename = item.ieName
			param.changevalve = item.changeValve
			param.username = this.user.username
			reqApi
				.sfytEdit(param)
				.then(res => {
					if (res.Code == 200) {
						this.$notify({
							title: '修改成功',
							type: 'success',
							duration: 2500,
						})
						this.changeKzq()
					} else {
						this.$notify({
							title: '修改失败，不可为空',
							type: 'warning',
							duration: 2500,
						})
					}
				})
				.catch(err => {
					console.log(err, 'err-------')
				})
		},
		pageChange(e) {
			this.page = e
			this.changeKzq()
		},
		sizeChange(e) {
			this.page = 1
			this.size = e
			this.changeKzq()
		},
	},
}
</script>
