list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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.totalCurrentStockQty || currentStock.totalCurrentStockQty==0) ? currentStock.totalCurrentStockQty : '--' }}</strong>;
  81. 现有库存总成本(¥):<strong>{{ currentStock&&(currentStock.totalCurrentStockCost || currentStock.totalCurrentStockCost==0) ? currentStock.totalCurrentStockCost : '--' }}</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: null
  213. }
  214. },
  215. methods: {
  216. // 重置
  217. resetSearchForm () {
  218. this.queryParam.productBrandSn = undefined
  219. this.queryParam.productTypeSn1 = ''
  220. this.queryParam.productTypeSn2 = ''
  221. this.queryParam.productTypeSn3 = ''
  222. this.queryParam.productCode = ''
  223. this.queryParam.productOrigCode = ''
  224. this.queryParam.productName = ''
  225. this.queryParam.brandName = undefined
  226. this.queryParam.productTypeName = undefined
  227. this.queryParam.zeroQtyFlag = undefined
  228. this.productTypeSn = []
  229. this.$refs.table.refresh(true)
  230. },
  231. // 合计
  232. getTotal (param) {
  233. stockCount(param).then(res => {
  234. if (res.status == 200 && res.data) {
  235. this.currentStock = res.data
  236. } else {
  237. this.currentStock = null
  238. }
  239. })
  240. },
  241. // 库存详情
  242. goDetail (row) {
  243. this.itemId = row.stockSn
  244. this.openModal = true
  245. },
  246. // 关闭弹框
  247. closeModal () {
  248. this.itemId = ''
  249. this.openModal = false
  250. },
  251. // 出入库明细
  252. goWarehouseDetail (row) {
  253. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  254. },
  255. // 导出
  256. handleExport () {
  257. const _this = this
  258. const params = this.queryParam
  259. this.exportLoading = true
  260. _this.spinning = true
  261. stockExport(params).then(res => {
  262. this.exportLoading = false
  263. _this.spinning = false
  264. if (res.type == 'application/json') {
  265. var reader = new FileReader()
  266. reader.addEventListener('loadend', function () {
  267. const obj = JSON.parse(reader.result)
  268. _this.$notification.error({
  269. message: '提示',
  270. description: obj.message
  271. })
  272. })
  273. reader.readAsText(res)
  274. } else {
  275. this.download(res)
  276. }
  277. })
  278. },
  279. download (data) {
  280. if (!data) { return }
  281. const url = window.URL.createObjectURL(new Blob([data]))
  282. const link = document.createElement('a')
  283. link.style.display = 'none'
  284. link.href = url
  285. const a = moment().format('YYYYMMDDHHmmss')
  286. const fname = '库存查询' + a
  287. link.setAttribute('download', fname + '.xlsx')
  288. document.body.appendChild(link)
  289. link.click()
  290. },
  291. getProductType () {
  292. dealerProductTypeList({}).then(res => {
  293. this.recursionFun(res.data)
  294. this.typeData = res.data
  295. })
  296. },
  297. // 递归函数
  298. recursionFun (data) {
  299. if (data) {
  300. data.map((item, index) => {
  301. if (item.children && item.children.length == 0) {
  302. delete item.children
  303. } else {
  304. this.recursionFun(item.children)
  305. }
  306. })
  307. }
  308. },
  309. // 分类 changeType
  310. changeType (val, selectedOptions) {
  311. for (let i = 0; i < val.length; i++) {
  312. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  313. }
  314. if (val.length == 0) {
  315. this.queryParam.productTypeSn1 = ''
  316. this.queryParam.productTypeSn2 = ''
  317. this.queryParam.productTypeSn3 = ''
  318. }
  319. },
  320. // 产品品牌 列表
  321. getProductBrand () {
  322. dealerProductBrandQuery({}).then(res => {
  323. if (res.status == 200) {
  324. this.brandData = res.data
  325. } else {
  326. this.brandData = []
  327. }
  328. })
  329. },
  330. filterOption (input, option) {
  331. return (
  332. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  333. )
  334. }
  335. }
  336. }
  337. </script>