list.vue 14 KB

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