<template>
<div style="margin-top: 20px">
<!-- <h2 align="center">农药购买与使用去向记载表</h2> -->
<!-- <el-dialog
:title="!dataForm.id ? '新增' : !disabled ? '修改' : '查看'"
:close-on-click-modal="false"
:visible.sync="visible"> -->
<div>
<div style="margin-bottom: 20px">
<el-button
type="white"
@click="
$router.push({
name: 'pesticide-useinfo',
})
"
>返回</el-button
>
<el-button
v-if="!disabled"
type="primary"
@click="dataFormSubmit()"
>保存</el-button
>
<!-- <el-button
v-if="!disabled"
type="primary"
@click="dataFormSubmit()"
>新增</el-button
> -->
</div>
<!-- :rules="dataRule" -->
<el-form
:model="dataForm"
:rules="dataRule"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()"
label-width="80px"
:inline="true"
>
<el-form-item label="户主编号" prop="farmerId">
<el-input
v-model="dataForm.farmerId"
:disabled="disabled"
placeholder="户主编号"
></el-input>
</el-form-item>
<el-form-item label="年份" prop="dateyear">
<el-input
v-model="dataForm.dateyear"
:disabled="disabled"
placeholder="年份"
></el-input>
</el-form-item>
<el-form-item label="任务id" prop="taskId">
<el-input
v-model="dataForm.taskId"
:disabled="disabled"
placeholder="任务id"
></el-input>
</el-form-item>
</el-form>
<el-form
:model="dataForm"
ref="dataForm"
@keyup.enter.native="dataFormSubmit()"
label-width="80px"
>
<!-- <el-input v-model="dataForm.farmerId"></el-input> -->
<!-- <el-form-item
label="户主编号"
style="float: left; white-space: nowrap"
prop="farmerId"
>
<el-input
v-model="dataForm.farmerId"
:disabled="disabled"
placeholder="户主编号"
style="width: 250px"
></el-input>
</el-form-item> -->
<!-- <el-form-item
label="年份"
prop="dateyear"
:rules="[{ required: true, message: '请选择年份', trigger: 'blur' }]"
style="width: 350px; float: left; white-space: nowrap"
>
<el-date-picker
type="year"
placeholder="选择年份"
v-model="dataForm.dateyear"
style="width: 100%"
format="yyyy"
value-format="yyyy"
:disabled="disabled"
></el-date-picker>
</el-form-item>
<el-form-item
label="任务id"
style="float: left; white-space: nowrap"
prop="taskId"
>
<el-input
v-model="dataForm.taskId"
:disabled="disabled"
placeholder="任务id"
style="width: 250px"
></el-input>
</el-form-item> -->
</el-form>
<el-table :data="dataForm.details">
<el-table-column
prop="id"
align="center"
label="农药购买记录"
width="150"
>
<el-table-column
prop="purchaseDate"
align="center"
label="日期"
width="120"
>
</el-table-column>
<el-table-column
prop="pdNo"
align="center"
label="农药登记证号"
width="180"
>
</el-table-column>
<el-table-column
prop="commonName"
align="center"
label="农药通用名"
width="180"
>
</el-table-column>
<el-table-column
prop="purchaseAmount"
align="center"
label="农药购买量(克、毫升)"
width="180"
>
</el-table-column>
<el-table-column
prop="purchaseCost"
align="center"
label="购买费用"
width="100"
>
</el-table-column>
<el-table-column
prop="packagings"
align="center"
label="包装物"
width="180"
>
</el-table-column>
<el-table-column
prop="packingSpecification"
align="center"
label="包装规格(克、毫升)/(瓶、袋)"
width="180"
>
</el-table-column>
</el-table-column>
<el-table-column
prop="name"
align="center"
label="农药使用去向记录"
width="180"
>
<el-table-column
prop="medicationDate"
align="center"
label="用药日期"
width="180"
>
<template slot-scope="scope">
<!-- <el-input
v-model="scope.row.sowingDate"
:disabled="disabled"
placeholder=""
></el-input> -->
<el-date-picker
type="datetime"
placeholder="播种日期"
v-model.trim="scope.row.medicationDate"
style="width: 100%"
:disabled="disabled"
format="MM-dd"
value-format="yyyy-MM-dd HH:mm:ss"
></el-date-picker>
</template>
</el-table-column>
<el-table-column
prop="cropId"
align="center"
label="用药作物名称"
width="180"
>
</el-table-column>
<el-table-column
prop="controlObject"
label="防治对象名称(病虫草鼠种类)"
width="180"
align="center"
>
</el-table-column>
<el-table-column
prop="medicationArea"
align="center"
label="用药面积(亩)"
width="200"
>
<template slot-scope="scope">
<!-- <el-input
v-model="scope.row.plantingArea"
:disabled="disabled"
placeholder=""
></el-input> -->
<el-input-number
:disabled="disabled"
v-model.trim="scope.row.medicationArea"
:min="0"
:max="10000000"
label="种植面积(亩)"
size="small"
></el-input-number>
</template>
</el-table-column>
<el-table-column
prop=" totalDosage"
align="center"
label="合计用药量(克、毫升)"
width="180"
>
</el-table-column>
</el-table-column>
</el-table>
<el-button
@click="addOneLine()"
style="right: 30px; position: absolute; margin-top: 20px"
type="primary"
>新增一条记录</el-button
>
</div>
</div>
</template>
<script>
export default {
data () {
return {
disabled: false,
visible: false,
dataForm: {
id: 0,
farmerId: '',
dateyear: '',
taskId: ''
},
detail: {
id: '',
purchaseDate: '',
pdNo: '',
commonName: '',
purchaseAmount: '',
purchaseCost: '',
packagings: '',
packingSpecification: '',
medicationDate: '',
cropId: '',
controlObject: '',
medicationArea: '',
totalDosage: '',
},
dataRule: {
name: [
{ required: true, message: '名称不能为空', trigger: 'blur' }
]
}
}
},
mounted () {
let id = this.$route.params.id
let disable = this.$route.params.disable
this.init(id, disable)
},
methods: {
addOneLine () {
// let data = JSON.parse(JSON.stringify(this.dataForm))
// let details = data.details
// details.push(JSON.parse(JSON.stringify(this.detail)))
// data.details = details
// this.dataForm = data
let data = this.dataForm
data.details.push(JSON.parse(JSON.stringify(this.detail)))
},
getDateList () {
},
// getAllCrop () {
// this.dataForm = {}
// this.cropList = []
// let dictList = sessionStorage.getItem("dictList")
// dictList = JSON.parse(dictList)
// // console.log(dictList);
// this.dataForm.plants = []
// // console.log(this.cropList);
// console.log(this.dataForm);
// this.init(this.id, this.disable)
// },
// wodetest1hao () {
//要动态地添加数据
//我要干什么
//为什么这么做
// 1.
// 2.
// },
init (id, disabled) {
this.disabled = disabled
this.dataForm.id = id || ''
this.visible = true
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
//判断是修改还是新增
if (this.dataForm.id) {
this.$http({
url: `/pesticide/useinfo/info/${this.dataForm.id}`,
method: 'get'
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataForm = data.useinfo
}
})
} else {
//如果是新增就 插入一条空数据(dataForm.details [detail])
//插入一条空数据怎么写呢
//
// this.dataForm = this.dataForm.details [this.detail]
// <template slot-scope="scope">
// {{(scope.row.id)}}
// </template>
// debugger
let data = JSON.parse(JSON.stringify(this.dataForm))
let details = []
details.push(JSON.parse(JSON.stringify(this.detail)))
data.details = details
this.dataForm = data
// this.dataForm.details = []
// this.dataForm.details.push(JSON.parse(JSON.stringify(this.detail)))
// console.log(this.dataForm);
}
})
},
// 表单提交
dataFormSubmit () {
this.$refs['dataForm']
.validate((valid) => {
if (valid) {
this.$http({
url: `/pesticide/useinfo/${!this.dataForm.id ? 'save' : 'update'}`,
method: 'post',
data: this.dataForm
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500
})
this.visible = false
this.$emit('refreshDataList')
}
})
}
})
}
}
}
</script>
.vue
<template>
<div class="mod-useinfo">
<el-form
:inline="true"
:model="searchForm"
@keyup.enter.native="getDataList()"
>
<el-form-item>
<el-input
v-model="searchForm.name"
placeholder="户主编号"
clearable
></el-input>
</el-form-item>
<el-form-item>
<el-button @click="getDataList()">查询</el-button>
<el-button
v-if="isAuth('pesticide:useinfo:save')"
type="primary"
@click="addOrUpdateHandle()"
>新增</el-button
>
<el-button
v-if="isAuth('pesticide:useinfo:delete')"
type="danger"
@click="deleteHandle()"
:disabled="dataListSelections.length <= 0"
>批量删除</el-button
>
</el-form-item>
</el-form>
<el-table
:data="dataList"
border
@selection-change="selectionChangeHandle"
style="width: 100%"
>
<el-table-column
type="selection"
header-align="center"
align="center"
width="50"
>
</el-table-column>
<el-table-column
prop="farmerId"
header-align="center"
align="center"
label="户主编号"
>
</el-table-column>
<el-table-column
prop="dateyear"
header-align="center"
align="center"
label="年份"
>
</el-table-column>
<el-table-column
prop="taskId"
header-align="center"
align="center"
label="任务id"
>
</el-table-column>
<el-table-column
fixed="right"
header-align="center"
align="center"
width="150"
label="操作"
>
<template slot-scope="scope">
<el-button
v-if="isAuth('pesticide:useinfo:info')"
type="text"
size="small"
@click="showDetails(scope.row.id)"
>查看</el-button
>
<el-button
v-if="isAuth('pesticide:useinfo:update')"
type="text"
size="small"
@click="addOrUpdateHandle(scope.row.id)"
>修改</el-button
>
<el-button
v-if="isAuth('pesticide:useinfo:delete')"
type="text"
size="small"
@click="deleteHandle(scope.row.id)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<el-pagination
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
:current-page="pageIndex"
:page-sizes="[10, 20, 50, 100]"
:page-size="pageSize"
:total="totalPage"
layout="total, sizes, prev, pager, next, jumper"
>
</el-pagination>
<!-- 弹窗, 新增 / 修改 -->
<add-or-update
v-if="addOrUpdateVisible"
ref="addOrUpdate"
@refreshDataList="getDataList"
></add-or-update>
</div>
</template>
<script>
import AddOrUpdate from './useinfo-add-or-update'
export default {
data () {
return {
searchForm: {
name: ''
},
dataList: [],
pageIndex: 1,
pageSize: 10,
totalPage: 0,
dataListSelections: [],
addOrUpdateVisible: false
}
},
components: {
AddOrUpdate
},
activated () {
this.getDataList()
},
methods: {
// 获取数据列表
getDataList () {
this.$http({
url: '/pesticide/useinfo/list',
method: 'get',
params: {
'page': this.pageIndex,
'limit': this.pageSize,
'name': this.searchForm.name
}
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataList = data.page.records
this.totalPage = data.page.total
} else {
this.dataList = []
this.totalPage = 0
}
})
},
// 每页数
sizeChangeHandle (val) {
this.pageSize = val
this.pageIndex = 1
this.getDataList()
},
// 当前页
currentChangeHandle (val) {
this.pageIndex = val
this.getDataList()
},
// 多选
selectionChangeHandle (val) {
this.dataListSelections = val
},
// 查看详情
showDetails (id) {
this.$router.push({
name: 'backUseinfo',
params: {
id: id,
disable: true
}
})
// this.addOrUpdateVisible = true
// this.$nextTick(() => {
// this.$refs.addOrUpdate.init(id, true)
// })
},
// 新增 / 修改
addOrUpdateHandle (id) {
this.$router.push({
name: 'backUseinfo',
params: {
id: id,
disable: false
}
})
// this.addOrUpdateVisible = true
// this.$nextTick(() => {
// this.$refs.addOrUpdate.init(id)
// })
},
// 删除
deleteHandle (id) {
let ids = id ? [id] : this.dataListSelections.map(item => {
return item.id
})
this.$confirm('确定对所选项进行[删除]操作?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$http({
url: '/pesticide/useinfo/delete',
method: 'post',
data: ids
}).then(({ data }) => {
if (data && data.code === 0) {
this.$message({
message: '操作成功',
type: 'success',
duration: 1500
})
this.getDataList()
}
})
}).catch(() => {
})
}
}
}
</script>