list.vue 17 KB

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