list.vue 17 KB

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