Blame view

ant-design-vue-jeecg/src/views/system/stocktaking/modules/CycleCountDetailModal.vue 12.2 KB
1
2
<template>
  <j-modal
3
4
    :title="title + '选择'"
    :width="1400"
5
6
7
8
9
10
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel">
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
    <a-row :gutter="24">
      <a-col :span="16">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" class="j-inline-form" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :xl="8" :lg="7" :md="8" :sm="24">
                <a-form-item label="库区">
                  <a-select
                    show-search
                    placeholder="请选择库区"
                    option-filter-prop="children"
                    v-model="queryParam.zoneCode"
                  >
                    <a-select-option v-for="item in zoneList" :key="item.name" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl="8" :lg="7" :md="8" :sm="24">
                <a-form-item label="库位编码">
                  <a-input placeholder="请输入库位编码" v-model="queryParam.locationCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="8" :lg="7" :md="8" :sm="24">
                <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              </a-col>
            </a-row>
          </a-form>
        </div>
        <div style="height: 340px">
          <a-table
45
            ref="table"
46
47
48
49
50
51
52
            size="middle"
            bordered
            :rowKey="rowKey"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
53
            :scroll="{ y: 235 }"
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
            :customRow="customRowFn"
            :rowSelection="{selectedRowKeys, onChange: onSelectChange, type: 'checkbox'}"
            class="j-table-force-nowrap"
            @change="handleTableChange">

              <span slot="zoneCode" slot-scope="zoneCode">
                <a-tag :key="zoneCode" color="blue">
                  {{ solutionZoneCode(zoneCode) }}
                </a-tag>
              </span>

          </a-table>
        </div>
      </a-col>
      <a-col :span="8">
69
        <a-card :title="'已选' + title" :bordered="false" :body-style="{padding:0}">
70
71
72
73
74
75
76
77
78
          <a-table size="middle" bordered :rowKey="rowKey" v-bind="selectedTable" class="j-table-force-nowrap">
            <span slot="action" slot-scope="text, record, index">
              <a @click="handleDeleteSelected(record, index)">删除</a>
            </span>
          </a-table>
        </a-card>
      </a-col>
    </a-row>
    <!-- 底部表格 start -->
79
    <div>
80
81
82
83
84
85
86
87
88
89
90
91
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="detailColumns"
        :dataSource="detailDataSource"
        :pagination="detailIpagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleDetailTableChange">
92
93
94
95
96
97
98
99
100
101
102
103
        <span slot="companyCode" slot-scope="companyCode">
          <a-tag :key="companyCode" color=blue>
            {{ solutionCompany(companyCode) }}
          </a-tag>
        </span>

        <span slot="inventoryStatus_dictText" slot-scope="inventoryStatus_dictText">
          <a-tag :key="inventoryStatus_dictText" :color="getStatusColor(inventoryStatus_dictText)">
            {{ inventoryStatus_dictText }}
          </a-tag>
        </span>
104
105
106
      </a-table>
    </div>
    <!-- 底部表格 end -->
107
108
109
110
  </j-modal>
</template>

<script>
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

import CycleCountDetailForm from './CycleCountDetailForm'
import JSelectBizQueryItem from "@comp/jeecgbiz/JButtonBizComponent/JSelectBizQueryItem";
import {JeecgListMixin} from "@/mixins/JeecgListMixin";
import {getCompanyList, getZoneList, createCycleCountDetailByInventory} from "@api/api";
import {getAction} from "@api/manage";

export default {
  name: 'CycleCountDetailModal',
  mixins: [JeecgListMixin],
  components: {
    JSelectBizQueryItem,
    CycleCountDetailForm
  },
  data() {
    return {
      title: '',
      loading: true,
      visible: false,
      disableSubmit: false,
      cycleCountHeader: {},
      queryParam: {},
      rowKey: 'id',
      selectedRowKeys: [],
      selectedRows: [],
      selectedRowIds: [],
      columns: [
138
139
140
141
142
143
144
        {title: 'ID', align: 'center', width: '10%', widthRight: '70%', dataIndex: 'id'},
        {title: '库区', align: 'center', width: '15%', widthRight: '70%', dataIndex: 'zoneCode', scopedSlots: {customRender: 'zoneCode'}},
        {title: '库位编码', align: 'center', dataIndex: 'locationCode'},
        {title: '容器编码', align: 'center', dataIndex: 'containerCode'},
        {title: '容器状态', align: 'center', width: '10%', dataIndex: 'containerStatus_dictText'},
        {title: '总数量', align: 'center', width: '15%', dataIndex: 'totalQty'},
        {title: '状态', align: 'center', width: '10%', dataIndex: 'enable_dictText'},
145
146
147
148
      ],
      detailColumns: [
        {title: '货主', align: "center", dataIndex: 'companyCode', scopedSlots: {customRender: 'companyCode'}},
        {title: '库位编码', align: "center", dataIndex: 'locationCode'},
谭毅彬 authored
149
        {title: '容器编码', align: "center", dataIndex: 'containerCode'},
150
151
152
153
154
        {title: '物料编码', align: "center", dataIndex: 'materialCode'},
        {title: '物料名称', align: "center", dataIndex: 'materialName'},
        {title: '物料规格', align: "center", dataIndex: 'materialSpec'},
        {title: '物料单位', align: "center", dataIndex: 'materialUnit'},
        {title: '数量', align: "center", dataIndex: 'qty'},
谭毅彬 authored
155
        {title: '库存状态', align: "center", dataIndex: 'inventoryStatus_dictText', scopedSlots: {customRender: 'inventoryStatus_dictText'}},
156
157
158
159
160
        {title: '批次', align: "center", dataIndex: 'batch'},
        {title: '入库日期', align: "center", dataIndex: 'receiptDate'}
      ],
      selectedTable: {
        pagination: false,
161
        scroll: {y: 235},
162
163
164
165
166
        columns: [
          {title: '库位编码', align: 'center', width: '70%', dataIndex: 'locationCode'},
          {title: '操作', dataIndex: 'action', align: 'center', width: 60, scopedSlots: {customRender: 'action'},}
        ],
        dataSource: [],
167
      },
168
169
170
171
172
      dataSource: [],
      detailDataSource: [],
      url: {
        list: '/inventory/inventoryHeader/freeList',
        pageByMainIds: "/inventory/inventoryDetail/pageByMainIds"
173
      },
174
175
176
177
178
      zoneList: [],
      companyList: [],
      ipagination: {
        current: 1,
        pageSize: 5,
179
        pageSizeOptions: ['5', '10', '100'],
180
181
182
183
184
185
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
186
      },
187
188
189
      detailIpagination: {
        current: 1,
        pageSize: 5,
190
        pageSizeOptions: ['5', '10', '100'],
191
192
193
194
195
196
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
197
198
      }
    }
199
200
  },
  methods: {
201
202
203
204
205
206
207
208
209
    searchReset() {
      Object.keys(this.queryParam).forEach(key => {
        this.queryParam[key] = ''
      })
      this.selectedRowKeys = []
      this.selectedRows = []
      this.selectedRowIds = []
      this.selectedTable.dataSource = []
      this.detailDataSource = []
210
      this.detailIpagination.total = 0
211
212
      this.loadData(1)
    },
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
    handleOk() {
      let params = {
        inventoryHeaderIds: this.selectedRowIds,
        cycleCountHeaderId: this.cycleCountHeader.id,
        cycleCountHeaderCode: this.cycleCountHeader.code,
      }
      if (this.selectedRowIds.length > 0) {
        createCycleCountDetailByInventory(params).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.$emit('ok')
          } else {
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.confirmLoading = false;
          this.close()
        })
      } else {
        this.$message.warning("至少选择一项")
      }
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
谭毅彬 authored
237
      // 解决翻页后 selectionRows 没记录上一页的问题
238
239
240
241
242
243
244
245
      if (selectedRowKeys.length === selectionRows.length) {
        this.selectionRows = selectionRows;
      } else {
        this.selectionRows = selectedRowKeys.map(key => (
          this.selectionRows.find(row => row.id === key) || selectionRows.find(row => row.id === key)
        ))
      }
      this.selectedTable.dataSource = this.selectionRows;
谭毅彬 authored
246
247
      this.selectedRowIds = this.selectionRows.map(x => x.id)
      this.loadDetailDataSource(1)
248
249
250
251
252
253
254
255
256
257
258
    },
    customRowFn(record) {
      return {
        on: {
          click: () => {
            let key = record[this.rowKey]
            let index = this.selectedRowKeys.indexOf(key)
            if (index === -1) {
              this.selectedRowKeys.push(key)
              this.selectedTable.dataSource.push(record)
              this.selectedRowIds.push(record.id)
谭毅彬 authored
259
              this.loadDetailDataSource(1);
260
261
262
263
264
265
266
267
268
269
270
            } else {
              this.handleDeleteSelected(record, index)
            }
          }
        }
      }
    },
    handleDeleteSelected(record, index) {
      this.selectedRowKeys.splice(this.selectedRowKeys.indexOf(record[this.rowKey]), 1)
      this.selectedRowIds.splice(this.selectedRowIds.indexOf(record.id), 1)
      this.selectedTable.dataSource.splice(this.selectedTable.dataSource.indexOf(record), 1)
谭毅彬 authored
271
      this.loadDetailDataSource(1);
272
    },
谭毅彬 authored
273
274
275
276
    handleDetailTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" === sorter.order ? "asc" : "desc"
谭毅彬 authored
277
      }
谭毅彬 authored
278
279
280
281
282
283
284
285
      this.detailIpagination = pagination;
      this.loadDetailDataSource();
    },
    loadDetailDataSource(pageCurrent) {
      if (pageCurrent && typeof pageCurrent == 'number') {
        this.detailIpagination.current =  pageCurrent;
      }
      this.loading = true;
286
287
      let params = {
        inventoryHeaderIds: this.selectedRowIds.join(","),
谭毅彬 authored
288
        pageNo:  this.detailIpagination.current,
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
        pageSize: this.detailIpagination.pageSize
      }
      getAction(this.url.pageByMainIds, params).then((res) => {
        if (res.success) {
          this.detailDataSource = res.result ? res.result.records : null;
          if (res.result && res.result.total) {
            this.detailIpagination.total = res.result.total;
          } else {
            this.detailIpagination.total = 0;
          }
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    close() {
307
308
      this.searchReset()
      this.visible = false
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
    },
    handleCancel() {
      this.close()
    },
    loadForm() {
      getZoneList().then(res => {
        if (res.success) {
          this.zoneList = res.result
        }
      })
      getCompanyList().then(res => {
        if (res.success) {
          this.companyList = res.result
        }
      })
    },
    solutionZoneCode(value) {
      let actions = []
      Object.keys(this.zoneList).some(key => {
        if (this.zoneList[key].code === '' + value) {
          actions.push(this.zoneList[key].name)
          return true
        }
      })
      return actions.join('')
    },
    solutionCompany(value) {
      let actions = []
      Object.keys(this.companyList).some(key => {
        if (this.companyList[key].code === '' + value) {
          actions.push(this.companyList[key].name)
          return true
        }
      })
      return actions.join('')
    },
    getStatusColor(status) {
      const colors = {
        '良品': 'green',
        '报废品': 'purple',
        '待确认	': 'grey',
        '次品': 'red',
        default: 'blue'
      };
      return colors[status] || colors.default;
    },
  },
  created() {
    this.loadForm();
358
  }
359
}
360
361
</script>
362
<style lang="less" scoped>
363
</style>