展示:
代码实现:
<el-form-item label="物资编码:" prop="materialCode">
<el-input
@input="autoSearch"
v-model.trim="newForm.materialCode"
placeholder="请填写物资编码"
:disabled="diaTitle == '编辑物资'"
/>
</el-form-item>
<ul v-if="showList">
<p @click="chooseCode(index)" style="height:30px;line-height:30px;margin-left:70px" v-for="(it,index) in this.searchList" :key="index">
{{it}}
</p>
</ul>
data() {
return {
showList:true,
}
methods: {
// 模糊搜索功能
autoSearch(eve) {
console.log(eve);
this.showList = true // 选了编码后已经关闭可选内容,如改变搜索条件需要重启showList
materiaGetType().then(res => {
if (res.code === 0) {
this.searchList = res.data;
this.newSearchList = res.data
}
});
this.autoShow()
},
autoShow() {
var allowPass = true;
if (!allowPass) {
return;
}
setTimeout(() => {
allowPass = false;
console.log('来了没')
this.searchList = [];
this.newSearchList.forEach(ele => {
if(ele.indexOf(this.newForm.materialCode)!== -1){
console.log('是吗')
this.searchList.push(ele)
}
});
}, 1000);
},
chooseCode(ind){
this.showList = false
this.newForm.materialCode = this.searchList[ind]
},
}