list.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <a-card size="small" :bordered="false" class="inventoryWarningList-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="inventoryWarningList-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="inventoryWarningList-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="inventoryWarningList-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. <ProductBrand id="inventoryWarningList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-model-item label="产品分类">
  31. <ProductType id="inventoryWarningList-productType" placeholder="请选择产品分类" @change="changeProductType" v-model="productType"></ProductType>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24" v-if="isShowWarehouse">
  35. <a-form-item label="仓库">
  36. <warehouse
  37. v-model="queryParam.warehouseSn"
  38. isPermission
  39. id="inventoryWarningList-warehouseSn"
  40. placeholder="请选择仓库"
  41. />
  42. </a-form-item>
  43. </a-col>
  44. <a-col :md="6" :sm="24">
  45. <a-form-item label="预警提示">
  46. <v-select
  47. v-model="queryParam.stockState"
  48. ref="stockState"
  49. id="inventoryWarningList-stockState"
  50. code="STOCK_WARN_TIP"
  51. placeholder="请选择预警提示"
  52. allowClear
  53. ></v-select>
  54. </a-form-item>
  55. </a-col>
  56. </template>
  57. <a-col :md="6" :sm="24">
  58. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryWarningList-refresh">查询</a-button>
  59. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryWarningList-reset">重置</a-button>
  60. <a @click="advanced=!advanced" style="margin-left: 5px">
  61. {{ advanced ? '收起' : '展开' }}
  62. <a-icon :type="advanced ? 'up' : 'down'"/>
  63. </a>
  64. </a-col>
  65. </a-row>
  66. </a-form>
  67. </div>
  68. <!-- 操作按钮 -->
  69. <div v-if="$hasPermissions('B_inventoryWarning_refresh')" class="table-operator">
  70. <a-button class="button-error" type="primary" id="inventoryWarningList-update" :loading="loading" @click="handleupdate">批量更新</a-button>
  71. <span style="margin-left: 8px">
  72. <template v-if="rowSelectionInfo && rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
  73. </span>
  74. </div>
  75. <!-- 列表 -->
  76. <s-table
  77. class="sTable fixPagination"
  78. ref="table"
  79. :style="{ height: tableHeight+84.5+'px' }"
  80. size="small"
  81. :row-selection="$hasPermissions('B_inventoryWarning_refresh')?{ columnWidth: '4%' }:null"
  82. :rowKey="(record) => record.id"
  83. @rowSelection="rowSelectionFun"
  84. :columns="columns"
  85. :data="loadData"
  86. :scroll="{ y: tableHeight }"
  87. :defaultLoadData="false"
  88. bordered>
  89. <!-- 产品分类 -->
  90. <template slot="productType" slot-scope="text, record">
  91. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  92. <span v-else>--</span>
  93. </template>
  94. <!-- 实时库存数 -->
  95. <template slot="stockQty" slot-scope="text, record">
  96. {{ record.currentStockQty + record.freezeQty }}
  97. <span v-if="record.freezeQty">(冻结{{ record.freezeQty }})</span>
  98. </template>
  99. <!-- 预警提示 -->
  100. <template slot="stockState" slot-scope="text, record">
  101. <span v-if="record.stockStateDictValue" :class="[record.stockState=='OVERFLOW'?'yellow':record.stockState=='NOT_ENOUGH'?'red':record.stockState=='LACK'?'blue':record.stockState=='NORMAL'?'green':'']">{{ record.stockStateDictValue }}</span>
  102. <span v-else>--</span>
  103. </template>
  104. <!-- 在途数 -->
  105. <template slot="inTransit" slot-scope="text, record" >
  106. <div>
  107. <a-input-number
  108. size="small"
  109. id="inventoryWarningList-inTransit"
  110. v-model="record.inTransit"
  111. :precision="0"
  112. :min="0"
  113. :max="999999"
  114. style="width: 100%;"
  115. @change="numChange(record)"
  116. placeholder="请输入在途数" />
  117. </div>
  118. </template>
  119. <!-- 最大库存数 -->
  120. <template slot="upperLimit" slot-scope="text, record" >
  121. <div>
  122. <a-input-number
  123. size="small"
  124. id="inventoryWarningList-upperLimit"
  125. v-model="record.upperLimit"
  126. :precision="0"
  127. :min="0"
  128. :max="999999"
  129. style="width: 100%;"
  130. @change="numChange(record)"
  131. placeholder="请输入最大库存数" />
  132. </div>
  133. </template>
  134. <!-- 最小库存数 -->
  135. <template slot="lowerLimit" slot-scope="text, record" >
  136. <div>
  137. <a-input-number
  138. size="small"
  139. id="inventoryWarningList-lowerLimit"
  140. v-model="record.lowerLimit"
  141. :precision="0"
  142. :min="0"
  143. :max="record.upperLimit"
  144. style="width: 100%;"
  145. @change="numChange(record)"
  146. placeholder="请输入最小库存数" />
  147. </div>
  148. </template>
  149. <!-- 操作 -->
  150. <template slot="action" slot-scope="text, record">
  151. <a-button
  152. v-if="$hasPermissions('B_inventoryWarning_save')"
  153. type="link"
  154. size="small"
  155. class="button-info"
  156. @click="handleSave(record)"
  157. id="inventoryWarningList-add-btn">保存</a-button>
  158. <span v-else>--</span>
  159. </template>
  160. </s-table>
  161. </a-spin>
  162. </a-card>
  163. </template>
  164. <script>
  165. import { commonMixin } from '@/utils/mixin'
  166. import { STable, VSelect } from '@/components'
  167. import { stockWarnList, stockWarnSaveBatch } from '@/api/stock'
  168. import ProductType from '@/views/common/productType.js'
  169. import ProductBrand from '@/views/common/productBrand.js'
  170. import warehouse from '@/views/common/chooseWarehouse.js'
  171. export default {
  172. name: 'InventoryWarningList',
  173. mixins: [commonMixin],
  174. components: { STable, VSelect, ProductBrand, ProductType, warehouse },
  175. data () {
  176. return {
  177. spinning: false,
  178. advanced: true, // 高级搜索 展开/关闭
  179. tableHeight: 0,
  180. queryParam: { // 查询条件
  181. productCode: '',
  182. productName: '',
  183. productOrigCode: '', // 原厂编码
  184. productBrandSn: undefined,
  185. productTypeSn1: undefined,
  186. productTypeSn2: undefined,
  187. productTypeSn3: undefined,
  188. stockState: undefined,
  189. warehouseSn: undefined
  190. },
  191. exportLoading: false, // 导出loading
  192. disabled: false, // 查询、重置按钮是否可操作
  193. productType: [],
  194. // 加载数据方法 必须为 Promise 对象
  195. loadData: parameter => {
  196. this.disabled = true
  197. this.spinning = true
  198. return stockWarnList(Object.assign(parameter, this.queryParam)).then(res => {
  199. let data
  200. if (res.status == 200) {
  201. data = res.data
  202. const no = (data.pageNo - 1) * data.pageSize
  203. for (var i = 0; i < data.list.length; i++) {
  204. data.list[i].no = no + i + 1
  205. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  206. const ind = this.rowSelectionInfo.selectedRowKeys.indexOf(data.list[i].id)
  207. if (ind >= 0) {
  208. data.list[i].inTransit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].inTransit
  209. data.list[i].upperLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].upperLimit
  210. data.list[i].lowerLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].lowerLimit
  211. }
  212. }
  213. }
  214. this.disabled = false
  215. }
  216. this.spinning = false
  217. return data
  218. })
  219. },
  220. loading: false,
  221. rowSelectionInfo: null
  222. }
  223. },
  224. computed: {
  225. columns () {
  226. const _this = this
  227. const arr = [
  228. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  229. { title: '产品编码', dataIndex: 'productCode', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  230. { title: '产品名称', dataIndex: 'productName', width: '12%', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  231. { title: '原厂编码', dataIndex: 'productOrigCode', width: '7%', align: 'center', customRender: function (text) { return text || '--' } },
  232. { title: '产品品牌', dataIndex: 'productBrandName', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
  233. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '10%', align: 'center' },
  234. { title: '在途数(个)', scopedSlots: { customRender: 'inTransit' }, width: '6%', align: 'center' },
  235. { title: '总库存数(个)', dataIndex: 'currentStockQty', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  236. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: '6%', align: 'center' },
  237. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: '6%', align: 'center' },
  238. { title: '差异数量', dataIndex: 'differenceNum', width: '6%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  239. { title: '预警提示', scopedSlots: { customRender: 'stockState' }, width: '6%', align: 'center' },
  240. { title: '操作', scopedSlots: { customRender: 'action' }, width: '6%', align: 'center' }
  241. ]
  242. if(this.isShowWarehouse){
  243. arr.splice(6, 0, { title: '仓库', dataIndex: 'warehouseName', width: '8%', align: 'center', customRender: function (text) { return text || '--' } })
  244. }
  245. return arr
  246. }
  247. },
  248. methods: {
  249. // 表格选中项
  250. rowSelectionFun (obj) {
  251. this.rowSelectionInfo = obj || null
  252. },
  253. numChange (row) {
  254. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  255. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(row.id)
  256. if (ind >= 0) {
  257. this.rowSelectionInfo.selectedRows[ind].inTransit = row.inTransit
  258. this.rowSelectionInfo.selectedRows[ind].upperLimit = row.upperLimit
  259. this.rowSelectionInfo.selectedRows[ind].lowerLimit = row.lowerLimit
  260. }
  261. }
  262. },
  263. // 保存
  264. handleSave (row, isBatch) {
  265. const params = []
  266. if (isBatch) { // 批量更新
  267. const dataInd = []
  268. this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.map((item, index) => {
  269. if ((!item.inTransit && item.inTransit != 0) || (!item.upperLimit && item.upperLimit != 0) || (!item.lowerLimit && item.lowerLimit != 0)) {
  270. dataInd.push(item.no)
  271. }
  272. params.push({
  273. id: item.id,
  274. inTransit: item.inTransit,
  275. upperLimit: item.upperLimit,
  276. lowerLimit: item.lowerLimit
  277. })
  278. })
  279. if (dataInd.length > 0) {
  280. let str = ''
  281. dataInd.map(item => {
  282. str += item + '、'
  283. })
  284. str = str.substr(0, str.length - 1)
  285. this.$message.warning('请完善第' + str + '行数据后再提交')
  286. return
  287. }
  288. } else { // 单个保存
  289. if (!row.inTransit && row.inTransit != 0) {
  290. this.$message.warning('请输入在途数')
  291. return
  292. }
  293. if (!row.upperLimit && row.upperLimit != 0) {
  294. this.$message.warning('请输入最大库存数')
  295. return
  296. }
  297. if (!row.lowerLimit && row.lowerLimit != 0) {
  298. this.$message.warning('请输入最小库存数')
  299. return
  300. }
  301. params.push({
  302. id: row.id,
  303. inTransit: row.inTransit,
  304. upperLimit: row.upperLimit,
  305. lowerLimit: row.lowerLimit
  306. })
  307. }
  308. this.spinning = true
  309. stockWarnSaveBatch(params).then(res => {
  310. if (res.status == 200) {
  311. this.$message.success(res.message)
  312. this.$refs.table.refresh()
  313. this.$refs.table.clearSelected() // 清空表格选中项
  314. this.spinning = false
  315. } else {
  316. this.spinning = false
  317. }
  318. })
  319. },
  320. // 重置
  321. resetSearchForm () {
  322. this.queryParam.productCode = ''
  323. this.queryParam.productName = ''
  324. this.queryParam.productOrigCode = ''
  325. this.queryParam.productBrandSn = undefined
  326. this.queryParam.productTypeSn1 = undefined
  327. this.queryParam.productTypeSn2 = undefined
  328. this.queryParam.productTypeSn3 = undefined
  329. this.queryParam.stockState = undefined
  330. this.queryParam.warehouseSn = undefined
  331. this.productType = []
  332. this.$refs.table.refresh(true)
  333. },
  334. // 批量更新
  335. handleupdate () {
  336. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
  337. this.$message.warning('请在列表勾选后再进行批量操作!')
  338. return
  339. }
  340. const _this = this
  341. this.$confirm({
  342. title: '提示',
  343. content: '确定提交批量更新的内容吗?',
  344. centered: true,
  345. onOk () {
  346. _this.handleSave('', 'batch')
  347. }
  348. })
  349. },
  350. // 产品分类 change
  351. changeProductType (val, opt) {
  352. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  353. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  354. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  355. },
  356. pageInit () {
  357. const _this = this
  358. this.$nextTick(() => { // 页面渲染完成后的回调
  359. _this.setTableH()
  360. })
  361. this.rowSelectionInfo = null
  362. this.$refs.table.clearTable()
  363. },
  364. setTableH () {
  365. const tableSearchH = this.$refs.tableSearch.offsetHeight
  366. this.tableHeight = window.innerHeight - tableSearchH - 243
  367. }
  368. },
  369. watch: {
  370. advanced (newValue, oldValue) {
  371. const _this = this
  372. this.$nextTick(() => { // 页面渲染完成后的回调
  373. _this.setTableH()
  374. })
  375. },
  376. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  377. this.setTableH()
  378. }
  379. },
  380. mounted () {
  381. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  382. this.pageInit()
  383. this.resetSearchForm()
  384. }
  385. },
  386. activated () {
  387. // 如果是新页签打开,则重置当前页面
  388. if (this.$store.state.app.isNewTab) {
  389. this.pageInit()
  390. this.resetSearchForm()
  391. }
  392. // 仅刷新列表,不重置页面
  393. if (this.$store.state.app.updateList) {
  394. this.pageInit()
  395. this.$refs.table.refresh()
  396. }
  397. },
  398. beforeRouteEnter (to, from, next) {
  399. next(vm => {})
  400. }
  401. }
  402. </script>
  403. <style lang="less">
  404. .inventoryWarningList-wrap{
  405. .green{
  406. color: #19be6b;
  407. }
  408. .red{
  409. color: #ed1c24;
  410. }
  411. .yellow{
  412. color: #ff9900;
  413. }
  414. .blue{
  415. color: #2db7f5;
  416. }
  417. }
  418. </style>