Blame view

src/components/dev/SelectService.vue 3.76 KB
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  <template>
      <el-dialog :visible.sync="dialogVisible" title="选择接口" width="70%">
  
          <!-- 新增查询表单 -->
          <el-form :inline="true" :model="searchForm" class="search-form">
              <el-form-item :label="$t('service.table.serviceCode')">
                  <el-input v-model="searchForm.serviceCode" :placeholder="$t('service.table.serviceCode')"
                      clearable></el-input>
              </el-form-item>
              <el-form-item :label="$t('service.table.name')">
                  <el-input v-model="searchForm.name" :placeholder="$t('service.table.name')" clearable></el-input>
              </el-form-item>
              <el-form-item>
                  <el-button type="primary" @click="handleSearch">{{ $t('common.search') }}</el-button>
              </el-form-item>
          </el-form>
  
          <el-table :data="tableData" border style="width: 100%">
              <el-table-column :label="$t('service.table.serviceCode')" prop="serviceCode"></el-table-column>
              <el-table-column :label="$t('service.table.name')" prop="name"></el-table-column>
              <el-table-column :label="$t('service.table.serviceId')" prop="serviceId"></el-table-column>
              <el-table-column :label="$t('service.table.url')" prop="url"></el-table-column>
              <el-table-column label="操作" width="100">
                  <template slot-scope="scope">
                      <el-button @click="handleSelect(scope.row)" size="mini">
                          {{ $t('common.selectBtn') }}
                      </el-button>
                  </template>
              </el-table-column>
          </el-table>
          <div class="pagination-container">
              <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                  :current-page="page.current" :page-sizes="[10, 20, 30, 50]" :page-size="page.size"
                  layout="total, sizes, prev, pager, next, jumper" :total="page.total"></el-pagination>
          </div>
      </el-dialog>
  </template>
  
  <script>
  import { getServiceList } from '@/api/dev/serviceApi'
  
  export default {
      name: 'SelectService',
      data() {
          return {
              page: {
                  current: 1,
                  size: 10,
                  total: 0
              },
              tableData: [],
              dialogVisible: false,
              searchForm: {
                  serviceCode: '',
                  name: ''
              }
          }
      },
      created() { },
      methods: {
          openDialog() {
              this.dialogVisible = true;
              this._loadApiList();
          },
          async _loadApiList() {
              this.loading = true
              try {
                  const params = {
                      page: this.page.current,
                      row: this.page.size,
                      ...this.searchForm  // 将搜索条件合并到请求参数
                  }
                  const { services, total } = await getServiceList(params);
                  this.tableData = services;
                  this.page.total = total;
              } catch (error) {
                  console.error(error)
              } finally {
                  this.loading = false
              }
          },
          handleSelect(row) {
              this.$emit('select', row);
              this.dialogVisible = false;
          },
          handleSizeChange(val) {
              this.page.size = val;
              this._loadApiList();
          },
          handleCurrentChange(val) {
              this.page.current = val;
              this._loadApiList();
          },
          handleSearch() {
              this.page.current = 1; // 搜索时重置页码
              this._loadApiList();
          }
      }
  };
  </script>
  
  <style scoped>
  :deep(.el-dialog__header) {
      text-align: left;
  }
  
  :deep(.el-dialog__body) {
      padding-top: 10px
  }
  
  .search-form {
      text-align: right;
  }
  </style>