cuijian
2023-10-25 fa921a7f2a42a4215299b79a995aad18a6225f74
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
<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='12'>
            <a-form-model-item label='操作证编号' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='num'>
              <a-input v-model='model.num' placeholder='请输入操作证编号' disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='姓名' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='userId'>
              <j-select-user-by-dep v-model='model.userId' :multi='false' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='发证日期' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='issueDate'>
              <j-date placeholder='请选择发证日期' v-model='model.issueDate' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='开始时间' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='startTime'>
              <j-date placeholder='请选择开始时间' v-model='model.startTime' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='结束时间' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='endTime'>
              <j-date placeholder='请选择结束时间' v-model='model.endTime' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='当前周期分数' :labelCol='labelCol' :wrapperCol='wrapperCol'
                               prop='currentCycleScore'>
              <a-input-number v-model='model.currentCycleScore' placeholder='请输入当前周期分数' style='width: 100%' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='设备统一编码' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='equipmentIds'>
              <j-multi-select-tag type='list_multi' v-model='model.equipmentIds' dictCode='mom_eam_equipment,num,id'
                                  placeholder='请选择设备统一编码' />
            </a-form-model-item>
          </a-col>
          <a-col :span='12'>
            <a-form-model-item label='状态' :labelCol='labelCol' :wrapperCol='wrapperCol' prop='status'>
              <j-dict-select-tag type='list' v-model='model.status' dictCode='certificate_status'
                                 placeholder='请选择状态' disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span='24'>
            <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-form-model>
    </j-form-container>
    <!-- 子表单区域 -->
    <a-tabs v-model='activeKey' @change='handleChangeTabs'>
      <a-tab-pane tab='操作证管理明细' :key='refKeys[0]' :forceRender='true'>
        <j-vxe-table
          keep-source
          :ref='refKeys[0]'
          :loading='operationCertificateDetailTable.loading'
          :columns='operationCertificateDetailTable.columns'
          :dataSource='operationCertificateDetailTable.dataSource'
          :maxHeight='300'
          :disabled='formDisabled'
          :rowNumber='true'
          :rowSelection='true'
          :toolbar='true'
        />
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>
 
<script>
 
import { getAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
 
export default {
  name: 'OperationCertificateForm',
  mixins: [JVxeTableModelMixin],
  components: {
    JFormContainer
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      model: {},
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
 
      validatorRules: {
        num: [
          { required: true, message: '请输入操作证编号!' }
        ],
        currentCycleScore: [
          { required: true, message: '请输入当前周期分数!' },
          { pattern: /^-?\d+\.?\d*$/, message: '请输入数字!' }
        ]
      },
      refKeys: ['operationCertificateDetail'],
      tableKeys: ['operationCertificateDetail'],
      activeKey: 'operationCertificateDetail',
      // 操作证管理明细
      operationCertificateDetailTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '证书ID',
            key: 'operationCertificateId',
            type: JVXETypes.hidden,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '日期',
            key: 'happenDate',
            type: JVXETypes.date,
            width: '120px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '类型',
            key: 'type',
            type: JVXETypes.select,
            dictCode: 'certificate_change_type',
            width: '100px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          {
            title: '设备统一编码',
            key: 'equipmentId',
            type: JVXETypes.selectSearch,
            dictCode: 'mom_eam_equipment,num,id ',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '扣分项',
            key: 'deductionItem',
            type: JVXETypes.selectSearch,
            dictCode: 'mom_eam_base_deduction_item,content,id ',
            width: '500px',
            placeholder: '请输入${title}',
            defaultValue: ''
          },
          // {
          //   title: '扣分周期',
          //   key: 'period',
          //   type: JVXETypes.normal,
          //   width: '200px',
          //   placeholder: '请输入${title}',
          //   defaultValue: ''
          // }
        ]
      },
      url: {
        add: '/eam/operationCertificate/add',
        edit: '/eam/operationCertificate/edit',
        queryById: '/eam/operationCertificate/queryById',
        operationCertificateDetail: {
          list: '/eam/operationCertificate/queryOperationCertificateDetailByMainId'
        }
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    //子表加载
    loadSubTableData: {
      type: Boolean,
      default: true,
      required: false
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
    loadSubTableDataMode() {
      return this.loadSubTableData
    }
  },
  created() {
  },
  methods: {
    addBefore() {
      this.operationCertificateDetailTable.dataSource = []
    },
    getAllTable() {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      this.$nextTick(() => {
      })
      console.log( "this.loadSubTableDataMode:"+this.loadSubTableDataMode)
      // 加载子表数据
      if (this.model.id && this.loadSubTableDataMode) {
        let params = { id: this.model.id }
        // 加载子表数据
        this.requestSubTableData(this.url.operationCertificateDetail.list, params, this.operationCertificateDetailTable)
      }
 
    },
    //校验所有一对一子表表单
    validateSubForm(allValues) {
      return new Promise((resolve, reject) => {
        Promise.all([]).then(() => {
          resolve(allValues)
        }).catch(e => {
          if (e.error === VALIDATE_FAILED) {
            // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
            this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
          } else {
            console.error(e)
          }
        })
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        operationCertificateDetailList: allValues.tablesValue[0].tableData
      }
    },
    validateError(msg) {
      this.$message.error(msg)
    }
 
  }
}
</script>
 
<style scoped>
</style>