list.vue 18 KB

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