Blame view

src/components/inspection/chooseMaintainancePlanMachine.vue 5.32 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
daaebda8   wuxw   开发保养计划功能
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
    <el-dialog
      :title="$t('chooseMaintainancePlanMachine.title')"
      :visible.sync="visible"
      width="80%"
      @close="handleClose">
  
        <el-row :gutter="20">
          <el-col :span="8">
            <el-input
              v-model="searchForm.machineName"
              :placeholder="$t('chooseMaintainancePlanMachine.machineNamePlaceholder')"
              clearable
              @keyup.enter.native="queryMachines">
            </el-input>
          </el-col>
          <el-col :span="16">
            <el-button type="primary" @click="queryMachines">
              <i class="el-icon-search"></i>
              {{ $t('chooseMaintainancePlanMachine.search') }}
            </el-button>
            <el-button @click="resetMachines" style="margin-left: 10px;">
              <i class="el-icon-refresh"></i>
              {{ $t('chooseMaintainancePlanMachine.reset') }}
            </el-button>
          </el-col>
        </el-row>
  
        <el-table
          :data="tableData"
          border
          style="width: 100%; margin-top: 20px;">
          <el-table-column width="50">
            <template slot="header">
              <el-checkbox v-model="isAllChecked" @change="handleCheckAllChange"></el-checkbox>
            </template>
            <template slot-scope="scope">
              <el-checkbox
                v-model="scope.row.checked"
                @change="handleCheckChange(scope.row)">
              </el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="machineId"
            :label="$t('chooseMaintainancePlanMachine.machineId')"
            align="center">
          </el-table-column>
          <el-table-column
            prop="machineName"
            :label="$t('chooseMaintainancePlanMachine.machineName')"
            align="center">
          </el-table-column>
        </el-table>
  
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pagination.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.total"
          style="margin-top: 20px;">
        </el-pagination>
  
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('chooseMaintainancePlanMachine.cancel') }}</el-button>
        <el-button type="primary" @click="submitSelected">{{ $t('chooseMaintainancePlanMachine.submit') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { listEquipmentAccount, saveMaintainancePlanMachine } from '@/api/inspection/maintainancePlanMachineApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'ChooseMaintainancePlanMachine',
    data() {
      return {
        visible: false,
        searchForm: {
          machineName: ''
        },
        tableData: [],
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        isAllChecked: false,
        selectedMachines: [],
        formData: {}
      }
    },
    methods: {
      open(params) {
        this.formData = { ...params }
        this.visible = true
        this.resetMachines()
      },
      async queryMachines() {
        try {
          const params = {
            page: this.pagination.current,
            row: this.pagination.size,
            machineName: this.searchForm.machineName,
            communityId: getCommunityId()
          }
          const { data, records } = await listEquipmentAccount(params)
          this.tableData = data.map(item => ({
            ...item,
            checked: false
          }))
          this.pagination.total = records
          this.isAllChecked = false
        } catch (error) {
          this.$message.error(this.$t('chooseMaintainancePlanMachine.fetchError'))
        }
      },
      resetMachines() {
        this.searchForm.machineName = ''
        this.pagination.current = 1
        this.queryMachines()
      },
      handleCheckAllChange(val) {
        this.tableData.forEach(item => {
          item.checked = val
        })
        this.updateSelectedMachines()
      },
      handleCheckChange(row) {
        console.log(row)
        this.isAllChecked = this.tableData.every(item => item.checked)
        this.updateSelectedMachines()
      },
      updateSelectedMachines() {
        this.selectedMachines = this.tableData
          .filter(item => item.checked)
          .map(item => item.machineId)
      },
      async submitSelected() {
        if (this.selectedMachines.length === 0) {
          this.$message.warning(this.$t('chooseMaintainancePlanMachine.selectWarning'))
          return
        }
  
        try {
          const params = {
            communityId: getCommunityId(),
            planId: this.formData.planId,
            machines: this.selectedMachines
          }
          await saveMaintainancePlanMachine(params)
          this.$emit('success')
          this.visible = false
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
159
          this.$message.success(this.$t('common.operationSuccess'))
daaebda8   wuxw   开发保养计划功能
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
        } catch (error) {
          this.$message.error(this.$t('chooseMaintainancePlanMachine.addError'))
        }
      },
      handleSizeChange(val) {
        this.pagination.size = val
        this.queryMachines()
      },
      handleCurrentChange(val) {
        this.pagination.current = val
        this.queryMachines()
      },
      handleClose() {
        this.searchForm.machineName = ''
        this.tableData = []
        this.selectedMachines = []
        this.isAllChecked = false
      }
    }
  }
  </script>
  
  <style scoped>
  .dialog-footer {
    text-align: right;
  }
  </style>