diff --git a/application/admin/controller/Granary.php b/application/admin/controller/Granary.php
index 59cb577..a068267 100644
--- a/application/admin/controller/Granary.php
+++ b/application/admin/controller/Granary.php
@@ -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']);
// 添加
diff --git a/application/admin/view/granary/index.html b/application/admin/view/granary/index.html
index d05d93d..75397b6 100644
--- a/application/admin/view/granary/index.html
+++ b/application/admin/view/granary/index.html
@@ -258,8 +258,8 @@
v-model="formData.storage">
-
+
-
+
+
+ 立式油罐 (油类)
+ 房型平房仓 (粮类)
+
+
+
-
- {{item}}
-
+
+
+ {{item}}
+
+ 自定义
+
+
+
+
+
+
+ 稻谷类指标模板
+ 小麦/玉米/杂粮指标模板
diff --git a/public/assets/js/backend/granary.js b/public/assets/js/backend/granary.js
index 81743e5..7b5ccec 100644
--- a/public/assets/js/backend/granary.js
+++ b/public/assets/js/backend/granary.js
@@ -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({