CatModal.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-dialog class="cat-modal" top="6vh" width="800px" title="分类列表" :visible="_visible" @close="handleClose" append-to-body center>
  3. <el-row class="cat-modal__header" gutter="10">
  4. <el-col :span="8">
  5. <el-input v-model="params.cat_name" size="mini" placeholder="分类名称" @change="pageInfo.page=1;onSearch()" />
  6. </el-col>
  7. </el-row>
  8. <el-table size="mini" border v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
  9. <el-table-column type="selection" />
  10. <el-table-column label="序号" type="index" />
  11. <el-table-column label="分类名称" prop="search" />
  12. </el-table>
  13. <div class="cat-modal__bottom">
  14. <el-pagination
  15. size="mini"
  16. @current-change="handleCurrentChange"
  17. :current-page="pageInfo.page"
  18. :page-size="pageInfo.size"
  19. layout="total, prev, pager, next"
  20. :total="pageInfo.total"
  21. background
  22. />
  23. <el-button size="mini" type="primary" @click="submit">保存</el-button>
  24. </div>
  25. </el-dialog>
  26. </template>
  27. <script>
  28. import asyncRequest from '@/apis/service/serviceParam/supplierCat'
  29. export default {
  30. name: "CatModal",
  31. props:['visible'],
  32. computed:{
  33. _visible:{
  34. get(){
  35. return this.visible;
  36. },
  37. set(newVal){
  38. this.$emit('update:visible', newVal);
  39. }
  40. }
  41. },
  42. watch:{
  43. visible:{
  44. handler(newVisible){
  45. if(!newVisible) return;
  46. this.onSearch();
  47. },
  48. immediate: true
  49. }
  50. },
  51. data(){
  52. return {
  53. params:{
  54. cat_name: ""
  55. },
  56. selected:[],
  57. tableData:[],
  58. loading: false,
  59. pageInfo:{
  60. size: 10,
  61. page: 1,
  62. total:0
  63. },
  64. }
  65. },
  66. methods:{
  67. submit(){
  68. if(this.selected.length === 0) {
  69. this.$message,warning("请选择分类");
  70. return
  71. }
  72. this.$emit("selection-change",this.selected)
  73. this._visible = false;
  74. },
  75. handleSelectionChange(data){
  76. this.selected = data.map(({ id, search }) => ({ id, search }))
  77. },
  78. handleCurrentChange(page){
  79. this.pageInfo.page = page;
  80. this.onSearch();
  81. },
  82. handleClose(){
  83. this._visible = false;
  84. },
  85. async onSearch(){
  86. this.loading = true;
  87. const { size,page } = this.pageInfo;
  88. const result = await asyncRequest.cat_list({
  89. size, page,
  90. ...this.params
  91. });
  92. this.loading = false;
  93. this.tableData = result.data.list;;
  94. this.pageInfo.total = result.data.count;
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .cat-modal{
  101. &__header {
  102. display: flex;
  103. margin-bottom: 10px;
  104. }
  105. &__bottom {
  106. display: flex;
  107. justify-content: space-between;
  108. margin-top:10px;
  109. }
  110. }
  111. </style>