list.vue 13 KB

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