list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <a-card size="small" :bordered="false" class="inventoryQueryList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="产品编码">
  10. <a-input id="inventoryQueryList-productCode" v-model="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="原厂编码">
  15. <a-input id="inventoryQueryList-productOrigCode" v-model.trim="queryParam.productOrigCode" allowClear placeholder="请输入原厂编码"/>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="5" :sm="24">
  19. <a-form-item label="产品名称">
  20. <a-input id="inventoryQueryList-productName" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
  21. </a-form-item>
  22. </a-col>
  23. <template v-if="advanced">
  24. <a-col :md="6" :sm="24">
  25. <a-form-item label="产品品牌">
  26. <a-select
  27. placeholder="请选择产品品牌"
  28. id="inventoryQueryList-productBrandSn"
  29. allowClear
  30. v-model="queryParam.productBrandSn"
  31. :showSearch="true"
  32. option-filter-prop="children"
  33. :filter-option="filterOption">
  34. <a-select-option v-for="item in brandData" :key="item.brandSn" :value="item.brandSn">{{ item.brandName }}</a-select-option>
  35. </a-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24">
  39. <a-form-item label="产品分类">
  40. <a-cascader
  41. :options="typeData"
  42. expand-trigger="hover"
  43. :field-names="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  44. placeholder="请选择产品分类"
  45. allowClear
  46. v-model="productTypeSn"
  47. @change="changeType" />
  48. </a-form-item>
  49. </a-col>
  50. <a-col :md="6" :sm="24">
  51. <a-form-item label="库存情况">
  52. <a-select placeholder="请选择库存情况" id="inventoryQueryList-zeroQtyFlag" allowClear v-model="queryParam.zeroQtyFlag">
  53. <a-select-option v-for="item in zeroQtyData" :key="item.id" :value="item.id">{{ item.name }}</a-select-option>
  54. </a-select>
  55. </a-form-item>
  56. </a-col>
  57. </template>
  58. <a-col :md="7" :sm="24">
  59. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryQueryList-refresh">查询</a-button>
  60. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryQueryList-reset">重置</a-button>
  61. <a-button
  62. type="primary"
  63. v-if="$hasPermissions('B_inventoryInventoryQueryExport')"
  64. class="button-warning"
  65. @click="handleExport"
  66. :disabled="disabled"
  67. :loading="exportLoading"
  68. id="inventoryQueryList-export">导出</a-button>
  69. <a @click="advanced=!advanced" style="margin-left: 5px">
  70. {{ advanced ? '收起' : '展开' }}
  71. <a-icon :type="advanced ? 'up' : 'down'"/>
  72. </a>
  73. </a-col>
  74. </a-row>
  75. </a-form>
  76. </div>
  77. <!-- 合计 -->
  78. <a-alert type="info" showIcon style="margin-bottom:15px">
  79. <div class="ftext" slot="message">
  80. 现有库存总数量(个):<strong>{{ currentStock&&(currentStock.currentStockQty || currentStock.currentStockQty==0) ? currentStock.currentStockQty : '--' }}</strong>;
  81. 现有库存总成本(¥):<strong>{{ currentStock&&(currentStock.currentStockCost || currentStock.currentStockCost==0) ? currentStock.currentStockCost : '--' }}</strong>。
  82. </div>
  83. </a-alert>
  84. <!-- 列表 -->
  85. <s-table
  86. class="sTable"
  87. ref="table"
  88. size="default"
  89. :rowKey="(record) => record.id"
  90. :columns="columns"
  91. :data="loadData"
  92. :scroll="{ x: 1630, y: tableHeight }"
  93. bordered>
  94. <!-- 产品分类 -->
  95. <template slot="productTypeName" slot-scope="text, record">
  96. <span v-if="record.productTypeName2">{{ record.productTypeName2 || '' }} ></span>
  97. <span v-if="record.productTypeName3">{{ record.productTypeName3 || '' }}</span>
  98. </template>
  99. <!-- 现有库存数量 -->
  100. <template slot="currentStockQty" slot-scope="text, record">
  101. {{ (record.currentStockQty + record.freezeQty) || 0 }}
  102. <span v-if="Number(record.freezeQty)">(冻结{{ record.freezeQty }})</span>
  103. </template>
  104. <template slot="currentStockCost" slot-scope="text, record">
  105. {{ (Number(record.currentStockCost)*1000 + Number(record.freezeCost)*1000)/1000 || 0 }}
  106. </template>
  107. <!-- 操作 -->
  108. <template slot="action" slot-scope="text, record">
  109. <a-button
  110. size="small"
  111. type="link"
  112. v-if="$hasPermissions('B_inventoryInventoryQueryDetail')"
  113. class="button-success"
  114. @click="goDetail(record)"
  115. id="inventoryQueryList-detail-btn">库存详情</a-button>
  116. <a-button
  117. size="small"
  118. type="link"
  119. v-if="$hasPermissions('B_inventoryInventoryQueryStock')"
  120. class="button-warning"
  121. @click="goWarehouseDetail(record)"
  122. id="inventoryQueryList-warehouseDetail-btn">出入库明细</a-button>
  123. <span v-if="!$hasPermissions('B_inventoryInventoryQueryDetail') && !$hasPermissions('B_inventoryInventoryQueryStock')">--</span>
  124. </template>
  125. </s-table>
  126. </a-spin>
  127. <!-- 库存详情 -->
  128. <inventory-query-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  129. </a-card>
  130. </template>
  131. <script>
  132. import moment from 'moment'
  133. import { stockList, stockCount, stockExport } from '@/api/stock'
  134. import { dealerProductTypeList } from '@/api/dealerProductType'
  135. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  136. import { STable, VSelect } from '@/components'
  137. import inventoryQueryDetailModal from './detailModal.vue'
  138. export default {
  139. components: { STable, VSelect, inventoryQueryDetailModal },
  140. data () {
  141. return {
  142. spinning: false,
  143. advanced: false, // 高级搜索 展开/关闭
  144. tableHeight: 0,
  145. queryParam: { // 查询条件
  146. productCode: '', // 产品编码
  147. productName: '', // 产品名称
  148. productOrigCode: '', // 原厂编码
  149. productBrandSn: undefined, // 产品品牌
  150. productTypeSn1: '', // 产品分类1
  151. productTypeSn2: '', // 产品分类2
  152. productTypeSn3: '', // 产品分类3
  153. zeroQtyFlag: undefined // 库存数量是否为0
  154. },
  155. productTypeSn: [],
  156. exportLoading: false, // 导出loading
  157. disabled: false, // 查询、重置按钮是否可操作
  158. brandData: [], // 产品品牌下拉数据
  159. typeData: [], // 产品分类下拉数据
  160. zeroQtyData: [ // 库存情况
  161. { name: '库存数量为0', id: '1' },
  162. { name: '库存数量不为0', id: '0' }
  163. ],
  164. columns: [
  165. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  166. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  167. { title: '产品名称', dataIndex: 'productName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  168. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  169. { title: '产品品牌', dataIndex: 'brandName', width: 140, align: 'center', customRender: function (text) { return text || '--' } },
  170. { title: '产品分类', scopedSlots: { customRender: 'productTypeName' }, width: 240, align: 'center' },
  171. { title: '现有库存数量(个)', dataIndex: 'currentStockQty', scopedSlots: { customRender: 'currentStockQty' }, width: 165, align: 'center', sorter: true },
  172. { title: '现有库存成本(¥)', dataIndex: 'currentStockCost', scopedSlots: { customRender: 'currentStockCost' }, width: 165, align: 'center', sorter: true },
  173. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center', fixed: 'right' }
  174. ],
  175. // 加载数据方法 必须为 Promise 对象
  176. loadData: parameter => {
  177. this.disabled = true
  178. if (this.tableHeight == 0) {
  179. this.tableHeight = window.innerHeight - 370
  180. }
  181. // 排序
  182. if (parameter.sortField == 'currentStockQty') {
  183. parameter.sortField = 'qty'
  184. parameter.sortAlias = ''
  185. }
  186. if (parameter.sortField == 'currentStockCost') {
  187. parameter.sortField = 'currentStockCost'
  188. parameter.sortAlias = 'stock'
  189. }
  190. return stockList(Object.assign(parameter, this.queryParam)).then(res => {
  191. const data = res.data
  192. const no = (data.pageNo - 1) * data.pageSize
  193. for (var i = 0; i < data.list.length; i++) {
  194. data.list[i].no = no + i + 1
  195. }
  196. this.disabled = false
  197. // 总计
  198. this.getTotal(Object.assign(parameter, this.queryParam))
  199. // 产品分类
  200. if (this.typeData.length == 0) {
  201. this.getProductType()
  202. }
  203. // 产品品牌
  204. if (this.brandData.length == 0) {
  205. this.getProductBrand()
  206. }
  207. return data
  208. })
  209. },
  210. openModal: false, // 查看库存详情 弹框
  211. itemId: '', // 当前库存记录id
  212. currentStock: { // 合计信息
  213. currentStockQty: '',
  214. currentStockCost: ''
  215. }
  216. }
  217. },
  218. methods: {
  219. // 重置
  220. resetSearchForm () {
  221. this.queryParam.productBrandSn = undefined
  222. this.queryParam.productTypeSn1 = ''
  223. this.queryParam.productTypeSn2 = ''
  224. this.queryParam.productTypeSn3 = ''
  225. this.queryParam.productCode = ''
  226. this.queryParam.productOrigCode = ''
  227. this.queryParam.productName = ''
  228. this.queryParam.brandName = undefined
  229. this.queryParam.productTypeName = undefined
  230. this.queryParam.zeroQtyFlag = undefined
  231. this.productTypeSn = []
  232. this.$refs.table.refresh(true)
  233. },
  234. // 合计
  235. getTotal (param) {
  236. stockCount(param).then(res => {
  237. if (res.status == 200 && res.data) {
  238. this.currentStock = res.data
  239. } else {
  240. this.currentStock = { // 合计信息
  241. currentStockQty: '',
  242. currentStockCost: ''
  243. }
  244. }
  245. })
  246. },
  247. // 库存详情
  248. goDetail (row) {
  249. this.itemId = row.stockSn
  250. this.openModal = true
  251. },
  252. // 关闭弹框
  253. closeModal () {
  254. this.itemId = ''
  255. this.openModal = false
  256. },
  257. // 出入库明细
  258. goWarehouseDetail (row) {
  259. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  260. },
  261. // 导出
  262. handleExport () {
  263. const _this = this
  264. const params = this.queryParam
  265. this.exportLoading = true
  266. _this.spinning = true
  267. stockExport(params).then(res => {
  268. this.exportLoading = false
  269. _this.spinning = false
  270. if (res.type == 'application/json') {
  271. var reader = new FileReader()
  272. reader.addEventListener('loadend', function () {
  273. const obj = JSON.parse(reader.result)
  274. _this.$notification.error({
  275. message: '提示',
  276. description: obj.message
  277. })
  278. })
  279. reader.readAsText(res)
  280. } else {
  281. this.download(res)
  282. }
  283. })
  284. },
  285. download (data) {
  286. if (!data) { return }
  287. const url = window.URL.createObjectURL(new Blob([data]))
  288. const link = document.createElement('a')
  289. link.style.display = 'none'
  290. link.href = url
  291. const a = moment().format('YYYYMMDDHHmmss')
  292. const fname = '库存查询' + a
  293. link.setAttribute('download', fname + '.xlsx')
  294. document.body.appendChild(link)
  295. link.click()
  296. },
  297. getProductType () {
  298. dealerProductTypeList({}).then(res => {
  299. this.recursionFun(res.data)
  300. this.typeData = res.data
  301. })
  302. },
  303. // 递归函数
  304. recursionFun (data) {
  305. if (data) {
  306. data.map((item, index) => {
  307. if (item.children && item.children.length == 0) {
  308. delete item.children
  309. } else {
  310. this.recursionFun(item.children)
  311. }
  312. })
  313. }
  314. },
  315. // 分类 changeType
  316. changeType (val, selectedOptions) {
  317. for (let i = 0; i < val.length; i++) {
  318. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  319. }
  320. if (val.length == 0) {
  321. this.queryParam.productTypeSn1 = ''
  322. this.queryParam.productTypeSn2 = ''
  323. this.queryParam.productTypeSn3 = ''
  324. }
  325. },
  326. // 产品品牌 列表
  327. getProductBrand () {
  328. dealerProductBrandQuery({}).then(res => {
  329. if (res.status == 200) {
  330. this.brandData = res.data
  331. } else {
  332. this.brandData = []
  333. }
  334. })
  335. },
  336. filterOption (input, option) {
  337. return (
  338. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  339. )
  340. }
  341. }
  342. }
  343. </script>