list.vue 17 KB

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