list.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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" :showDefault="false" :changeOnSelect="true" 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+68.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. <a-button v-if="record.dealerProduct.sysFlag==1&&record.dealerProduct.onlineFalg==1&&$hasPermissions('M_shoppingCart')" type="link" @click="addShopCar(record)">加入购物车</a-button>
  157. <span v-if="!$hasPermissions('B_inventoryInventoryQueryDetail') && !$hasPermissions('B_inventoryInventoryQueryStock')">--</span>
  158. </template>
  159. </s-table>
  160. </a-spin>
  161. <!-- 库存详情 -->
  162. <inventory-query-detail-modal v-drag :openModal="openModal" :nowData="nowData" @close="closeModal" />
  163. <!-- 设置采购数量 -->
  164. <set-purchase-qty ref="setPurchaseQty" :openModal="openPurchaseModal" @close="openPurchaseModal=false" v-drag></set-purchase-qty>
  165. </a-card>
  166. </template>
  167. <script>
  168. import { commonMixin } from '@/utils/mixin'
  169. import { stockList, stockCount, stockExport } from '@/api/stock'
  170. import { purchaseCartExistProduct } from '@/api/purchaseCart'
  171. import ProductType from '../../common/productType.js'
  172. import ProductBrand from '../../common/productBrand.js'
  173. import Warehouse from '@/views/common/warehouse.js'
  174. import { STable, VSelect } from '@/components'
  175. import inventoryQueryDetailModal from './detailModal.vue'
  176. import setPurchaseQty from './setPurchaseQty.vue'
  177. import { downloadExcel } from '@/libs/JGPrint.js'
  178. export default {
  179. name: 'InventoryQueryList',
  180. components: { STable, VSelect, inventoryQueryDetailModal, ProductType, ProductBrand, Warehouse, setPurchaseQty },
  181. mixins: [commonMixin],
  182. data () {
  183. return {
  184. spinning: false,
  185. advanced: true, // 高级搜索 展开/关闭
  186. tableHeight: 0,
  187. queryParam: { // 查询条件
  188. productCode: '', // 产品编码
  189. productName: '', // 产品名称
  190. productOrigCode: '', // 原厂编码
  191. productBrandSn: undefined, // 产品品牌
  192. productTypeSn1: '', // 产品分类1
  193. productTypeSn2: '', // 产品分类2
  194. productTypeSn3: '', // 产品分类3
  195. warehouse: [],
  196. warehouseSn: '',
  197. warehouseLocationSn: '',
  198. zeroQtyFlag: false, // 库存情况
  199. enableFlag: true, // 显示禁用产品
  200. minUnsalableDays: undefined, // 滞销天数最小值
  201. maxUnsalableDays: undefined, // 滞销天数最大值
  202. productSysFlag: undefined
  203. },
  204. productTypeSn: [],
  205. exportLoading: false, // 导出loading
  206. disabled: false, // 查询、重置按钮是否可操作
  207. zeroQtyData: [ // 库存情况
  208. { name: '库存数量为0', id: '1' },
  209. { name: '库存数量不为0', id: '0' }
  210. ],
  211. openPurchaseModal: false,
  212. // 加载数据方法 必须为 Promise 对象
  213. loadData: parameter => {
  214. console.log(parameter)
  215. // 查询条件有直销天数先校验滞销天数
  216. if (this.checkValueRange()) {
  217. this.disabled = true
  218. this.spinning = true
  219. // 排序
  220. if (parameter.sortField == 'currentStockQty') {
  221. parameter.sortField = 'currentStockQty'
  222. parameter.sortAlias = ''
  223. }
  224. if (parameter.sortField == 'currentStockCost') {
  225. parameter.sortField = 'currentStockCost'
  226. parameter.sortAlias = 'stock'
  227. }
  228. if (parameter.sortField == 'unsalableDays') {
  229. parameter.sortField = 'unsalableDays'
  230. parameter.sortAlias = ''
  231. }
  232. const params = Object.assign(parameter, this.queryParam)
  233. params.zeroQtyFlag = params.zeroQtyFlag ? '0' : ''
  234. params.enableFlag = params.enableFlag ? '' : '1'
  235. params.product = {
  236. sysFlag: params.productSysFlag || undefined
  237. }
  238. // 仓库仓位
  239. params.warehouseSn = params.warehouse[0]
  240. params.warehouseLocationSn = params.warehouse[1]
  241. return stockList(params).then(res => {
  242. let data
  243. if (res.status == 200) {
  244. data = res.data
  245. const no = (data.pageNo - 1) * data.pageSize
  246. for (var i = 0; i < data.list.length; i++) {
  247. data.list[i].no = no + i + 1
  248. }
  249. this.disabled = false
  250. // 总计
  251. this.getTotal(params)
  252. }
  253. this.spinning = false
  254. return data
  255. })
  256. } else {
  257. const _this = this
  258. this.disabled = true
  259. this.spinning = true
  260. return new Promise(function (resolve, reject) {
  261. const data = { list: [], count: 0, pageNo: 1, pageSize: 10 }
  262. _this.disabled = false
  263. _this.spinning = false
  264. resolve(data)
  265. })
  266. }
  267. },
  268. openModal: false, // 查看库存详情 弹框
  269. nowData: null,
  270. currentStock: null
  271. }
  272. },
  273. computed: {
  274. columns () {
  275. const _this = this
  276. const arr = [
  277. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  278. { title: '产品编码', dataIndex: 'productCode', width: '16%', align: 'center', customRender: function (text) { return text || '--' } },
  279. { title: '产品名称', dataIndex: 'productName', width: '16%', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } },
  280. { title: '原厂编码', dataIndex: 'productOrigCode', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  281. { title: '产品品牌', dataIndex: 'brandName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } },
  282. { title: '产品分类', scopedSlots: { customRender: 'productTypeName' }, width: '13%', align: 'center' },
  283. { title: '可用库存数量(个)', dataIndex: 'currentStockQty', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  284. // { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '8%', align: 'center', sorter: true, customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  285. { 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 },
  286. { title: <div><a-tooltip placement='top' title='注意:购物车仅限添加箭冠已上线产品。'><a-icon type="question-circle" /></a-tooltip>&nbsp;操作</div>, scopedSlots: { customRender: 'action' }, width: '16%', align: 'center' }
  287. ]
  288. if (this.$hasPermissions('M_ShowAllCost')) {
  289. arr.splice(7, 0, { title: '可用库存成本(¥)', dataIndex: 'currentStockCost', width: '8%', align: 'right', sorter: true, customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } })
  290. }
  291. return arr
  292. }
  293. },
  294. methods: {
  295. // 加入购物车
  296. addShopCar (row) {
  297. this.spinning = true
  298. purchaseCartExistProduct({
  299. productSn: row.productSn
  300. }).then(res => {
  301. if (res.status == 200) {
  302. if (res.data) {
  303. this.$message.info('此产品已添加到购物车!')
  304. } else {
  305. this.$refs.setPurchaseQty.setData(row)
  306. this.openPurchaseModal = true
  307. }
  308. }
  309. this.spinning = false
  310. })
  311. },
  312. // 校验滞销天数数值范围
  313. checkValueRange () {
  314. const isONull = this.queryParam.minUnsalableDays === null || this.queryParam.minUnsalableDays === undefined
  315. const isOEmpty = this.queryParam.minUnsalableDays === ''
  316. const isOZero = this.queryParam.minUnsalableDays === 0
  317. const isTNull = this.queryParam.maxUnsalableDays === null || this.queryParam.maxUnsalableDays === undefined
  318. const isTEmpty = this.queryParam.maxUnsalableDays === ''
  319. const isTZero = this.queryParam.maxUnsalableDays === 0
  320. // 第一个为空(可为null可为空字符)第二个不为空
  321. // 第一个不为空第二个为空(可为null可为空字符)
  322. // 第一个大于第二个
  323. if ((isONull || isOEmpty) && (this.queryParam.maxUnsalableDays || isTZero)) {
  324. this.$message.info('请输入正确的滞销天数查询范围!')
  325. return false
  326. }
  327. if ((this.queryParam.minUnsalableDays || isOZero) && (isTNull || isTEmpty)) {
  328. this.$message.info('请输入正确的滞销天数查询范围!')
  329. return false
  330. }
  331. if (this.queryParam.minUnsalableDays > this.queryParam.maxUnsalableDays) {
  332. this.$message.info('请输入正确的滞销天数查询范围!')
  333. return false
  334. }
  335. this.queryParam.minUnsalableDays = this.queryParam.minUnsalableDays > 999999999 ? 999999999 : this.queryParam.minUnsalableDays
  336. this.queryParam.maxUnsalableDays = this.queryParam.maxUnsalableDays > 999999999 ? 999999999 : this.queryParam.maxUnsalableDays
  337. return true
  338. },
  339. // 格式化滞销天数为几个月零几天
  340. num (val) {
  341. let days
  342. if (val != null && val != undefined) {
  343. if (val >= 30) {
  344. const a = Math.floor(val / 30)
  345. const b = val - a * 30
  346. if (b > 0) {
  347. days = a + '个月' + b + '天'
  348. } else {
  349. days = a + '个月'
  350. }
  351. } else {
  352. days = val + '天'
  353. }
  354. } else {
  355. days = '--'
  356. }
  357. return days
  358. },
  359. // 重置
  360. resetSearchForm () {
  361. this.queryParam.productBrandSn = undefined
  362. this.queryParam.productTypeSn1 = ''
  363. this.queryParam.productTypeSn2 = ''
  364. this.queryParam.productTypeSn3 = ''
  365. this.queryParam.productCode = ''
  366. this.queryParam.productOrigCode = ''
  367. this.queryParam.productName = ''
  368. this.queryParam.brandName = undefined
  369. this.queryParam.productTypeName = undefined
  370. this.queryParam.zeroQtyFlag = false
  371. this.queryParam.warehouse = []
  372. this.queryParam.warehouseSn = ''
  373. this.queryParam.warehouseLocationSn = ''
  374. this.$refs.warehouse.setDefaultVal()
  375. this.productTypeSn = []
  376. this.queryParam.minUnsalableDays = undefined // 滞销天数最小值
  377. this.queryParam.maxUnsalableDays = undefined // 滞销天数最大值
  378. this.queryParam.productSysFlag = undefined
  379. this.$refs.table.refresh(true)
  380. },
  381. // 合计
  382. getTotal (param) {
  383. stockCount(param).then(res => {
  384. if (res.status == 200 && res.data) {
  385. this.currentStock = res.data
  386. } else {
  387. this.currentStock = null
  388. }
  389. })
  390. },
  391. // 库存详情
  392. goDetail (row) {
  393. this.nowData = row
  394. this.openModal = true
  395. },
  396. // 关闭弹框
  397. closeModal () {
  398. this.nowData = null
  399. this.openModal = false
  400. },
  401. // 出入库明细
  402. goWarehouseDetail (row) {
  403. this.$router.push({ path: `/inventoryManagement/inventoryQuery/warehouseDetail/${row.productSn}` })
  404. },
  405. // 导出
  406. handleExport () {
  407. const _this = this
  408. const params = JSON.parse(JSON.stringify(this.queryParam))
  409. params.zeroQtyFlag = params.zeroQtyFlag ? '0' : ''
  410. params.enableFlag = params.enableFlag ? '' : '1'
  411. params.showCost = this.$hasPermissions('M_ShowAllCost') ? 1 : 0
  412. // 仓库仓位
  413. params.warehouseSn = params.warehouse[0]
  414. params.warehouseLocationSn = params.warehouse[1]
  415. this.exportLoading = true
  416. _this.spinning = true
  417. stockExport(params).then(res => {
  418. this.exportLoading = false
  419. _this.spinning = false
  420. if (res.type == 'application/json') {
  421. var reader = new FileReader()
  422. reader.addEventListener('loadend', function () {
  423. const obj = JSON.parse(reader.result)
  424. _this.$notification.error({
  425. message: '提示',
  426. description: obj.message
  427. })
  428. })
  429. reader.readAsText(res)
  430. } else {
  431. downloadExcel(res, '库存查询')
  432. }
  433. })
  434. },
  435. // 递归函数
  436. recursionFun (data) {
  437. if (data) {
  438. data.map((item, index) => {
  439. if (item.children && item.children.length == 0) {
  440. delete item.children
  441. } else {
  442. this.recursionFun(item.children)
  443. }
  444. })
  445. }
  446. },
  447. // 分类 changeType
  448. changeType (val, selectedOptions) {
  449. for (let i = 0; i < val.length; i++) {
  450. this.queryParam['productTypeSn' + (i + 1)] = val[i]
  451. }
  452. if (val.length == 0) {
  453. this.queryParam.productTypeSn1 = ''
  454. this.queryParam.productTypeSn2 = ''
  455. this.queryParam.productTypeSn3 = ''
  456. }
  457. },
  458. filterOption (input, option) {
  459. return (
  460. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  461. )
  462. },
  463. pageInit () {
  464. const _this = this
  465. this.$nextTick(() => { // 页面渲染完成后的回调
  466. _this.setTableH()
  467. })
  468. // 是否默认包括禁用产品
  469. this.queryParam.enableFlag = localStorage.getItem('productEnabledFlag-' + this.$store.state.user.info.orgId) != 'false'
  470. },
  471. setTableH () {
  472. const tableSearchH = this.$refs.tableSearch.offsetHeight
  473. this.tableHeight = window.innerHeight - tableSearchH - 216
  474. }
  475. },
  476. watch: {
  477. advanced (newValue, oldValue) {
  478. const _this = this
  479. this.$nextTick(() => { // 页面渲染完成后的回调
  480. _this.setTableH()
  481. })
  482. },
  483. 'queryParam.enableFlag' (newValue, oldValue) {
  484. localStorage.setItem('productEnabledFlag-' + this.$store.state.user.info.orgId, newValue)
  485. },
  486. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  487. this.setTableH()
  488. }
  489. },
  490. mounted () {
  491. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  492. this.pageInit()
  493. this.resetSearchForm()
  494. }
  495. },
  496. activated () {
  497. // 如果是新页签打开,则重置当前页面
  498. if (this.$store.state.app.isNewTab) {
  499. this.pageInit()
  500. this.resetSearchForm()
  501. }
  502. // 仅刷新列表,不重置页面
  503. if (this.$store.state.app.updateList) {
  504. this.pageInit()
  505. this.$refs.table.refresh()
  506. }
  507. },
  508. beforeRouteEnter (to, from, next) {
  509. next(vm => {})
  510. }
  511. }
  512. </script>