list.vue 14 KB

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