list.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. <ProductBrand id="inventoryQueryList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-item>
  28. </a-form-item>
  29. </a-col>
  30. <a-col :md="6" :sm="24">
  31. <a-form-item label="产品分类">
  32. <a-cascader
  33. @change="changeProductType"
  34. expand-trigger="hover"
  35. change-on-select
  36. :options="productTypeList"
  37. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  38. id="inventoryQueryList-productType"
  39. placeholder="请选择产品分类"
  40. allowClear
  41. v-model="productType" />
  42. </a-form-item>
  43. </a-col>
  44. <a-col :md="6" :sm="24">
  45. <a-form-item label="库存情况">
  46. <a-checkbox v-model="queryParam.zeroQtyFlag" id="inventoryQueryList-zeroQtyFlag">只查看有库存</a-checkbox>
  47. </a-form-item>
  48. </a-col>
  49. </template>
  50. <a-col :md="7" :sm="24">
  51. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryQueryList-refresh">查询</a-button>
  52. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryQueryList-reset">重置</a-button>
  53. <a-button
  54. v-if="$hasPermissions('B_inventoryQuery_export')"
  55. type="primary"
  56. style="margin-left: 5px"
  57. class="button-warning"
  58. @click="openExcelModal=true"
  59. :disabled="disabled"
  60. :loading="exportLoading"
  61. id="inventoryQueryList-export">导出</a-button>
  62. <a @click="advanced=!advanced" style="margin-left: 5px">
  63. {{ advanced ? '收起' : '展开' }}
  64. <a-icon :type="advanced ? 'up' : 'down'"/>
  65. </a>
  66. </a-col>
  67. </a-row>
  68. </a-form>
  69. </div>
  70. <!-- 合计 -->
  71. <a-alert type="info" style="margin-bottom:10px">
  72. <div class="ftext" slot="message">
  73. 可用库存总数量(个):<strong>{{ (currentStock&&(currentStock.currentStockQty || currentStock.currentStockQty==0)) ? currentStock.currentStockQty : '--' }}</strong>;
  74. <span v-if="$hasPermissions('B_isShowCost')">可用库存总成本(¥):<strong>{{ (currentStock&&(currentStock.currentStockCost || currentStock.currentStockCost==0)) ? currentStock.currentStockCost : '--' }}</strong>。</span>
  75. </div>
  76. </a-alert>
  77. <!-- 列表 -->
  78. <s-table
  79. class="sTable fixPagination"
  80. ref="table"
  81. :style="{ height: tableHeight+84.5+'px' }"
  82. size="small"
  83. :rowKey="(record) => record.id"
  84. :columns="columns"
  85. :data="loadData"
  86. :scroll="{ y: tableHeight }"
  87. :defaultLoadData="false"
  88. bordered>
  89. <!-- 操作 -->
  90. <template slot="action" slot-scope="text, record">
  91. <a-button
  92. v-if="$hasPermissions('B_inventoryQuery_detail')"
  93. size="small"
  94. type="link"
  95. class="button-success"
  96. @click="goDetail(record)"
  97. id="inventoryQueryList-detail-btn">库存详情</a-button>
  98. <a-button
  99. v-if="$hasPermissions('B_inventoryQuery_rkDetail')"
  100. size="small"
  101. type="link"
  102. class="button-warning"
  103. @click="goWarehouseDetail(record)"
  104. id="inventoryQueryList-warehouseDetail-btn">出入库明细</a-button>
  105. <span v-if="!$hasPermissions('B_inventoryQuery_detail')&&!$hasPermissions('B_inventoryQuery_rkDetail')">--</span>
  106. </template>
  107. </s-table>
  108. </a-spin>
  109. <!-- 库存详情 -->
  110. <inventory-query-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  111. <!-- 导出Excel -->
  112. <export-excel-modal :openModal="openExcelModal" @ok="handleExcelOk" @close="openExcelModal=false" />
  113. </a-card>
  114. </template>
  115. <script>
  116. import moment from 'moment'
  117. import { STable, VSelect } from '@/components'
  118. import inventoryQueryDetailModal from './detailModal.vue'
  119. import exportExcelModal from './exportExcelModal.vue'
  120. import { productBrandQuery } from '@/api/productBrand'
  121. import { productTypeQuery } from '@/api/productType'
  122. import { hdExportExcel } from '@/libs/exportExcel'
  123. import ProductBrand from '@/views/common/productBrand.js'
  124. import { stockList, stockCount, stockExport } from '@/api/stock'
  125. export default {
  126. components: { STable, VSelect, inventoryQueryDetailModal, exportExcelModal, ProductBrand },
  127. data () {
  128. return {
  129. spinning: false,
  130. advanced: true, // 高级搜索 展开/关闭
  131. tableHeight: 0,
  132. queryParam: { // 查询条件
  133. productCode: '', // 产品编码
  134. productName: '', // 产品名称
  135. productOrigCode: '', // 原厂编码
  136. productBrandSn: undefined, // 产品品牌
  137. productTypeSn1: '', // 产品分类1
  138. productTypeSn2: '', // 产品分类2
  139. productTypeSn3: '', // 产品分类3
  140. zeroQtyFlag: false // 库存情况
  141. },
  142. productType: [],
  143. exportLoading: false, // 导出loading
  144. disabled: false, // 查询、重置按钮是否可操作
  145. productBrandList: [], // 品牌下拉数据
  146. productTypeList: [], // 分类下拉数据
  147. zeroQtyData: [ // 库存情况
  148. { name: '库存数量为0', id: '1' },
  149. { name: '库存数量不为0', id: '0' }
  150. ],
  151. // 加载数据方法 必须为 Promise 对象
  152. loadData: parameter => {
  153. this.disabled = true
  154. this.spinning = true
  155. // 排序
  156. if (parameter.sortField == 'currentStockQty') {
  157. parameter.sortField = 'qty'
  158. parameter.sortAlias = ''
  159. }
  160. if (parameter.sortField == 'currentStockCost') {
  161. parameter.sortField = 'currentStockCost'
  162. parameter.sortAlias = 'stock'
  163. }
  164. const params = Object.assign(parameter, this.queryParam)
  165. if (params.zeroQtyFlag) {
  166. params.zeroQtyFlag = '0'
  167. } else {
  168. params.zeroQtyFlag = ''
  169. }
  170. return stockList(params).then(res => {
  171. const data = res.data
  172. const no = (data.pageNo - 1) * data.pageSize
  173. for (var i = 0; i < data.list.length; i++) {
  174. data.list[i].no = no + i + 1
  175. }
  176. this.disabled = false
  177. this.spinning = false
  178. // 总计
  179. this.getTotal(params)
  180. // 产品分类
  181. if (this.productTypeList.length == 0) {
  182. this.getProductType()
  183. }
  184. // 产品品牌
  185. if (this.productBrandList.length == 0) {
  186. this.getProductBrand()
  187. }
  188. return data
  189. })
  190. },
  191. openModal: false, // 查看库存详情 弹框
  192. itemId: '', // 当前库存记录id
  193. currentStock: null,
  194. openExcelModal: false
  195. }
  196. },
  197. computed: {
  198. columns () {
  199. const arr = [
  200. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  201. { title: '产品编码', dataIndex: 'productCode', width: '9%', align: 'center', customRender: function (text) { return text || '--' } },
  202. { title: '产品名称', dataIndex: 'productName', width: '21%', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  203. { title: '最后入库时间', dataIndex: 'lastStockTime', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  204. { title: '单位', dataIndex: 'productUnit', width: '5%', align: 'center', customRender: function (text) { return text || '--' } },
  205. { title: '产品品牌', dataIndex: 'productBrandName', width: '14%', align: 'center', customRender: function (text) { return text || '--' } },
  206. { title: '可用库存数量', dataIndex: 'currentStockQty', width: '10%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  207. { title: '操作', scopedSlots: { customRender: 'action' }, width: '16%', align: 'center' }
  208. ]
  209. if (this.$hasPermissions('B_isShowCost')) {
  210. arr.splice(7, 0, { title: '可用库存成本', dataIndex: 'currentStockCost', width: '10%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  211. }
  212. return arr
  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.zeroQtyFlag = false
  226. this.productType = []
  227. this.$refs.table.refresh(true)
  228. },
  229. // 合计
  230. getTotal (param) {
  231. stockCount(param).then(res => {
  232. if (res.status == 200 && res.data) {
  233. this.currentStock = res.data
  234. } else {
  235. this.currentStock = null
  236. }
  237. })
  238. },
  239. // 库存详情
  240. goDetail (row) {
  241. this.itemId = row.stockSn
  242. this.openModal = true
  243. },
  244. // 关闭弹框
  245. closeModal () {
  246. this.itemId = ''
  247. this.openModal = false
  248. },
  249. // 出入库明细
  250. goWarehouseDetail (row) {
  251. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  252. },
  253. // 导出Excel
  254. handleExcelOk (exportType) {
  255. const _this = this
  256. const params = JSON.parse(JSON.stringify(this.queryParam))
  257. if (params.zeroQtyFlag) {
  258. params.zeroQtyFlag = '0'
  259. } else {
  260. params.zeroQtyFlag = ''
  261. }
  262. params.exportType = exportType
  263. this.exportLoading = true
  264. this.spinning = true
  265. hdExportExcel(stockExport, params, '库存查询', function () {
  266. _this.exportLoading = false
  267. _this.spinning = false
  268. })
  269. },
  270. // 产品分类 change
  271. changeProductType (val, opt) {
  272. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  273. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  274. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  275. },
  276. // 产品品牌 列表
  277. getProductBrand () {
  278. productBrandQuery({}).then(res => {
  279. if (res.status == 200) {
  280. this.productBrandList = res.data
  281. } else {
  282. this.productBrandList = []
  283. }
  284. })
  285. },
  286. // 产品分类 列表
  287. getProductType () {
  288. productTypeQuery({}).then(res => {
  289. if (res.status == 200) {
  290. this.productTypeList = res.data
  291. } else {
  292. this.productTypeList = []
  293. }
  294. })
  295. },
  296. pageInit () {
  297. const _this = this
  298. this.$nextTick(() => { // 页面渲染完成后的回调
  299. _this.setTableH()
  300. })
  301. },
  302. setTableH () {
  303. const tableSearchH = this.$refs.tableSearch.offsetHeight
  304. this.tableHeight = window.innerHeight - tableSearchH - 233
  305. }
  306. },
  307. watch: {
  308. advanced (newValue, oldValue) {
  309. const _this = this
  310. setTimeout(() => {
  311. _this.setTableH()
  312. }, 400)
  313. },
  314. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  315. this.setTableH()
  316. }
  317. },
  318. mounted () {
  319. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  320. this.pageInit()
  321. this.resetSearchForm()
  322. }
  323. },
  324. activated () {
  325. // 如果是新页签打开,则重置当前页面
  326. if (this.$store.state.app.isNewTab) {
  327. this.pageInit()
  328. this.resetSearchForm()
  329. }
  330. // 仅刷新列表,不重置页面
  331. if (this.$store.state.app.updateList) {
  332. this.pageInit()
  333. this.$refs.table.refresh()
  334. }
  335. },
  336. beforeRouteEnter (to, from, next) {
  337. next(vm => {})
  338. }
  339. }
  340. </script>