<template>
<template v-slot:form="{ item }">
<el-row v-for="(dishesIngredient, index) in parArr" :key="index">
<el-form-item :label="'原料'+(index+1)" :prop="'data.ingredients.'+index+'.ingredientId'" :rules="{required: true, message:'原料不能为空', trigger: 'blur'}">
<el-select v-model="dishesIngredient.ingredientId" clearable :placeholder="`请选择原料`" @change="handleIngredientListChange($event, index)">
<el-option v-for="ingredient in ingredientList" v-show="dishesIngredient.ingredientId == ingredient.ingredientId || !selectIdsArr.includes(ingredient.ingredientId)" :key="ingredient.ingredientId" :label="ingredient.ingredientName" :value="ingredient.ingredientId" />
</el-select>
</el-form-item>
</el-row>
</template>
</template>
<script>
export default {
data() {
selectIdsArr:[],
parArr:[{guid:'ddddd',ingredientId:null,},{guid:'eeeee',ingredientId:null,},{guid:'ffff',ingredientId:null,}],
programList:[{
"ingredientId":1,
"ingredientName":"选项1"
},{
"ingredientId":2,
"ingredientName":"选项2"
},{
"ingredientId":3,
"ingredientName":"选项3"
}],
},
methods:{
// 切换原料
handleIngredientListChange(id, index) {
this.selectIdsArr = []
const ingredients = parArr
for (const item of ingredients) {
if (item.ingredientId) {
this.selectIdsArr.push(item.ingredientId)
}
}
},
}
}
</script>
|