yangys
2024-01-14 d91893dbd49538d312e299c1cc507a7792abd7d7
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
<template>
  <div class="app-container">
    <el-form :model="dataForm" status-icon ref="dataForm" label-width="100px" style="margin-top:10px;">
      <el-row>
        <el-col :xs="24":sm="12":md="12":lg="12":xl="12">
          <el-form-item label="设备名称" prop="machineName">
            <el-select v-model="dataForm.machineName" @change="changeMachine" filterable clearable placeholder="选择或搜索">
              <el-option
                v-for="(item, index) in machineList"
                :key="index"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24":sm="12":md="12":lg="12":xl="12">
          <el-form-item label="" prop="shift">
            <el-radio-group v-model="dataForm.radio">
              <el-radio :label="1">无</el-radio>
              <el-radio :label="2">二班</el-radio>
              <el-radio :label="3">三班</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div style="display: flex;justify-content: center;align-items: center;margin-top:15px;">
      <el-button size="mini" type="primary" @click="submitForm()" plain>确定</el-button>
    </div>
  </div>
</template>
 
<script>
  import { getMachineList, updateMachineShiftType } from '@/api/MdcApi'
 
  export default {
    data() {
      return {
        dataForm: {
          machineName: '',
          radio: ''
        },
        machineList: []
      }
    },
    mounted() {
      this.initDevices()
    },
    methods: {
      initDevices() {
        this.machineName = []
        getMachineList().then(res => {
          res.list.map(item => {
            this.machineList.push({
              label: item.name,
              value: item.name,
              id: item.id,
              shift: item.shiftType
            })
          })
        })
      },
      changeMachine() {
        this.machineList.find(item => {
          if (item.value === this.dataForm.machineName) {
            this.dataForm.radio = parseInt(item.shift)
          }
        })
      },
      submitForm() {
        this.listLoading = true
        this.$refs.dataForm.validate((valid) => {
          // console.log(this.dataForm.machineName)
          // console.log(this.dataForm.radio)
          if (valid) {
            updateMachineShiftType(this.dataForm.machineName, this.dataForm.radio).then(res => {
              this.listLoading = false
              if (res.result === 'SUCCESS') {
                // console.log('SUCCESS')
                this.machineList.find(item => {
                  if (item.value === this.dataForm.machineName) {
                    item.shift = this.dataForm.radio
                  }
                })
                alert('设置成功')
              } else {
                alert('设置失败')
              }
            })
          }
        })
      }
    }
  }
</script>