schangxiang@126.com
2024-08-16 65bd2dc1d4c1fb136af853c7ede93a338431be29
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<template>
  <a-modal
    :title="type == 'change' ? '设备换刀' : '设备上刀'"
    :width="1300"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
    <x-card :bordered="false">
      <div slot="content" class="table-page-search-wrapper">
        <a-form :form="form" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row :gutter="gutter">
 
            <a-col :md="colMd" :sm="colSm" v-if="type=='change'">
              <a-form-item label="原刀当前寿命(件)" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
                <a-input-number
                  :min="0"
                  :max="record.knifeToolLife"
                  style="width: 100%"
                  placeholder="请输入原刀当前寿命"
                  v-decorator="['oldCurrentLife', { rules: [{ required: true, message: '原刀当前寿命不能为空' }] }]"
                />
              </a-form-item>
            </a-col>
            <a-col :md="colMd" :sm="colSm" v-if="type=='change'">
              <a-form-item label="原刀计划寿命(件)" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
                <a-input-number
                  disabled
                  v-decorator="['oldKnifeToolLife']"
                  style="width: 100%" />
              </a-form-item>
            </a-col>
            <a-col :md="colMd" :sm="colSm" v-if="type=='change'">
              <a-form-item label="上刀时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
                <a-input disabled :value="record.changeStartTime" />
              </a-form-item>
            </a-col>
            <a-col :md="colMd" :sm="colSm">
              <a-form-item label="设备工位">
                <a-input
                  :disabled="type=='change'"
                  v-decorator="['station', { rules: [{ required: true, message: '设备工位不能为空' }] }]"
                  allow-clear
                  placeholder="请输入设备工位"
                />
              </a-form-item>
            </a-col>
 
            <a-col :md="colMd" :sm="colSm" v-show="false">
              <a-form-item label="id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback >
                <a-input v-decorator="['oldId']" />
              </a-form-item>
            </a-col>
 
            <!-- <a-col :md="colMd" :sm="colSm">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="getData(1)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col> -->
          </a-row>
        </a-form>
      </div>
    </x-card>
    <a-spin :spinning="spinning">
      <a-tabs v-model="key" @change="callback">
        <a-tab-pane key="1" tab="新刀">
          <a-table
            :columns="columns"
            :data-source="newData"
            :rowKey="(record) => record.id"
            :pagination="pages"
            :row-selection="{ type: 'radio', selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          >
            <span slot="currentLifeSlots" slot-scope="text, record">
              <a-input-number v-model="record.currentLife" :min="0" :max="record.knifeToolLife"> </a-input-number>
            </span>
          </a-table>
        </a-tab-pane>
<!--        <a-tab-pane key="2" tab="旧刀" force-render>
          <a-table
            :columns="columns"
            :data-source="oldData"
            :pagination="pages"
            :rowKey="(record) => record.id"
            :row-selection="{ type: 'radio', selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
          >
            <span slot="currentLifeSlots" slot-scope="text, record">
              <a-input-number v-model="record.currentLife" :min="0" :max="record.knifeToolLife"> </a-input-number>
            </span>
          </a-table>
        </a-tab-pane> -->
      </a-tabs>
    </a-spin>
  </a-modal>
</template>
 
<script>
import { XCard } from '@/components'
import { KnifeToolBaseInfoPage } from '@/api/modular/main/KnifeToolBaseInfoManage'
import { UpperKnife, ChangeKnife, OldKnifeQuery } from '@/api/modular/main/KnifeToolDataMonitorManage'
export default {
  components: { XCard },
  data() {
    return {
      gutter: 36,
      colMd: 6,
      colSm: 18,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 11 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 13 }
      },
      queryParam: {},
      visible: false,
      confirmLoading: false,
      spinning: false,
      key: '1',
      selectedRowKeys: [],
      selectedRows: [],
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          key: 'index',
          align: 'center',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          title: '刀具编号',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeToolID'
        },
        {
          title: '刀具型号',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeToolModel'
        },
        {
          title: '刀沿数',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeEdgeNumber'
        },
        {
          title: '计划寿命(件)',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeToolLife'
        },
        {
          title: '当前寿命(件)',
          align: 'center',
          sorter: true,
          dataIndex: 'currentLife',
          scopedSlots: { customRender: 'currentLifeSlots' }
        },
        {
          title: '刀身长度',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeLength'
        },
        {
          title: '刀具预警阈值(件)',
          align: 'center',
          sorter: true,
          dataIndex: 'knifeToolChangeAlertThreshold'
        },
        {
          title: '适配设备',
          align: 'center',
          sorter: true,
          dataIndex: 'equipmentName'
        },
        {
          title: '备注',
          align: 'center',
          sorter: true,
          dataIndex: 'remarks'
        }
      ],
      newData: [],
      oldData: [],
      record: {},
      pages: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true,
        showTotal: (total, range) => `${range[0]}-${range[1]}共${total}条`,
        pageSizeOptions: ['10', '20', '30', '40'],
        onChange: this.getData,
        onShowSizeChange: this.pageSizeChange
      },
      form: this.$form.createForm(this),
      type: ''
    }
  },
  methods: {
    show(record, type) {
      this.visible = true
      this.record = record
      this.type = type
      if (type == 'change') {
        this.$nextTick(() => {
          this.form.setFieldsValue(
            {
              oldId: record.id,
              station: record.station,
              oldKnifeToolLife: record.knifeToolLife,
              oldCurrentLife: record.currentLife
            })
        })
      }
      this.queryParam.equipmentID = record.equipmentID
      this.getData()
    },
    // 获取数据
    async getData(pageNo) {
      if (pageNo) {
        this.pages.current = pageNo
      }
      this.queryParam.pageNo = this.pages.current
      this.queryParam.pageSize = this.pages.pageSize
      this.spinning = true
      try {
        if (this.key == 1) {
          const { data } = await KnifeToolBaseInfoPage(this.queryParam)
          data.rows.forEach((item) => {
            item.currentLife = 0
          })
          this.newData = data.rows
          this.pages.total = data.totalRows
        } else {
          this.queryParam.workingProcedure = this.record.workingProcedure
          const { data } = await OldKnifeQuery(this.queryParam)
          data.rows.forEach((item) => {
            item.currentLife = 0
          })
          this.oldData = data.rows
          this.pages.total = data.totalRows
        }
      } catch (error) {
        console.log(error)
      }
      this.spinning = false
    },
    // 面板切换
    callback(key) {
      this.key = key
      this.selectedRowKeys = this.selectedRows = []
      this.pages = Object.assign(this.pages, { current: 1, pageSize: 10, total: 0 })
      this.getData()
    },
    handleSubmit() {
      const {
        form: { validateFields }
      } = this
 
      validateFields(async (errors, values) => {
        if (!errors) {
          for (const key in values) {
            if (typeof values[key] === 'object') {
              values[key] = JSON.stringify(values[key])
            }
          }
 
          if (this.selectedRows.length == 1) {
            Object.assign(values, this.selectedRows[0])
            values.workingProcedure = this.record.workingProcedure
            values.type = this.key
            this.confirmLoading = true
            console.log(values, 'values')
            if (this.type == 'change') {
              try {
              await ChangeKnife(values)
              this.$message.success('设备换刀成功')
              this.$emit('reflesh')
              this.handleCancel()
            } catch (error) {
              console.log(error)
            }
            } else {
              try {
              await UpperKnife(values)
              this.$message.success('设备上刀成功')
              this.$emit('toolDetailReflesh', this.record)
              this.handleCancel()
            } catch (error) {
              console.log(error)
            }
            }
          } else {
            this.$message.error('请选择刀具')
          }
          this.confirmLoading = false
        }
      })
    },
    handleCancel() {
      this.key = '1'
      this.selectedRowKeys = this.selectedRows = []
      this.form.resetFields()
      this.pages = Object.assign(this.pages, { current: 1, pageSize: 10, total: 0 })
      this.visible = false
    },
    // 选中数据改变
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    // 分页改变
    pageSizeChange(current, size) {
      this.pages.pageSize = size
      this.getData(1)
    }
  }
}
</script>
 
<style>
</style>