list.vue 16 KB

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