yangys
2024-01-16 c5488b34876f863558219f998e75c798c34af3cd
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
<!-- 日常保养 编辑 -->
<template>
    <!-- 新增弹框 -->
    <el-dialog
        :title="title"
        width="80%"
        :visible.sync="dialogVisibleAdd" class="role-select">
         <!-- 查询表单 -->
        <el-form :model="dataForm" ref="dataForm" label-width="150px" style="margin-top:10px;">
            <el-row :gutter="24">
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="设备名称" prop="machineName">
                        <el-select v-model="dataForm.machineId" placeholder="---请选择---">
                            <el-option
                            v-for="item in machineList"
                            :key="item.id"
                            :label="item.machineName"
                            :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="使用部门" prop="department">
                        <el-select v-model="dataForm.department" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in departmentlist"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="保养者" prop="maintainPerson">
                        <el-select v-model="dataForm.maintainPerson" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in userList"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="是否合格" prop="isQualified">
                        <el-select v-model="dataForm.isQualified" placeholder="---请选择---" clearable >
                            <el-option
                            v-for="item in isQualified"
                            :key="item.id"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                    <el-form-item label="保养内容与存在问题" prop="detail">
                        <el-input size="mini" type="text" v-model="dataForm.detail"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                </el-col>
                <el-col :xs="24":sm="10":md="10":lg="10":xl="10">
                    <el-form-item label="计划开始日期" prop="planStartDate">
                        <el-date-picker
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                        v-model="dataForm.planStartDate"
                        range-separator="至"
                        type="daterange"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :xs="24":sm="10":md="10":lg="10":xl="10">
                    <el-form-item label="计划完成日期" prop="planFinishDate">
                        <el-date-picker
                        format="yyyy 年 MM 月 dd 日"
                        value-format="yyyy-MM-dd"
                        v-model="dataForm.planFinishDate"
                        range-separator="至"
                        type="daterange"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                        </el-date-picker>
                    </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="savedata()" plain>保存</el-button>
            <el-button size="mini" type="warning" @click="resetForm()" plain>重置</el-button>
        </div>
 
    </el-dialog>
</template>
 
<script>
// import { getMachineList, maintainCreate, maintainUpdate, deviceManage, userList, departmentGet } from '@/api/MdcApi'
import { getMachineList, maintainCreate, maintainUpdate, userList, departmentGet } from '@/api/MdcApi'
import { getRequest } from '@/api/Api'
export default {
  props: ['styleName','styles','styleValue', 'departmentlist','machineList','userList'],
  data() {
    return {
      dataForm: {
        machineId: '',
        department: '',
        maintainPerson: '',
        isQualified: '',
        detail: '',
        style: '',
      },
      dialogVisibleAdd: false,
      // 下拉框
      isQualified: [{ // 是否合格
        label: '合格',
        value: '合格'
      }, {
        label: '不合格',
        value: '不合格'
      }], // 设备名称
      title: '新增',
      data: null, // 编辑数据回填
      no: null
    }
  },
  methods: {
    // 初始化
    init(n, data) {
      this.data = data
      this.no = n
      
      if (n === 1) {
        this.title = '新增' + this.styleName
        Object.keys(this.dataForm).forEach(key => {
          this.dataForm[key] = ''
        })
        this.dataForm['style'] = ''
      } else {
        this.title = '修改' + this.style
        Object.keys(this.dataForm).forEach(key => {
          this.dataForm[key] = data[key]
        })
      }
      this.dialogVisibleAdd = true
      this.machineName = []
      this.maintainPerson = []
      // this.initDevices() // 初始化数据
    },
    // 保存
    savedata() {
      // 新增保存
      // const style = 1
      const startDateFrom = this.dataForm.planStartDate[0]
      const startDateTo = this.dataForm.planStartDate[1]
      const completeDateFrom = this.dataForm.planFinishDate[0]
      const completeDateTo = this.dataForm.planFinishDate[1]
      const isQualified = this.dataForm.isQualified === '合格' ? 1 : 0
      if (this.no === 1) {
        console.log({
          ...this.dataForm,
          startDateFrom,
          startDateTo,
          completeDateFrom,
          completeDateTo,
          isQualified,
          styles: this.style
        })
        // return
        getRequest('maintainCreate',{
          ...this.dataForm,
          startDateFrom,
          startDateTo,
          completeDateFrom,
          completeDateTo,
          isQualified,
          style: this.styleValue
        }).then(res => {
          if (res.result === 'SUCCESS') {
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            this.$emit('reflash')
            // const that = this
            this.dialogVisibleAdd = false
          } else {
            this.$message({
              type: 'error',
              message: res.result
            })
          }
        })
      } else {
        getRequest('maintainUpdate',{
          ...this.dataForm,
          startDateFrom,
          startDateTo,
          completeDateFrom,
          completeDateTo,
          isQualified,
          style: this.styleValue
        }).then(res => {
          if (res.result === 'SUCCESS') {
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            this.$emit('reflash')
            // const that = this
            this.dialogVisibleAdd = false
          } else {
            this.$message({
              type: 'error',
              message: res.result
            })
          }
        })
      }
    },
    /**
         * 初始化已有机床
         */
    // 重置
    resetForm() {
      this.$refs.dataForm.resetFields()
    }
  },
  created() {
    // this.initDevices()
  }
}
</script>
<style lang="scss">
.el-form-item__content {
    .el-select,.el-input {
      width: 100%;
    }
  }
  .el-dialog__body {
    overflow: hidden;
  }
</style>
<style scoped>
    /* .el-table__body .cell{padding:3px;}
    .el-input__icon{line-height: 30px;}
    .el-input__inner{height:30px;line-height: 30px;}
    .el-form-item__content{line-height: 40px;}
    .el-col{height:36px;} */
</style>