Skip to content

Instantly share code, notes, and snippets.

@wisetc
Last active September 29, 2017 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wisetc/293bd6f9041bc2deec6843cd03442921 to your computer and use it in GitHub Desktop.
Save wisetc/293bd6f9041bc2deec6843cd03442921 to your computer and use it in GitHub Desktop.
el-autocomplete in el-table inline suggestion.
<template lang="pug">
el-table(:data="data" border)
el-table-column(label="批次")
template(scope="scope")
el-autocomplete(v-model="scope.row.rowTempModel.batch" :maxlength="50" style="width:100%;"
:fetch-suggestions="(queryString, cb) => {\
searchBatchOpt(scope.row, scope.$index).then(batchs => { \
let suggestions = batchs.map(batch => ({value: batch})); \
queryString ? cb(suggestions.filter(suggestion => suggestion.value.indexOf(queryString) > -1)) : cb(suggestions.slice(0,6))\
});\
}")
</template>
<script>
import { listMaterialBatch } from '@/xhr';
export default {
data() {
return {
data: []
}
},
methods: {
searchBatchOpt(row, index) {
return new Promise((resolve, reject) => {
if (!row.rowTempModel.batchOpts) {
listMaterialBatch({materialId: row.id}).then(({data}) => {
row.rowTempModel.batchOpts = data.data.data.sort((x, y) => y.id - x.id).map(item => item.batch);
resolve(row.rowTempModel.batchOpts);
});
} else {
resolve(row.rowTempModel.batchOpts);
}
});
}
}
}
</script>
@wisetc
Copy link
Author

wisetc commented Sep 29, 2017

You need listMaterialBatch function and element-ui to run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment