list.vue 20 KB

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