list.vue 17 KB

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