list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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="primary"
  70. class="button-warning"
  71. @click="handleExport"
  72. :disabled="disabled"
  73. :loading="exportLoading"
  74. id="inventoryWarningList-export">导出</a-button>
  75. <a @click="advanced=!advanced" style="margin-left: 8px">
  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 class="table-operator">
  85. <a-button 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. <a-table
  92. class="sTable"
  93. ref="table"
  94. size="default"
  95. :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  96. :rowKey="(record) => record.id"
  97. :columns="columns"
  98. :dataSource="loadData"
  99. :scroll="{ x: 2120, y: tableHeight }"
  100. :pagination="paginationProps"
  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="warnTip" slot-scope="text, record">
  114. <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>
  115. <span v-else>--</span>
  116. </template>
  117. <!-- 在途数 -->
  118. <template slot="inTransit" slot-scope="text, record" >
  119. <div>
  120. <a-input-number
  121. id="inventoryWarningList-inTransit"
  122. v-model="record.inTransit"
  123. :precision="0"
  124. :min="0"
  125. :max="999999"
  126. placeholder="请输入在途数" />
  127. </div>
  128. </template>
  129. <!-- 最大库存数 -->
  130. <template slot="upperLimit" slot-scope="text, record" >
  131. <div>
  132. <a-input-number
  133. id="inventoryWarningList-upperLimit"
  134. v-model="record.upperLimit"
  135. :precision="0"
  136. :min="0"
  137. :max="999999"
  138. placeholder="请输入最大库存数" />
  139. </div>
  140. </template>
  141. <!-- 最小库存数 -->
  142. <template slot="lowerLimit" slot-scope="text, record" >
  143. <div>
  144. <a-input-number
  145. id="inventoryWarningList-lowerLimit"
  146. v-model="record.lowerLimit"
  147. :precision="0"
  148. :min="0"
  149. :max="record.upperLimit"
  150. placeholder="请输入最小库存数" />
  151. </div>
  152. </template>
  153. <!-- 操作 -->
  154. <template slot="action" slot-scope="text, record">
  155. <a-button type="primary" size="small" class="button-info" @click="handleSave(record)" id="inventoryWarningList-add-btn">保存</a-button>
  156. </template>
  157. </a-table>
  158. </a-card>
  159. </template>
  160. <script>
  161. import moment from 'moment'
  162. import { STable, VSelect } from '@/components'
  163. import { stockWarnList, stockWarnSaveBatch } from '@/api/stockWarn'
  164. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  165. import { dealerProductTypeList } from '@/api/dealerProductType'
  166. export default {
  167. components: { STable, VSelect },
  168. data () {
  169. return {
  170. advanced: false, // 高级搜索 展开/关闭
  171. tableHeight: 0,
  172. queryParam: { // 查询条件
  173. productCode: '',
  174. productName: '',
  175. productOrigCode: '', // 原厂编码
  176. productBrandSn: undefined,
  177. productTypeSn1: undefined,
  178. productTypeSn2: undefined,
  179. productTypeSn3: undefined,
  180. warnTip: undefined
  181. },
  182. exportLoading: false, // 导出loading
  183. disabled: false, // 查询、重置按钮是否可操作
  184. productBrandList: [], // 产品品牌下拉数据
  185. productTypeList: [], // 产品类别下拉数据
  186. productType: [],
  187. columns: [
  188. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  189. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  190. { title: '产品名称', dataIndex: 'productName', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
  191. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  192. { title: '产品品牌', dataIndex: 'brandName', width: 200, align: 'center', customRender: function (text) { return text || '--' } },
  193. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 200, align: 'center' },
  194. { title: '实时库存数(个)', scopedSlots: { customRender: 'stockQty' }, width: 180, align: 'center' },
  195. { title: '在途数(个)', scopedSlots: { customRender: 'inTransit' }, width: 130, align: 'center' },
  196. { title: '总库存数(个)', dataIndex: 'totalStockQty', width: 130, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  197. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: 130, align: 'center' },
  198. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: 130, align: 'center' },
  199. { title: '差异数量', dataIndex: 'differenceNum', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  200. { title: '预警提示', scopedSlots: { customRender: 'warnTip' }, width: 100, align: 'center' },
  201. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  202. ],
  203. loadData: [],
  204. pageNo: 1, // 分页页码
  205. pageSize: 10, // 分页 每页多少条
  206. paginationProps: {
  207. showSizeChanger: true, // 是否可以改变 pageSize
  208. total: 0, // 分页总条数
  209. current: 1,
  210. onShowSizeChange: (current, pageSize) => this.changePageSize(current, pageSize),
  211. onChange: (current) => this.changePage(current)
  212. },
  213. selectedRowKeys: [],
  214. selectedRows: [],
  215. loading: false
  216. }
  217. },
  218. computed: {
  219. hasSelected () {
  220. return this.selectedRowKeys.length > 0
  221. }
  222. },
  223. methods: {
  224. // 分页 一页多少条change
  225. changePageSize (current, pageSize) {
  226. this.pageNo = current
  227. this.pageSize = pageSize
  228. this.pageInit()
  229. },
  230. // 分页 页码change
  231. changePage (current) {
  232. this.pageNo = current
  233. this.pageInit()
  234. },
  235. // 列表数据
  236. pageInit (pageNo) {
  237. if (this.tableHeight == 0) {
  238. this.tableHeight = window.innerHeight - 380
  239. }
  240. this.disabled = true
  241. this.pageNo = pageNo || this.pageNo
  242. const params = Object.assign({ pageNo: this.pageNo, pageSize: this.pageSize }, this.queryParam)
  243. stockWarnList(params).then(res => {
  244. if (res.status == 200) {
  245. const data = res.data
  246. this.paginationProps.total = Number(res.data.count) || 0
  247. this.paginationProps.current = this.pageNo
  248. const no = (data.pageNo - 1) * data.pageSize
  249. for (var i = 0; i < data.list.length; i++) {
  250. data.list[i].no = no + i + 1
  251. }
  252. this.loadData = data.list
  253. this.disabled = false
  254. } else {
  255. this.paginationProps.total = 0
  256. this.paginationProps.current = 1
  257. this.loadData = []
  258. }
  259. })
  260. },
  261. // 保存
  262. handleSave (row, isBatch) {
  263. const params = []
  264. if (isBatch) { // 批量更新
  265. const dataInd = []
  266. this.selectedRows.map((item, index) => {
  267. if ((!item.inTransit && item.inTransit != 0) || (!item.upperLimit && item.upperLimit != 0) || (!item.lowerLimit && item.lowerLimit != 0)) {
  268. dataInd.push(item.no)
  269. }
  270. params.push({
  271. id: item.id,
  272. inTransit: item.inTransit,
  273. upperLimit: item.upperLimit,
  274. lowerLimit: item.lowerLimit
  275. })
  276. })
  277. if (dataInd.length > 0) {
  278. let str = ''
  279. dataInd.map(item => {
  280. str += item + '、'
  281. })
  282. str = str.substr(0, str.length - 1)
  283. this.$message.warning('请完善第' + str + '行数据后再提交')
  284. return
  285. }
  286. } else { // 单个保存
  287. if (!row.inTransit && row.inTransit != 0) {
  288. this.$message.warning('请输入在途数')
  289. return
  290. }
  291. if (!row.upperLimit && row.upperLimit != 0) {
  292. this.$message.warning('请输入最大库存数')
  293. return
  294. }
  295. if (!row.lowerLimit && row.lowerLimit != 0) {
  296. this.$message.warning('请输入最小库存数')
  297. return
  298. }
  299. params.push({
  300. id: row.id,
  301. inTransit: row.inTransit,
  302. upperLimit: row.upperLimit,
  303. lowerLimit: row.lowerLimit
  304. })
  305. }
  306. stockWarnSaveBatch(params).then(res => {
  307. if (res.status == 200) {
  308. this.$message.success(res.message)
  309. this.pageInit()
  310. this.selectedRowKeys = []
  311. this.selectedRows = []
  312. }
  313. })
  314. },
  315. onSelectChange (selectedRowKeys, selectedRows) {
  316. console.log('selectedRowKeys changed: ', selectedRowKeys, selectedRows)
  317. this.selectedRowKeys = selectedRowKeys
  318. this.selectedRows = selectedRows
  319. },
  320. // 重置
  321. resetSearchForm () {
  322. this.queryParam.productCode = ''
  323. this.queryParam.productName = ''
  324. this.queryParam.productOrigCode = ''
  325. this.queryParam.productBrandSn = undefined
  326. this.queryParam.productTypeSn1 = undefined
  327. this.queryParam.productTypeSn2 = undefined
  328. this.queryParam.productTypeSn3 = undefined
  329. this.queryParam.warnTip = undefined
  330. this.pageNo = 1
  331. this.pageSize = 10
  332. this.paginationProps.total = 0
  333. this.paginationProps.current = 1
  334. this.pageInit(1)
  335. },
  336. // 批量更新
  337. handleupdate () {
  338. if (this.selectedRowKeys.length < 1) {
  339. this.$message.warning('请在列表勾选后再进行批量操作!')
  340. return
  341. }
  342. const _this = this
  343. this.$confirm({
  344. title: '提示',
  345. content: '确定提交批量更新的内容吗?',
  346. centered: true,
  347. onOk () {
  348. _this.handleSave('', 'batch')
  349. }
  350. })
  351. },
  352. // 产品分类 change
  353. changeProductType (val, opt) {
  354. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  355. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  356. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  357. },
  358. // 产品品牌 列表
  359. getProductBrand () {
  360. // sysFlag不传,此处应查询所有产品
  361. dealerProductBrandQuery({}).then(res => {
  362. if (res.status == 200) {
  363. this.productBrandList = res.data
  364. } else {
  365. this.productBrandList = []
  366. }
  367. })
  368. },
  369. // 产品分类 列表
  370. getProductType () {
  371. dealerProductTypeList({}).then(res => {
  372. if (res.status == 200) {
  373. this.productTypeList = res.data
  374. } else {
  375. this.productTypeList = []
  376. }
  377. })
  378. },
  379. filterOption (input, option) {
  380. return (
  381. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  382. )
  383. },
  384. // 导出
  385. handleExport () {
  386. const params = this.queryParam
  387. this.exportLoading = true
  388. // customerBundleExportDelay(params).then(res => {
  389. // this.exportLoading = false
  390. // this.download(res)
  391. // })
  392. },
  393. // 下载
  394. download (data) {
  395. if (!data) { return }
  396. const url = window.URL.createObjectURL(new Blob([data]))
  397. const link = document.createElement('a')
  398. link.style.display = 'none'
  399. link.href = url
  400. const a = moment().format('YYYYMMDDHHmmss')
  401. const fname = '库存预警' + a
  402. link.setAttribute('download', fname + '.xlsx')
  403. document.body.appendChild(link)
  404. link.click()
  405. }
  406. },
  407. beforeRouteEnter (to, from, next) {
  408. next(vm => {
  409. vm.pageInit(1)
  410. vm.getProductType()
  411. vm.getProductBrand()
  412. })
  413. }
  414. }
  415. </script>
  416. <style lang="less">
  417. .inventoryWarningList-wrap{
  418. .green{
  419. color: #19be6b;
  420. }
  421. .red{
  422. color: #ed1c24;
  423. }
  424. .yellow{
  425. color: #ff9900;
  426. }
  427. .blue{
  428. color: #2db7f5;
  429. }
  430. }
  431. </style>