list.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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="6" :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. <a-col :md="6" :sm="24">
  24. <a-form-model-item label="产品品牌">
  25. <ProductBrand id="inventoryQueryList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  26. </a-form-model-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24">
  29. <a-form-model-item label="产品分类">
  30. <ProductType id="inventoryQueryList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeType" v-model="productTypeSn"></ProductType>
  31. </a-form-model-item>
  32. </a-col>
  33. <a-col :md="6" :sm="24">
  34. <a-form-model-item label="仓库仓位">
  35. <Warehouse id="inventoryQueryList-warehouse" ref="warehouse" v-model="queryParam.warehouse"></Warehouse>
  36. </a-form-model-item>
  37. </a-col>
  38. <template v-if="advanced">
  39. <a-col :md="6" :sm="24">
  40. <a-form-model-item label="滞销天数">
  41. <a-input-group>
  42. <a-row>
  43. <a-col :span="11">
  44. <a-input-number
  45. id="shelfMonitoringList-minUnsalableDays"
  46. v-model="queryParam.minUnsalableDays"
  47. :precision="0"
  48. :min="0"
  49. :max="999999"
  50. placeholder="起始天数"
  51. style="width: 100%;display: inline-block;" />
  52. </a-col>
  53. <a-col :span="2"><span style="display: block;text-align: center;line-height: 32px;">至</span></a-col>
  54. <a-col :span="11">
  55. <a-input-number
  56. id="shelfMonitoringList-maxUnsalableDays"
  57. v-model="queryParam.maxUnsalableDays"
  58. :precision="0"
  59. :min="0"
  60. :max="999999"
  61. placeholder="截止天数"
  62. style="width: 100%;display: inline-block;" />
  63. </a-col>
  64. </a-row>
  65. </a-input-group>
  66. </a-form-model-item>
  67. </a-col>
  68. <a-col :md="6" :sm="24">
  69. <a-form-item label="产品来源">
  70. <a-select
  71. allowClear
  72. placeholder="请选择产品来源"
  73. v-model="queryParam.productSysFlag"
  74. >
  75. <a-select-option value="1">
  76. 箭冠
  77. </a-select-option>
  78. <a-select-option value="0">
  79. 自建
  80. </a-select-option>
  81. </a-select>
  82. </a-form-item>
  83. </a-col>
  84. </template>
  85. <a-col :md="12" :sm="24">
  86. <div style="margin-bottom: 10px;">
  87. <a-checkbox v-model="queryParam.zeroQtyFlag" id="inventoryQueryList-zeroQtyFlag">只查看有库存</a-checkbox>
  88. <a-checkbox v-model="queryParam.enableFlag" :checked="queryParam.enableFlag" id="inventoryQueryList-enableFlag">包括禁用产品</a-checkbox>
  89. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryQueryList-refresh">查询</a-button>
  90. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryQueryList-reset">重置</a-button>
  91. <a-button
  92. type="primary"
  93. v-if="$hasPermissions('B_inventoryInventoryQueryExport')"
  94. class="button-warning"
  95. @click="handleExport"
  96. :disabled="disabled"
  97. :loading="exportLoading"
  98. id="inventoryQueryList-export">导出</a-button>
  99. <a @click="advanced=!advanced" style="margin-left: 5px">
  100. {{ advanced ? '收起' : '展开' }}
  101. <a-icon :type="advanced ? 'up' : 'down'"/>
  102. </a>
  103. </div>
  104. </a-col>
  105. </a-row>
  106. </a-form>
  107. </div>
  108. <!-- 合计 -->
  109. <a-alert type="info" style="margin-bottom:10px">
  110. <div class="ftext" slot="message">
  111. 可用库存总数量:<strong>{{ currentStock&&(currentStock.totalCurrentStockQty || currentStock.totalCurrentStockQty==0) ? currentStock.totalCurrentStockQty : '--' }}个</strong>;
  112. <div style="display: inline-block;" v-if="$hasPermissions('M_ShowAllCost')">
  113. 可用库存总成本:<strong>{{ currentStock&&(currentStock.totalCurrentStockCost || currentStock.totalCurrentStockCost==0) ? toThousands(currentStock.totalCurrentStockCost) : '--' }}</strong>。
  114. </div>
  115. </div>
  116. </a-alert>
  117. <!-- 列表 -->
  118. <s-table
  119. class="sTable fixPagination"
  120. ref="table"
  121. :style="{ height: tableHeight+84.5+'px' }"
  122. size="small"
  123. :rowKey="(record) => record.id"
  124. :columns="columns"
  125. :data="loadData"
  126. :scroll="{ y: tableHeight }"
  127. :defaultLoadData="false"
  128. bordered>
  129. <!-- 产品分类 -->
  130. <template slot="productTypeName" slot-scope="text, record">
  131. <span v-if="record.productTypeName2">{{ record.productTypeName2 || '' }} ></span>
  132. <span v-if="record.productTypeName3">{{ record.productTypeName3 || '' }}</span>
  133. </template>
  134. <!-- 直销天数 -->
  135. <template slot="unsalableDays" slot-scope="text, record" >
  136. <span v-if="record.unsalableDays>=180&&record.unsalableDays<=360" style="color:#FF9900">{{ num(record.unsalableDays) }}</span>
  137. <span v-else-if="record.unsalableDays>360" style="color:#FF0000">{{ num(record.unsalableDays) }}</span>
  138. <span v-else >{{ num(record.unsalableDays) }}</span>
  139. </template>
  140. <!-- 操作 -->
  141. <template slot="action" slot-scope="text, record">
  142. <a-button
  143. size="small"
  144. type="link"
  145. v-if="$hasPermissions('B_inventoryInventoryQueryDetail')"
  146. class="button-success"
  147. @click="goDetail(record)"
  148. id="inventoryQueryList-detail-btn">库存详情</a-button>
  149. <a-button
  150. size="small"
  151. type="link"
  152. v-if="$hasPermissions('B_inventoryInventoryQueryStock')"
  153. class="button-primary"
  154. @click="goWarehouseDetail(record)"
  155. id="inventoryQueryList-warehouseDetail-btn">出入库明细</a-button>
  156. <span v-if="!$hasPermissions('B_inventoryInventoryQueryDetail') && !$hasPermissions('B_inventoryInventoryQueryStock')">--</span>
  157. </template>
  158. </s-table>
  159. </a-spin>
  160. <!-- 库存详情 -->
  161. <inventory-query-detail-modal :openModal="openModal" :nowData="nowData" @close="closeModal" />
  162. </a-card>
  163. </template>
  164. <script>
  165. import { commonMixin } from '@/utils/mixin'
  166. import { stockList, stockCount, stockExport } from '@/api/stock'
  167. import ProductType from '../../common/productType.js'
  168. import ProductBrand from '../../common/productBrand.js'
  169. import Warehouse from '@/views/common/warehouse.js'
  170. import { STable, VSelect } from '@/components'
  171. import inventoryQueryDetailModal from './detailModal.vue'
  172. import { downloadExcel } from '@/libs/JGPrint.js'
  173. export default {
  174. name: 'InventoryQueryList',
  175. components: { STable, VSelect, inventoryQueryDetailModal, ProductType, ProductBrand, Warehouse },
  176. mixins: [commonMixin],
  177. data () {
  178. return {
  179. spinning: false,
  180. advanced: true, // 高级搜索 展开/关闭
  181. tableHeight: 0,
  182. queryParam: { // 查询条件
  183. productCode: '', // 产品编码
  184. productName: '', // 产品名称
  185. productOrigCode: '', // 原厂编码
  186. productBrandSn: undefined, // 产品品牌
  187. productTypeSn1: '', // 产品分类1
  188. productTypeSn2: '', // 产品分类2
  189. productTypeSn3: '', // 产品分类3
  190. warehouse: undefined,
  191. zeroQtyFlag: false, // 库存情况
  192. enableFlag: true, // 显示禁用产品
  193. minUnsalableDays: undefined, // 滞销天数最小值
  194. maxUnsalableDays: undefined, // 滞销天数最大值
  195. productSysFlag: undefined
  196. },
  197. productTypeSn: [],
  198. exportLoading: false, // 导出loading
  199. disabled: false, // 查询、重置按钮是否可操作
  200. zeroQtyData: [ // 库存情况
  201. { name: '库存数量为0', id: '1' },
  202. { name: '库存数量不为0', id: '0' }
  203. ],
  204. // 加载数据方法 必须为 Promise 对象
  205. loadData: parameter => {
  206. console.log(parameter)
  207. // 查询条件有直销天数先校验滞销天数
  208. if (this.checkValueRange()) {
  209. this.disabled = true
  210. this.spinning = true
  211. // 排序
  212. if (parameter.sortField == 'currentStockQty') {
  213. parameter.sortField = 'currentStockQty'
  214. parameter.sortAlias = ''
  215. }
  216. if (parameter.sortField == 'currentStockCost') {
  217. parameter.sortField = 'currentStockCost'
  218. parameter.sortAlias = 'stock'
  219. }
  220. if (parameter.sortField == 'unsalableDays') {
  221. parameter.sortField = 'unsalableDays'
  222. parameter.sortAlias = ''
  223. }
  224. const params = Object.assign(parameter, this.queryParam)
  225. params.zeroQtyFlag = params.zeroQtyFlag ? '0' : ''
  226. params.enableFlag = params.enableFlag ? '' : '1'
  227. params.product = {
  228. sysFlag: params.productSysFlag || undefined
  229. }
  230. return stockList(params).then(res => {
  231. let data
  232. if (res.status == 200) {
  233. data = res.data
  234. const no = (data.pageNo - 1) * data.pageSize
  235. for (var i = 0; i < data.list.length; i++) {
  236. data.list[i].no = no + i + 1
  237. }
  238. this.disabled = false
  239. // 总计
  240. this.getTotal(params)
  241. }
  242. this.spinning = false
  243. return data
  244. })
  245. } else {
  246. const _this = this
  247. this.disabled = true
  248. this.spinning = true
  249. return new Promise(function (resolve, reject) {
  250. const data = { list: [], count: 0, pageNo: 1, pageSize: 10 }
  251. _this.disabled = false
  252. _this.spinning = false
  253. resolve(data)
  254. })
  255. }
  256. },
  257. openModal: false, // 查看库存详情 弹框
  258. nowData: null,
  259. currentStock: null
  260. }
  261. },
  262. computed: {
  263. columns () {
  264. const _this = this
  265. const arr = [
  266. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  267. { title: '产品编码', dataIndex: 'productCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  268. { title: '产品名称', dataIndex: 'productName', width: '16%', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } },
  269. { title: '原厂编码', dataIndex: 'productOrigCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  270. { title: '产品品牌', dataIndex: 'brandName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  271. { title: '产品分类', scopedSlots: { customRender: 'productTypeName' }, width: '13%', align: 'center' },
  272. { title: '可用库存数量(个)', dataIndex: 'currentStockQty', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  273. // { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  274. { title: <div><a-tooltip placement='top' title='1:产品距离最近一次销售的时间,30天算一个月 2:采购退货,调拨等不算销售,不用来计算滞销天数'><a-icon type="question-circle" /></a-tooltip>&nbsp;滞销天数</div>, width: '10%', align: 'center', dataIndex: 'unsalableDays', scopedSlots: { customRender: 'unsalableDays' }, sorter: true },
  275. { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
  276. ]
  277. if (this.$hasPermissions('M_ShowAllCost')) {
  278. arr.splice(7, 0, { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '8%', align: 'right', sorter: true, customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
  279. }
  280. return arr
  281. }
  282. },
  283. methods: {
  284. // 校验滞销天数数值范围
  285. checkValueRange () {
  286. const isONull = this.queryParam.minUnsalableDays === null || this.queryParam.minUnsalableDays === undefined
  287. const isOEmpty = this.queryParam.minUnsalableDays === ''
  288. const isOZero = this.queryParam.minUnsalableDays === 0
  289. const isTNull = this.queryParam.maxUnsalableDays === null || this.queryParam.maxUnsalableDays === undefined
  290. const isTEmpty = this.queryParam.maxUnsalableDays === ''
  291. const isTZero = this.queryParam.maxUnsalableDays === 0
  292. // 第一个为空(可为null可为空字符)第二个不为空
  293. // 第一个不为空第二个为空(可为null可为空字符)
  294. // 第一个大于第二个
  295. if ((isONull || isOEmpty) && (this.queryParam.maxUnsalableDays || isTZero)) {
  296. this.$message.info('请输入正确的滞销天数查询范围!')
  297. return false
  298. }
  299. if ((this.queryParam.minUnsalableDays || isOZero) && (isTNull || isTEmpty)) {
  300. this.$message.info('请输入正确的滞销天数查询范围!')
  301. return false
  302. }
  303. if (this.queryParam.minUnsalableDays > this.queryParam.maxUnsalableDays) {
  304. this.$message.info('请输入正确的滞销天数查询范围!')
  305. return false
  306. }
  307. this.queryParam.minUnsalableDays = this.queryParam.minUnsalableDays > 999999999 ? 999999999 : this.queryParam.minUnsalableDays
  308. this.queryParam.maxUnsalableDays = this.queryParam.maxUnsalableDays > 999999999 ? 999999999 : this.queryParam.maxUnsalableDays
  309. return true
  310. },
  311. // 格式化滞销天数为几个月零几天
  312. num (val) {
  313. let days
  314. if (val != null && val != undefined) {
  315. if (val >= 30) {
  316. const a = Math.floor(val / 30)
  317. const b = val - a * 30
  318. if (b > 0) {
  319. days = a + '个月' + b + '天'
  320. } else {
  321. days = a + '个月'
  322. }
  323. } else {
  324. days = val + '天'
  325. }
  326. } else {
  327. days = '--'
  328. }
  329. return days
  330. },
  331. // 重置
  332. resetSearchForm () {
  333. this.queryParam.productBrandSn = undefined
  334. this.queryParam.productTypeSn1 = ''
  335. this.queryParam.productTypeSn2 = ''
  336. this.queryParam.productTypeSn3 = ''
  337. this.queryParam.productCode = ''
  338. this.queryParam.productOrigCode = ''
  339. this.queryParam.productName = ''
  340. this.queryParam.brandName = undefined
  341. this.queryParam.productTypeName = undefined
  342. this.queryParam.zeroQtyFlag = false
  343. this.queryParam.warehouse = undefined
  344. this.$refs.warehouse.setDefaultVal()
  345. this.productTypeSn = []
  346. this.queryParam.minUnsalableDays = undefined // 滞销天数最小值
  347. this.queryParam.maxUnsalableDays = undefined // 滞销天数最大值
  348. this.queryParam.productSysFlag = undefined
  349. this.$refs.table.refresh(true)
  350. },
  351. // 合计
  352. getTotal (param) {
  353. stockCount(param).then(res => {
  354. if (res.status == 200 && res.data) {
  355. this.currentStock = res.data
  356. } else {
  357. this.currentStock = null
  358. }
  359. })
  360. },
  361. // 库存详情
  362. goDetail (row) {
  363. this.nowData = row
  364. this.openModal = true
  365. },
  366. // 关闭弹框
  367. closeModal () {
  368. this.nowData = null
  369. this.openModal = false
  370. },
  371. // 出入库明细
  372. goWarehouseDetail (row) {
  373. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  374. },
  375. // 导出
  376. handleExport () {
  377. const _this = this
  378. const params = JSON.parse(JSON.stringify(this.queryParam))
  379. params.zeroQtyFlag = params.zeroQtyFlag ? '0' : ''
  380. params.enableFlag = params.enableFlag ? '' : '1'
  381. params.showCost = this.$hasPermissions('M_ShowAllCost') ? 1 : 0
  382. this.exportLoading = true
  383. _this.spinning = true
  384. stockExport(params).then(res => {
  385. this.exportLoading = false
  386. _this.spinning = false
  387. if (res.type == 'application/json') {
  388. var reader = new FileReader()
  389. reader.addEventListener('loadend', function () {
  390. const obj = JSON.parse(reader.result)
  391. _this.$notification.error({
  392. message: '提示',
  393. description: obj.message
  394. })
  395. })
  396. reader.readAsText(res)
  397. } else {
  398. downloadExcel(res, '库存查询')
  399. }
  400. })
  401. },
  402. // 递归函数
  403. recursionFun (data) {
  404. if (data) {
  405. data.map((item, index) => {
  406. if (item.children && item.children.length == 0) {
  407. delete item.children
  408. } else {
  409. this.recursionFun(item.children)
  410. }
  411. })
  412. }
  413. },
  414. // 分类 changeType
  415. changeType (val, selectedOptions) {
  416. for (let i = 0; i < val.length; i++) {
  417. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  418. }
  419. if (val.length == 0) {
  420. this.queryParam.productTypeSn1 = ''
  421. this.queryParam.productTypeSn2 = ''
  422. this.queryParam.productTypeSn3 = ''
  423. }
  424. },
  425. filterOption (input, option) {
  426. return (
  427. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  428. )
  429. },
  430. pageInit () {
  431. const _this = this
  432. this.$nextTick(() => { // 页面渲染完成后的回调
  433. _this.setTableH()
  434. })
  435. // 是否默认包括禁用产品
  436. this.queryParam.enableFlag = localStorage.getItem('productEnabledFlag-' + this.$store.state.user.info.orgId) != 'false'
  437. },
  438. setTableH () {
  439. const tableSearchH = this.$refs.tableSearch.offsetHeight
  440. this.tableHeight = window.innerHeight - tableSearchH - 230
  441. }
  442. },
  443. watch: {
  444. advanced (newValue, oldValue) {
  445. const _this = this
  446. this.$nextTick(() => { // 页面渲染完成后的回调
  447. _this.setTableH()
  448. })
  449. },
  450. 'queryParam.enableFlag' (newValue, oldValue) {
  451. localStorage.setItem('productEnabledFlag-' + this.$store.state.user.info.orgId, newValue)
  452. },
  453. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  454. this.setTableH()
  455. }
  456. },
  457. mounted () {
  458. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  459. this.pageInit()
  460. this.resetSearchForm()
  461. }
  462. },
  463. activated () {
  464. // 如果是新页签打开,则重置当前页面
  465. if (this.$store.state.app.isNewTab) {
  466. this.pageInit()
  467. this.resetSearchForm()
  468. }
  469. // 仅刷新列表,不重置页面
  470. if (this.$store.state.app.updateList) {
  471. this.pageInit()
  472. this.$refs.table.refresh()
  473. }
  474. },
  475. beforeRouteEnter (to, from, next) {
  476. next(vm => {})
  477. }
  478. }
  479. </script>