list.vue 17 KB

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