gaosp
2024-01-14 0d626ae57149d5ed40a32bd8b808ca6069aa6d5e
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
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
159
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!-- 机床状态分布 -->
<template>
  <div class="app-container">
    <div class="padding20" v-loading="loading" element-loading-text="查询数据中,请稍等">
      <el-form :inline="true" :model="dataForm" ref="dataForm" class="margintop20">
        <el-form-item label="车间" prop="workshop">
          <el-select size="mini" v-model="dataForm.workshop" filterable clearable placeholder="选择或搜索" @change="workshopChange()">
            <el-option
              v-for="item in workshoplist"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工段" prop="section">
          <el-select size="mini" v-model="dataForm.section" filterable clearable placeholder="选择或搜索" @change="sectionChange()">
            <el-option
              v-for="item in sectionlist"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机床">
          <el-select size="mini" v-model="dataForm.machines" filterable clearable multiple placeholder="选择或搜索机床名">
            <el-option
              v-for="item in machinelist"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备类型">
          <el-select size="mini" v-model="dataForm.machineType" filterable clearable placeholder="选择或搜索机床名">
            <el-option
              v-for="item in machineTypes"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="queryMachineAndTypes">查询</el-button>
          <el-button size="mini" type="primary" @click="updateMachineTypes">确定</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableData" v-loading.table="loading" element-loading-text="Loading" fit
                bclass="mdc-table" :row-class-name="tableRowClassName" style="width: 100%;border: 1px solid #ebeef5;">
        <el-table-column label='车间' align='center' prop='workshopName'></el-table-column>
        <el-table-column label='工段' align='center' prop='sectionName'></el-table-column>
        <el-table-column label='机床' align='center' prop='machineName'></el-table-column>
        <el-table-column label='型号' align='center' prop='typesName'></el-table-column>
      </el-table>
    </div>
    <div style="padding-top: 10px;display: flex;justify-content: flex-end;align-items: center;">
      <el-button-group>
        <el-button type="primary" icon="el-icon-arrow-left" size="mini" round @click="prePage()" :disabled="canPaging[0]">上一页</el-button>
        <el-button disabled  size="mini" plain>{{currentPage}}/{{totalPage}}</el-button>
        <el-button type="primary" size="mini" round @click="nextPage()" :disabled="canPaging[1]">下一页<i class="el-icon-arrow-right el-icon--right"></i></el-button>
      </el-button-group>
    </div>
  </div>
</template>
 
<script>
import { queryworkshoplist, getByWorkshopSection, queryMachineTypes, queryMachineAndTypes, updateMachineTypes } from '@/api/MdcApi'
export default {
  data() {
    return {
      loading: false,
      dataForm: {
        startTime: '',
        endTime: '',
        workshop: '', // 车间
        section: '', // 工段
        machines: [],
        machineType: '',
        pageNo: 0
      },
      tableData: [],
      workshoplistall: [],
      sectionlistall: [],
      machinelistall: [],
      workshoplist: [],
      sectionlist: [],
      machinelist: [],
      machineTypes: [],
      currentPage: 1,
      totalPage: 0
    }
  },
  mounted() {
    this.queryListByOrgTypecj()
    this.queryMachineTypes()
  },
  computed: {
    canPaging() {
      const tem = [false, false]
      tem[0] = (this.currentPage <= 1)
      tem[1] = (this.currentPage >= this.totalPage)
      return tem
    }
  },
  methods: {
    // 获取车间list
    queryListByOrgTypecj() {
      queryworkshoplist().then(res => {
        this.workshoplist = []
        if (res.workshopList.length > 0) {
          this.oldworkshoplist = res.workshopList
          res.workshopList.map(item => {
            this.workshoplist.push({
              value: item.name,
              label: item.name
            })
            item.sectionList.map(item => {
              this.sectionlist.push({
                value: item.name,
                label: item.name
              })
            })
          })
        }
        this.sectionChange()
        this.workshoplistall = this.workshoplist
        this.sectionlistall = this.sectionlist
        this.machinelistall = this.machinelist
      })
    },
    workshopChange() {
      const workshop = this.dataForm.workshop
      this.dataForm.section = ''
      if (workshop === '') {
        this.sectionlist = this.sectionlistall
        this.machinelist = this.machinelistall
      } else {
        this.sectionlist = []
        this.oldworkshoplist.map(item => {
          if (item.name === workshop) {
            item.sectionList.map(items => {
              this.sectionlist.push({
                value: items.name,
                label: items.name
              })
            })
          }
        })
        // this.dataForm.section = this.sectionlist[0].value
      }
      this.sectionChange()
    },
    sectionChange() {
      const workshop = this.dataForm.workshop
      const section = this.dataForm.section
      getByWorkshopSection(workshop, section).then(res => {
        this.machinelist = []
        res.map(item => {
          this.machinelist.push({
            value: item,
            label: item
          })
        })
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'odd-row'
      } else {
        return 'even-row'
      }
    },
    queryMachineTypes() {
      queryMachineTypes().then(res => {
        this.machineTypes = []
        if (res.machineTypes.length > 0) {
          res.machineTypes.map(item => {
            this.machineTypes.push({
              value: item.name,
              label: item.name
            })
          })
        }
      })
    },
    queryMachineAndTypes() {
      const currentPage = this.currentPage
      const workshop = this.dataForm.workshop
      const section = this.dataForm.section
      const machines = this.dataForm.machines
      queryMachineAndTypes(currentPage, workshop, section, machines).then(res => {
        this.totalPage = res.totalPage
        this.tableData = res.list
      })
    },
    updateMachineTypes() {
      const workshop = this.dataForm.workshop
      const section = this.dataForm.section
      const machines = this.dataForm.machines
      const machineType = this.dataForm.machineType
      updateMachineTypes(workshop, section, machines, machineType).then(res => {
        if (res.result === 'SUCCESS') {
          this.$message({
            type: 'success',
            message: '设置成功!'
          })
          this.queryMachineAndTypes()
        } else {
          this.$message({
            type: 'error',
            message: '失败!'
          })
        }
      })
    },
    // 前一页
    prePage() {
      if (this.currentPage > 1) {
        this.currentPage--
        this.queryMachineAndTypes()
      }
    },
    // 后一页
    nextPage() {
      if (this.currentPage < this.totalPage) {
        this.currentPage++
        this.queryMachineAndTypes()
      }
    }
  }
}
</script>
 
<style scoped>
  .padding20{
    margin-top: 50px
  }
</style>