index.vue
11 KB
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
<template>
<div class="NCC-common-layout">
<div class="NCC-common-layout-center">
<!-- 搜索区域 -->
<el-row class="NCC-common-search-box" :gutter="16">
<el-form @submit.native.prevent>
<el-col :span="6">
<el-form-item label="产品名称">
<el-input v-model="query.productName" placeholder="请输入产品名称" clearable />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="产品分类">
<el-input v-model="query.productCategory" placeholder="请输入产品分类" clearable />
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="负责部门">
<el-select v-model="query.departmentId" placeholder="请选择负责部门" clearable style="width: 100%">
<el-option v-for="dept in departmentList" :key="dept.id" :label="dept.name"
:value="dept.id">
</el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
<el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
</el-form-item>
</el-col>
</el-form>
</el-row>
<!-- 主要内容区域 -->
<div class="NCC-common-layout-main NCC-flex-main">
<!-- 操作按钮区域 -->
<div class="NCC-common-head">
<div>
<el-button type="primary" icon="el-icon-plus" @click="addInventoryHandle()">添加库存</el-button>
<!-- <el-button type="success" icon="el-icon-edit" @click="editInventoryHandle()"
:disabled="selectedIds.length !== 1">编辑库存</el-button> -->
<el-button type="warning" icon="el-icon-s-operation"
@click="usageRecordHandle()">使用记录</el-button>
<el-button type="text" icon="el-icon-download" @click="exportData()">导出</el-button>
</div>
<div class="NCC-common-head-right">
<el-tooltip effect="dark" content="刷新" placement="top">
<el-link icon="icon-ym icon-ym-Refresh NCC-common-head-icon" :underline="false"
@click="reset()" />
</el-tooltip>
<screenfull isContainer />
</div>
</div>
<!-- 库存列表表格 -->
<NCC-table v-loading="listLoading" :data="list" has-c @selection-change="handleSelectionChange">
<el-table-column prop="productName" label="产品名称" align="left" show-overflow-tooltip />
<el-table-column prop="productCategory" label="产品分类" align="left" />
<el-table-column prop="price" label="单价" align="left">
<template slot-scope="scope">
{{ formatMoney(scope.row.price) }}
</template>
</el-table-column>
<el-table-column prop="quantity" label="库存数量" align="left" >
<template slot-scope="scope">
<span :class="scope.row.quantity <= 10 ? 'text-danger' : ''">{{ scope.row.quantity }}</span>
</template>
</el-table-column>
<el-table-column prop="standardUnit" label="单位" align="left" />
<el-table-column prop="totalValue" label="总价值" align="left">
<template slot-scope="scope">
{{ formatMoney(scope.row.totalValue) }}
</template>
</el-table-column>
<!-- <el-table-column prop="departmentName" label="负责部门" align="left" /> -->
<el-table-column prop="createTime" label="创建时间" align="left" :formatter="ncc.tableDateFormat">
<!-- <template slot-scope="scope">
{{ scope.row.createTime | dateTimeFormat }}
</template> -->
</el-table-column>
<el-table-column label="操作" align="center" width="200" fixed="right">
<template slot-scope="scope">
<el-button type="text" @click="viewInventoryInfo(scope.row)">查看详情</el-button>
<el-button type="text" @click="editInventory(scope.row)">编辑</el-button>
<el-button type="text" @click="viewUsageRecords(scope.row)">使用记录</el-button>
</template>
</el-table-column>
</NCC-table>
<!-- 分页组件 -->
<pagination v-show="total > 0" :total="total" :page.sync="query.currentPage"
:limit.sync="query.pageSize" @pagination="getList" />
</div>
</div>
<!-- 添加/编辑库存弹窗 -->
<InventoryForm v-if="inventoryFormVisible" ref="InventoryForm" @refreshDataList="getList" />
<!-- 库存详情弹窗 -->
<InventoryInfoDialog v-if="inventoryInfoVisible" ref="InventoryInfoDialog" />
<!-- 使用记录弹窗 -->
<UsageRecordDialog v-if="usageRecordVisible" ref="UsageRecordDialog" />
</div>
</template>
<script>
import { getInventoryList } from '@/api/extend/lqInventory'
import { getUserList } from '@/api/permission/user'
import InventoryForm from './InventoryForm'
import InventoryInfoDialog from './InventoryInfoDialog'
import UsageRecordDialog from './UsageRecordDialog'
import Pagination from '@/components/Pagination'
import request from '@/utils/request'
export default {
name: 'LqInventory',
components: {
InventoryForm,
InventoryInfoDialog,
UsageRecordDialog,
Pagination
},
data() {
return {
query: {
productName: '',
productCategory: '',
departmentId: '',
currentPage: 1,
pageSize: 20
},
list: [],
total: 0,
listLoading: true,
inventoryFormVisible: false,
inventoryInfoVisible: false,
usageRecordVisible: false,
selectedIds: [],
departmentList: [] // 部门列表
}
},
created() {
this.getDepartmentList()
this.getList()
},
methods: {
// 获取部门列表
getDepartmentList() {
request({
url: `/api/permission/Organize/96240625-934F-490B-8AA6-0BC775B18468/Department`,
method: 'GET',
}).then((res) => {
if (res.code == 200 && res.data.list.length > 0) {
this.departmentList = res.data.list.map(item => ({
id: item.id,
name: item.fullName,
}))
} else {
this.departmentList = []
}
})
},
// 获取库存列表
getList() {
this.listLoading = true
getInventoryList(this.query).then(response => {
if (response.code === 200) {
this.list = response.data.list || []
this.total = (response.data.pagination && response.data.pagination.total) || 0
} else {
this.$message.error(response.msg || '获取库存列表失败')
}
this.listLoading = false
}).catch(() => {
this.listLoading = false
})
},
// 搜索
search() {
this.query.currentPage = 1
this.getList()
},
// 重置
reset() {
this.query = {
productName: '',
productCategory: '',
departmentId: '',
currentPage: 1,
pageSize: 20
}
this.getList()
},
// 添加库存
addInventoryHandle() {
this.inventoryFormVisible = true
this.$nextTick(() => {
this.$refs.InventoryForm.init()
})
},
// 编辑库存
editInventoryHandle() {
if (this.selectedIds.length === 0) {
this.$message.warning('请选择一个库存记录')
return
}
if (this.selectedIds.length > 1) {
this.$message.warning('请只选择一个库存记录')
return
}
const selectedInventory = this.list.find(item => item.id === this.selectedIds[0])
if (selectedInventory) {
this.inventoryFormVisible = true
this.$nextTick(() => {
this.$refs.InventoryForm.init(selectedInventory.id)
})
}
},
// 编辑库存(从操作列)
editInventory(row) {
this.inventoryFormVisible = true
this.$nextTick(() => {
this.$refs.InventoryForm.init(row.id)
})
},
// 查看库存详情
viewInventoryInfo(row) {
this.inventoryInfoVisible = true
this.$nextTick(() => {
this.$refs.InventoryInfoDialog.init(row.id)
})
},
// 使用记录管理
usageRecordHandle() {
this.usageRecordVisible = true
this.$nextTick(() => {
this.$refs.UsageRecordDialog.init()
})
},
// 查看使用记录
viewUsageRecords(row) {
this.usageRecordVisible = true
this.$nextTick(() => {
this.$refs.UsageRecordDialog.init(row.id, row.productName)
})
},
// 多选
handleSelectionChange(selection) {
this.selectedIds = selection.map(item => item.id)
},
// 格式化金额
formatMoney(value) {
if (value === null || value === undefined || value === '') {
return '0.00'
}
return Number(value).toFixed(2)
},
// 导出
exportData() {
this.$message.info('导出功能开发中...')
}
}
}
</script>
<style scoped>
.NCC-common-layout {
height: 100%;
}
.text-danger {
color: #f56c6c;
font-weight: bold;
}
</style>