zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <el-dialog
    width="60%"
    title="下发包装任务"
    top="15vh"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    :close-on-click-modal="false"
    class="establishpackaging-dialog"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      label-width="80px"
      class="l-mes"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="工作站" prop="workstationName">
            <el-input
              v-model="dataForm.workstationName"
              placeholder="工作站"
              readonly
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="openWorkstationDialog()"
              ></el-button>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="库位" prop="locationName">
            <el-input
              v-model="dataForm.locationName"
              placeholder="库位"
              readonly
            >
              <el-button
                slot="append"
                icon="el-icon-search"
                @click="openLocationDialog()"
              ></el-button>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button
        type="primary"
        :disabled="isSubmit"
        v-thinclick="`createPackaging`"
        >下 发</el-button
      >
    </div>
    <workstationDialog
      :currshowlist.sync="showWorkstation"
      @listenToWorkStationEvent="selectWorkstation"
    />
    <locationDialog
      :currshowlist.sync="showLocation"
      @listenToLocationEvent="selectLocation"
    />
  </el-dialog>
</template>
<script>
import { addObj } from '@/api/warehouse/splittask'
import { fetchList as fetchLocationList } from '@/api/warehouse/location'
import workstationDialog from '@/views/common/workstation.vue'
import locationDialog from '@/views/common/location.vue'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    splitTasks: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  components: {
    workstationDialog,
    locationDialog
  },
  data() {
    return {
      innerVisible: false,
      showWorkstation: false,
      showLocation: false,
      dataForm: {
        locationId: null,
        locationName: null,
        workstationId: null,
        workstationName: null
      },
      dataRule: {
        workstationName: [
          { required: true, message: '工作站不能为空', trigger: 'blur' }
        ],
        locationName: [
          { required: true, message: '库位不能为空', trigger: 'blur' }
        ]
      },
      isSubmit: false
    }
  },
  methods: {
    // 初始化页面数据
    initForm() {
      this.$refs.dataForm.resetFields()
      this.getDefaultLocation()
    },
    // 获取默认的待发货库位
    getDefaultLocation() {
      fetchLocationList(
        Object.assign(
          {
            current: 1,
            size: 20
          },
          { locType: '9' }
        )
      ).then((res) => {
        if (res.data.code === 0) {
          const toBeShippeds = res.data.data.records
          if ((toBeShippeds != null) & (toBeShippeds.length > 0)) {
            const toBeShipped = toBeShippeds[0]
            this.dataForm.locationId = toBeShipped.id
            this.dataForm.locationName = toBeShipped.locName
          }
        }
      })
    },
    // 打开工作站对话框
    openWorkstationDialog() {
      this.showWorkstation = true
    },
    // 选中工作站
    selectWorkstation(workstation) {
      if (workstation) {
        this.dataForm.workstationId = workstation.id
        this.dataForm.workstationName = workstation.name
      }
    },
    // 库位弹窗
    openLocationDialog() {
      this.showLocation = true
    },
    // 选中库位
    selectLocation(location) {
      if (location) {
        this.dataForm.locationId = location.id
        this.dataForm.locationName = location.locName
      }
    },
    // 下达包装任务
    createPackaging() {
      this.isSubmit = true
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          let splitTask
          let packaging
          const packagings = []
          for (let i = 0; i < this.splitTasks.length; i++) {
            splitTask = this.splitTasks[i]
            packaging = {
              splitTaskId: splitTask.id,
              stockOrderId: splitTask.stockOrderId,
              partId: splitTask.partId,
              number: splitTask.reservedQuantity,
              outLocationId: splitTask.locationId,
              inLocationId: this.dataForm.locationId,
              partBatchNo: splitTask.partBatchNo,
              workstationId: this.dataForm.workstationId,
              reelNumber: splitTask.reelNumber,
              packingManner: '不打圈'
            }
            packagings.push(packaging)
          }
          addObj(packagings).then((response) => {
            if (response.data.code === 0) {
              // const data = response.data.data
              this.$message.success('下发成功')
              this.innerVisible = false
              this.$emit('refreshDataList')
            } else {
              this.$message.error('下发失败')
            }
            this.isSubmit = false
          })
        } else {
          this.isSubmit = false
        }
      })
    }
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.$nextTick(() => {
          this.initForm()
        })
      }
    }
  }
}
</script>
<style>
/*.establishpackaging-dialog .el-dialog__header {
  padding: 10px 20px 10px;
}
.establishpackaging-dialog .el-dialog__header .el-dialog__headerbtn {
  top: 10px;
}
.establishpackaging-dialog .el-dialog__body {
  padding: 5px 20px;
}
 
.establishpackaging-dialog .el-dialog__footer {
  padding: 5px 20px 10px;
}
 
.establishpackaging-dialog .el-dialog__body .avue-crud__pagination {
  margin-top: 0px;
  margin-bottom: 5px;
}*/
</style>