list.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 @click="advanced=!advanced" style="margin-left: 5px">
  69. {{ advanced ? '收起' : '展开' }}
  70. <a-icon :type="advanced ? 'up' : 'down'"/>
  71. </a>
  72. </a-col>
  73. </a-row>
  74. </a-form>
  75. </div>
  76. <!-- 操作按钮 -->
  77. <div class="table-operator">
  78. <a-button type="primary" v-if="$hasPermissions('B_inventoryWarningBatchSave')" id="inventoryWarningList-update" @click="handleupdate">批量更新</a-button>
  79. <span style="margin-left: 5px" v-if="$hasPermissions('B_inventoryWarningBatchSave')">
  80. <template v-if="rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
  81. </span>
  82. </div>
  83. <!-- 列表 -->
  84. <s-table
  85. class="sTable fixPagination"
  86. ref="table"
  87. :style="{ height: tableHeight+84.5+'px' }"
  88. size="small"
  89. :rowKey="(record) => record.id"
  90. :row-selection="$hasPermissions('B_inventoryWarningBatchSave') ? { columnWidth: 40 } : null"
  91. @rowSelection="rowSelectionFun"
  92. :columns="columns"
  93. :data="loadData"
  94. :scroll="{ x: 1330, y: tableHeight }"
  95. :defaultLoadData="false"
  96. bordered>
  97. <!-- 产品分类 -->
  98. <template slot="productType" slot-scope="text, record">
  99. <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
  100. <span v-else>--</span>
  101. </template>
  102. <!-- 实时库存数 -->
  103. <template slot="stockQty" slot-scope="text, record">
  104. {{ record.currentStockQty + record.freezeQty }}
  105. <span v-if="record.freezeQty">(冻结{{ record.freezeQty }})</span>
  106. </template>
  107. <!-- 预警提示 -->
  108. <template slot="stockState" slot-scope="text, record">
  109. <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>
  110. <span v-else>--</span>
  111. </template>
  112. <!-- 在途数 -->
  113. <template slot="inTransit" slot-scope="text, record" >
  114. <div>
  115. <a-input-number
  116. id="inventoryWarningList-inTransit"
  117. size="small"
  118. v-model="record.inTransit"
  119. :precision="0"
  120. :min="0"
  121. :max="999999"
  122. style="width: 100%;"
  123. @change="numChange(record)"
  124. placeholder="请输入在途数" />
  125. </div>
  126. </template>
  127. <!-- 最大库存数 -->
  128. <template slot="upperLimit" slot-scope="text, record" >
  129. <div>
  130. <a-input-number
  131. id="inventoryWarningList-upperLimit"
  132. size="small"
  133. v-model="record.upperLimit"
  134. :precision="0"
  135. :min="0"
  136. :max="999999"
  137. style="width: 100%;"
  138. @change="numChange(record)"
  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. size="small"
  148. v-model="record.lowerLimit"
  149. :precision="0"
  150. :min="0"
  151. :max="record.upperLimit"
  152. style="width: 100%;"
  153. @change="numChange(record)"
  154. placeholder="请输入最小库存数" />
  155. </div>
  156. </template>
  157. <!-- 操作 -->
  158. <template slot="action" slot-scope="text, record">
  159. <a-button
  160. type="primary"
  161. v-if="$hasPermissions('B_inventoryWarningSave')"
  162. size="small"
  163. class="button-info"
  164. @click="handleSave(record)"
  165. id="inventoryWarningList-add-btn">保存</a-button>
  166. <span v-if="!$hasPermissions('B_inventoryWarningSave')">--</span>
  167. </template>
  168. </s-table>
  169. </a-spin>
  170. </a-card>
  171. </template>
  172. <script>
  173. import { commonMixin } from '@/utils/mixin'
  174. import { STable, VSelect } from '@/components'
  175. import { stockWarnList, stockWarnSaveBatch } from '@/api/stockWarn'
  176. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  177. import { dealerProductTypeList } from '@/api/dealerProductType'
  178. export default {
  179. name: 'InventoryWarning',
  180. components: { STable, VSelect },
  181. mixins: [commonMixin],
  182. data () {
  183. return {
  184. spinning: false,
  185. advanced: true, // 高级搜索 展开/关闭
  186. tableHeight: 0,
  187. queryParam: { // 查询条件
  188. productCode: '',
  189. productName: '',
  190. productOrigCode: '', // 原厂编码
  191. productBrandSn: undefined,
  192. productTypeSn1: undefined,
  193. productTypeSn2: undefined,
  194. productTypeSn3: undefined,
  195. stockState: undefined
  196. },
  197. exportLoading: false, // 导出loading
  198. disabled: false, // 查询、重置按钮是否可操作
  199. productBrandList: [], // 产品品牌下拉数据
  200. productTypeList: [], // 产品类别下拉数据
  201. productType: [],
  202. columns: [
  203. { title: '序号', dataIndex: 'no', width: 50, align: 'center' },
  204. { title: '产品编码', dataIndex: 'productCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  205. { title: '产品名称', dataIndex: 'productName', align: 'left', customRender: function (text) { return text || '--' }, ellipsis: true },
  206. { title: '原厂编码', dataIndex: 'productOrigCode', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  207. { title: '产品品牌', dataIndex: 'brandName', width: 120, align: 'center', customRender: function (text) { return text || '--' } },
  208. { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: 120, align: 'center' },
  209. { title: '在途数(个)', scopedSlots: { customRender: 'inTransit' }, width: 80, align: 'center' },
  210. { title: '总库存数(个)', dataIndex: 'currentStockQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  211. { title: '最大库存数(个)', scopedSlots: { customRender: 'upperLimit' }, width: 100, align: 'center' },
  212. { title: '最小库存数(个)', scopedSlots: { customRender: 'lowerLimit' }, width: 100, align: 'center' },
  213. { title: '差异数量', dataIndex: 'differenceNum', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  214. { title: '预警提示', scopedSlots: { customRender: 'stockState' }, width: 100, align: 'center' },
  215. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center', fixed: 'right' }
  216. ],
  217. // 加载数据方法 必须为 Promise 对象
  218. loadData: parameter => {
  219. this.disabled = true
  220. this.spinning = true
  221. return stockWarnList(Object.assign(parameter, this.queryParam)).then(res => {
  222. let data
  223. if (res.status == 200) {
  224. data = res.data
  225. const no = (data.pageNo - 1) * data.pageSize
  226. for (var i = 0; i < data.list.length; i++) {
  227. data.list[i].no = no + i + 1
  228. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  229. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(data.list[i].id)
  230. if (ind >= 0) {
  231. data.list[i].inTransit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].inTransit
  232. data.list[i].upperLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].upperLimit
  233. data.list[i].lowerLimit = this.rowSelectionInfo && this.rowSelectionInfo.selectedRows[ind].lowerLimit
  234. }
  235. }
  236. }
  237. this.disabled = false
  238. }
  239. this.spinning = false
  240. return data
  241. })
  242. },
  243. loading: false,
  244. rowSelectionInfo: null
  245. }
  246. },
  247. methods: {
  248. // 表格选中项
  249. rowSelectionFun (obj) {
  250. this.rowSelectionInfo = obj || null
  251. },
  252. numChange (row) {
  253. if (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys) { // 处理切换页码后 上页已选已输数据保留
  254. const ind = this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.indexOf(row.id)
  255. if (ind >= 0) {
  256. this.rowSelectionInfo.selectedRows[ind].inTransit = row.inTransit
  257. this.rowSelectionInfo.selectedRows[ind].upperLimit = row.upperLimit
  258. this.rowSelectionInfo.selectedRows[ind].lowerLimit = row.lowerLimit
  259. }
  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. // 产品品牌 列表
  355. getProductBrand () {
  356. // sysFlag不传,此处应查询所有产品
  357. dealerProductBrandQuery({}).then(res => {
  358. if (res.status == 200) {
  359. this.productBrandList = res.data
  360. } else {
  361. this.productBrandList = []
  362. }
  363. })
  364. },
  365. // 产品分类 列表
  366. getProductType () {
  367. dealerProductTypeList({}).then(res => {
  368. if (res.status == 200) {
  369. this.productTypeList = res.data
  370. } else {
  371. this.productTypeList = []
  372. }
  373. })
  374. },
  375. filterOption (input, option) {
  376. return (
  377. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  378. )
  379. },
  380. pageInit () {
  381. const _this = this
  382. this.$nextTick(() => { // 页面渲染完成后的回调
  383. _this.setTableH()
  384. })
  385. this.getProductType()
  386. this.getProductBrand()
  387. },
  388. setTableH () {
  389. const tableSearchH = this.$refs.tableSearch.offsetHeight
  390. this.tableHeight = window.innerHeight - tableSearchH - 235
  391. }
  392. },
  393. watch: {
  394. advanced (newValue, oldValue) {
  395. const _this = this
  396. this.$nextTick(() => { // 页面渲染完成后的回调
  397. _this.setTableH()
  398. })
  399. },
  400. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  401. this.setTableH()
  402. }
  403. },
  404. mounted () {
  405. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  406. this.pageInit()
  407. this.resetSearchForm()
  408. }
  409. },
  410. activated () {
  411. // 如果是新页签打开,则重置当前页面
  412. if (this.$store.state.app.isNewTab) {
  413. this.pageInit()
  414. this.resetSearchForm()
  415. }
  416. },
  417. beforeRouteEnter (to, from, next) {
  418. next(vm => {})
  419. }
  420. }
  421. </script>
  422. <style lang="less">
  423. .inventoryWarningList-wrap{
  424. .green{
  425. color: #19be6b;
  426. }
  427. .red{
  428. color: #ed1c24;
  429. }
  430. .yellow{
  431. color: #ff9900;
  432. }
  433. .blue{
  434. color: #2db7f5;
  435. }
  436. }
  437. </style>