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
<template>
  <a-card
    :bordered="false"
    :class="'cust-erp-sub-tab'"
  >
    <a-table
      ref="table"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      @change="handleTableChange"
    >
 
      <template
        v-for="col in columns"
        :slot="col.dataIndex"
        slot-scope='text, record, index'
      >
        <div :key="col.dataIndex">
          <a-input-search
            v-if="col.dataIndex == 'materialName'"
            enter-button
            @search="onSearchMaterial(index)"
            :value="text"
            :read-only="true"
            @change="(e) => handleChange(e, record.key, col, index)"
          />
          <a-input-number
            :value="text"
            v-if="col.dataIndex == 'actualQuantity'"
            :min="1"
            :max="99999"
            @change="(e)=>handleChange(e, record.key, col, index)"
            :disabled="record.disabled"
          />
 
        </div>
      </template>
      <span
        slot='action'
        slot-scope='text, record,index'
      >
        <a @click="handleDeleteFake(index)">删除</a>
      </span>
    </a-table>
    <a-button
      style="width: 100%; margin-top: 16px; margin-bottom: 8px"
      type="dashed"
      icon="plus"
      @click="addMaterial"
      :disabled="repairOrderStatus!='3'"
    >添加实际用料
 
    </a-button>
    <div :style="{width: '100%',border: '1px solid #e9e9e9',padding: '10px 16px',background: '#fff',}">
      <a-row :style="{textAlign:'right'}">
        <a-button
          :style="{marginRight: '8px'}"
          @click="handleCancel"
          :disabled="repairOrderStatus!='3'"
        >
          清空
        </a-button>
        <a-button
          @click="handleOk(1)"
          type="primary"
          :style="{marginRight: '8px'}"
          :disabled="repairOrderStatus!='3'"
        >暂存</a-button>
        <a-button
          @click="handleOk(0)"
          type="primary"
          :disabled="repairOrderStatus!='3'"
        >保存</a-button>
      </a-row>
      <!-- :disabled="false" -->
    </div>
    <actual-material-select
      ref="actualMaterialSelect"
      @sendMaterialRecord="sendMaterialRecord"
    >
    </actual-material-select>
  </a-card>
</template>
<script>
import { postAction, getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import pick from 'lodash.pick'
import JEllipsis from '@/components/jeecg/JEllipsis'
import ActualMaterialSelect from './select/ActualMaterialSelect.vue'
export default {
  name: 'ActualMaterialEditTable',
  mixins: [JeecgListMixin],
  components: {
    JEllipsis,
    ActualMaterialSelect
  },
  props: {
    repairOrderId: {
      type: String,
      required: false,
      default: '-1'
    },
    repairOrderStatus: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      title: "工艺确认",
      flag: false,//主页面的标记位  用于区分是否确认过工单工艺 来区分table页展示 工单工序 还是产品工序
      visible: false,
      model: {},
      obj: {},
      maskClosable: true,
      confirmLoading: false,
      form: this.$form.createForm(this),
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 99,
        pageSizeOptions: ['99', '199'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      validatorRules: {
        materialId: {
          rules: [
            { required: true, message: '请选择物料!' },
          ]
        },
        actualQuantity: {
          rules: [
            { required: false, message: '请填写数量!' },
          ]
        },
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      drawerWidth: "100%",
      visible: false,
      disableSubmit: false,
      disableSelect: false,
      loading: false,
      dataSource: [],
      columns: [
       {
          title: '领料出库单号',
          dataIndex: 'num',
          align: "center",
          width: 150,
        },
        {
          title: '备件编码',
          dataIndex: 'sparePartNum',
          align: "center",
 
        },
        {
          title: '备件名称',
          dataIndex: 'sparePartName',
          align: "center",
 
        },
        {
          title: '规格',
          dataIndex: 'specification',
          align: "center",
        },
        {
          title: '型号',
          dataIndex: 'model',
          align: "center",
        },
        {
          title: '制造商',
          dataIndex: 'constructorName',
          align: "center",
        },
        {
          title: '主单位',
          dataIndex: 'mainUnitName',
          align: "center",
 
        },
        {
          title: '主数量',
          align: 'center',
          dataIndex: 'mainQuantity'
        },
        {
          title: '可用数量',
          align: 'center',
          dataIndex: 'availableQuantity'
        },
        {
          title: '使用数量',
          dataIndex: 'quantity',
          align: "center",
          scopedSlots: { customRender: 'quantity' },
          className: 'red',
 
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 250,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/eam/repairOrder/listRepairOrderActualMaterialByMainId",
        confirmMaterial: "/eam/repairOrder/addRepairOrderActualMaterial"
      },
      changeIndex: 0
    }
  },
 
  created() {
    this.queryParam['repairOrderId'] = this.repairOrderId;
    this.loadData(1);
  },
  methods: {
    addMaterial() {
      this.dataSource.push({ materialId: '', repairOrderId: this.repairOrderId, actualQuantity: 1, materialNum: '', materialName: '', materialModel: '', materialSpecification: '', unitId_dictText: '' })
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.$emit('close');
      this.dataSource = [];
      this.disableSubmit = false;
      this.visible = false;
    },
    handleDeleteFake(index) {
      this.dataSource.pop(index);
    },
    handleOk(saveStatus) {
      const that = this
      if (saveStatus == 0) {
        let materialDataSource = that.dataSource;
        let indexIdList = [];
        for (let i = 0; i < materialDataSource.length; i++) {
          if (materialDataSource[i].materialId == undefined || materialDataSource[i].materialId == null || materialDataSource[i].materialId == '') {
            that.$message.warning("请选择第" + (i + 1) + "行物料!");
            return false;
          }
          if (materialDataSource[i].actualQuantity == undefined || materialDataSource[i].actualQuantity == null || materialDataSource[i].actualQuantity == '') {
            that.$message.warning("请填写第" + (i + 1) + "行用料数!");
            return false;
          }
        }
      }
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = {}
          formData.repairOrderId = that.repairOrderId;
          formData.actualMaterialList = that.dataSource;
          let obj = obj = postAction(this.url.confirmMaterial, formData)
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
            that.loadData(1);
          })
        }
      })
    },
    handleChange(value, key, column, index) {
      let that = this;
      const temp = [...that.dataSource];
      const target = temp[index];
      if (target) {
        target[column.dataIndex] = value;
        if ('materialId' == column.dataIndex) {
          target['materialId'] = value;
        }
        if ('actualQuantity' == column.dataIndex) {
          target['actualQuantity'] = value;
        }
        that.dataSource = temp;
      }
    },
    onSearchMaterial(index) {
      this.recordIndex = index
      this.$refs.actualMaterialSelect.list()
      this.$refs.actualMaterialSelect.title = '物料选择'
    },
    sendMaterialRecord(data, val) {
      let record = data.record
      const temp = [...this.dataSource]
      const target = temp[this.recordIndex]
      if (target) {
        console.log(target)
        target.materialId = record.id;
        target.materialName = record.name;
        target.materialNum = record.num;
        target.materialModel = record.model;
        target.materialSpecification = record.specification;
        target.unitId_dictText = record.unitId_dictText;
        this.dataSource = temp
      }
    },
    clearList() {
      this.dataSource = [];
      this.ipagination.current = 1
    }
  },
 
  watch: {
    repairOrderId: {
      immediate: true,
      handler(val) {
        this.clearList();
        this.queryParam['repairOrderId'] = val
        this.loadData(1);
      }
    }
  }
}
</script>
 
<style scoped>
/deep/ .red {
  color: red;
}
</style>