|
|
@@ -185,6 +185,13 @@
|
|
|
<span>{{ parseTime(scope.row.packageDate, '{y}-{m}-{d}') }}</span>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="种植开始时间" align="center" prop="startPlantingTime" width="180">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ parseTime(scope.row.startPlantingTime, '{y}-{m}-{d}') }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
<el-table-column label="状态" align="center" prop="status">
|
|
|
<template slot-scope="scope">
|
|
|
<dict-tag :options="dict.type.batch_status" :value="scope.row.status"/>
|
|
|
@@ -250,8 +257,8 @@
|
|
|
<!-- 添加或修改批次管理对话框 -->
|
|
|
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
|
- <el-form-item label="批次号" prop="batchNo">
|
|
|
- <el-input v-model="form.batchNo" placeholder="请输入批次号" />
|
|
|
+ <el-form-item label="批次号" prop="batchNo" v-if="form.id">
|
|
|
+ <el-input v-model="form.batchNo" :disabled="true" />
|
|
|
</el-form-item>
|
|
|
<el-form-item label="商品名称" prop="productName">
|
|
|
<el-input v-model="form.productName" placeholder="请输入商品名称" />
|
|
|
@@ -265,6 +272,18 @@
|
|
|
<el-form-item label="商品简介" prop="productDesc">
|
|
|
<el-input v-model="form.productDesc" type="textarea" placeholder="请输入内容" />
|
|
|
</el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="所属农场" prop="farmId">
|
|
|
+ <treeselect v-model="form.farmId" :options="enabledDeptOptions"
|
|
|
+ @input="queryMachineNameFieldUser(form.farmId)" placeholder="请先选择所属农场" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="所属地块" prop="fieldId"> <!-- 修改这里 -->
|
|
|
+ <el-select v-model="form.fieldId" placeholder="请选择作业地块" :disabled="!form.farmId || loadingFields"
|
|
|
+ @change="handleFieldChange">
|
|
|
+ <el-option v-for="item in fields" :key="item.id" :label="item.fieldName" :value="item.id" />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
<el-form-item label="农场名称" prop="farmName">
|
|
|
<el-input v-model="form.farmName" placeholder="请输入农场名称" />
|
|
|
</el-form-item>
|
|
|
@@ -293,6 +312,17 @@
|
|
|
placeholder="请选择包装日期">
|
|
|
</el-date-picker>
|
|
|
</el-form-item>
|
|
|
+
|
|
|
+ <el-form-item label="开始种植时间" prop="startPlantingTime">
|
|
|
+ <el-date-picker clearable
|
|
|
+ v-model="form.startPlantingTime"
|
|
|
+ type="date"
|
|
|
+ value-format="yyyy-MM-dd"
|
|
|
+ placeholder="请选择开始种植日期">
|
|
|
+ </el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+
|
|
|
<el-form-item label="状态" prop="status">
|
|
|
<el-radio-group v-model="form.status">
|
|
|
<el-radio
|
|
|
@@ -302,6 +332,8 @@
|
|
|
>{{dict.label}}</el-radio>
|
|
|
</el-radio-group>
|
|
|
</el-form-item>
|
|
|
+
|
|
|
+
|
|
|
<!-- <el-form-item label="创建时间" prop="createdAt">
|
|
|
<el-date-picker clearable
|
|
|
v-model="form.createdAt"
|
|
|
@@ -554,15 +586,19 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { getMachineNameFieldUser, MachineNameFieldUserText } from "@/api/base/machineWorkRecords"
|
|
|
import { listBatch, getBatch, delBatch, addBatch, updateBatch } from "@/api/base/batch"
|
|
|
import QRCode from 'qrcode'
|
|
|
import { listReport, getReport, addReport, updateReport,batchAddReport,delReport } from "@/api/base/report"
|
|
|
import { listCertificate, getCertificate, addCertificate, updateCertificate } from "@/api/base/certificate"
|
|
|
-
|
|
|
-
|
|
|
+import { deptTreeSelect } from "@/api/system/user";
|
|
|
+import { listFieldName } from "@/api/base/field"
|
|
|
+import Treeselect from "@riophae/vue-treeselect";
|
|
|
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
|
|
|
|
|
|
export default {
|
|
|
name: "Batch",
|
|
|
+ components: { Treeselect },
|
|
|
dicts: ['batch_status'],
|
|
|
data() {
|
|
|
return {
|
|
|
@@ -570,6 +606,7 @@ export default {
|
|
|
loading: true,
|
|
|
// 选中数组
|
|
|
ids: [],
|
|
|
+ batchNos: [],
|
|
|
// 非单个禁用
|
|
|
single: true,
|
|
|
// 非多个禁用
|
|
|
@@ -584,6 +621,16 @@ export default {
|
|
|
title: "",
|
|
|
// 是否显示弹出层
|
|
|
open: false,
|
|
|
+ // 部门树选项
|
|
|
+ deptOptions: undefined,
|
|
|
+ // 所属地块
|
|
|
+ fieldIdList: [],
|
|
|
+ // 过滤掉已禁用部门树选项
|
|
|
+ enabledDeptOptions: undefined,
|
|
|
+
|
|
|
+ fields: [],
|
|
|
+ userName: [],
|
|
|
+ loadingFields: false, // 新增字段,用于控制地块加载状态
|
|
|
|
|
|
// 日期范围
|
|
|
dateRange: {
|
|
|
@@ -677,15 +724,18 @@ export default {
|
|
|
form: {},
|
|
|
// 表单校验
|
|
|
rules: {
|
|
|
- batchNo: [
|
|
|
- { required: true, message: "批次号不能为空", trigger: "blur" }
|
|
|
- ],
|
|
|
productName: [
|
|
|
{ required: true, message: "商品名称不能为空", trigger: "blur" }
|
|
|
],
|
|
|
farmName: [
|
|
|
{ required: true, message: "农场名称不能为空", trigger: "blur" }
|
|
|
],
|
|
|
+ farmId: [
|
|
|
+ { required: true, message: "所属农场不能为空", trigger: "blur" }
|
|
|
+ ],
|
|
|
+ fieldId: [
|
|
|
+ { required: true, message: "所属地块不能为空", trigger: "blur" }
|
|
|
+ ],
|
|
|
farmRegion: [
|
|
|
{ required: true, message: "农场所在地不能为空", trigger: "blur" }
|
|
|
],
|
|
|
@@ -697,8 +747,84 @@ export default {
|
|
|
},
|
|
|
created() {
|
|
|
this.getList()
|
|
|
+ this.getDeptTree();
|
|
|
+ this.getFieldNameList();
|
|
|
},
|
|
|
methods: {
|
|
|
+
|
|
|
+
|
|
|
+ handleFieldChange(value) {
|
|
|
+ // 当用户选择地块时,确保选中的地块属于当前农场
|
|
|
+ if (value && !this.fields.find(field => field.id === value)) {
|
|
|
+ // 如果选中的地块不在当前农场的地块列表中,清空选中
|
|
|
+ this.form.fieldId = null;
|
|
|
+ this.$message.warning('该地块不属于当前农场');
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ queryMachineNameFieldUser(farmId) {
|
|
|
+ // 清空地块列表,避免选择不同农场时出现残留数据
|
|
|
+ this.fields = [];
|
|
|
+
|
|
|
+ // 如果没有农场 ID,直接返回
|
|
|
+ if (!farmId) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置 loading 状态(可选)
|
|
|
+ this.loadingFields = true;
|
|
|
+
|
|
|
+ const data = {
|
|
|
+ deptId: farmId
|
|
|
+ }
|
|
|
+
|
|
|
+ getMachineNameFieldUser(data).then(response => {
|
|
|
+ this.fields = response.data.fields || [];
|
|
|
+
|
|
|
+ // 如果响应中有默认地块,设置为选中状态
|
|
|
+ if (response.data.defaultFieldId) {
|
|
|
+ this.form.fieldId = response.data.defaultFieldId;
|
|
|
+ } else if (this.form.fieldId && !this.fields.find(field => field.id === this.form.fieldId)) {
|
|
|
+ // 如果当前选中的地块不在新农场的地块列表中,清空选中
|
|
|
+ this.form.fieldId = null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭 loading 状态
|
|
|
+ this.loadingFields = false;
|
|
|
+ }).catch(() => {
|
|
|
+ this.loadingFields = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 查询地块名称 **/
|
|
|
+ getFieldNameList() {
|
|
|
+ listFieldName().then(res => {
|
|
|
+ this.fieldIdList = res;
|
|
|
+ this.fieldIdList.forEach(x => {
|
|
|
+ x.value = x.id;
|
|
|
+ x.label = x.fieldName;
|
|
|
+ })
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 查询部门下拉树结构 */
|
|
|
+ getDeptTree() {
|
|
|
+ deptTreeSelect().then(response => {
|
|
|
+ this.deptOptions = response.data;
|
|
|
+ this.enabledDeptOptions = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)))
|
|
|
+ });
|
|
|
+ },
|
|
|
+ filterDisabledDept(deptList) {
|
|
|
+ return deptList.filter(dept => {
|
|
|
+ if (dept.disabled) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (dept.children && dept.children.length) {
|
|
|
+ dept.children = this.filterDisabledDept(dept.children)
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ })
|
|
|
+ },
|
|
|
/** 查询批次管理列表 */
|
|
|
getList() {
|
|
|
this.loading = true
|
|
|
@@ -722,12 +848,15 @@ export default {
|
|
|
productSpec: null,
|
|
|
productImage: null,
|
|
|
productDesc: null,
|
|
|
+ farmId: null,
|
|
|
+ fieldId: null,
|
|
|
farmName: null,
|
|
|
farmRegion: null,
|
|
|
farmImage: null,
|
|
|
farmIntro: null,
|
|
|
produceDate: null,
|
|
|
packageDate: null,
|
|
|
+ startPlantingTime: null,
|
|
|
status: null,
|
|
|
createdAt: null,
|
|
|
updatedAt: null
|
|
|
@@ -753,6 +882,7 @@ export default {
|
|
|
// 多选框选中数据
|
|
|
handleSelectionChange(selection) {
|
|
|
this.ids = selection.map(item => item.id)
|
|
|
+ this.batchNos = selection.map(item => item.batchNo)
|
|
|
this.single = selection.length!==1
|
|
|
this.multiple = !selection.length
|
|
|
},
|
|
|
@@ -795,7 +925,8 @@ export default {
|
|
|
/** 删除按钮操作 */
|
|
|
handleDelete(row) {
|
|
|
const ids = row.id || this.ids
|
|
|
- this.$modal.confirm('是否确认删除批次管理编号为"' + ids + '"的数据项?').then(function() {
|
|
|
+ const batchNos = row.batchNo || this.batchNos
|
|
|
+ this.$modal.confirm('是否确认删除批次管理编号为"' + batchNos + '"的数据项?').then(function() {
|
|
|
return delBatch(ids)
|
|
|
}).then(() => {
|
|
|
this.getList()
|