update 完成dialogForm的字段监听更新逻辑

This commit is contained in:
lb 2023-08-04 14:19:42 +08:00
parent 61a6e7dafb
commit bd56b12560
3 changed files with 194 additions and 203 deletions

View File

@ -38,80 +38,7 @@
@close="cancel" @close="cancel"
@cancel="cancel" @cancel="cancel"
@confirm="submitForm"> @confirm="submitForm">
<DialogForm <DialogForm v-if="open" ref="form" :dataForm="form" :rows="rows" />
v-if="open"
ref="form"
:dataForm="form"
:rows="[
[
{
select: true,
label: '产线',
url: '/base/production-line/listAll',
prop: 'productionId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
bind: {
filterable: true,
},
},
],
[
{
select: true,
label: '工段',
url: '/base/workshop-section/listAll',
prop: 'sectionId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
// {
// select: true,
// url: '', //
// label: '',
// prop: 'inspectionDetContent',
// rules: [{ required: true, message: '', trigger: 'blur' }],
// },
],
[
{
input: true,
label: '按钮盒识别码',
prop: 'buttonId',
rules: [
{
type: 'number',
message: '请输入数字',
trigger: 'blur',
transform: (val) => Number(val),
},
],
},
],
[{ input: true, label: '按钮盒模式', prop: 'model' }],
[
{
input: true,
label: '按钮值',
prop: 'keyValue',
rules: [
{
type: 'number',
message: '请输入100以内的数字',
trigger: 'blur',
transform: (val) => Number(val) <= 100 && Number(val),
},
],
bind: { type: 'number', min: 0, max: 100 },
},
],
[
{
textarea: true,
label: '检测内容',
prop: 'inspectionDetContent',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
]" />
</base-dialog> </base-dialog>
</div> </div>
</template> </template>
@ -134,6 +61,69 @@ export default {
components: {}, components: {},
data() { data() {
return { return {
rows: [
[
{
select: true,
label: '产线',
url: '/base/production-line/listAll',
prop: 'productionId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
bind: {
filterable: true,
},
},
],
[
{
select: true,
label: '工段',
url: '/base/workshop-section/listAll',
prop: 'sectionId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[
{
input: true,
label: '按钮盒识别码',
prop: 'buttonId',
rules: [
{
type: 'number',
message: '请输入数字',
trigger: 'blur',
transform: (val) => Number(val),
},
],
},
],
[{ input: true, label: '按钮盒模式', prop: 'model' }],
[
{
input: true,
label: '按钮值',
prop: 'keyValue',
rules: [
{
type: 'number',
message: '请输入100以内的数字',
trigger: 'blur',
transform: (val) => Number(val) <= 100 && Number(val),
},
],
bind: { type: 'number', min: 0, max: 100 },
},
],
[
{
textarea: true,
label: '检测内容',
prop: 'inspectionDetContent',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
],
searchBarFormConfig: [ searchBarFormConfig: [
{ {
type: 'input', type: 'input',

View File

@ -108,6 +108,18 @@ export default {
}, },
}, },
}, },
watch: {
rows: {
handler() {
console.log('watch triggered!');
this.$nextTick(() => {
this.handleOptions('watch');
});
},
deep: true,
immediate: false,
},
},
mounted() { mounted() {
// options // options
this.handleOptions(); this.handleOptions();
@ -125,32 +137,18 @@ export default {
const response = await this.$axios(url); const response = await this.$axios(url);
return response.data; return response.data;
}, },
handleOptions() { async handleOptions(trigger = 'monuted') {
// console.log("[dialogForm:handleOptions]") // console.log("[dialogForm:handleOptions]")
const promiseList = []; const promiseList = [];
this.rows.forEach((cols) => { this.rows.forEach((cols) => {
cols.forEach(async (opt) => { cols.forEach((opt) => {
if (opt.onChange) { if (opt.value && !this.form[opt.prop]) {
this.$watch(`form.${opt.prop}`, {
handler: (val) => {
this.$emit(opt.onChange.emit, val);
},
immediate: true,
});
}
if (opt.listen) {
//
this.$on(opt.listen, (val) => {
alert(val);
});
}
if (opt.value) {
// //
this.form[opt.prop] = opt.value; this.form[opt.prop] = opt.value;
} }
if (opt.options) { if (opt.options) {
this.optionListOf[opt.prop] = opt.options; this.$set(this.optionListOf, opt.prop, opt.options);
} else if (opt.url) { } else if (opt.url) {
// //
if (opt.select || (opt.input && !this.form?.id)) { if (opt.select || (opt.input && !this.form?.id)) {
@ -179,19 +177,23 @@ export default {
} }
}); });
} }
try {
// this.formLoading = true;
// console.log("[dialogForm:handleOptions:promiseList]", promiseList)
await Promise.all(promiseList.map((fn) => fn()));
this.formLoading = false;
// console.log("[dialogForm:handleOptions:optionListOf]", this.optionListOf)
} catch (error) {
console.log('[dialogForm:handleOptions:error]', error);
this.formLoading = false;
}
} }
}); });
}); });
// watch
if (trigger == 'watch') {
this.formLoading = false;
return;
}
try {
await Promise.all(promiseList.map((fn) => fn()));
this.formLoading = false;
// console.log("[dialogForm:handleOptions:optionListOf]", this.optionListOf)
} catch (error) {
console.log('[dialogForm:handleOptions:error]', error);
this.formLoading = false;
}
if (!promiseList.length) this.formLoading = false; if (!promiseList.length) this.formLoading = false;
}, },
}, },

View File

@ -38,107 +38,7 @@
@close="cancel" @close="cancel"
@cancel="cancel" @cancel="cancel"
@confirm="submitForm"> @confirm="submitForm">
<DialogForm <DialogForm v-if="open" ref="form" :dataForm="form" :rows="rows" />
v-if="open"
ref="form"
:dataForm="form"
:rows="[
[
{
select: true,
label: '检测内容ID',
url: '/base/quality-inspection-det/listAll',
prop: 'inspectionDetId',
labelKey: 'content',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
bind: {
filterable: true,
},
},
{
select: true,
label: '来源',
prop: 'source',
value: 1, //
options: [
{ label: '手动', value: 1 },
{ label: '自动', value: 2 },
],
bind: {
filterable: true,
},
},
// {
// input: true,
// label: '',
// prop: 'buttonId',
// rules: [
// {
// type: 'number',
// message: '',
// trigger: 'blur',
// transform: (val) => Number(val),
// },
// ],
// },
],
[
// listen线onChange
{
select: true,
label: '工段',
url: '/base/workshop-section/listAll',
prop: 'sectionId',
listen: 'productionLineChange', // emit
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
{
select: true,
label: '产线',
url: '/base/production-line/listAll',
prop: 'productionLineId',
onChange: { emit: 'productionLineChange' },
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[
{
input: true,
label: '检测人员',
prop: 'checkPerson',
rules: [
// {
// type: 'number',
// message: '',
// trigger: 'blur',
// transform: (val) => Number(val),
// },
],
},
{
datetime: true,
label: '检测时间',
prop: 'checkTime',
bind: {
format: 'yyyy-MM-dd HH:mm:ss',
'value-format': 'timestamp',
// 'value-format': 'yyyy-MM-dd HH:mm:ss',
clearable: true,
},
},
],
[
{
textarea: true,
label: '检测内容',
prop: 'inspectionDetContent',
value: '',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[{ textarea: true, label: '描述', prop: 'explainText' }],
[{ input: true, label: '备注', prop: 'remark' }],
]" />
</base-dialog> </base-dialog>
</div> </div>
</template> </template>
@ -164,6 +64,80 @@ export default {
mixins: [basicPageMixin], mixins: [basicPageMixin],
data() { data() {
return { return {
rows: [
[
{
select: true,
label: '检测内容ID',
url: '/base/quality-inspection-det/listAll',
prop: 'inspectionDetId',
labelKey: 'content',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
bind: {
filterable: true,
},
},
{
select: true,
label: '来源',
prop: 'source',
value: 1, //
options: [
{ label: '手动', value: 1 },
{ label: '自动', value: 2 },
],
bind: {
filterable: true,
},
},
],
[
{
select: true,
label: '产线',
url: '/base/production-line/listAll',
prop: 'productionLineId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
{
select: true,
label: '工段',
url: '/base/workshop-section/listAll', // url options
options: [], // options, options
prop: 'sectionId',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[
{
input: true,
label: '检测人员',
prop: 'checkPerson',
},
{
datetime: true,
label: '检测时间',
prop: 'checkTime',
bind: {
format: 'yyyy-MM-dd HH:mm:ss',
'value-format': 'timestamp',
// 'value-format': 'yyyy-MM-dd HH:mm:ss',
clearable: true,
},
},
],
[
{
textarea: true,
label: '检测内容',
prop: 'inspectionDetContent',
value: '',
rules: [{ required: true, message: '不能为空', trigger: 'blur' }],
},
],
[{ textarea: true, label: '描述', prop: 'explainText' }],
[{ input: true, label: '备注', prop: 'remark' }],
],
searchBarFormConfig: [ searchBarFormConfig: [
{ {
type: 'select', type: 'select',
@ -296,6 +270,31 @@ export default {
this.getList(); this.getList();
this.getProductLineList(); this.getProductLineList();
}, },
watch: {
// 线
'form.productionLineId': {
handler: function (val) {
if (val == null) return;
this.$axios('/base/workshop-section/listByParentId', {
params: {
id: val,
},
}).then((response) => {
this.$set(
this.rows[1][1], // this.rows
'options',
response.data.map((item) => {
return {
label: item.name,
value: item.id,
};
})
);
});
},
immediate: true,
},
},
methods: { methods: {
/** 获取搜索栏的产线列表 */ /** 获取搜索栏的产线列表 */
getProductLineList() { getProductLineList() {