Mr.Shi
2023-08-11 5a7fb4358eb902ce139096f20ef3c0625adcd7f4
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
367
<template>
  <TableLayout v-permissions="['ext:woutboundext:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="120px" label-suffix=":" inline>
      <el-form-item label="出库单号" prop="code">
        <el-input v-model="searchForm.code" placeholder="请输入" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="出库仓库" prop="warehouseId">
        <el-select v-model="searchForm.warehouseId" clearable filterable placeholder="请选择仓库">
          <el-option
            v-for="item in warehouses"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="来源单据类型" prop="originType">
        <el-select v-model="searchForm.originType" clearable placeholder="请选择来源单据类型">
          <el-option
            v-for="(item, index) in originTypes"
            :key="index"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="来源单据编号" prop="originCode">
        <el-input v-model="searchForm.originCode" placeholder="请输入来源单据编号" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="单据状态" prop="status">
        <el-select v-model="searchForm.status" clearable placeholder="请选择">
          <el-option
            v-for="(item, index) in status"
            :key="index"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="单据类型" prop="billType">
        <el-select v-model="searchForm.billType" clearable placeholder="请选择单据类型">
          <el-option
            v-for="(item, index) in billType"
            :key="index"
            :label="item.name"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="计划出库时间" prop="planDate">
        <el-date-picker
          v-model="planDate"
          type="daterange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="dateChange">
        </el-date-picker>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['ext:woutboundext:create']">
        <li><el-button type="primary" @click="openWOutbound(1)" v-permissions="['ext:woutboundext:create']">新建</el-button></li>
        <li><el-button type="primary" @click="openWOutbound(2)" v-permissions="['ext:woutboundext:create']">销售出库</el-button></li>
      </ul>
      <el-table
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="出库单号" fixed="left" min-width="140px">
          <template slot-scope="{row}">
            <el-button type="text" @click="showDetail(row)">
              {{ row.code }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="单据类型" min-width="100px">
          <template slot-scope="{row}">
            {{ billToStr(row.billType) }}
          </template>
        </el-table-column>
        <el-table-column prop="planDate" label="计划出库时间" min-width="100px"></el-table-column>
        <el-table-column label="物料信息" min-width="180px">
          <template slot-scope="{row}">
            <div :title="materailsStr(row)" style="width:100%">
              <div class="long-title-style" v-if="row.woutboundDetails.length >= 1">{{ materailStr(row.woutboundDetails[0]) }}</div>
              <div class="long-title-style" v-if="row.woutboundDetails.length >= 2">{{ materailStr(row.woutboundDetails[1]) }}</div>
              <div class="long-title-style" v-if="row.woutboundDetails.length >= 3">{{ materailStr(row.woutboundDetails[2]) }}</div>
              <div class="long-title-style" v-if="row.woutboundDetails.length >= 4">{{ materailStr(row.woutboundDetails[3]) }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="originType" label="来源单据类型" min-width="100px">
          <template slot-scope="{row}">
            {{ originTypeToStr(row.originType) }}
          </template>
        </el-table-column>
        <el-table-column prop="originCode" label="来源单据编号" min-width="140px">
          <template slot-scope="{row}">
            {{ row.originCode || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="发货仓库" show-overflow-tooltip min-width="140px">
          <template slot-scope="{row}">
            <span class="long-title-style">{{ row.warehouseCode + '|' + row.warehouseName}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="procedureName" label="申请工序" min-width="100px"></el-table-column> -->
        <el-table-column prop="status" label="申请人员" show-overflow-tooltip min-width="100px">
          <template slot-scope="{row}">
            <span class="long-title-style">{{ applyStr(row) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="单据状态" min-width="100px">
          <template slot-scope="{row}">
            {{ statusToStr(row.status) }}
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="140px"></el-table-column>
        <el-table-column label="操作" fixed="right" min-width="80px">
          <template slot-scope="{row}">
            <span v-if="row.status==0" style="margin-left:8px" v-permissions="['ext:woutboundext:delete']">
              <el-button type="text" @click="cancel(row)" >取消</el-button>
            </span>
            <span v-else>-</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      ></pagination>
    </template>
    <!-- 新建/修改 -->
    <OperaWOutboundExtWindow ref="operaWOutboundExtWindow" @success="handlePageChange"/>
    <OperaWboundDetailExtWindow ref="operaWboundDetailExtWindow"/>
    <OrderCancel ref="orderCancel" @success="handlePageChange"/>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaWOutboundExtWindow from '@/components/ext/OperaWOutboundExtWindow'
import OperaWboundDetailExtWindow from '@/components/ext/OperaWboundDetailExtWindow'
import OrderCancel from '@/components/ext/OperaWOrderCancel'
import { wOutboundExt } from '@/api/ext/wOutboundExt'
import { queryWarehouseAllData } from '@/api/ext/warehouseExt'
export default {
  name: 'WOutboundExt',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaWOutboundExtWindow, OperaWboundDetailExtWindow, OrderCancel },
  data () {
    return {
      // 搜索
      searchForm: {
        code: '',
        originType: '',
        originCode: '',
        warehouseId: '',
        status: '',
        planDateStart: '',
        planDateEnd: '',
        billType: '',
        type: 0 // 0出库 1入口
      },
      planDate: [],
      warehouses:[],
      warehousesChild: [],  // 传给子级的仓库
      originTypes: [
      // 0采购订单、1生产工单、2销售订单、3转库单、4盘点单
        { name: '采购订单', id: 0 },
        { name: '生产工单', id: 1 },
        { name: '销售订单', id: 2 },
        { name: '转库单', id: 3 },
        { name: '盘点单', id: 4 }
      ],
      status: [
      // 0已生成、1已处理、2已取消
        { name: '待出库', id: 0 },
        { name: '已出库', id: 1 },
        { name: '已取消', id: 2 }
      ],
      // billType: [
      //   { name: '车间领料', id: 1 },
      //   { name: '计划领料', id: 2 },
      //   { name: '机台备料', id: 3 },
      //   { name: '完工入库', id: 4 },
      //   { name: '车间转库', id: 5 },
      //   { name: '外协领料转库', id: 6 },
      //   { name: '外协完工转库', id: 7 },
      //   { name: '产品入库', id: 8 },
      //   { name: '产品转库', id: 9 },
      //   { name: '让步放行入库', id: 10 },
      //   { name: '让步放行转库', id: 11 },
      //   { name: '客返品返修领料', id: 12 },
      //   { name: '客返品返修入库', id: 13 },
      //   { name: '跨组织转库', id: 14 },
      //   { name: '工序报废', id: 15 },
      //   { name: '客退品返修领料', id: 16 },
      //   { name: '客退品返修入库', id: 17 },
      //   { name: '销售出库', id: 18 },
      //   { name: '让步销售', id: 19 },
      //   { name: '工单投料', id: 20 },
      //   { name: '仓库报废', id: 21 },
      //   { name: '客退品检验领料', id: 22 },
      //   { name: '客返品检验领料', id: 23 },
      // ],
      billType: [
        { name: '车间领料', id: 1 },
        { name: '计划领料', id: 2 },
        { name: '机台备料', id: 3 },
        { name: '完工入库', id: 4 },
        { name: '车间转库', id: 5 },
        { name: '外协领料转库', id: 6 },
        { name: '外协完工转库', id: 7 },
        { name: '产品入库', id: 8 },
        { name: '产品转库', id: 9 },
        { name: '让步放行入库', id: 10 },
        { name: '让步放行转库', id: 11 },
        { name: '客返返修领料', id: 12 },
        { name: '客返返修入库', id: 13 },
        { name: '跨组织转库', id: 14 },
        { name: '工序报废', id: 15 },
        { name: '客退返修领料', id: 16 },
        { name: '客退返修入库', id: 17 },
        { name: '销售出库', id: 18 },
        { name: '让步销售', id: 19 },
        { name: '工单投料', id: 20 },
        { name: '仓库报废', id: 21 },
        { name: '客退检验领料', id: 22 },
        { name: '客返检验领料', id: 23 },
        { name: '库存调整', id: 28 },
        { name: '废品入库', id: 30 },
      ]
    }
  },
  provide() {
    return {
      warehouses: () => this.warehousesChild
    }
  },
  created () {
    this.config({
      module: '出库单信息',
      api: '/ext/wOutboundExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    this.search()
  },
  activated() {
    queryWarehouseAllData({ status: 1, rootDepartId: this.$store.state.userInfo.curComDepartment.id })
      .then(res => {
        this.warehouses = res
      })
      .catch(err => {
        console.log(err)
      })
  },
  methods: {
    openWOutbound(type) {
      if (type == 1) {
        this.warehousesChild = this.warehouses
        this.$refs.operaWOutboundExtWindow.open('新建出库单')
      } else {
        let arr = []
        this.warehouses.forEach(element => {
          if (element.isSales == '0') {
            arr.push(element)
          }
        });
        this.warehousesChild = arr
        this.$refs.operaWOutboundExtWindow.open('新建销售出库单')
      }
    },
    dateChange (v) {
      this.searchForm.planDateStart = v[0]
      this.searchForm.planDateEnd = v[1]
    },
    reset () {
      // console.log('rest', this.searchDate)
      this.planDate = []
      this.searchForm.planDateStart = ''
      this.searchForm.planDateEnd = ''
      this.$refs.searchForm.resetFields()
      this.search()
    },
    showDetail (row) {
      wOutboundExt(row.id)
        .then(res => {
          this.$refs.operaWboundDetailExtWindow.open('出库详情', res, 0)
        })
        .catch(err => {
          this.$tip.errpr(err)
        })
    },
    cancel (row) {
      this.$refs.orderCancel.open('取消出库', { id: row.id }, 0)
    },
    originTypeToStr (type) {
      for (const item of this.originTypes) {
        if (item.id === parseInt(type)) {
          return item.name
        }
      }
      return '-'
    },
    statusToStr (status) {
      for (const item of this.status) {
        if (item.id === status) {
          return item.name
        }
      }
      return ''
    },
    materailsStr (row) {
      let str = ''
      for (const item of row.woutboundDetails) {
        if (str) {
          str = str.concat('\n')
        }
        str = str.concat(this.materailStr(item))
      }
      return str
    },
    materailStr (item) {
      let str = '';
      str += `【${item.materialCode}】${item.materialName}`
      if (item.batch) {
        str += `(${item.batch})`
      }
      if (item.procedureName) {
        str += ` | ${item.procedureName}`
      }
      switch (item.qualityType) {
        case 0: str += ' | 合格'; break;
        case 1: str += ' | 不良'; break
        case 2: str += ' | 报废'; break
      }
      str += ` X ${item.num}`
      return str
    },
    applyStr (row) {
      return `${row.userName}/${row.userDepartName}`
    },
    billToStr (type) {
      for (const item of this.billType) {
        if (item.id === type) return item.name
      }
      return '-'
    }
  }
}
</script>