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
<template>
  <a-modal
    :title="title"
    :width="700"
    @cancel="close"
    :visible="visible"
    :footer="null"
    style="height: 100%;overflow: auto;padding-bottom: 53px;">
 
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :form="form" :model="model" :rules="validatorRules" :labelCol="labelCol"
                    :wrapperCol="wrapperCol">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item label="车间分配" prop="productionId">
              <a-select v-model="model.productionId" placeholder="请选择车间" @change="handleSelectChange"
                        :disabled="disabledEdit">
                <a-select-option v-for="item in workshopTreeData" :key="item.id">
                  {{ item.productionName }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
 
          <a-col :span="12">
            <a-form-model-item label="轴数" prop="deviceManagementCode">
              <a-input allow-clear placeholder="请输入轴数" :readOnly="disabledEdit"
                       v-model="model.deviceManagementCode"/>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-model-item label="数控系统类别" prop="deviceManagementName">
              <a-input allow-clear placeholder="请输入数控系统类别" :readOnly="disabledEdit"
                       v-model="model.deviceManagementName"/>
            </a-form-model-item>
          </a-col>
        </a-row>
 
        <a-row :gutter="24">
          <a-col :span="24">
            <a-form-model-item label="设备组编号" :labelCol="labelColLong" :wrapperCol="wrapperColLong"
                               prop="equipmentIds">
              <a-input-search v-model="model.equipmentIds" :disabled="!model.productionId" @search="deviceSearch"
                              enter-button :placeholder='!model.productionId?"请选择车间":"请选择设备组编号"'/>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
 
 
    <div class="drawer-bottom-button">
      <a-space>
        <a-button @click="close">取消</a-button>
        <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
      </a-space>
    </div>
 
    <workshop-device-list-modal :productionId="model.productionId" ref="deviceListModel"
                                @sendSelectedRowKeys="getDeviceRowKeys"/>
  </a-modal>
</template>
 
<script>
import { httpAction } from '@/api/manage'
import WorkshopDeviceListModal from '@views/dnc/base/modules/DeviceCustomTypeManagement/WorkshopDeviceListModal.vue'
 
export default {
  name: 'DeviceCustomTypeManagementModal',
  components: { WorkshopDeviceListModal },
  props: {
    workshopTreeData: {
      type: Array
    }
  },
  data() {
    return {
      title: '',
      form: this.$form.createForm(this),
      validatorRules: {
        productionId: [
          {
            required: true, message: '请选择车间!'
          }
        ],
        deviceManagementCode: [
          {
            required: true, message: '请输入轴数!'
          }
        ],
        deviceManagementName: [
          {
            required: true, message: '请输入数控系统类别!'
          }
        ],
        equipmentIds: [
          {
            required: true, message: '请选择设备编号!'
          }
        ]
      },
      visible: false,
      disabledEdit: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 }
      },
      labelColLong: {
        xs: { span: 24 },
        sm: { span: 4 }
      },
      wrapperColLong: {
        xs: { span: 24 },
        sm: { span: 19 }
      },
      confirmLoading: false,
      url: {
        add: '/nc/deviceManagement/add',
        edit: '/nc/deviceManagement/edit'
      }
    }
  },
  methods: {
    // 车间选择器值发生改变时触发清空已选择的设备编号组
    handleSelectChange() {
      if (this.model.equipmentIds) delete this.model.equipmentIds
    },
 
    /**
     * 当设备选择完成后提交将已选择的设备编号列表以逗号隔开拆分到参数中
     * @param selectedRowKeys
     */
    getDeviceRowKeys(selectedRowKeys) {
      if (selectedRowKeys.length === 0) return
      this.$set(this.model, 'equipmentIds', selectedRowKeys.join(','))
      this.$refs.form.clearValidate()
    },
 
    deviceSearch() {
      this.$refs.deviceListModel.openPage()
      this.$refs.deviceListModel.title = '选择设备'
      this.$refs.deviceListModel.disableSubmit = false
    },
 
    add() {
      this.edit({})
    },
 
    edit(record) {
      this.visible = true
      this.model = Object.assign({}, record)
    },
 
    handleSubmit() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let apiUrl, method
          if (!this.model.id) {
            apiUrl = this.url.add
            method = 'post'
          } else {
            apiUrl = this.url.edit
            method = 'put'
          }
          httpAction(apiUrl, this.model, method)
            .then((res) => {
              if (res.success) {
                that.$notification.success({
                  message: '消息',
                  description: res.message
                })
                that.$emit('ok')
                that.close()
              } else {
                that.$notification.warning({
                  message: '消息',
                  description: res.message
                })
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        } else {
          return false
        }
      })
    },
 
    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form.clearValidate()
    }
  }
 
}
</script>
 
<style scoped>
.drawer-bottom-button {
  position: absolute;
  bottom: -40px;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>