优化:后台仓库支持任意仓号输入、仓型自由切换、自定义品种及参数智能兜底

这个提交包含在:
wikiboss
2026-10-15 11:25:34 +08:00
父节点 dbcd692bae
当前提交 1a2c1c342a
共有 3 个文件被更改,包括 126 次插入 和 40 次删除

查看文件

@@ -100,7 +100,11 @@ class Granary extends Backend
$data = $this->request->post();
if (!empty($data)) {
$id = $this->model->where(['num' => $data['num']])->value('id');
$data['granary_type'] = $data['num'] > 18 ? 2 : 1;
if (isset($data['granary_type']) && in_array(intval($data['granary_type']), [1, 2])) {
$data['granary_type'] = intval($data['granary_type']);
} else {
$data['granary_type'] = $data['num'] > 18 ? 2 : 1;
}
$data['content'] = json_encode($data['content']);
// 添加

查看文件

@@ -258,8 +258,8 @@
v-model="formData.storage"></el-input>
</el-form-item>
<el-form-item label="仓号:" prop="num">
<el-select @change="handleSelectNum" style="width: 330px;" v-model="formData.num" filterable clearable
placeholder="请您选择仓号">
<el-select @change="handleSelectNum" style="width: 330px;" v-model="formData.num" filterable allow-create default-first-option clearable
placeholder="请选择或直接输入仓号数字">
<el-option
v-for="(item, index) of numList"
:key="item"
@@ -268,11 +268,27 @@
</el-option>
</el-select>
</el-form-item>
<div v-if="formData.num">
<el-form-item label="仓房类型:" prop="granary_type">
<el-radio-group v-model="formData.granary_type" @change="changeGranaryType" size="small">
<el-radio-button :label="1">立式油罐 (油类)</el-radio-button>
<el-radio-button :label="2">房型平房仓 (粮类)</el-radio-button>
</el-radio-group>
</el-form-item>
<div v-if="formData.num !== '' && formData.num !== undefined">
<el-form-item label="存储品种:" prop="varieties">
<el-radio-group @input="varietiesChange" size="small" v-model="formData.varieties">
<el-radio-button v-for="(item, index) of varietiesList[varietiesType]" :label="item">{{item}}
</el-radio-button>
<div style="display: flex; align-items: center; flex-wrap: wrap; gap: 10px;">
<el-radio-group @input="varietiesChange" size="small" v-model="formData.varieties">
<el-radio-button v-for="(item, index) of varietiesList[varietiesType]" :key="item" :label="item">{{item}}
</el-radio-button>
<el-radio-button label="自定义">自定义</el-radio-button>
</el-radio-group>
<el-input v-if="isCustomVariety" v-model="customVariety" @input="handleCustomVarietyChange" placeholder="请输入自定义品种名称" style="width: 180px;" maxlength="20" show-word-limit size="small"></el-input>
</div>
</el-form-item>
<el-form-item v-if="formData.granary_type == 2" label="参数模板:">
<el-radio-group v-model="contentType" size="mini">
<el-radio-button label="two">稻谷类指标模板</el-radio-button>
<el-radio-button label="three">小麦/玉米/杂粮指标模板</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="" label="内容:" prop="content">

查看文件

@@ -188,6 +188,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
addDialog: false,
submitLoading: false,
title: '',
isCustomVariety: false,
customVariety: '',
// 类型:rapeseed=菜籽油、bean=大豆油、wheat=小麦、paddy=稻谷、corn=玉米
typeOptList: [{
id: '',
@@ -274,30 +276,78 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
};
this.loadData(this.search.keyword, this.currentPage, this.pageSize, this.search.sort);
},
// 仓号选择
// 仓号选择或任意输入
handleSelectNum(e) {
if (e > 18) {
this.varietiesType = 'two';
this.contentType = 'two';
this.formData.varieties = '稻谷';
this.contentFields[this.contentType]['varieties'] = '稻谷';
} else {
this.varietiesType = 'one';
this.contentType = 'one';
this.formData.varieties = '菜籽油';
this.contentFields[this.contentType]['varieties'] = '菜籽油';
if (!e && e !== 0) return;
let num = parseInt(e, 10);
if (isNaN(num)) return;
this.formData.num = num;
if (this.title === '添加') {
this.formData.granary_type = num > 18 ? 2 : 1;
this.changeGranaryType(this.formData.granary_type);
}
},
varietiesChange(e) {
if (e === '菜籽油' || e === '大豆油') {
// 自由切换仓型(1: 圆型油罐,2: 房型平房仓)
changeGranaryType(type) {
this.formData.granary_type = type;
if (type === 1) {
this.varietiesType = 'one';
this.contentType = 'one';
} else if (e === '小麦' || e === '玉米') {
this.contentType = 'three';
if (this.formData.varieties !== '菜籽油' && this.formData.varieties !== '大豆油' && !this.isCustomVariety) {
this.formData.varieties = '菜籽油';
}
} else {
this.contentType = 'two';
this.varietiesType = 'two';
if (this.formData.varieties === '菜籽油' || this.formData.varieties === '大豆油') {
this.formData.varieties = '稻谷';
this.contentType = 'two';
} else if (this.formData.varieties === '小麦' || this.formData.varieties === '玉米') {
this.contentType = 'three';
} else if (!this.isCustomVariety) {
this.contentType = 'two';
}
}
this.contentFields[this.contentType]['varieties'] = e;
this.contentFields[this.contentType]['varieties'] = this.formData.varieties;
},
// 品种切换
varietiesChange(e) {
if (e === '自定义') {
this.isCustomVariety = true;
if (this.customVariety) {
this.formData.varieties = this.customVariety;
}
} else {
this.isCustomVariety = false;
this.customVariety = '';
this.formData.varieties = e;
if (e === '菜籽油' || e === '大豆油') {
this.contentType = 'one';
this.formData.granary_type = 1;
this.varietiesType = 'one';
} else if (e === '小麦' || e === '玉米') {
this.contentType = 'three';
this.formData.granary_type = 2;
this.varietiesType = 'two';
} else {
this.contentType = 'two';
this.formData.granary_type = 2;
this.varietiesType = 'two';
}
}
this.contentFields[this.contentType]['varieties'] = this.formData.varieties;
},
// 自定义品种输入变更
handleCustomVarietyChange(val) {
this.formData.varieties = val;
if (val && val.indexOf('油') !== -1) {
this.contentType = 'one';
this.formData.granary_type = 1;
this.varietiesType = 'one';
} else {
this.formData.granary_type = 2;
this.varietiesType = 'two';
}
this.contentFields[this.contentType]['varieties'] = val;
},
// 选择图片
selectImage() {
@@ -328,18 +378,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
this.addDialog = true;
if (type === 'add') {
this.title = '添加';
this.contentFields = this.contentNewFields;
this.isCustomVariety = false;
this.customVariety = '';
this.contentFields = JSON.parse(JSON.stringify(this.contentNewFields));
this.formData = {
id: 0,
name: '',
image: '',
storage: '',
storage: '成都直属库有限公司本部',
num: '',
granary_type: 1,
varieties: '菜籽油',
content: []
};
this.contentType = 'one';
this.varietiesType = 'one';
} else {
this.title = '编辑';
let isPreset = ['菜籽油', '大豆油', '稻谷', '小麦', '玉米'].indexOf(item.varieties) !== -1;
this.isCustomVariety = !isPreset;
this.customVariety = isPreset ? '' : item.varieties;
this.formData = {
id: item.id,
@@ -348,24 +406,26 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
storage: item.storage,
num: item.num,
old_num: item.num,
granary_type: item.granary_type || (item.num > 18 ? 2 : 1),
varieties: item.varieties,
content: []
};
if (item.varieties === '菜籽油' || item.varieties === '大豆油') {
if (item.varieties === '菜籽油' || item.varieties === '大豆油' || (item.varieties && item.varieties.indexOf('油') !== -1)) {
this.contentType = 'one';
} else if (item.varieties === '小麦' || item.varieties === '玉米') {
} else if (item.varieties === '小麦' || item.varieties === '玉米') {
this.contentType = 'three';
} else {
this.contentType = 'two';
}
if (item.num > 18) {
this.varietiesType = 'two';
} else {
if (this.formData.granary_type == 1) {
this.varietiesType = 'one';
} else {
this.varietiesType = 'two';
}
this.contentFields[this.contentType]= item.content;
this.contentFields[this.contentType] = item.content || {};
}
},
// 查看详情
@@ -418,17 +478,23 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
return false;
}
let fields = this.contentFields[this.contentType];
if (!this.formData.varieties || this.formData.varieties === '自定义') {
this._sweetMsg({
type: 'warning',
content: '请您输入或选择存储品种'
});
return false;
}
let fields = this.contentFields[this.contentType] || {};
// 智能缺省填充:对未填写的非关键参数自动补全默认占位符 '-',避免粗暴拦截阻断创建
for (let key in fields) {
if (fields[key] === '') {
this._sweetMsg({
type: 'warning',
content: '请您完善仓库内容信息'
});
return false;
if (fields[key] === '' || fields[key] === null || fields[key] === undefined) {
fields[key] = '-';
}
}
fields['varieties'] = this.formData.varieties;
// 提交
let loading = this.$loading({