hyingbo
8 小时以前 e0e111d15a3f3995799b8b480c162c619ec897aa
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8">
            <a-form-model-item label="维修编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repairCode">
              <a-input v-model="model.repairCode" placeholder="系统自动生成" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repairName">
              <a-input v-model="model.repairName" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="disabled">
            <a-form-model-item label="维修状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repairStatus">
              <j-dict-select-tag placeholder="请选择维修状态" v-model="model.repairStatus" dictCode="major_partial_repair_status" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="维修类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="repairType">
              <a-select v-model="model.repairType" placeholder="请选择维修类型">
                <a-select-option value="大修">大修</a-select-option>
                <a-select-option value="项修">项修</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicant">
              <j-search-select-tag disabled placeholder="请选择申请人" v-model="model.applicant" dict="sys_user,realname, username, del_flag=0 and status=1"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请车间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicantProduction">
              <a-tree-select v-model="model.applicantProduction"
                             style="width: 100%"
                             :tree-data="treeDataAlias"
                             :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                             placeholder="请选择申请车间"
                             allow-clear
                             tree-default-expand-all
                             @change="handleWorkShopChange"
              >
              </a-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="计划开始日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="planStartDate">
              <j-date placeholder="请选择计划开始日期" v-model="model.planStartDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="计划结束日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="planEndDate">
              <j-date placeholder="请选择计划结束日期" v-model="model.planEndDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="disabled">
            <a-form-model-item label="实际开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualStartTime">
              <j-date :show-time="true" dateFormat="YYYY-MM-DD HH" placeholder="请选择实际开始时间" v-model="model.actualStartTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="disabled">
            <a-form-model-item label="实际结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="actualEndTime">
              <j-date :show-time="true" dateFormat="YYYY-MM-DD HH" placeholder="请选择实际结束时间" v-model="model.actualEndTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="disabled">
            <a-form-model-item label="总金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalAmount">
              <a-input-number :min=0 :precision="2" v-model="model.totalAmount" placeholder="请输入总金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicantReason">
              <a-input v-model="model.applicantReason" placeholder="请输入申请原因"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" v-if="disabled">
            <a-form-model-item label="责任人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="responsiblePerson">
              <j-search-select-tag  placeholder="请选择责任人" v-model="model.responsiblePerson" dict="sys_user,realname, username, del_flag=0 and status=1"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="故障描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="faultDescription">
              <a-textarea v-model="model.faultDescription" placeholder="请输入故障描述"  ></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" placeholder="请输入备注"  ></a-textarea>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-tabs defaultActiveKey="1">
            <a-tab-pane key="1" tab="维修明细">
                <j-vxe-table
                  ref="editableDetailTable"
                  :rowNumber="true"
                  :rowSelection="true"
                  :bordered="true"
                  :alwaysEdit="true"
                  :toolbar="true"
                  :toolbar-config="detailToolbarConfig"
                  keep-source
                  :height="300"
                  :loading="detail.loading"
                  :dataSource="detail.dataSource"
                  :columns="equipmentColumns"
                  style="margin-top: 8px;"/>
            </a-tab-pane>
          </a-tabs>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>
 
<script>
 
import { getAction, httpAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'
 
export default {
    name: 'EamMajorPartialRepairForm',
    mixins: [JVxeTableModelMixin],
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {},
        treeDataAlias: [],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          repairName: { required: true, message: '请输入项目名称!' },
          repairType: { required: true, message: '请选择维修类型!' },
          applicant: { required: true, message: '请选择申请人!' },
          applicantProduction: { required: true, message: '请输入申请车间!' },
          planStartDate: { required: true, message: '请选择计划开始日期!' },
          planEndDate: { required: true, message: '请选择计划结束日期!' },
          applicantReason: { required: true, message: '请输入申请原因!' },
          // responsiblePerson: { required: true, message: '请输入责任人!' },
          faultDescription: { required: true, message: '请输入故障描述!' }
        },
        treeData: [],
        equipmentOptions: [],
        detail: {
          loading: false,
          dataSource: [],
        },
        url: {
          add: "/eam/eamMajorPartialRepair/add",
          edit: "/eam/eamMajorPartialRepair/edit",
          queryById: "/eam/eamMajorPartialRepair/queryById",
          queryDetailList: "/eam/eamMajorPartialRepairDetail/list",
          queryEquipmentList: "/eam/equipment/asyncLoadEquipment",
          queryEquipmentByProductionList: "/eam/equipment/asyncLoadEquipmentByProduction",
          loadWorkShopOptions:'/mdc/mdcProduction/loadProductionTreeOptions'
        }
      }
    },
    computed: {
      detailToolbarConfig() {
        return {
          // 如果是详情页,则不显示 add 按钮
          btns: this.disabled ? ['remove', 'clearSelection'] : ['add', 'remove', 'clearSelection'],
          slots: ['prefix', 'suffix']
        };
      },
      formDisabled(){
        return this.disabled
      },
      equipmentColumns() {
        return [
          {
            title: '设备',
            key: 'equipmentId',
            type: JVXETypes.select,
            options: this.equipmentOptions,
            width: '20%',
            align: 'center',
            validateRules: [{ required: true, message: '设备不能为空!' }]
          },
          {
            title: '单价',
            key: 'unitPrice',
            type: JVXETypes.inputNumber,
            width: '10%',
            align: 'center',
            validateRules: [{ required: true, message: '单价不能为空!' }]
          },
          {
            title: '维修结果',
            key: 'repairResult',
            type: JVXETypes.textarea,
            width: '20%',
            align: 'center',
            visible: this.disabled
          },
          {
            title: '维修描述',
            key: 'repairDescription',
            type: JVXETypes.textarea,
            width: '30%',
            align: 'center',
            visible: this.disabled
          }
        ];
      }
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.loadWorkShopTree()
    },
    methods: {
      loadWorkShopTree() {
        //加载车间选择树
        getAction(this.url.loadWorkShopOptions).then(res => {
          if (res.success) {
            this.treeData = [...res.result]
            this.treeDataAlias = this.deepCopyAndModify(res.result)
          }else {
            that.$message.warning(res.message)
          }
        })
      },
      handleWorkShopChange(productionId) {
        this.detail.dataSource = []
        if (productionId) {
          this.getEquipmentList(productionId);
        } else {
          this.equipmentOptions = [];
        }
      },
      getEquipmentList(productionId) {
        //加载车间选择树
        getAction(this.url.queryEquipmentByProductionList, {productionId: productionId}).then((res) => {
          if (res.success) {
            this.equipmentOptions = res.result.map(item => {
              return {
                label: item.text,
                value: item.value
              }
            })
          }
        })
      },
      deepCopyAndModify(arr) {
        // 如果当前元素不是数组或对象,直接返回
        if (!Array.isArray(arr) && typeof arr !== 'object' || arr === null || arr.length === 0) {
          return arr;
        }
 
        // 如果是数组,创建一个新数组并递归处理每个元素
        if (Array.isArray(arr)) {
          const newArray = [];
          for (let i = 0; i < arr.length; i++) {
            newArray.push(this.deepCopyAndModify(arr[i]));
          }
          return newArray;
        }
 
        // 如果是对象,创建一个新对象并递归处理每个属性
        const newObj = {};
        for (const key in arr) {
          if (arr.hasOwnProperty(key)) {
            if(key === 'selectable') {
              newObj[key] = true;
            } else if(key === 'children') {
              newObj[key] = this.deepCopyAndModify(arr[key]);
            }else {
              newObj[key] = arr[key];
            }
          }
        }
        return newObj;
      },
      add () {
        this.edit(this.modelDefault)
      },
      edit (record) {
        this.model = Object.assign({
          applicant: Vue.ls.get(USER_INFO).username
        }, record);
        console.log("this.model", this.model)
        this.visible = true
        if (this.model.id) {
          getAction(this.url.queryDetailList, { repairId: this.model.id }).then((res) => {
            if (res.success) {
              console.log(res.result)
              if (res.result.total) {
                this.detail.dataSource = res.result.records
              }
            }
          })
        }
        getAction(this.url.queryEquipmentList, {}).then((res) => {
          if (res.success) {
            this.equipmentOptions = res.result.map(item => {
              return {
                label: item.text,
                value: item.value
              }
            })
          }
        })
      },
      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';
            }
            const detailList = this.$refs.editableDetailTable.getTableData()
            if (detailList.length === 0 || !detailList[0].equipmentId) {
              this.$message.warning('请添加维修明细!')
              that.confirmLoading = false;
              return
            }
            this.model.eamMajorPartialRepairDetailList = this.$refs.editableDetailTable.getTableData()
            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>