list.vue 20 KB

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