list.vue 15 KB

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