list.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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-model-item label="产品品牌">
  26. <ProductBrand id="inventoryWarningList-productBrandSn" placeholder="请选择产品品牌" v-model="queryParam.productBrandSn"></ProductBrand>
  27. </a-form-model-item>
  28. </a-col>
  29. <a-col :md="6" :sm="24">
  30. <a-form-model-item label="产品分类">
  31. <ProductType id="inventoryWarningList-productType" placeholder="请选择产品分类" :isDealer="true" @change="changeProductType" v-model="productType"></ProductType>
  32. </a-form-model-item>
  33. </a-col>
  34. <a-col :md="6" :sm="24">
  35. <a-form-item label="预警提示">
  36. <v-select
  37. v-model="queryParam.stockState"
  38. ref="stockState"
  39. id="inventoryWarningList-stockState"
  40. code="STOCK_WARN_TIP"
  41. placeholder="请选择预警提示"
  42. allowClear
  43. ></v-select>
  44. </a-form-item>
  45. </a-col>
  46. </template>
  47. <a-col :md="6" :sm="24">
  48. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="inventoryWarningList-refresh">查询</a-button>
  49. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="inventoryWarningList-reset">重置</a-button>
  50. <a-button
  51. type="primary"
  52. style="margin-left: 5px"
  53. @click="handleExport"
  54. :disabled="disabled"
  55. :loading="exportLoading"
  56. class="button-warning"
  57. id="inventoryWarningList-export-btn">导出</a-button>
  58. <a @click="advanced=!advanced" style="margin-left: 5px">
  59. {{ advanced ? '收起' : '展开' }}
  60. <a-icon :type="advanced ? 'up' : 'down'"/>
  61. </a>
  62. </a-col>
  63. </a-row>
  64. </a-form>
  65. </div>
  66. <!-- 操作按钮 -->
  67. <div class="table-operator">
  68. <a-button type="primary" v-if="$hasPermissions('B_inventoryWarningBatchSave')" id="inventoryWarningList-update" @click="handleupdate">批量更新</a-button>
  69. <span style="margin-left: 5px" v-if="$hasPermissions('B_inventoryWarningBatchSave')">
  70. <template v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
  71. </span>
  72. </div>
  73. <!-- 列表 -->
  74. <s-table
  75. class="sTable fixPagination"
  76. ref="table"
  77. :style="{ height: tableHeight+84.5+'px' }"
  78. size="small"
  79. :rowKey="(record) => record.id"
  80. :row-selection="$hasPermissions('B_inventoryWarningBatchSave') ? { columnWidth: 40 } : null"
  81. @rowSelection="rowSelectionFun"
  82. :columns="columns"
  83. :data="loadData"
  84. :scroll="{ x: 1330, y: tableHeight }"
  85. :defaultLoadData="false"
  86. bordered>
  87. <!-- 产品分类 -->
  88. <template slot="productType" slot-scope="text, record">
  89. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  90. <span v-else>--</span>
  91. </template>
  92. <!-- 实时库存数 -->
  93. <template slot="stockQty" slot-scope="text, record">
  94. {{ record.currentStockQty + record.freezeQty }}
  95. <span v-if="record.freezeQty">(冻结{{ record.freezeQty }})</span>
  96. </template>
  97. <!-- 预警提示 -->
  98. <template slot="stockState" slot-scope="text, record">
  99. <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>
  100. <span v-else>--</span>
  101. </template>
  102. <!-- 在途数 -->
  103. <template slot="inTransit" slot-scope="text, record" >
  104. <div>
  105. <a-input-number
  106. id="inventoryWarningList-inTransit"
  107. size="small"
  108. v-model="record.inTransit"
  109. :precision="0"
  110. :min="0"
  111. :max="999999"
  112. style="width: 100%;"
  113. @change="numChange(record)"
  114. placeholder="请输入在途数" />
  115. </div>
  116. </template>
  117. <!-- 最大库存数 -->
  118. <template slot="upperLimit" slot-scope="text, record" >
  119. <div>
  120. <a-input-number
  121. id="inventoryWarningList-upperLimit"
  122. size="small"
  123. v-model="record.upperLimit"
  124. :precision="0"
  125. :min="0"
  126. :max="999999"
  127. style="width: 100%;"
  128. @change="numChange(record)"
  129. placeholder="请输入最大库存数" />
  130. </div>
  131. </template>
  132. <!-- 最小库存数 -->
  133. <template slot="lowerLimit" slot-scope="text, record" >
  134. <div>
  135. <a-input-number
  136. id="inventoryWarningList-lowerLimit"
  137. size="small"
  138. v-model="record.lowerLimit"
  139. :precision="0"
  140. :min="0"
  141. :max="record.upperLimit"
  142. style="width: 100%;"
  143. @change="numChange(record)"
  144. placeholder="请输入最小库存数" />
  145. </div>
  146. </template>
  147. <!-- 操作 -->
  148. <template slot="action" slot-scope="text, record">
  149. <a-button
  150. type="link"
  151. v-if="$hasPermissions('B_inventoryWarningSave')"
  152. size="small"
  153. class="button-primary"
  154. @click="handleSave(record)"
  155. id="inventoryWarningList-add-btn">保存</a-button>
  156. <span v-if="!$hasPermissions('B_inventoryWarningSave')">--</span>
  157. </template>
  158. </s-table>
  159. </a-spin>
  160. </a-card>
  161. </template>
  162. <script>
  163. import { commonMixin } from '@/utils/mixin'
  164. import { STable, VSelect } from '@/components'
  165. import { stockWarnList, stockWarnSaveBatch, stockWarnExport } from '@/api/stockWarn'
  166. import { downloadExcel } from '@/libs/JGPrint.js'
  167. import ProductType from '../../common/productType.js'
  168. import ProductBrand from '../../common/productBrand.js'
  169. export default {
  170. name: 'InventoryWarning',
  171. components: { STable, VSelect, ProductType, ProductBrand },
  172. mixins: [commonMixin],
  173. data () {
  174. return {
  175. spinning: false,
  176. advanced: true, // 高级搜索 展开/关闭
  177. tableHeight: 0,
  178. queryParam: { // 查询条件
  179. productCode: '',
  180. productName: '',
  181. productOrigCode: '', // 原厂编码
  182. productBrandSn: undefined,
  183. productTypeSn1: undefined,
  184. productTypeSn2: undefined,
  185. productTypeSn3: undefined,
  186. stockState: undefined
  187. },
  188. exportLoading: false, // 导出loading
  189. disabled: false, // 查询、重置按钮是否可操作
  190. productBrandList: [], // 产品品牌下拉数据
  191. productTypeList: [], // 产品类别下拉数据
  192. productType: [],
  193. columns: [
  194. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  195. { title: '产品编码', dataIndex: 'productCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  196. { title: '产品名称', dataIndex: 'productName', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  197. { title: '原厂编码', dataIndex: 'productOrigCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  198. { title: '产品品牌', dataIndex: 'brandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  199. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 120, align: 'center' },
  200. { title: '在途数(个)', scopedSlots: { customRender: 'inTransit' }, width: 80, align: 'center' },
  201. { title: '总库存数(个)', dataIndex: 'currentStockQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  202. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: 100, align: 'center' },
  203. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: 100, align: 'center' },
  204. { title: '差异数量', dataIndex: 'differenceNum', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  205. { title: '预警提示', scopedSlots: { customRender: 'stockState' }, width: 100, align: 'center' },
  206. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  207. ],
  208. // 加载数据方法 必须为 Promise 对象
  209. loadData: parameter => {
  210. this.disabled = true
  211. this.spinning = true
  212. return stockWarnList(Object.assign(parameter, this.queryParam)).then(res => {
  213. let data
  214. if (res.status == 200) {
  215. data = res.data
  216. const no = (data.pageNo - 1) * data.pageSize
  217. for (var i = 0; i < data.list.length; i++) {
  218. data.list[i].no = no + i + 1
  219. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  220. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(data.list[i].id)
  221. if (ind >= 0) {
  222. data.list[i].inTransit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].inTransit
  223. data.list[i].upperLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].upperLimit
  224. data.list[i].lowerLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].lowerLimit
  225. }
  226. }
  227. }
  228. this.disabled = false
  229. }
  230. this.spinning = false
  231. return data
  232. })
  233. },
  234. loading: false,
  235. rowSelectionInfo: null
  236. }
  237. },
  238. methods: {
  239. // 表格选中项
  240. rowSelectionFun (obj) {
  241. this.rowSelectionInfo = obj || null
  242. },
  243. numChange (row) {
  244. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  245. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(row.id)
  246. if (ind >= 0) {
  247. this.rowSelectionInfo.selectedRows[ind].inTransit = row.inTransit
  248. this.rowSelectionInfo.selectedRows[ind].upperLimit = row.upperLimit
  249. this.rowSelectionInfo.selectedRows[ind].lowerLimit = row.lowerLimit
  250. }
  251. }
  252. },
  253. // 导出
  254. handleExport () {
  255. const _this = this
  256. _this.exportLoading = true
  257. stockWarnExport(_this.queryParam).then(res => {
  258. downloadExcel(res, '库存预警')
  259. _this.exportLoading = false
  260. })
  261. },
  262. // 保存
  263. handleSave (row, isBatch) {
  264. const params = []
  265. if (isBatch) { // 批量更新
  266. const dataInd = []
  267. this.rowSelectionInfo && this.rowSelectionInfo.selectedRows.map((item, index) => {
  268. if ((!item.inTransit && item.inTransit != 0) || (!item.upperLimit && item.upperLimit != 0) || (!item.lowerLimit && item.lowerLimit != 0)) {
  269. dataInd.push(item.no)
  270. }
  271. params.push({
  272. id: item.id,
  273. inTransit: item.inTransit,
  274. upperLimit: item.upperLimit,
  275. lowerLimit: item.lowerLimit
  276. })
  277. })
  278. if (dataInd.length > 0) {
  279. let str = ''
  280. dataInd.map(item => {
  281. str += item + '、'
  282. })
  283. str = str.substr(0, str.length - 1)
  284. this.$message.warning('请完善第' + str + '行数据后再提交')
  285. return
  286. }
  287. } else { // 单个保存
  288. if (!row.inTransit && row.inTransit != 0) {
  289. this.$message.warning('请输入在途数')
  290. return
  291. }
  292. if (!row.upperLimit && row.upperLimit != 0) {
  293. this.$message.warning('请输入最大库存数')
  294. return
  295. }
  296. if (!row.lowerLimit && row.lowerLimit != 0) {
  297. this.$message.warning('请输入最小库存数')
  298. return
  299. }
  300. params.push({
  301. id: row.id,
  302. inTransit: row.inTransit,
  303. upperLimit: row.upperLimit,
  304. lowerLimit: row.lowerLimit
  305. })
  306. }
  307. this.spinning = true
  308. stockWarnSaveBatch(params).then(res => {
  309. if (res.status == 200) {
  310. this.$message.success(res.message)
  311. this.$refs.table.refresh()
  312. this.$refs.table.clearSelected() // 清空表格选中项
  313. this.spinning = false
  314. } else {
  315. this.spinning = false
  316. }
  317. })
  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.stockState = undefined
  329. this.productType = []
  330. this.$refs.table.refresh(true)
  331. },
  332. // 批量更新
  333. handleupdate () {
  334. if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.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. pageInit () {
  355. const _this = this
  356. this.$nextTick(() => { // 页面渲染完成后的回调
  357. _this.setTableH()
  358. })
  359. },
  360. setTableH () {
  361. const tableSearchH = this.$refs.tableSearch.offsetHeight
  362. this.tableHeight = window.innerHeight - tableSearchH - 235
  363. }
  364. },
  365. watch: {
  366. advanced (newValue, oldValue) {
  367. const _this = this
  368. this.$nextTick(() => { // 页面渲染完成后的回调
  369. _this.setTableH()
  370. })
  371. },
  372. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  373. this.setTableH()
  374. }
  375. },
  376. mounted () {
  377. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  378. this.pageInit()
  379. this.resetSearchForm()
  380. }
  381. },
  382. activated () {
  383. // 如果是新页签打开,则重置当前页面
  384. if (this.$store.state.app.isNewTab) {
  385. this.pageInit()
  386. this.resetSearchForm()
  387. }
  388. },
  389. beforeRouteEnter (to, from, next) {
  390. next(vm => {})
  391. }
  392. }
  393. </script>
  394. <style lang="less">
  395. .inventoryWarningList-wrap{
  396. .green{
  397. color: #19be6b;
  398. }
  399. .red{
  400. color: #ed1c24;
  401. }
  402. .yellow{
  403. color: #ff9900;
  404. }
  405. .blue{
  406. color: #2db7f5;
  407. }
  408. }
  409. </style>