zenglf
2023-08-17 7442a435d058bd17d6fc679e1b7956bf3a5d32ae
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model
        ref="form"
        :model="model"
        :rules="validatorRules"
        slot="detail"
      >
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item
              label="单据号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="num"
            >
              <a-input
                v-model="model.num"
                placeholder="请输入单据号"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="是否停机维修"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="isStop"
            >
              <a-select
                v-model="isStop"
                :placeholder="disableSubmit ? '' : '请选择状态'"
                :options="isMaintenance"
                @change="(e) => handleChange(e, 1)"
                style="width: 100%"
                :disabled="disableSubmit"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item
              label="设备编码/名称/型号"
              :labelCol="{span:6}"
              :wrapperCol="{span:15}"
              prop="equipmentId"
            >
              <a-select
                v-model="equipmentId"
                :placeholder="disableSubmit ? '' : '请选择设备编码 / 名称 / 型号'"
                :options="equipmentList"
                @change="(e) => handleChange(e, 2)"
                :disabled="disableSubmit"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item
              label="故障描述"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-model="model.faultDescription"
                placeholder="请输入故障描述"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item
              label="故障时间"
              prop="name"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <j-date
                style="width: 100%"
                v-model="model.faultTime"
                placeholder="请选择故障时间"
                :showTime="true"
                dateFormat="YYYY-MM-DD HH:mm:ss"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="备 注"
            >
              <a-textarea
                allow-clear
                placeholder="请输入备注"
                v-model="model.remark"
              />
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item
              label="故障照片"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="name"
            >
              <j-image-upload-self
                v-model="model.photo"
                @ok="uploadOk"
              >
              </j-image-upload-self>
 
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>
 
<script>
 
import { httpAction, getAction, getFileAccessHttpUrl } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import JImageUploadSelf from '@/components/jeecg/JImageUploadSelf'
import Vue from 'vue'
export default {
  name: 'MalfunctionRepaireForm',
  components: {
    JImageUploadSelf
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        num: {
          rules: [
            { required: true, message: '请输入单据号!' },
          ]
        },
        equipmentId: {
          rules: [
            { required: true, message: '请选择设备!' },
          ]
        },
        faultTime: {
          rules: [
            { required: true, message: '请选择故障日期!' },
          ]
        },
      },
      disableSubmit: false,
      url: {
        add: "/eam/equipmentReportRepair/add",
        edit: "/eam/equipmentReportRepair/edit",
        queryById: "/eam/equipmentReportRepair/queryById",
        equipmentList: '/eam/equipment/list'
      },
      isMaintenance: [
        { label: '是', value: true },
        { label: '否', value: false },
      ],
      equipmentList: [],
      selectStatus: 1,
      isStop: false,
      equipmentId: '',
      equipmentList_bf: []
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    uploadOk(imgList) {
      debugger
      const res = this.getSrc(imgList[0])
      this.$set(this.model, 'photo', res);
      this.$set(this.model, 'sysUploadList', imgList);
    },
 
    getSrc(record) {
      if (!record.path) {
        return '';
      }
      //本地:local\Minio:minio\阿里云:alioss
      if (record.uploadType == 'local') {
        let ssoLoginFlag = Vue.ls.get("ssoLoginFlag");
        let deployMode = Vue.ls.get("deployMode");
        if (ssoLoginFlag && deployMode == "container") {
          var baseProject = Vue.ls.get("baseProject");
          console.log("baseProject==>" + baseProject)
 
          var hostname = window.location.protocol + "//" + window.location.host;
          var url = hostname + '/' + baseProject + '/sys/common/static';
          // return getFileAccessHttpUrl(record.path + record.encodeName, url, window._CONFIG['hyperTextTransfer'])
          return record.path + record.encodeName
        } else {
          //根据发布状态修改https 或 http
          // return getFileAccessHttpUrl(record.path + record.encodeName, this.url.urlDownload, window._CONFIG['hyperTextTransfer'])
          return record.path + record.encodeName
        }
      } else if (record.uploadType == 'alioss') {
        const OSS = require('ali-oss')
        const client = new OSS({
          // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
          region: window._CONFIG['region'],
          // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
          accessKeyId: window._CONFIG['accessKeyId'],
          accessKeySecret: window._CONFIG['accessKeySecret'],
          bucket: window._CONFIG['bucket'],
        })
        // object-key表示从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
        return client.signatureUrl(record.path)
      }
    },
    async fetchList() {
      this.equipmentList = []
      await getAction(this.url.equipmentList).then(res => {
        console.log(res);
        this.equipmentList_bf = res.result.records
        let tmparr = res.result.records
        tmparr.forEach(r => {
          this.equipmentList.push({
            label: `${r.num}/${r.name}/${r.model}`,
            value: r.id
          })
        })
 
      })
    },
    handleChange(e, type) {
      switch (type) {
        case 0:
          this.$set(this.model, 'status', e);
          return
        case 1:
          this.$set(this.model, 'isStop', e);
          return
        case 2:
          this.$set(this.model, 'equipmentId', e);
          return
      };
    },
    add() {
      this.modelDefault.status = 1
      this.modelDefault.isStop = false
      this.edit(this.modelDefault);
    },
    async edit(record) {
      await this.fetchList()
      this.model = Object.assign({}, record);
      if (this.model.id) {
 
        this.selectStatus = Number(record.status)
        record.isStop == 'true' ? this.isStop = true : this.isStop = false
        this.equipmentId = String(record.equipmentId)
      }
      this.visible = true;
 
    },
    handleOkAndAdd() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          httpAction(this.url.add, this.model, 'post').then((res) => {
            if (res.success) {
              that.$message.success(res.message);
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            this.model = {}
            this.$set(this.model, 'status', 1);
            this.$set(this.model, 'isStop', false);
            this.selectStatus = this.isStop = this.equipmentId = ''
          })
        }
      })
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
 
      })
    },
  }
}
</script>
<style>
</style>