list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. 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 { stockList, stockCount, stockExport } from '@/api/stock'
  126. import { dealerProductTypeList } from '@/api/dealerProductType'
  127. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  128. import { STable, VSelect } from '@/components'
  129. import inventoryQueryDetailModal from './detailModal.vue'
  130. import { downloadExcel } from '@/libs/JGPrint.js'
  131. export default {
  132. components: { STable, VSelect, inventoryQueryDetailModal },
  133. data () {
  134. return {
  135. spinning: false,
  136. advanced: true, // 高级搜索 展开/关闭
  137. tableHeight: 0,
  138. queryParam: { // 查询条件
  139. productCode: '', // 产品编码
  140. productName: '', // 产品名称
  141. productOrigCode: '', // 原厂编码
  142. productBrandSn: undefined, // 产品品牌
  143. productTypeSn1: '', // 产品分类1
  144. productTypeSn2: '', // 产品分类2
  145. productTypeSn3: '', // 产品分类3
  146. zeroQtyFlag: false // 库存情况
  147. },
  148. productTypeSn: [],
  149. exportLoading: false, // 导出loading
  150. disabled: false, // 查询、重置按钮是否可操作
  151. brandData: [], // 产品品牌下拉数据
  152. typeData: [], // 产品分类下拉数据
  153. zeroQtyData: [ // 库存情况
  154. { name: '库存数量为0', id: '1' },
  155. { name: '库存数量不为0', id: '0' }
  156. ],
  157. columns: [
  158. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  159. { title: '产品编码', dataIndex: 'productCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  160. { title: '产品名称', dataIndex: 'productName', width: '16%', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } },
  161. { title: '原厂编码', dataIndex: 'productOrigCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  162. { title: '产品品牌', dataIndex: 'brandName', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  163. { title: '产品分类', scopedSlots: { customRender: 'productTypeName' }, width: '13%', align: 'center' },
  164. { title: '可用库存数量(个)', dataIndex: 'currentStockQty', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  165. { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  166. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  167. ],
  168. // 加载数据方法 必须为 Promise 对象
  169. loadData: parameter => {
  170. this.disabled = true
  171. this.spinning = true
  172. // 排序
  173. if (parameter.sortField == 'currentStockQty') {
  174. parameter.sortField = 'currentStockQty'
  175. parameter.sortAlias = ''
  176. }
  177. if (parameter.sortField == 'currentStockCost') {
  178. parameter.sortField = 'currentStockCost'
  179. parameter.sortAlias = 'stock'
  180. }
  181. const params = Object.assign(parameter, this.queryParam)
  182. if (params.zeroQtyFlag) {
  183. params.zeroQtyFlag = '0'
  184. } else {
  185. params.zeroQtyFlag = ''
  186. }
  187. return stockList(params).then(res => {
  188. const data = res.data
  189. const no = (data.pageNo - 1) * data.pageSize
  190. for (var i = 0; i < data.list.length; i++) {
  191. data.list[i].no = no + i + 1
  192. }
  193. this.disabled = false
  194. this.spinning = false
  195. // 总计
  196. this.getTotal(params)
  197. // 产品分类
  198. if (this.typeData.length == 0) {
  199. this.getProductType()
  200. }
  201. // 产品品牌
  202. if (this.brandData.length == 0) {
  203. this.getProductBrand()
  204. }
  205. return data
  206. })
  207. },
  208. openModal: false, // 查看库存详情 弹框
  209. nowData: null,
  210. currentStock: null
  211. }
  212. },
  213. methods: {
  214. // 重置
  215. resetSearchForm () {
  216. this.queryParam.productBrandSn = undefined
  217. this.queryParam.productTypeSn1 = ''
  218. this.queryParam.productTypeSn2 = ''
  219. this.queryParam.productTypeSn3 = ''
  220. this.queryParam.productCode = ''
  221. this.queryParam.productOrigCode = ''
  222. this.queryParam.productName = ''
  223. this.queryParam.brandName = undefined
  224. this.queryParam.productTypeName = undefined
  225. this.queryParam.zeroQtyFlag = false
  226. this.productTypeSn = []
  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.nowData = row
  242. this.openModal = true
  243. },
  244. // 关闭弹框
  245. closeModal () {
  246. this.nowData = null
  247. this.openModal = false
  248. },
  249. // 出入库明细
  250. goWarehouseDetail (row) {
  251. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  252. },
  253. // 导出
  254. handleExport () {
  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. this.exportLoading = true
  263. _this.spinning = true
  264. stockExport(params).then(res => {
  265. this.exportLoading = false
  266. _this.spinning = false
  267. if (res.type == 'application/json') {
  268. var reader = new FileReader()
  269. reader.addEventListener('loadend', function () {
  270. const obj = JSON.parse(reader.result)
  271. _this.$notification.error({
  272. message: '提示',
  273. description: obj.message
  274. })
  275. })
  276. reader.readAsText(res)
  277. } else {
  278. downloadExcel(res, '库存查询')
  279. }
  280. })
  281. },
  282. getProductType () {
  283. dealerProductTypeList({}).then(res => {
  284. this.recursionFun(res.data)
  285. this.typeData = res.data
  286. })
  287. },
  288. // 递归函数
  289. recursionFun (data) {
  290. if (data) {
  291. data.map((item, index) => {
  292. if (item.children && item.children.length == 0) {
  293. delete item.children
  294. } else {
  295. this.recursionFun(item.children)
  296. }
  297. })
  298. }
  299. },
  300. // 分类 changeType
  301. changeType (val, selectedOptions) {
  302. for (let i = 0; i < val.length; i++) {
  303. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  304. }
  305. if (val.length == 0) {
  306. this.queryParam.productTypeSn1 = ''
  307. this.queryParam.productTypeSn2 = ''
  308. this.queryParam.productTypeSn3 = ''
  309. }
  310. },
  311. // 产品品牌 列表
  312. getProductBrand () {
  313. dealerProductBrandQuery({}).then(res => {
  314. if (res.status == 200) {
  315. this.brandData = res.data
  316. } else {
  317. this.brandData = []
  318. }
  319. })
  320. },
  321. filterOption (input, option) {
  322. return (
  323. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  324. )
  325. },
  326. pageInit () {
  327. const _this = this
  328. this.$nextTick(() => { // 页面渲染完成后的回调
  329. _this.setTableH()
  330. })
  331. },
  332. setTableH () {
  333. const tableSearchH = this.$refs.tableSearch.offsetHeight
  334. this.tableHeight = window.innerHeight - tableSearchH - 230
  335. }
  336. },
  337. watch: {
  338. advanced (newValue, oldValue) {
  339. const _this = this
  340. setTimeout(() => {
  341. _this.setTableH()
  342. }, 400)
  343. },
  344. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  345. this.setTableH()
  346. }
  347. },
  348. mounted () {
  349. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  350. this.pageInit()
  351. this.resetSearchForm()
  352. }
  353. },
  354. activated () {
  355. // 如果是新页签打开,则重置当前页面
  356. if (this.$store.state.app.isNewTab) {
  357. this.pageInit()
  358. this.resetSearchForm()
  359. }
  360. // 仅刷新列表,不重置页面
  361. if (this.$store.state.app.updateList) {
  362. this.pageInit()
  363. this.$refs.table.refresh()
  364. }
  365. },
  366. beforeRouteEnter (to, from, next) {
  367. next(vm => {})
  368. }
  369. }
  370. </script>