list.vue 22 KB

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